Don't query user ID via main thread binder calls

This removes constant binder calls for User ID on main thread from
NavigationModeController - cached value in UserTracker is used instead.

This also uses UserTracker for user change callback to ensure timing
consistency (previous approach uses the same signal as well).

Bug: 283808194
Test: since there's no automated tests, manually tested nav mode
      controller while switching user profiles on cheetah.
      Monitored both logcat and product behaviour to check that
      user ids still correctly change.
Change-Id: I89ad7711282a31286b1f7b9092098817bb0f2d01
This commit is contained in:
Jernej Virag
2023-07-04 14:35:42 +02:00
parent b6ca21a64d
commit 156e2cf3d4

View File

@@ -28,18 +28,21 @@ import android.content.res.ApkAssets;
import android.os.PatternMatcher;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.Trace;
import android.os.UserHandle;
import android.provider.Settings;
import android.provider.Settings.Secure;
import android.util.Log;
import androidx.annotation.NonNull;
import com.android.systemui.Dumpable;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.dagger.qualifiers.UiBackground;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -64,22 +67,21 @@ public class NavigationModeController implements Dumpable {
private Context mCurrentUserContext;
private final IOverlayManager mOverlayManager;
private final Executor mUiBgExecutor;
private final UserTracker mUserTracker;
private ArrayList<ModeChangedListener> mListeners = new ArrayList<>();
private final DeviceProvisionedController.DeviceProvisionedListener mDeviceProvisionedCallback =
new DeviceProvisionedController.DeviceProvisionedListener() {
@Override
public void onUserSwitched() {
if (DEBUG) {
Log.d(TAG, "onUserSwitched: "
+ ActivityManagerWrapper.getInstance().getCurrentUserId());
}
private final UserTracker.Callback mUserTrackerCallback = new UserTracker.Callback() {
@Override
public void onUserChanged(int newUser, @NonNull Context userContext) {
if (DEBUG) {
Log.d(TAG, "onUserChanged: "
+ newUser);
}
// Update the nav mode for the current user
updateCurrentInteractionMode(true /* notify */);
}
};
updateCurrentInteractionMode(true /* notify */);
}
};
// The primary user SysUI process doesn't get AppInfo changes from overlay package changes for
// the secondary user (b/158613864), so we need to update the interaction mode here as well
@@ -97,19 +99,20 @@ public class NavigationModeController implements Dumpable {
@Inject
public NavigationModeController(Context context,
DeviceProvisionedController deviceProvisionedController,
ConfigurationController configurationController,
UserTracker userTracker,
@Main Executor mainExecutor,
@UiBackground Executor uiBgExecutor,
DumpManager dumpManager) {
mContext = context;
mCurrentUserContext = context;
mUserTracker = userTracker;
mUserTracker.addCallback(mUserTrackerCallback, mainExecutor);
mOverlayManager = IOverlayManager.Stub.asInterface(
ServiceManager.getService(Context.OVERLAY_SERVICE));
mUiBgExecutor = uiBgExecutor;
dumpManager.registerDumpable(getClass().getSimpleName(), this);
deviceProvisionedController.addCallback(mDeviceProvisionedCallback);
IntentFilter overlayFilter = new IntentFilter(ACTION_OVERLAY_CHANGED);
overlayFilter.addDataScheme("package");
overlayFilter.addDataSchemeSpecificPart("android", PatternMatcher.PATTERN_LITERAL);
@@ -129,6 +132,7 @@ public class NavigationModeController implements Dumpable {
}
public void updateCurrentInteractionMode(boolean notify) {
Trace.beginSection("NMC#updateCurrentInteractionMode");
mCurrentUserContext = getCurrentUserContext();
int mode = getCurrentInteractionMode(mCurrentUserContext);
mUiBgExecutor.execute(() ->
@@ -144,6 +148,7 @@ public class NavigationModeController implements Dumpable {
mListeners.get(i).onNavigationModeChanged(mode);
}
}
Trace.endSection();
}
public int addListener(ModeChangedListener listener) {
@@ -171,7 +176,7 @@ public class NavigationModeController implements Dumpable {
}
public Context getCurrentUserContext() {
int userId = ActivityManagerWrapper.getInstance().getCurrentUserId();
int userId = mUserTracker.getUserId();
if (DEBUG) {
Log.d(TAG, "getCurrentUserContext: contextUser=" + mContext.getUserId()
+ " currentUser=" + userId);