Merge "Don't query user ID via main thread binder calls" into udc-qpr-dev am: 5318b30a7c

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23894146

Change-Id: Ibb8feb7083766efcb4a5535bb76e7587aadb89d3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot
2023-07-04 16:05:19 +00:00
committed by Automerger Merge Worker

View File

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