Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 156e2cf3 authored by Jernej Virag's avatar Jernej Virag
Browse files

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
parent b6ca21a6
Loading
Loading
Loading
Loading
+24 −19
Original line number Diff line number Diff line
@@ -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,19 +67,18 @@ 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() {
    private final UserTracker.Callback mUserTrackerCallback = new UserTracker.Callback() {
        @Override
                public void onUserSwitched() {
        public void onUserChanged(int newUser, @NonNull Context userContext) {
            if (DEBUG) {
                        Log.d(TAG, "onUserSwitched: "
                                + ActivityManagerWrapper.getInstance().getCurrentUserId());
                Log.d(TAG, "onUserChanged: "
                        + newUser);
            }

                    // Update the nav mode for the current user
            updateCurrentInteractionMode(true /* notify */);
        }
    };
@@ -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);