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

Commit dfe2c5cc authored by Alex Stetson's avatar Alex Stetson Committed by Android (Google) Code Review
Browse files

Merge "Replace ACTION_USER_SWITCHED with UserTracker" into tm-qpr-dev

parents 6420742c bff66dca
Loading
Loading
Loading
Loading
+47 −53
Original line number Diff line number Diff line
@@ -17,24 +17,25 @@
package com.android.systemui;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.UserInfo;
import android.os.UserHandle;
import android.util.Log;

import androidx.annotation.NonNull;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.UiEventLogger;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.qs.QSUserSwitcherEvent;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.phone.SystemUIDialog;
import com.android.systemui.statusbar.policy.UserSwitcherController;
import com.android.systemui.util.settings.SecureSettings;

import java.util.concurrent.Executor;

import javax.inject.Inject;

import dagger.assisted.Assisted;
@@ -44,82 +45,75 @@ import dagger.assisted.AssistedInject;
/**
 * Manages notification when a guest session is resumed.
 */
public class GuestResumeSessionReceiver extends BroadcastReceiver {

    private static final String TAG = GuestResumeSessionReceiver.class.getSimpleName();
public class GuestResumeSessionReceiver {

    @VisibleForTesting
    public static final String SETTING_GUEST_HAS_LOGGED_IN = "systemui.guest_has_logged_in";

    @VisibleForTesting
    public AlertDialog mNewSessionDialog;
    private final Executor mMainExecutor;
    private final UserTracker mUserTracker;
    private final SecureSettings mSecureSettings;
    private final BroadcastDispatcher mBroadcastDispatcher;
    private final ResetSessionDialog.Factory mResetSessionDialogFactory;
    private final GuestSessionNotification mGuestSessionNotification;

    @Inject
    public GuestResumeSessionReceiver(
            UserTracker userTracker,
            SecureSettings secureSettings,
            BroadcastDispatcher broadcastDispatcher,
            GuestSessionNotification guestSessionNotification,
            ResetSessionDialog.Factory resetSessionDialogFactory) {
        mUserTracker = userTracker;
        mSecureSettings = secureSettings;
        mBroadcastDispatcher = broadcastDispatcher;
        mGuestSessionNotification = guestSessionNotification;
        mResetSessionDialogFactory = resetSessionDialogFactory;
    }

    /**
     * Register this receiver with the {@link BroadcastDispatcher}
     */
    public void register() {
        IntentFilter f = new IntentFilter(Intent.ACTION_USER_SWITCHED);
        mBroadcastDispatcher.registerReceiver(this, f, null /* handler */, UserHandle.SYSTEM);
    }

    @VisibleForTesting
    public final UserTracker.Callback mUserChangedCallback =
            new UserTracker.Callback() {
                @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();

        if (Intent.ACTION_USER_SWITCHED.equals(action)) {
                public void onUserChanged(int newUser, @NonNull Context userContext) {
                    cancelDialog();

            int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
            if (userId == UserHandle.USER_NULL) {
                Log.e(TAG, intent + " sent to " + TAG + " without EXTRA_USER_HANDLE");
                return;
            }

                    UserInfo currentUser = mUserTracker.getUserInfo();
                    if (!currentUser.isGuest()) {
                        return;
                    }

                    int guestLoginState = mSecureSettings.getIntForUser(
                    SETTING_GUEST_HAS_LOGGED_IN, 0, userId);
                            SETTING_GUEST_HAS_LOGGED_IN, 0, newUser);

                    if (guestLoginState == 0) {
                        // set 1 to indicate, 1st login
                        guestLoginState = 1;
                mSecureSettings.putIntForUser(SETTING_GUEST_HAS_LOGGED_IN, guestLoginState, userId);
                        mSecureSettings.putIntForUser(SETTING_GUEST_HAS_LOGGED_IN, guestLoginState,
                                newUser);
                    } else if (guestLoginState == 1) {
                        // set 2 to indicate, 2nd or later login
                        guestLoginState = 2;
                mSecureSettings.putIntForUser(SETTING_GUEST_HAS_LOGGED_IN, guestLoginState, userId);
                        mSecureSettings.putIntForUser(SETTING_GUEST_HAS_LOGGED_IN, guestLoginState,
                                newUser);
                    }

                    mGuestSessionNotification.createPersistentNotification(currentUser,
                            (guestLoginState <= 1));

                    if (guestLoginState > 1) {
                mNewSessionDialog = mResetSessionDialogFactory.create(userId);
                        mNewSessionDialog = mResetSessionDialogFactory.create(newUser);
                        mNewSessionDialog.show();
                    }
                }
            };

