Merge "Replace ACTION_USER_SWITCHED with UserTracker" into tm-qpr-dev
This commit is contained in:
@@ -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,31 +45,66 @@ 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;
|
||||
|
||||
@VisibleForTesting
|
||||
public final UserTracker.Callback mUserChangedCallback =
|
||||
new UserTracker.Callback() {
|
||||
@Override
|
||||
public void onUserChanged(int newUser, @NonNull Context userContext) {
|
||||
cancelDialog();
|
||||
|
||||
UserInfo currentUser = mUserTracker.getUserInfo();
|
||||
if (!currentUser.isGuest()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int guestLoginState = mSecureSettings.getIntForUser(
|
||||
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,
|
||||
newUser);
|
||||
} else if (guestLoginState == 1) {
|
||||
// set 2 to indicate, 2nd or later login
|
||||
guestLoginState = 2;
|
||||
mSecureSettings.putIntForUser(SETTING_GUEST_HAS_LOGGED_IN, guestLoginState,
|
||||
newUser);
|
||||
}
|
||||
|
||||
mGuestSessionNotification.createPersistentNotification(currentUser,
|
||||
(guestLoginState <= 1));
|
||||
|
||||
if (guestLoginState > 1) {
|
||||
mNewSessionDialog = mResetSessionDialogFactory.create(newUser);
|
||||
mNewSessionDialog.show();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Inject
|
||||
public GuestResumeSessionReceiver(
|
||||
@Main Executor mainExecutor,
|
||||
UserTracker userTracker,
|
||||
SecureSettings secureSettings,
|
||||
BroadcastDispatcher broadcastDispatcher,
|
||||
GuestSessionNotification guestSessionNotification,
|
||||
ResetSessionDialog.Factory resetSessionDialogFactory) {
|
||||
mMainExecutor = mainExecutor;
|
||||
mUserTracker = userTracker;
|
||||
mSecureSettings = secureSettings;
|
||||
mBroadcastDispatcher = broadcastDispatcher;
|
||||
mGuestSessionNotification = guestSessionNotification;
|
||||
mResetSessionDialogFactory = resetSessionDialogFactory;
|
||||
}
|
||||
@@ -77,49 +113,7 @@ public class GuestResumeSessionReceiver extends BroadcastReceiver {
|
||||
* 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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
|
||||
if (Intent.ACTION_USER_SWITCHED.equals(action)) {
|
||||
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);
|
||||
|
||||
if (guestLoginState == 0) {
|
||||
// set 1 to indicate, 1st login
|
||||
guestLoginState = 1;
|
||||
mSecureSettings.putIntForUser(SETTING_GUEST_HAS_LOGGED_IN, guestLoginState, userId);
|
||||
} else if (guestLoginState == 1) {
|
||||
// set 2 to indicate, 2nd or later login
|
||||
guestLoginState = 2;
|
||||
mSecureSettings.putIntForUser(SETTING_GUEST_HAS_LOGGED_IN, guestLoginState, userId);
|
||||
}
|
||||
|
||||
mGuestSessionNotification.createPersistentNotification(currentUser,
|
||||
(guestLoginState <= 1));
|
||||
|
||||
if (guestLoginState > 1) {
|
||||
mNewSessionDialog = mResetSessionDialogFactory.create(userId);
|
||||
mNewSessionDialog.show();
|
||||
}
|
||||
}
|
||||
mUserTracker.addCallback(mUserChangedCallback, mMainExecutor);
|
||||
}
|
||||
|
||||
private void cancelDialog() {
|
||||
|
||||
@@ -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,18 +886,18 @@ public class ScreenDecorations implements CoreStartable, Tunable , Dumpable {
|
||||
}
|
||||
}
|
||||
|
||||
private final BroadcastReceiver mUserSwitchIntentReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
int newUserId = mUserTracker.getUserId();
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "UserSwitched newUserId=" + newUserId);
|
||||
}
|
||||
// update color inversion setting to the new user
|
||||
mColorInversionSetting.setUserId(newUserId);
|
||||
updateColorInversion(mColorInversionSetting.getValue());
|
||||
}
|
||||
};
|
||||
private final UserTracker.Callback mUserChangedCallback =
|
||||
new UserTracker.Callback() {
|
||||
@Override
|
||||
public void onUserChanged(int newUser, @NonNull Context userContext) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "UserSwitched newUserId=" + newUser);
|
||||
}
|
||||
// update color inversion setting to the new user
|
||||
mColorInversionSetting.setUserId(newUser);
|
||||
updateColorInversion(mColorInversionSetting.getValue());
|
||||
}
|
||||
};
|
||||
|
||||
private void updateColorInversion(int colorsInvertedValue) {
|
||||
mTintColor = colorsInvertedValue != 0 ? Color.WHITE : Color.BLACK;
|
||||
|
||||
@@ -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) {
|
||||
userChanging = true
|
||||
val newUser =
|
||||
UserHandle.of(intent.getIntExtra(Intent.EXTRA_USER_HANDLE, sendingUserId))
|
||||
if (currentUser == newUser) {
|
||||
userChanging = false
|
||||
return
|
||||
}
|
||||
setValuesForUser(newUser)
|
||||
private val userTrackerCallback = object : UserTracker.Callback {
|
||||
override fun onUserChanged(newUser: Int, userContext: Context) {
|
||||
userChanging = true
|
||||
val newUserHandle = UserHandle.of(newUser)
|
||||
if (currentUser == newUserHandle) {
|
||||
userChanging = false
|
||||
return
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -32,10 +32,12 @@ import com.android.systemui.Dumpable
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher
|
||||
import com.android.systemui.dagger.SysUISingleton
|
||||
import com.android.systemui.dagger.qualifiers.Background
|
||||
import com.android.systemui.dagger.qualifiers.Main
|
||||
import com.android.systemui.dump.DumpManager
|
||||
import com.android.systemui.media.controls.models.player.MediaData
|
||||
import com.android.systemui.media.controls.pipeline.MediaDataManager
|
||||
import com.android.systemui.media.controls.pipeline.RESUME_MEDIA_TIMEOUT
|
||||
import com.android.systemui.settings.UserTracker
|
||||
import com.android.systemui.tuner.TunerService
|
||||
import com.android.systemui.util.Utils
|
||||
import com.android.systemui.util.time.SystemClock
|
||||
@@ -55,6 +57,8 @@ class MediaResumeListener
|
||||
constructor(
|
||||
private val context: Context,
|
||||
private val broadcastDispatcher: BroadcastDispatcher,
|
||||
private val userTracker: UserTracker,
|
||||
@Main private val mainExecutor: Executor,
|
||||
@Background private val backgroundExecutor: Executor,
|
||||
private val tunerService: TunerService,
|
||||
private val mediaBrowserFactory: ResumeMediaBrowserFactory,
|
||||
@@ -77,18 +81,26 @@ constructor(
|
||||
private var currentUserId: Int = context.userId
|
||||
|
||||
@VisibleForTesting
|
||||
val userChangeReceiver =
|
||||
val userUnlockReceiver =
|
||||
object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (Intent.ACTION_USER_UNLOCKED == intent.action) {
|
||||
loadMediaResumptionControls()
|
||||
} else if (Intent.ACTION_USER_SWITCHED == intent.action) {
|
||||
currentUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1)
|
||||
loadSavedComponents()
|
||||
val userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1)
|
||||
if (userId == currentUserId) {
|
||||
loadMediaResumptionControls()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val userTrackerCallback =
|
||||
object : UserTracker.Callback {
|
||||
override fun onUserChanged(newUser: Int, userContext: Context) {
|
||||
currentUserId = newUser
|
||||
loadSavedComponents()
|
||||
}
|
||||
}
|
||||
|
||||
private val mediaBrowserCallback =
|
||||
object : ResumeMediaBrowser.Callback() {
|
||||
override fun addTrack(
|
||||
@@ -126,13 +138,13 @@ constructor(
|
||||
dumpManager.registerDumpable(TAG, this)
|
||||
val unlockFilter = IntentFilter()
|
||||
unlockFilter.addAction(Intent.ACTION_USER_UNLOCKED)
|
||||
unlockFilter.addAction(Intent.ACTION_USER_SWITCHED)
|
||||
broadcastDispatcher.registerReceiver(
|
||||
userChangeReceiver,
|
||||
userUnlockReceiver,
|
||||
unlockFilter,
|
||||
null,
|
||||
UserHandle.ALL
|
||||
)
|
||||
userTracker.addCallback(userTrackerCallback, mainExecutor)
|
||||
loadSavedComponents()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,13 +52,12 @@ import static com.android.systemui.statusbar.phone.CentralSurfaces.dumpBarTransi
|
||||
import static com.android.systemui.util.Utils.isGesturalModeOnDefaultDisplay;
|
||||
|
||||
import android.annotation.IdRes;
|
||||
import android.annotation.NonNull;
|
||||
import android.app.ActivityTaskManager;
|
||||
import android.app.IActivityTaskManager;
|
||||
import android.app.StatusBarManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Insets;
|
||||
import android.graphics.PixelFormat;
|
||||
@@ -114,7 +113,6 @@ import com.android.internal.view.AppearanceRegion;
|
||||
import com.android.systemui.Gefingerpoken;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.assist.AssistManager;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.dagger.qualifiers.Background;
|
||||
import com.android.systemui.dagger.qualifiers.DisplayId;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
@@ -132,6 +130,7 @@ import com.android.systemui.plugins.statusbar.StatusBarStateController;
|
||||
import com.android.systemui.recents.OverviewProxyService;
|
||||
import com.android.systemui.recents.Recents;
|
||||
import com.android.systemui.settings.UserContextProvider;
|
||||
import com.android.systemui.settings.UserTracker;
|
||||
import com.android.systemui.shade.ShadeController;
|
||||
import com.android.systemui.shared.navigationbar.RegionSamplingHelper;
|
||||
import com.android.systemui.shared.recents.utilities.Utilities;
|
||||
@@ -202,7 +201,7 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
|
||||
private final NotificationRemoteInputManager mNotificationRemoteInputManager;
|
||||
private final OverviewProxyService mOverviewProxyService;
|
||||
private final NavigationModeController mNavigationModeController;
|
||||
private final BroadcastDispatcher mBroadcastDispatcher;
|
||||
private final UserTracker mUserTracker;
|
||||
private final CommandQueue mCommandQueue;
|
||||
private final Optional<Pip> mPipOptional;
|
||||
private final Optional<Recents> mRecentsOptional;
|
||||
@@ -504,7 +503,7 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
|
||||
StatusBarStateController statusBarStateController,
|
||||
StatusBarKeyguardViewManager statusBarKeyguardViewManager,
|
||||
SysUiState sysUiFlagsContainer,
|
||||
BroadcastDispatcher broadcastDispatcher,
|
||||
UserTracker userTracker,
|
||||
CommandQueue commandQueue,
|
||||
Optional<Pip> pipOptional,
|
||||
Optional<Recents> recentsOptional,
|
||||
@@ -547,7 +546,7 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
|
||||
mNotificationRemoteInputManager = notificationRemoteInputManager;
|
||||
mOverviewProxyService = overviewProxyService;
|
||||
mNavigationModeController = navigationModeController;
|
||||
mBroadcastDispatcher = broadcastDispatcher;
|
||||
mUserTracker = userTracker;
|
||||
mCommandQueue = commandQueue;
|
||||
mPipOptional = pipOptional;
|
||||
mRecentsOptional = recentsOptional;
|
||||
@@ -729,9 +728,7 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
|
||||
prepareNavigationBarView();
|
||||
checkNavBarModes();
|
||||
|
||||
IntentFilter filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
|
||||
mBroadcastDispatcher.registerReceiverWithHandler(mBroadcastReceiver, filter,
|
||||
Handler.getMain(), UserHandle.ALL);
|
||||
mUserTracker.addCallback(mUserChangedCallback, mContext.getMainExecutor());
|
||||
mWakefulnessLifecycle.addObserver(mWakefulnessObserver);
|
||||
notifyNavigationBarScreenOn();
|
||||
|
||||
@@ -782,7 +779,7 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
|
||||
mView.setUpdateActiveTouchRegionsCallback(null);
|
||||
getBarTransitions().destroy();
|
||||
mOverviewProxyService.removeCallback(mOverviewProxyListener);
|
||||
mBroadcastDispatcher.unregisterReceiver(mBroadcastReceiver);
|
||||
mUserTracker.removeCallback(mUserChangedCallback);
|
||||
mWakefulnessLifecycle.removeObserver(mWakefulnessObserver);
|
||||
if (mOrientationHandle != null) {
|
||||
resetSecondaryHandle();
|
||||
@@ -1674,21 +1671,14 @@ public class NavigationBar extends ViewController<NavigationBarView> implements
|
||||
}
|
||||
};
|
||||
|
||||
private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
// TODO(193941146): Currently unregistering a receiver through BroadcastDispatcher is
|
||||
// async, but we've already cleared the fields. Just return early in this case.
|
||||
if (mView == null) {
|
||||
return;
|
||||
}
|
||||
String action = intent.getAction();
|
||||
if (Intent.ACTION_USER_SWITCHED.equals(action)) {
|
||||
// The accessibility settings may be different for the new user
|
||||
updateAccessibilityStateFlags();
|
||||
}
|
||||
}
|
||||
};
|
||||
private final UserTracker.Callback mUserChangedCallback =
|
||||
new UserTracker.Callback() {
|
||||
@Override
|
||||
public void onUserChanged(int newUser, @NonNull Context userContext) {
|
||||
// The accessibility settings may be different for the new user
|
||||
updateAccessibilityStateFlags();
|
||||
}
|
||||
};
|
||||
|
||||
@VisibleForTesting
|
||||
int getNavigationIconHints() {
|
||||
|
||||
@@ -39,6 +39,8 @@ import android.text.format.DateUtils;
|
||||
import android.util.Log;
|
||||
import android.util.Slog;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settingslib.fuelgauge.Estimate;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
@@ -47,6 +49,7 @@ import com.android.systemui.R;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.dagger.SysUISingleton;
|
||||
import com.android.systemui.keyguard.WakefulnessLifecycle;
|
||||
import com.android.systemui.settings.UserTracker;
|
||||
import com.android.systemui.statusbar.CommandQueue;
|
||||
import com.android.systemui.statusbar.phone.CentralSurfaces;
|
||||
|
||||
@@ -80,6 +83,7 @@ public class PowerUI implements CoreStartable, CommandQueue.Callbacks {
|
||||
private final PowerManager mPowerManager;
|
||||
private final WarningsUI mWarnings;
|
||||
private final WakefulnessLifecycle mWakefulnessLifecycle;
|
||||
private final UserTracker mUserTracker;
|
||||
private InattentiveSleepWarningView mOverlayView;
|
||||
private final Configuration mLastConfiguration = new Configuration();
|
||||
private int mPlugType = 0;
|
||||
@@ -122,12 +126,21 @@ public class PowerUI implements CoreStartable, CommandQueue.Callbacks {
|
||||
}
|
||||
};
|
||||
|
||||
private final UserTracker.Callback mUserChangedCallback =
|
||||
new UserTracker.Callback() {
|
||||
@Override
|
||||
public void onUserChanged(int newUser, @NonNull Context userContext) {
|
||||
mWarnings.userSwitched();
|
||||
}
|
||||
};
|
||||
|
||||
@Inject
|
||||
public PowerUI(Context context, BroadcastDispatcher broadcastDispatcher,
|
||||
CommandQueue commandQueue, Lazy<Optional<CentralSurfaces>> centralSurfacesOptionalLazy,
|
||||
WarningsUI warningsUI, EnhancedEstimates enhancedEstimates,
|
||||
WakefulnessLifecycle wakefulnessLifecycle,
|
||||
PowerManager powerManager) {
|
||||
PowerManager powerManager,
|
||||
UserTracker userTracker) {
|
||||
mContext = context;
|
||||
mBroadcastDispatcher = broadcastDispatcher;
|
||||
mCommandQueue = commandQueue;
|
||||
@@ -136,6 +149,7 @@ public class PowerUI implements CoreStartable, CommandQueue.Callbacks {
|
||||
mEnhancedEstimates = enhancedEstimates;
|
||||
mPowerManager = powerManager;
|
||||
mWakefulnessLifecycle = wakefulnessLifecycle;
|
||||
mUserTracker = userTracker;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
@@ -154,6 +168,7 @@ public class PowerUI implements CoreStartable, CommandQueue.Callbacks {
|
||||
false, obs, UserHandle.USER_ALL);
|
||||
updateBatteryWarningLevels();
|
||||
mReceiver.init();
|
||||
mUserTracker.addCallback(mUserChangedCallback, mContext.getMainExecutor());
|
||||
mWakefulnessLifecycle.addObserver(mWakefulnessObserver);
|
||||
|
||||
// Check to see if we need to let the user know that the phone previously shut down due
|
||||
@@ -250,7 +265,6 @@ public class PowerUI implements CoreStartable, CommandQueue.Callbacks {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED);
|
||||
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
||||
filter.addAction(Intent.ACTION_USER_SWITCHED);
|
||||
mBroadcastDispatcher.registerReceiverWithHandler(this, filter, mHandler);
|
||||
// Force get initial values. Relying on Sticky behavior until API for getting info.
|
||||
if (!mHasReceivedBattery) {
|
||||
@@ -332,8 +346,6 @@ public class PowerUI implements CoreStartable, CommandQueue.Callbacks {
|
||||
plugged, bucket);
|
||||
});
|
||||
|
||||
} else if (Intent.ACTION_USER_SWITCHED.equals(action)) {
|
||||
mWarnings.userSwitched();
|
||||
} else {
|
||||
Slog.w(TAG, "unknown intent: " + intent);
|
||||
}
|
||||
|
||||
@@ -51,10 +51,13 @@ import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.navigationbar.NavigationBarView;
|
||||
import com.android.systemui.navigationbar.NavigationModeController;
|
||||
import com.android.systemui.settings.UserTracker;
|
||||
import com.android.systemui.shared.system.QuickStepContract;
|
||||
import com.android.systemui.statusbar.phone.CentralSurfaces;
|
||||
import com.android.systemui.util.leak.RotationUtils;
|
||||
@@ -76,6 +79,7 @@ public class ScreenPinningRequest implements View.OnClickListener,
|
||||
private final AccessibilityManager mAccessibilityService;
|
||||
private final WindowManager mWindowManager;
|
||||
private final BroadcastDispatcher mBroadcastDispatcher;
|
||||
private final UserTracker mUserTracker;
|
||||
|
||||
private RequestWindowView mRequestWindow;
|
||||
private int mNavBarMode;
|
||||
@@ -83,12 +87,21 @@ public class ScreenPinningRequest implements View.OnClickListener,
|
||||
/** ID of task to be pinned or locked. */
|
||||
private int taskId;
|
||||
|
||||
private final UserTracker.Callback mUserChangedCallback =
|
||||
new UserTracker.Callback() {
|
||||
@Override
|
||||
public void onUserChanged(int newUser, @NonNull Context userContext) {
|
||||
clearPrompt();
|
||||
}
|
||||
};
|
||||
|
||||
@Inject
|
||||
public ScreenPinningRequest(
|
||||
Context context,
|
||||
Lazy<Optional<CentralSurfaces>> centralSurfacesOptionalLazy,
|
||||
NavigationModeController navigationModeController,
|
||||
BroadcastDispatcher broadcastDispatcher) {
|
||||
BroadcastDispatcher broadcastDispatcher,
|
||||
UserTracker userTracker) {
|
||||
mContext = context;
|
||||
mCentralSurfacesOptionalLazy = centralSurfacesOptionalLazy;
|
||||
mAccessibilityService = (AccessibilityManager)
|
||||
@@ -97,6 +110,7 @@ public class ScreenPinningRequest implements View.OnClickListener,
|
||||
mContext.getSystemService(Context.WINDOW_SERVICE);
|
||||
mNavBarMode = navigationModeController.addListener(this);
|
||||
mBroadcastDispatcher = broadcastDispatcher;
|
||||
mUserTracker = userTracker;
|
||||
}
|
||||
|
||||
public void clearPrompt() {
|
||||
@@ -228,9 +242,9 @@ public class ScreenPinningRequest implements View.OnClickListener,
|
||||
}
|
||||
|
||||
IntentFilter filter = new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED);
|
||||
filter.addAction(Intent.ACTION_USER_SWITCHED);
|
||||
filter.addAction(Intent.ACTION_SCREEN_OFF);
|
||||
mBroadcastDispatcher.registerReceiver(mReceiver, filter);
|
||||
mUserTracker.addCallback(mUserChangedCallback, mContext.getMainExecutor());
|
||||
}
|
||||
|
||||
private void inflateView(int rotation) {
|
||||
@@ -358,6 +372,7 @@ public class ScreenPinningRequest implements View.OnClickListener,
|
||||
@Override
|
||||
public void onDetachedFromWindow() {
|
||||
mBroadcastDispatcher.unregisterReceiver(mReceiver);
|
||||
mUserTracker.removeCallback(mUserChangedCallback);
|
||||
}
|
||||
|
||||
protected void onConfigurationChanged() {
|
||||
@@ -388,8 +403,7 @@ public class ScreenPinningRequest implements View.OnClickListener,
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
|
||||
post(mUpdateLayoutRunnable);
|
||||
} else if (intent.getAction().equals(Intent.ACTION_USER_SWITCHED)
|
||||
|| intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
|
||||
} else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
|
||||
clearPrompt();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,13 +33,16 @@ import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.systemui.animation.DialogLaunchAnimator;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.dagger.SysUISingleton;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.flags.FeatureFlags;
|
||||
import com.android.systemui.flags.Flags;
|
||||
import com.android.systemui.plugins.ActivityStarter;
|
||||
import com.android.systemui.settings.UserContextProvider;
|
||||
import com.android.systemui.settings.UserTracker;
|
||||
import com.android.systemui.statusbar.policy.CallbackController;
|
||||
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@@ -55,8 +58,10 @@ public class RecordingController
|
||||
private boolean mIsRecording;
|
||||
private PendingIntent mStopIntent;
|
||||
private CountDownTimer mCountDownTimer = null;
|
||||
private BroadcastDispatcher mBroadcastDispatcher;
|
||||
private UserContextProvider mUserContextProvider;
|
||||
private final Executor mMainExecutor;
|
||||
private final BroadcastDispatcher mBroadcastDispatcher;
|
||||
private final UserContextProvider mUserContextProvider;
|
||||
private final UserTracker mUserTracker;
|
||||
|
||||
protected static final String INTENT_UPDATE_STATE =
|
||||
"com.android.systemui.screenrecord.UPDATE_STATE";
|
||||
@@ -66,12 +71,13 @@ public class RecordingController
|
||||
new CopyOnWriteArrayList<>();
|
||||
|
||||
@VisibleForTesting
|
||||
protected final BroadcastReceiver mUserChangeReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
stopRecording();
|
||||
}
|
||||
};
|
||||
final UserTracker.Callback mUserChangedCallback =
|
||||
new UserTracker.Callback() {
|
||||
@Override
|
||||
public void onUserChanged(int newUser, @NonNull Context userContext) {
|
||||
stopRecording();
|
||||
}
|
||||
};
|
||||
|
||||
@VisibleForTesting
|
||||
protected final BroadcastReceiver mStateChangeReceiver = new BroadcastReceiver() {
|
||||
@@ -92,10 +98,14 @@ public class RecordingController
|
||||
* Create a new RecordingController
|
||||
*/
|
||||
@Inject
|
||||
public RecordingController(BroadcastDispatcher broadcastDispatcher,
|
||||
UserContextProvider userContextProvider) {
|
||||
public RecordingController(@Main Executor mainExecutor,
|
||||
BroadcastDispatcher broadcastDispatcher,
|
||||
UserContextProvider userContextProvider,
|
||||
UserTracker userTracker) {
|
||||
mMainExecutor = mainExecutor;
|
||||
mBroadcastDispatcher = broadcastDispatcher;
|
||||
mUserContextProvider = userContextProvider;
|
||||
mUserTracker = userTracker;
|
||||
}
|
||||
|
||||
/** Create a dialog to show screen recording options to the user. */
|
||||
@@ -139,9 +149,7 @@ public class RecordingController
|
||||
}
|
||||
try {
|
||||
startIntent.send();
|
||||
IntentFilter userFilter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
|
||||
mBroadcastDispatcher.registerReceiver(mUserChangeReceiver, userFilter, null,
|
||||
UserHandle.ALL);
|
||||
mUserTracker.addCallback(mUserChangedCallback, mMainExecutor);
|
||||
|
||||
IntentFilter stateFilter = new IntentFilter(INTENT_UPDATE_STATE);
|
||||
mBroadcastDispatcher.registerReceiver(mStateChangeReceiver, stateFilter, null,
|
||||
@@ -211,7 +219,7 @@ public class RecordingController
|
||||
public synchronized void updateState(boolean isRecording) {
|
||||
if (!isRecording && mIsRecording) {
|
||||
// Unregister receivers if we have stopped recording
|
||||
mBroadcastDispatcher.unregisterReceiver(mUserChangeReceiver);
|
||||
mUserTracker.removeCallback(mUserChangedCallback);
|
||||
mBroadcastDispatcher.unregisterReceiver(mStateChangeReceiver);
|
||||
}
|
||||
mIsRecording = isRecording;
|
||||
|
||||
@@ -30,6 +30,7 @@ import android.content.IntentSender;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.database.ContentObserver;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerExecutor;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
@@ -37,6 +38,7 @@ import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.util.SparseBooleanArray;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.internal.statusbar.NotificationVisibility;
|
||||
@@ -127,21 +129,6 @@ public class NotificationLockscreenUserManagerImpl implements
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
switch (action) {
|
||||
case Intent.ACTION_USER_SWITCHED:
|
||||
mCurrentUserId = intent.getIntExtra(
|
||||
Intent.EXTRA_USER_HANDLE, UserHandle.USER_ALL);
|
||||
updateCurrentProfilesCache();
|
||||
|
||||
Log.v(TAG, "userId " + mCurrentUserId + " is in the house");
|
||||
|
||||
updateLockscreenNotificationSetting();
|
||||
updatePublicMode();
|
||||
mPresenter.onUserSwitched(mCurrentUserId);
|
||||
|
||||
for (UserChangedListener listener : mListeners) {
|
||||
listener.onUserChanged(mCurrentUserId);
|
||||
}
|
||||
break;
|
||||
case Intent.ACTION_USER_REMOVED:
|
||||
int removedUserId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
|
||||
if (removedUserId != -1) {
|
||||
@@ -181,6 +168,25 @@ public class NotificationLockscreenUserManagerImpl implements
|
||||
}
|
||||
};
|
||||
|
||||
protected final UserTracker.Callback mUserChangedCallback =
|
||||
new UserTracker.Callback() {
|
||||
@Override
|
||||
public void onUserChanged(int newUser, @NonNull Context userContext) {
|
||||
mCurrentUserId = newUser;
|
||||
updateCurrentProfilesCache();
|
||||
|
||||
Log.v(TAG, "userId " + mCurrentUserId + " is in the house");
|
||||
|
||||
updateLockscreenNotificationSetting();
|
||||
updatePublicMode();
|
||||
mPresenter.onUserSwitched(mCurrentUserId);
|
||||
|
||||
for (UserChangedListener listener : mListeners) {
|
||||
listener.onUserChanged(mCurrentUserId);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
protected final Context mContext;
|
||||
private final Handler mMainHandler;
|
||||
protected final SparseArray<UserInfo> mCurrentProfiles = new SparseArray<>();
|
||||
@@ -284,7 +290,6 @@ public class NotificationLockscreenUserManagerImpl implements
|
||||
null /* handler */, UserHandle.ALL);
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_USER_SWITCHED);
|
||||
filter.addAction(Intent.ACTION_USER_ADDED);
|
||||
filter.addAction(Intent.ACTION_USER_REMOVED);
|
||||
filter.addAction(Intent.ACTION_USER_UNLOCKED);
|
||||
@@ -298,6 +303,8 @@ public class NotificationLockscreenUserManagerImpl implements
|
||||
mContext.registerReceiver(mBaseBroadcastReceiver, internalFilter, PERMISSION_SELF, null,
|
||||
Context.RECEIVER_EXPORTED_UNAUDITED);
|
||||
|
||||
mUserTracker.addCallback(mUserChangedCallback, new HandlerExecutor(mMainHandler));
|
||||
|
||||
mCurrentUserId = mUserTracker.getUserId(); // in case we reg'd receiver too late
|
||||
updateCurrentProfilesCache();
|
||||
|
||||
|
||||
@@ -2,22 +2,20 @@ package com.android.systemui.statusbar.notification.interruption
|
||||
|
||||
import android.app.Notification
|
||||
import android.app.Notification.VISIBILITY_SECRET
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.database.ContentObserver
|
||||
import android.net.Uri
|
||||
import android.os.Handler
|
||||
import android.os.HandlerExecutor
|
||||
import android.os.UserHandle
|
||||
import android.provider.Settings
|
||||
import com.android.keyguard.KeyguardUpdateMonitor
|
||||
import com.android.keyguard.KeyguardUpdateMonitorCallback
|
||||
import com.android.systemui.CoreStartable
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher
|
||||
import com.android.systemui.dagger.SysUISingleton
|
||||
import com.android.systemui.dagger.qualifiers.Main
|
||||
import com.android.systemui.plugins.statusbar.StatusBarStateController
|
||||
import com.android.systemui.settings.UserTracker
|
||||
import com.android.systemui.statusbar.NotificationLockscreenUserManager
|
||||
import com.android.systemui.statusbar.StatusBarState
|
||||
import com.android.systemui.statusbar.SysuiStatusBarStateController
|
||||
@@ -78,7 +76,7 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor(
|
||||
private val keyguardUpdateMonitor: KeyguardUpdateMonitor,
|
||||
private val highPriorityProvider: HighPriorityProvider,
|
||||
private val statusBarStateController: SysuiStatusBarStateController,
|
||||
private val broadcastDispatcher: BroadcastDispatcher,
|
||||
private val userTracker: UserTracker,
|
||||
private val secureSettings: SecureSettings,
|
||||
private val globalSettings: GlobalSettings
|
||||
) : CoreStartable, KeyguardNotificationVisibilityProvider {
|
||||
@@ -87,6 +85,15 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor(
|
||||
private val onStateChangedListeners = ListenerSet<Consumer<String>>()
|
||||
private var hideSilentNotificationsOnLockscreen: Boolean = false
|
||||
|
||||
private val userTrackerCallback = object : UserTracker.Callback {
|
||||
override fun onUserChanged(newUser: Int, userContext: Context) {
|
||||
if (isLockedOrLocking) {
|
||||
// maybe public mode changed
|
||||
notifyStateChanged("onUserSwitched")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun start() {
|
||||
readShowSilentNotificationSetting()
|
||||
keyguardStateController.addCallback(object : KeyguardStateController.Callback {
|
||||
@@ -143,14 +150,7 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor(
|
||||
notifyStateChanged("onStatusBarUpcomingStateChanged")
|
||||
}
|
||||
})
|
||||
broadcastDispatcher.registerReceiver(object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (isLockedOrLocking) {
|
||||
// maybe public mode changed
|
||||
notifyStateChanged(intent.action!!)
|
||||
}
|
||||
}
|
||||
}, IntentFilter(Intent.ACTION_USER_SWITCHED))
|
||||
userTracker.addCallback(userTrackerCallback, HandlerExecutor(handler))
|
||||
}
|
||||
|
||||
override fun addOnStateChangedListener(listener: Consumer<String>) {
|
||||
|
||||
@@ -15,23 +15,21 @@
|
||||
package com.android.systemui.statusbar.phone;
|
||||
|
||||
import android.app.StatusBarManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.dagger.SysUISingleton;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.settings.UserTracker;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@@ -43,9 +41,9 @@ public class ManagedProfileControllerImpl implements ManagedProfileController {
|
||||
private final List<Callback> mCallbacks = new ArrayList<>();
|
||||
|
||||
private final Context mContext;
|
||||
private final Executor mMainExecutor;
|
||||
private final UserManager mUserManager;
|
||||
private final UserTracker mUserTracker;
|
||||
private final BroadcastDispatcher mBroadcastDispatcher;
|
||||
private final LinkedList<UserInfo> mProfiles;
|
||||
private boolean mListening;
|
||||
private int mCurrentUser;
|
||||
@@ -53,12 +51,12 @@ public class ManagedProfileControllerImpl implements ManagedProfileController {
|
||||
/**
|
||||
*/
|
||||
@Inject
|
||||
public ManagedProfileControllerImpl(Context context, UserTracker userTracker,
|
||||
BroadcastDispatcher broadcastDispatcher) {
|
||||
public ManagedProfileControllerImpl(Context context, @Main Executor mainExecutor,
|
||||
UserTracker userTracker) {
|
||||
mContext = context;
|
||||
mMainExecutor = mainExecutor;
|
||||
mUserManager = UserManager.get(mContext);
|
||||
mUserTracker = userTracker;
|
||||
mBroadcastDispatcher = broadcastDispatcher;
|
||||
mProfiles = new LinkedList<UserInfo>();
|
||||
}
|
||||
|
||||
@@ -130,30 +128,34 @@ public class ManagedProfileControllerImpl implements ManagedProfileController {
|
||||
}
|
||||
|
||||
private void setListening(boolean listening) {
|
||||
if (mListening == listening) {
|
||||
return;
|
||||
}
|
||||
mListening = listening;
|
||||
if (listening) {
|
||||
reloadManagedProfiles();
|
||||
|
||||
final IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_USER_SWITCHED);
|
||||
filter.addAction(Intent.ACTION_MANAGED_PROFILE_ADDED);
|
||||
filter.addAction(Intent.ACTION_MANAGED_PROFILE_REMOVED);
|
||||
filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
|
||||
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
|
||||
mBroadcastDispatcher.registerReceiver(
|
||||
mReceiver, filter, null /* handler */, UserHandle.ALL);
|
||||
mUserTracker.addCallback(mUserChangedCallback, mMainExecutor);
|
||||
} else {
|
||||
mBroadcastDispatcher.unregisterReceiver(mReceiver);
|
||||
mUserTracker.removeCallback(mUserChangedCallback);
|
||||
}
|
||||
}
|
||||
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
reloadManagedProfiles();
|
||||
for (Callback callback : mCallbacks) {
|
||||
callback.onManagedProfileChanged();
|
||||
}
|
||||
}
|
||||
};
|
||||
private final UserTracker.Callback mUserChangedCallback =
|
||||
new UserTracker.Callback() {
|
||||
@Override
|
||||
public void onUserChanged(int newUser, @NonNull Context userContext) {
|
||||
reloadManagedProfiles();
|
||||
for (Callback callback : mCallbacks) {
|
||||
callback.onManagedProfileChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProfilesChanged(@NonNull List<UserInfo> profiles) {
|
||||
reloadManagedProfiles();
|
||||
for (Callback callback : mCallbacks) {
|
||||
callback.onManagedProfileChanged();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -120,6 +120,7 @@ public class Clock extends TextView implements
|
||||
@Override
|
||||
public void onUserChanged(int newUser, @NonNull Context userContext) {
|
||||
mCurrentUserId = newUser;
|
||||
updateClock();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -190,7 +191,6 @@ public class Clock extends TextView implements
|
||||
filter.addAction(Intent.ACTION_TIME_CHANGED);
|
||||
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
|
||||
filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
|
||||
filter.addAction(Intent.ACTION_USER_SWITCHED);
|
||||
|
||||
// NOTE: This receiver could run before this method returns, as it's not dispatching
|
||||
// on the main thread and BroadcastDispatcher may not need to register with Context.
|
||||
|
||||
@@ -28,11 +28,14 @@ import androidx.annotation.NonNull;
|
||||
import com.android.systemui.Dumpable;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.dagger.SysUISingleton;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.dump.DumpManager;
|
||||
import com.android.systemui.settings.UserTracker;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@@ -45,22 +48,34 @@ public class NextAlarmControllerImpl extends BroadcastReceiver
|
||||
|
||||
private final ArrayList<NextAlarmChangeCallback> mChangeCallbacks = new ArrayList<>();
|
||||
|
||||
private final UserTracker mUserTracker;
|
||||
private AlarmManager mAlarmManager;
|
||||
private AlarmManager.AlarmClockInfo mNextAlarm;
|
||||
|
||||
private final UserTracker.Callback mUserChangedCallback =
|
||||
new UserTracker.Callback() {
|
||||
@Override
|
||||
public void onUserChanged(int newUser, @NonNull Context userContext) {
|
||||
updateNextAlarm();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*/
|
||||
@Inject
|
||||
public NextAlarmControllerImpl(
|
||||
@Main Executor mainExecutor,
|
||||
AlarmManager alarmManager,
|
||||
BroadcastDispatcher broadcastDispatcher,
|
||||
DumpManager dumpManager) {
|
||||
DumpManager dumpManager,
|
||||
UserTracker userTracker) {
|
||||
dumpManager.registerDumpable("NextAlarmController", this);
|
||||
mAlarmManager = alarmManager;
|
||||
mUserTracker = userTracker;
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_USER_SWITCHED);
|
||||
filter.addAction(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED);
|
||||
broadcastDispatcher.registerReceiver(this, filter, null, UserHandle.ALL);
|
||||
mUserTracker.addCallback(mUserChangedCallback, mainExecutor);
|
||||
updateNextAlarm();
|
||||
}
|
||||
|
||||
@@ -98,14 +113,13 @@ public class NextAlarmControllerImpl extends BroadcastReceiver
|
||||
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
if (action.equals(Intent.ACTION_USER_SWITCHED)
|
||||
|| action.equals(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED)) {
|
||||
if (action.equals(AlarmManager.ACTION_NEXT_ALARM_CLOCK_CHANGED)) {
|
||||
updateNextAlarm();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateNextAlarm() {
|
||||
mNextAlarm = mAlarmManager.getNextAlarmClock(UserHandle.USER_CURRENT);
|
||||
mNextAlarm = mAlarmManager.getNextAlarmClock(mUserTracker.getUserId());
|
||||
fireNextAlarmChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,6 @@ import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.keyguard.KeyguardUpdateMonitor;
|
||||
import com.android.systemui.biometrics.AuthController;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.decor.CornerDecorProvider;
|
||||
import com.android.systemui.decor.CutoutDecorProviderFactory;
|
||||
import com.android.systemui.decor.CutoutDecorProviderImpl;
|
||||
@@ -132,8 +131,6 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
||||
@Mock
|
||||
private TunerService mTunerService;
|
||||
@Mock
|
||||
private BroadcastDispatcher mBroadcastDispatcher;
|
||||
@Mock
|
||||
private UserTracker mUserTracker;
|
||||
@Mock
|
||||
private PrivacyDotViewController mDotViewController;
|
||||
@@ -223,8 +220,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
||||
mExecutor));
|
||||
|
||||
mScreenDecorations = spy(new ScreenDecorations(mContext, mExecutor, mSecureSettings,
|
||||
mBroadcastDispatcher, mTunerService, mUserTracker, mDotViewController,
|
||||
mThreadFactory, mPrivacyDotDecorProviderFactory, mFaceScanningProviderFactory) {
|
||||
mTunerService, mUserTracker, mDotViewController, mThreadFactory,
|
||||
mPrivacyDotDecorProviderFactory, mFaceScanningProviderFactory) {
|
||||
@Override
|
||||
public void start() {
|
||||
super.start();
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.android.systemui.controls.controller
|
||||
|
||||
import android.app.PendingIntent
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
@@ -31,7 +30,6 @@ import android.testing.AndroidTestingRunner
|
||||
import androidx.test.filters.SmallTest
|
||||
import com.android.systemui.SysuiTestCase
|
||||
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
|
||||
@@ -85,10 +83,8 @@ class ControlsControllerImplTest : SysuiTestCase() {
|
||||
@Mock
|
||||
private lateinit var auxiliaryPersistenceWrapper: AuxiliaryPersistenceWrapper
|
||||
@Mock
|
||||
private lateinit var broadcastDispatcher: BroadcastDispatcher
|
||||
@Mock
|
||||
private lateinit var listingController: ControlsListingController
|
||||
@Mock(stubOnly = true)
|
||||
@Mock
|
||||
private lateinit var userTracker: UserTracker
|
||||
@Mock
|
||||
private lateinit var userFileManager: UserFileManager
|
||||
@@ -104,7 +100,7 @@ class ControlsControllerImplTest : SysuiTestCase() {
|
||||
ArgumentCaptor<ControlsBindingController.LoadCallback>
|
||||
|
||||
@Captor
|
||||
private lateinit var broadcastReceiverCaptor: ArgumentCaptor<BroadcastReceiver>
|
||||
private lateinit var userTrackerCallbackCaptor: ArgumentCaptor<UserTracker.Callback>
|
||||
@Captor
|
||||
private lateinit var listingCallbackCaptor:
|
||||
ArgumentCaptor<ControlsListingController.ControlsListingCallback>
|
||||
@@ -170,16 +166,15 @@ class ControlsControllerImplTest : SysuiTestCase() {
|
||||
uiController,
|
||||
bindingController,
|
||||
listingController,
|
||||
broadcastDispatcher,
|
||||
userFileManager,
|
||||
userTracker,
|
||||
Optional.of(persistenceWrapper),
|
||||
mock(DumpManager::class.java),
|
||||
userTracker
|
||||
mock(DumpManager::class.java)
|
||||
)
|
||||
controller.auxiliaryPersistenceWrapper = auxiliaryPersistenceWrapper
|
||||
|
||||
verify(broadcastDispatcher).registerReceiver(
|
||||
capture(broadcastReceiverCaptor), any(), any(), eq(UserHandle.ALL), anyInt(), any()
|
||||
verify(userTracker).addCallback(
|
||||
capture(userTrackerCallbackCaptor), any()
|
||||
)
|
||||
|
||||
verify(listingController).addCallback(capture(listingCallbackCaptor))
|
||||
@@ -227,11 +222,10 @@ class ControlsControllerImplTest : SysuiTestCase() {
|
||||
uiController,
|
||||
bindingController,
|
||||
listingController,
|
||||
broadcastDispatcher,
|
||||
userFileManager,
|
||||
userTracker,
|
||||
Optional.of(persistenceWrapper),
|
||||
mock(DumpManager::class.java),
|
||||
userTracker
|
||||
mock(DumpManager::class.java)
|
||||
)
|
||||
assertEquals(listOf(TEST_STRUCTURE_INFO), controller_other.getFavorites())
|
||||
}
|
||||
@@ -518,14 +512,8 @@ class ControlsControllerImplTest : SysuiTestCase() {
|
||||
delayableExecutor.runAllReady()
|
||||
|
||||
reset(persistenceWrapper)
|
||||
val intent = Intent(Intent.ACTION_USER_SWITCHED).apply {
|
||||
putExtra(Intent.EXTRA_USER_HANDLE, otherUser)
|
||||
}
|
||||
val pendingResult = mock(BroadcastReceiver.PendingResult::class.java)
|
||||
`when`(pendingResult.sendingUserId).thenReturn(otherUser)
|
||||
broadcastReceiverCaptor.value.pendingResult = pendingResult
|
||||
|
||||
broadcastReceiverCaptor.value.onReceive(mContext, intent)
|
||||
userTrackerCallbackCaptor.value.onUserChanged(otherUser, mContext)
|
||||
|
||||
verify(persistenceWrapper).changeFileAndBackupManager(any(), any())
|
||||
verify(persistenceWrapper).readFavorites()
|
||||
|
||||
@@ -38,6 +38,7 @@ import com.android.systemui.media.controls.models.player.MediaData
|
||||
import com.android.systemui.media.controls.models.player.MediaDeviceData
|
||||
import com.android.systemui.media.controls.pipeline.MediaDataManager
|
||||
import com.android.systemui.media.controls.pipeline.RESUME_MEDIA_TIMEOUT
|
||||
import com.android.systemui.settings.UserTracker
|
||||
import com.android.systemui.tuner.TunerService
|
||||
import com.android.systemui.util.concurrency.FakeExecutor
|
||||
import com.android.systemui.util.time.FakeSystemClock
|
||||
@@ -79,6 +80,7 @@ private fun <T> any(): T = Mockito.any<T>()
|
||||
class MediaResumeListenerTest : SysuiTestCase() {
|
||||
|
||||
@Mock private lateinit var broadcastDispatcher: BroadcastDispatcher
|
||||
@Mock private lateinit var userTracker: UserTracker
|
||||
@Mock private lateinit var mediaDataManager: MediaDataManager
|
||||
@Mock private lateinit var device: MediaDeviceData
|
||||
@Mock private lateinit var token: MediaSession.Token
|
||||
@@ -131,12 +133,15 @@ class MediaResumeListenerTest : SysuiTestCase() {
|
||||
whenever(sharedPrefsEditor.putString(any(), any())).thenReturn(sharedPrefsEditor)
|
||||
whenever(mockContext.packageManager).thenReturn(context.packageManager)
|
||||
whenever(mockContext.contentResolver).thenReturn(context.contentResolver)
|
||||
whenever(mockContext.userId).thenReturn(context.userId)
|
||||
|
||||
executor = FakeExecutor(clock)
|
||||
resumeListener =
|
||||
MediaResumeListener(
|
||||
mockContext,
|
||||
broadcastDispatcher,
|
||||
userTracker,
|
||||
executor,
|
||||
executor,
|
||||
tunerService,
|
||||
resumeBrowserFactory,
|
||||
@@ -177,6 +182,8 @@ class MediaResumeListenerTest : SysuiTestCase() {
|
||||
MediaResumeListener(
|
||||
context,
|
||||
broadcastDispatcher,
|
||||
userTracker,
|
||||
executor,
|
||||
executor,
|
||||
tunerService,
|
||||
resumeBrowserFactory,
|
||||
@@ -185,7 +192,7 @@ class MediaResumeListenerTest : SysuiTestCase() {
|
||||
)
|
||||
listener.setManager(mediaDataManager)
|
||||
verify(broadcastDispatcher, never())
|
||||
.registerReceiver(eq(listener.userChangeReceiver), any(), any(), any(), anyInt(), any())
|
||||
.registerReceiver(eq(listener.userUnlockReceiver), any(), any(), any(), anyInt(), any())
|
||||
|
||||
// When data is loaded, we do NOT execute or update anything
|
||||
listener.onMediaDataLoaded(KEY, OLD_KEY, data)
|
||||
@@ -289,7 +296,7 @@ class MediaResumeListenerTest : SysuiTestCase() {
|
||||
resumeListener.setManager(mediaDataManager)
|
||||
verify(broadcastDispatcher)
|
||||
.registerReceiver(
|
||||
eq(resumeListener.userChangeReceiver),
|
||||
eq(resumeListener.userUnlockReceiver),
|
||||
any(),
|
||||
any(),
|
||||
any(),
|
||||
@@ -299,7 +306,8 @@ class MediaResumeListenerTest : SysuiTestCase() {
|
||||
|
||||
// When we get an unlock event
|
||||
val intent = Intent(Intent.ACTION_USER_UNLOCKED)
|
||||
resumeListener.userChangeReceiver.onReceive(context, intent)
|
||||
intent.putExtra(Intent.EXTRA_USER_HANDLE, context.userId)
|
||||
resumeListener.userUnlockReceiver.onReceive(context, intent)
|
||||
|
||||
// Then we should attempt to find recent media for each saved component
|
||||
verify(resumeBrowser, times(3)).findRecentMedia()
|
||||
@@ -375,6 +383,8 @@ class MediaResumeListenerTest : SysuiTestCase() {
|
||||
MediaResumeListener(
|
||||
mockContext,
|
||||
broadcastDispatcher,
|
||||
userTracker,
|
||||
executor,
|
||||
executor,
|
||||
tunerService,
|
||||
resumeBrowserFactory,
|
||||
@@ -386,7 +396,8 @@ class MediaResumeListenerTest : SysuiTestCase() {
|
||||
|
||||
// When we load a component that was played recently
|
||||
val intent = Intent(Intent.ACTION_USER_UNLOCKED)
|
||||
resumeListener.userChangeReceiver.onReceive(mockContext, intent)
|
||||
intent.putExtra(Intent.EXTRA_USER_HANDLE, context.userId)
|
||||
resumeListener.userUnlockReceiver.onReceive(mockContext, intent)
|
||||
|
||||
// We add its resume controls
|
||||
verify(resumeBrowser, times(1)).findRecentMedia()
|
||||
@@ -404,6 +415,8 @@ class MediaResumeListenerTest : SysuiTestCase() {
|
||||
MediaResumeListener(
|
||||
mockContext,
|
||||
broadcastDispatcher,
|
||||
userTracker,
|
||||
executor,
|
||||
executor,
|
||||
tunerService,
|
||||
resumeBrowserFactory,
|
||||
@@ -415,7 +428,8 @@ class MediaResumeListenerTest : SysuiTestCase() {
|
||||
|
||||
// When we load a component that is not recent
|
||||
val intent = Intent(Intent.ACTION_USER_UNLOCKED)
|
||||
resumeListener.userChangeReceiver.onReceive(mockContext, intent)
|
||||
intent.putExtra(Intent.EXTRA_USER_HANDLE, context.userId)
|
||||
resumeListener.userUnlockReceiver.onReceive(mockContext, intent)
|
||||
|
||||
// We do not try to add resume controls
|
||||
verify(resumeBrowser, times(0)).findRecentMedia()
|
||||
@@ -443,6 +457,8 @@ class MediaResumeListenerTest : SysuiTestCase() {
|
||||
MediaResumeListener(
|
||||
mockContext,
|
||||
broadcastDispatcher,
|
||||
userTracker,
|
||||
executor,
|
||||
executor,
|
||||
tunerService,
|
||||
resumeBrowserFactory,
|
||||
|
||||
@@ -44,14 +44,11 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Resources;
|
||||
import android.hardware.display.DisplayManagerGlobal;
|
||||
import android.os.Handler;
|
||||
import android.os.SystemClock;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.DeviceConfig;
|
||||
import android.telecom.TelecomManager;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
@@ -79,7 +76,6 @@ import com.android.systemui.accessibility.AccessibilityButtonModeObserver;
|
||||
import com.android.systemui.accessibility.AccessibilityButtonTargetsObserver;
|
||||
import com.android.systemui.accessibility.SystemActions;
|
||||
import com.android.systemui.assist.AssistManager;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.dump.DumpManager;
|
||||
import com.android.systemui.keyguard.WakefulnessLifecycle;
|
||||
import com.android.systemui.model.SysUiState;
|
||||
@@ -119,6 +115,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@RunWithLooper(setAsMainLooper = true)
|
||||
@@ -166,7 +163,7 @@ public class NavigationBarTest extends SysuiTestCase {
|
||||
@Mock
|
||||
private Handler mHandler;
|
||||
@Mock
|
||||
private BroadcastDispatcher mBroadcastDispatcher;
|
||||
private UserTracker mUserTracker;
|
||||
@Mock
|
||||
private UiEventLogger mUiEventLogger;
|
||||
@Mock
|
||||
@@ -315,14 +312,10 @@ public class NavigationBarTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisteredWithDispatcher() {
|
||||
public void testRegisteredWithUserTracker() {
|
||||
mNavigationBar.init();
|
||||
mNavigationBar.onViewAttached();
|
||||
verify(mBroadcastDispatcher).registerReceiverWithHandler(
|
||||
any(BroadcastReceiver.class),
|
||||
any(IntentFilter.class),
|
||||
any(Handler.class),
|
||||
any(UserHandle.class));
|
||||
verify(mUserTracker).addCallback(any(UserTracker.Callback.class), any(Executor.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -463,7 +456,7 @@ public class NavigationBarTest extends SysuiTestCase {
|
||||
mStatusBarStateController,
|
||||
mStatusBarKeyguardViewManager,
|
||||
mMockSysUiState,
|
||||
mBroadcastDispatcher,
|
||||
mUserTracker,
|
||||
mCommandQueue,
|
||||
Optional.of(mock(Pip.class)),
|
||||
Optional.of(mock(Recents.class)),
|
||||
|
||||
@@ -48,6 +48,7 @@ import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.keyguard.WakefulnessLifecycle;
|
||||
import com.android.systemui.power.PowerUI.WarningsUI;
|
||||
import com.android.systemui.settings.UserTracker;
|
||||
import com.android.systemui.statusbar.CommandQueue;
|
||||
import com.android.systemui.statusbar.phone.CentralSurfaces;
|
||||
|
||||
@@ -85,6 +86,7 @@ public class PowerUITest extends SysuiTestCase {
|
||||
private PowerUI mPowerUI;
|
||||
@Mock private EnhancedEstimates mEnhancedEstimates;
|
||||
@Mock private PowerManager mPowerManager;
|
||||
@Mock private UserTracker mUserTracker;
|
||||
@Mock private WakefulnessLifecycle mWakefulnessLifecycle;
|
||||
@Mock private IThermalService mThermalServiceMock;
|
||||
private IThermalEventListener mUsbThermalEventListener;
|
||||
@@ -682,7 +684,8 @@ public class PowerUITest extends SysuiTestCase {
|
||||
private void createPowerUi() {
|
||||
mPowerUI = new PowerUI(
|
||||
mContext, mBroadcastDispatcher, mCommandQueue, mCentralSurfacesOptionalLazy,
|
||||
mMockWarnings, mEnhancedEstimates, mWakefulnessLifecycle, mPowerManager);
|
||||
mMockWarnings, mEnhancedEstimates, mWakefulnessLifecycle, mPowerManager,
|
||||
mUserTracker);
|
||||
mPowerUI.mThermalService = mThermalServiceMock;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,9 @@ import androidx.test.filters.SmallTest;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.settings.UserContextProvider;
|
||||
import com.android.systemui.settings.UserTracker;
|
||||
import com.android.systemui.util.concurrency.FakeExecutor;
|
||||
import com.android.systemui.util.time.FakeSystemClock;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -49,12 +52,16 @@ import org.mockito.MockitoAnnotations;
|
||||
*/
|
||||
public class RecordingControllerTest extends SysuiTestCase {
|
||||
|
||||
private FakeSystemClock mFakeSystemClock = new FakeSystemClock();
|
||||
private FakeExecutor mMainExecutor = new FakeExecutor(mFakeSystemClock);
|
||||
@Mock
|
||||
private RecordingController.RecordingStateChangeCallback mCallback;
|
||||
@Mock
|
||||
private BroadcastDispatcher mBroadcastDispatcher;
|
||||
@Mock
|
||||
private UserContextProvider mUserContextProvider;
|
||||
@Mock
|
||||
private UserTracker mUserTracker;
|
||||
|
||||
private RecordingController mController;
|
||||
|
||||
@@ -63,7 +70,8 @@ public class RecordingControllerTest extends SysuiTestCase {
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mController = new RecordingController(mBroadcastDispatcher, mUserContextProvider);
|
||||
mController = new RecordingController(mMainExecutor, mBroadcastDispatcher,
|
||||
mUserContextProvider, mUserTracker);
|
||||
mController.addCallback(mCallback);
|
||||
}
|
||||
|
||||
@@ -176,9 +184,7 @@ public class RecordingControllerTest extends SysuiTestCase {
|
||||
mController.updateState(true);
|
||||
|
||||
// and user is changed
|
||||
Intent intent = new Intent(Intent.ACTION_USER_SWITCHED)
|
||||
.putExtra(Intent.EXTRA_USER_HANDLE, USER_ID);
|
||||
mController.mUserChangeReceiver.onReceive(mContext, intent);
|
||||
mController.mUserChangedCallback.onUserChanged(USER_ID, mContext);
|
||||
|
||||
// Ensure that the recording was stopped
|
||||
verify(mCallback).onRecordingEnd();
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package com.android.systemui.statusbar;
|
||||
|
||||
import static android.content.Intent.ACTION_USER_SWITCHED;
|
||||
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
@@ -34,7 +32,6 @@ import android.app.Notification;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.database.ContentObserver;
|
||||
import android.os.Handler;
|
||||
@@ -293,11 +290,9 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testActionUserSwitchedCallsOnUserSwitched() {
|
||||
Intent intent = new Intent()
|
||||
.setAction(ACTION_USER_SWITCHED)
|
||||
.putExtra(Intent.EXTRA_USER_HANDLE, mSecondaryUser.id);
|
||||
mLockscreenUserManager.getBaseBroadcastReceiverForTest().onReceive(mContext, intent);
|
||||
public void testUserSwitchedCallsOnUserSwitched() {
|
||||
mLockscreenUserManager.getUserTrackerCallbackForTest().onUserChanged(mSecondaryUser.id,
|
||||
mContext);
|
||||
verify(mPresenter, times(1)).onUserSwitched(mSecondaryUser.id);
|
||||
}
|
||||
|
||||
@@ -366,6 +361,10 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
|
||||
return mBaseBroadcastReceiver;
|
||||
}
|
||||
|
||||
public UserTracker.Callback getUserTrackerCallbackForTest() {
|
||||
return mUserChangedCallback;
|
||||
}
|
||||
|
||||
public ContentObserver getLockscreenSettingsObserverForTest() {
|
||||
return mLockscreenSettingsObserver;
|
||||
}
|
||||
|
||||
@@ -26,22 +26,17 @@ import static android.app.NotificationManager.IMPORTANCE_MIN;
|
||||
import static com.android.systemui.statusbar.StatusBarState.KEYGUARD;
|
||||
import static com.android.systemui.statusbar.StatusBarState.SHADE;
|
||||
import static com.android.systemui.statusbar.notification.collection.EntryUtilKt.modifyEntry;
|
||||
import static com.android.systemui.util.mockito.KotlinMockitoHelpersKt.argThat;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
@@ -54,10 +49,10 @@ import com.android.keyguard.KeyguardUpdateMonitor;
|
||||
import com.android.keyguard.KeyguardUpdateMonitorCallback;
|
||||
import com.android.systemui.CoreStartable;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.broadcast.BroadcastDispatcher;
|
||||
import com.android.systemui.dagger.SysUISingleton;
|
||||
import com.android.systemui.dagger.qualifiers.Main;
|
||||
import com.android.systemui.plugins.statusbar.StatusBarStateController;
|
||||
import com.android.systemui.settings.UserTracker;
|
||||
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
|
||||
import com.android.systemui.statusbar.RankingBuilder;
|
||||
import com.android.systemui.statusbar.SysuiStatusBarStateController;
|
||||
@@ -97,7 +92,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
|
||||
@Mock private KeyguardUpdateMonitor mKeyguardUpdateMonitor;
|
||||
@Mock private HighPriorityProvider mHighPriorityProvider;
|
||||
@Mock private SysuiStatusBarStateController mStatusBarStateController;
|
||||
@Mock private BroadcastDispatcher mBroadcastDispatcher;
|
||||
@Mock private UserTracker mUserTracker;
|
||||
private final FakeSettings mFakeSettings = new FakeSettings();
|
||||
|
||||
private KeyguardNotificationVisibilityProvider mKeyguardNotificationVisibilityProvider;
|
||||
@@ -117,7 +112,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
|
||||
mKeyguardUpdateMonitor,
|
||||
mHighPriorityProvider,
|
||||
mStatusBarStateController,
|
||||
mBroadcastDispatcher,
|
||||
mUserTracker,
|
||||
mFakeSettings,
|
||||
mFakeSettings);
|
||||
mKeyguardNotificationVisibilityProvider = component.getProvider();
|
||||
@@ -205,23 +200,19 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notifyListeners_onReceiveUserSwitchBroadcast() {
|
||||
ArgumentCaptor<BroadcastReceiver> callbackCaptor =
|
||||
ArgumentCaptor.forClass(BroadcastReceiver.class);
|
||||
verify(mBroadcastDispatcher).registerReceiver(
|
||||
public void notifyListeners_onReceiveUserSwitchCallback() {
|
||||
ArgumentCaptor<UserTracker.Callback> callbackCaptor =
|
||||
ArgumentCaptor.forClass(UserTracker.Callback.class);
|
||||
verify(mUserTracker).addCallback(
|
||||
callbackCaptor.capture(),
|
||||
argThat(intentFilter -> intentFilter.hasAction(Intent.ACTION_USER_SWITCHED)),
|
||||
isNull(),
|
||||
isNull(),
|
||||
eq(Context.RECEIVER_EXPORTED),
|
||||
isNull());
|
||||
BroadcastReceiver callback = callbackCaptor.getValue();
|
||||
any());
|
||||
UserTracker.Callback callback = callbackCaptor.getValue();
|
||||
|
||||
Consumer<String> listener = mock(Consumer.class);
|
||||
mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener);
|
||||
|
||||
when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD);
|
||||
callback.onReceive(mContext, new Intent(Intent.ACTION_USER_SWITCHED));
|
||||
callback.onUserChanged(CURR_USER_ID, mContext);
|
||||
|
||||
verify(listener).accept(anyString());
|
||||
}
|
||||
@@ -619,7 +610,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
|
||||
@BindsInstance KeyguardUpdateMonitor keyguardUpdateMonitor,
|
||||
@BindsInstance HighPriorityProvider highPriorityProvider,
|
||||
@BindsInstance SysuiStatusBarStateController statusBarStateController,
|
||||
@BindsInstance BroadcastDispatcher broadcastDispatcher,
|
||||
@BindsInstance UserTracker userTracker,
|
||||
@BindsInstance SecureSettings secureSettings,
|
||||
@BindsInstance GlobalSettings globalSettings
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user