summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2022-02-24 17:53:46 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2022-02-24 17:53:46 +0000
commit41c0e3f765be8163e550b9ec0eb0c0d1bcc8a73d (patch)
treee13911dfe0c59325abfb1d931f4ed017e59c1fca
parent757c9f21446094fb8dfd07de21f0c8ac688cbb1e (diff)
parent62105c711321adedaee041fbe4eb0a5480e285ff (diff)
Merge "FocusRequest token can be nullable" into tm-dev
-rw-r--r--libs/gui/android/gui/FocusRequest.aidl2
-rw-r--r--services/inputflinger/tests/FocusResolver_test.cpp24
2 files changed, 25 insertions, 1 deletions
diff --git a/libs/gui/android/gui/FocusRequest.aidl b/libs/gui/android/gui/FocusRequest.aidl
index 90186351c5..b13c60049c 100644
--- a/libs/gui/android/gui/FocusRequest.aidl
+++ b/libs/gui/android/gui/FocusRequest.aidl
@@ -21,7 +21,7 @@ parcelable FocusRequest {
/**
* Input channel token used to identify the window that should gain focus.
*/
- IBinder token;
+ @nullable IBinder token;
@utf8InCpp String windowName;
/**
* The token that the caller expects currently to be focused. If the
diff --git a/services/inputflinger/tests/FocusResolver_test.cpp b/services/inputflinger/tests/FocusResolver_test.cpp
index ffce9f68cc..91be4a30bf 100644
--- a/services/inputflinger/tests/FocusResolver_test.cpp
+++ b/services/inputflinger/tests/FocusResolver_test.cpp
@@ -84,6 +84,30 @@ TEST(FocusResolverTest, SetFocusedWindow) {
ASSERT_FALSE(changes);
}
+TEST(FocusResolverTest, RemoveFocusFromFocusedWindow) {
+ sp<IBinder> focusableWindowToken = new BBinder();
+ std::vector<sp<WindowInfoHandle>> windows;
+ windows.push_back(new FakeWindowHandle("Focusable", focusableWindowToken, true /* focusable */,
+ true /* visible */));
+
+ FocusRequest request;
+ request.displayId = 42;
+ request.token = focusableWindowToken;
+ FocusResolver focusResolver;
+ // Focusable window gets focus.
+ request.token = focusableWindowToken;
+ std::optional<FocusResolver::FocusChanges> changes =
+ focusResolver.setFocusedWindow(request, windows);
+ ASSERT_FOCUS_CHANGE(changes, nullptr, focusableWindowToken);
+
+ // Window token of a request is null, focus should be revoked.
+ request.token = NULL;
+ changes = focusResolver.setFocusedWindow(request, windows);
+ ASSERT_EQ(focusableWindowToken, changes->oldFocus);
+ ASSERT_EQ(nullptr, changes->newFocus);
+ ASSERT_FOCUS_CHANGE(changes, focusableWindowToken, nullptr);
+}
+
TEST(FocusResolverTest, SetFocusedMirroredWindow) {
sp<IBinder> focusableWindowToken = new BBinder();
sp<IBinder> invisibleWindowToken = new BBinder();