diff options
author | bkchoi <bkchoi@google.com> | 2022-02-14 23:00:08 -0800 |
---|---|---|
committer | bkchoi <bkchoi@google.com> | 2022-02-15 11:06:41 -0800 |
commit | 0addfd1e8488c33ebf16c194d28f2cf8a3e8260e (patch) | |
tree | f94e357b3715fe8e5c6cf420bd756b270ce798c9 | |
parent | d68e1f1645917fdd9b7ad29c2baf7757dbdb04da (diff) | |
download | Cluster-0addfd1e8488c33ebf16c194d28f2cf8a3e8260e.tar.gz |
Migrate ClusterHomeApplication to use CarUserManager#addListener with filter
Bug: 219099915
Test: $ adb shell cmd car_service disable-feature cluster_service
$ adb shell cmd car_service enable-feature cluster_home_service
$ adb shell stop && adb shell start
$ adb logcat ClusterHome *:s
Then compare the logs before and after the change and make sure
only the expected events are received.
Change-Id: Ic22cfdbe0de67f4bbf4df5ba3d66209df66a79ce
-rw-r--r-- | ClusterHomeSample/src/com/android/car/cluster/home/ClusterHomeApplication.java | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/ClusterHomeSample/src/com/android/car/cluster/home/ClusterHomeApplication.java b/ClusterHomeSample/src/com/android/car/cluster/home/ClusterHomeApplication.java index a1f5523..c85fa41 100644 --- a/ClusterHomeSample/src/com/android/car/cluster/home/ClusterHomeApplication.java +++ b/ClusterHomeSample/src/com/android/car/cluster/home/ClusterHomeApplication.java @@ -43,6 +43,7 @@ import android.car.input.CarInputManager; import android.car.input.CarInputManager.CarInputCaptureCallback; import android.car.user.CarUserManager; import android.car.user.CarUserManager.UserLifecycleListener; +import android.car.user.UserLifecycleEventFilter; import android.content.ComponentName; import android.content.Intent; import android.graphics.Rect; @@ -129,7 +130,12 @@ public final class ClusterHomeApplication extends Application { mHomeManager.reportState(mClusterState.uiType, UI_TYPE_CLUSTER_NONE, mUiAvailability); mHomeManager.registerClusterStateListener(getMainExecutor(), mClusterHomeCalback); - mUserManager.addListener(getMainExecutor(), mUserLifecycleListener); + // Using the filter, only listens to the current user starting or unlocked events. + UserLifecycleEventFilter filter = new UserLifecycleEventFilter.Builder() + .addUser(UserHandle.CURRENT) + .addEventType(USER_LIFECYCLE_EVENT_TYPE_STARTING) + .addEventType(USER_LIFECYCLE_EVENT_TYPE_UNLOCKED).build(); + mUserManager.addListener(getMainExecutor(), filter, mUserLifecycleListener); int r = mCarInputManager.requestInputEventCapture( DISPLAY_TYPE_INSTRUMENT_CLUSTER, @@ -259,9 +265,7 @@ public final class ClusterHomeApplication extends Application { private final UserLifecycleListener mUserLifecycleListener = (event) -> { if (DBG) Log.d(TAG, "UserLifecycleListener.onEvent: event=" + event); - if (event.getUserId() != ActivityManager.getCurrentUser()) { - return; - } + mUserLifeCycleEvent = event.getEventType(); if (mUserLifeCycleEvent == USER_LIFECYCLE_EVENT_TYPE_STARTING) { startClusterActivity(UI_TYPE_HOME); |