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

Commit 5318b30a authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

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

parents bd8a2265 156e2cf3
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);