Fix the issue that Cluster-showing when switching a user.
Bug: 144214625
Test: check if Cluster shouldn't show when creating a new user.
Change-Id: I084cb5754e59caf47f3d853547353da521ac586d
diff --git a/src/android/car/cluster/ClusterRenderingService.java b/src/android/car/cluster/ClusterRenderingService.java
index 2d2987b..8d0cafa 100644
--- a/src/android/car/cluster/ClusterRenderingService.java
+++ b/src/android/car/cluster/ClusterRenderingService.java
@@ -395,8 +395,7 @@
private class UserReceiver extends BroadcastReceiver {
void register(Context context) {
IntentFilter intentFilter = new IntentFilter(ACTION_USER_UNLOCKED);
- intentFilter.addAction(ACTION_USER_SWITCHED);
- context.registerReceiver(this, intentFilter);
+ context.registerReceiverAsUser(this, UserHandle.ALL, intentFilter, null, null);
}
void unregister(Context context) {
@@ -408,7 +407,11 @@
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Broadcast received: " + intent);
}
- mHandler.post(mLaunchMainActivity);
+ int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
+ if (userId == ActivityManager.getCurrentUser() &&
+ mInstrumentClusterHelperReady && mClusterDisplayId != INVALID_DISPLAY) {
+ mHandler.post(mLaunchMainActivity);
+ }
}
}
}