    @Inject
    public GuestResumeSessionReceiver(
            @Main Executor mainExecutor,
            UserTracker userTracker,
            SecureSettings secureSettings,
            GuestSessionNotification guestSessionNotification,
            ResetSessionDialog.Factory resetSessionDialogFactory) {
        mMainExecutor = mainExecutor;
        mUserTracker = userTracker;
        mSecureSettings = secureSettings;
        mGuestSessionNotification = guestSessionNotification;
        mResetSessionDialogFactory = resetSessionDialogFactory;
    }

    /**
     * Register this receiver with the {@link BroadcastDispatcher}
     */
    public void register() {
        mUserTracker.addCallback(mUserChangedCallback, mMainExecutor);
    }

    private void cancelDialog() {
+14 −25
Original line number Diff line number Diff line
@@ -26,10 +26,7 @@ import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_M
import android.annotation.IdRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
@@ -45,7 +42,6 @@ import android.hardware.graphics.common.DisplayDecorationSupport;
import android.os.Handler;
import android.os.SystemProperties;
import android.os.Trace;
import android.os.UserHandle;
import android.provider.Settings.Secure;
import android.util.DisplayUtils;
import android.util.Log;
@@ -68,7 +64,6 @@ import androidx.annotation.VisibleForTesting;

import com.android.internal.util.Preconditions;
import com.android.settingslib.Utils;
import com.android.systemui.broadcast.BroadcastDispatcher;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.decor.CutoutDecorProviderFactory;
@@ -128,7 +123,6 @@ public class ScreenDecorations implements CoreStartable, Tunable , Dumpable {
    private DisplayManager mDisplayManager;
    @VisibleForTesting
    protected boolean mIsRegistered;
    private final BroadcastDispatcher mBroadcastDispatcher;
    private final Context mContext;
    private final Executor mMainExecutor;
    private final TunerService mTunerService;
@@ -302,7 +296,6 @@ public class ScreenDecorations implements CoreStartable, Tunable , Dumpable {
    public ScreenDecorations(Context context,
            @Main Executor mainExecutor,
            SecureSettings secureSettings,
            BroadcastDispatcher broadcastDispatcher,
            TunerService tunerService,
            UserTracker userTracker,
            PrivacyDotViewController dotViewController,
@@ -312,7 +305,6 @@ public class ScreenDecorations implements CoreStartable, Tunable , Dumpable {
        mContext = context;
        mMainExecutor = mainExecutor;
        mSecureSettings = secureSettings;
        mBroadcastDispatcher = broadcastDispatcher;
        mTunerService = tunerService;
        mUserTracker = userTracker;
        mDotViewController = dotViewController;
@@ -598,10 +590,7 @@ public class ScreenDecorations implements CoreStartable, Tunable , Dumpable {
            mColorInversionSetting.onChange(false);
            updateColorInversion(mColorInversionSetting.getValue());

            IntentFilter filter = new IntentFilter();
            filter.addAction(Intent.ACTION_USER_SWITCHED);
            mBroadcastDispatcher.registerReceiver(mUserSwitchIntentReceiver, filter,
                    mExecutor, UserHandle.ALL);
            mUserTracker.addCallback(mUserChangedCallback, mExecutor);
            mIsRegistered = true;
        } else {
            mMainExecutor.execute(() -> mTunerService.removeTunable(this));
@@ -610,7 +599,7 @@ public class ScreenDecorations implements CoreStartable, Tunable , Dumpable {
                mColorInversionSetting.setListening(false);
            }

            mBroadcastDispatcher.unregisterReceiver(mUserSwitchIntentReceiver);
            mUserTracker.removeCallback(mUserChangedCallback);
            mIsRegistered = false;
        }
    }
@@ -897,15 +886,15 @@ public class ScreenDecorations implements CoreStartable, Tunable , Dumpable {
        }
    }

    private final BroadcastReceiver mUserSwitchIntentReceiver = new BroadcastReceiver() {
    private final UserTracker.Callback mUserChangedCallback =
            new UserTracker.Callback() {
                @Override
        public void onReceive(Context context, Intent intent) {
            int newUserId = mUserTracker.getUserId();
                public void onUserChanged(int newUser, @NonNull Context userContext) {
                    if (DEBUG) {
                Log.d(TAG, "UserSwitched newUserId=" + newUserId);
                        Log.d(TAG, "UserSwitched newUserId=" + newUser);
                    }
                    // update color inversion setting to the new user
            mColorInversionSetting.setUserId(newUserId);
                    mColorInversionSetting.setUserId(newUser);
                    updateColorInversion(mColorInversionSetting.getValue());
                }
            };
+11 −21
Original line number Diff line number Diff line
@@ -33,7 +33,6 @@ import android.util.Log
import com.android.internal.annotations.VisibleForTesting
import com.android.systemui.Dumpable
import com.android.systemui.backup.BackupHelper
import com.android.systemui.broadcast.BroadcastDispatcher
import com.android.systemui.controls.ControlStatus
import com.android.systemui.controls.ControlsServiceInfo
import com.android.systemui.controls.management.ControlsListingController
@@ -60,11 +59,10 @@ class ControlsControllerImpl @Inject constructor (
    private val uiController: ControlsUiController,
    private val bindingController: ControlsBindingController,
    private val listingController: ControlsListingController,
    private val broadcastDispatcher: BroadcastDispatcher,
    private val userFileManager: UserFileManager,
    private val userTracker: UserTracker,
    optionalWrapper: Optional<ControlsFavoritePersistenceWrapper>,
    dumpManager: DumpManager,
    userTracker: UserTracker
) : Dumpable, ControlsController {

    companion object {
@@ -121,18 +119,15 @@ class ControlsControllerImpl @Inject constructor (
        userChanging = false
    }

    private val userSwitchReceiver = object : BroadcastReceiver() {
        override fun onReceive(context: Context, intent: Intent) {
            if (intent.action == Intent.ACTION_USER_SWITCHED) {
    private val userTrackerCallback = object : UserTracker.Callback {
        override fun onUserChanged(newUser: Int, userContext: Context) {
            userChanging = true
                val newUser =
                        UserHandle.of(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, sendingUserId))
                if (currentUser == newUser) {
            val newUserHandle = UserHandle.of(newUser)
            if (currentUser == newUserHandle) {
                userChanging = false
                return
            }
                setValuesForUser(newUser)
            }
            setValuesForUser(newUserHandle)
        }
    }

@@ -234,12 +229,7 @@ class ControlsControllerImpl @Inject constructor (
        dumpManager.registerDumpable(javaClass.name, this)
        resetFavorites()
        userChanging = false
        broadcastDispatcher.registerReceiver(
                userSwitchReceiver,
                IntentFilter(Intent.ACTION_USER_SWITCHED),
                executor,
                UserHandle.ALL
        )
        userTracker.addCallback(userTrackerCallback, executor)
        context.registerReceiver(
            restoreFinishedReceiver,
            IntentFilter(BackupHelper.ACTION_RESTORE_FINISHED),
@@ -251,7 +241,7 @@ class ControlsControllerImpl @Inject constructor (
    }

    fun destroy() {
        broadcastDispatcher.unregisterReceiver(userSwitchReceiver)
        userTracker.removeCallback(userTrackerCallback)
        context.unregisterReceiver(restoreFinishedReceiver)
        listingController.removeCallback(listingCallback)
    }
+0 −10
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.systemui.dagger;
import android.content.BroadcastReceiver;

import com.android.systemui.GuestResetOrExitSessionReceiver;
import com.android.systemui.GuestResumeSessionReceiver;
import com.android.systemui.media.dialog.MediaOutputDialogReceiver;
import com.android.systemui.people.widget.PeopleSpaceWidgetPinnedReceiver;
import com.android.systemui.people.widget.PeopleSpaceWidgetProvider;
@@ -101,15 +100,6 @@ public abstract class DefaultBroadcastReceiverBinder {
    public abstract BroadcastReceiver bindPeopleSpaceWidgetProvider(
            PeopleSpaceWidgetProvider broadcastReceiver);

    /**
     *
     */
    @Binds
    @IntoMap
    @ClassKey(GuestResumeSessionReceiver.class)
    public abstract BroadcastReceiver bindGuestResumeSessionReceiver(
            GuestResumeSessionReceiver broadcastReceiver);

    /**
     *
     */
+15 −6
Original line number Diff line number Diff line
@@ -29,12 +29,13 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.display.AmbientDisplayConfiguration;
import android.os.SystemClock;
import android.os.UserHandle;
import android.text.format.Formatter;
import android.util.IndentingPrintWriter;
import android.util.Log;
import android.view.Display;

import androidx.annotation.NonNull;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.InstanceId;
import com.android.internal.logging.UiEvent;
@@ -100,6 +101,7 @@ public class DozeTriggers implements DozeMachine.Part {
    private final BroadcastDispatcher mBroadcastDispatcher;
    private final AuthController mAuthController;
    private final KeyguardStateController mKeyguardStateController;
    private final UserTracker mUserTracker;
    private final UiEventLogger mUiEventLogger;

    private long mNotificationPulseTime;
@@ -110,6 +112,14 @@ public class DozeTriggers implements DozeMachine.Part {
    private boolean mWantTouchScreenSensors;
    private boolean mWantSensors;

    private final UserTracker.Callback mUserChangedCallback =
            new UserTracker.Callback() {
                @Override
                public void onUserChanged(int newUser, @NonNull Context userContext) {
                    mDozeSensors.onUserSwitched();
                }
            };

    @VisibleForTesting
    public enum DozingUpdateUiEvent implements UiEventLogger.UiEventEnum {
        @UiEvent(doc = "Dozing updated due to notification.")
@@ -210,6 +220,7 @@ public class DozeTriggers implements DozeMachine.Part {
        mAuthController = authController;
        mUiEventLogger = uiEventLogger;
        mKeyguardStateController = keyguardStateController;
        mUserTracker = userTracker;
    }

    @Override
@@ -234,7 +245,7 @@ public class DozeTriggers implements DozeMachine.Part {
            return;
        }
        mNotificationPulseTime = SystemClock.elapsedRealtime();
        if (!mConfig.pulseOnNotificationEnabled(UserHandle.USER_CURRENT)) {
        if (!mConfig.pulseOnNotificationEnabled(mUserTracker.getUserId())) {
            runIfNotNull(onPulseSuppressedListener);
            mDozeLog.tracePulseDropped("pulseOnNotificationsDisabled");
            return;
@@ -490,12 +501,14 @@ public class DozeTriggers implements DozeMachine.Part {
        mBroadcastReceiver.register(mBroadcastDispatcher);
        mDockManager.addListener(mDockEventListener);
        mDozeHost.addCallback(mHostCallback);
        mUserTracker.addCallback(mUserChangedCallback, mContext.getMainExecutor());
    }

    private void unregisterCallbacks() {
        mBroadcastReceiver.unregister(mBroadcastDispatcher);
        mDozeHost.removeCallback(mHostCallback);
        mDockManager.removeListener(mDockEventListener);
        mUserTracker.removeCallback(mUserChangedCallback);
    }

    private void stopListeningToAllTriggers() {
@@ -620,9 +633,6 @@ public class DozeTriggers implements DozeMachine.Part {
                requestPulse(DozeLog.PULSE_REASON_INTENT, false, /* performedProxCheck */
                        null /* onPulseSuppressedListener */);
            }
            if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
                mDozeSensors.onUserSwitched();
            }
        }

        public void register(BroadcastDispatcher broadcastDispatcher) {
@@ -630,7 +640,6 @@ public class DozeTriggers implements DozeMachine.Part {
                return;
            }
            IntentFilter filter = new IntentFilter(PULSE_ACTION);
            filter.addAction(Intent.ACTION_USER_SWITCHED);
            broadcastDispatcher.registerReceiver(this, filter);
            mRegistered = true;
        }
Loading