diff options
| author | 2020-01-24 15:47:28 -0800 | |
|---|---|---|
| committer | 2020-01-28 17:12:56 -0800 | |
| commit | 960b7e7f74569c81fa8e05a6bacd59b9480d2874 (patch) | |
| tree | 73b62ca003f2f2c4f46964df90645662455deb66 | |
| parent | a2968105b289138974d86a75201918feba8c2c62 (diff) | |
Expose managed profile sensitiveness preferences
Test: atest NotificationLockscreenUserManagerTest
Test: atest KeyguardSliceProviderTest
Bug: 144299702
Change-Id: Ia91cab4ebeaa36a7f26588197c4aba3291f88d28
7 files changed, 140 insertions, 79 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIRootComponent.java b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIRootComponent.java index e14581ffcde8..e8509b366c5b 100644 --- a/packages/SystemUI/src/com/android/systemui/dagger/SystemUIRootComponent.java +++ b/packages/SystemUI/src/com/android/systemui/dagger/SystemUIRootComponent.java @@ -26,6 +26,7 @@ import com.android.systemui.InitController; import com.android.systemui.SystemUIAppComponentFactory; import com.android.systemui.SystemUIFactory; import com.android.systemui.fragments.FragmentService; +import com.android.systemui.keyguard.KeyguardSliceProvider; import com.android.systemui.statusbar.policy.ConfigurationController; import com.android.systemui.util.InjectionInflationController; @@ -105,4 +106,9 @@ public interface SystemUIRootComponent { * Member injection into the supplied argument. */ void inject(ContentProvider contentProvider); + + /** + * Member injection into the supplied argument. + */ + void inject(KeyguardSliceProvider keyguardSliceProvider); } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java index e66a9fadb937..2cc3d9e22a7d 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardSliceProvider.java @@ -52,13 +52,13 @@ import com.android.keyguard.KeyguardUpdateMonitorCallback; import com.android.systemui.Dependency; import com.android.systemui.R; import com.android.systemui.SystemUIAppComponentFactory; +import com.android.systemui.SystemUIFactory; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.statusbar.NotificationMediaManager; import com.android.systemui.statusbar.StatusBarState; import com.android.systemui.statusbar.phone.DozeParameters; import com.android.systemui.statusbar.phone.KeyguardBypassController; import com.android.systemui.statusbar.policy.NextAlarmController; -import com.android.systemui.statusbar.policy.NextAlarmControllerImpl; import com.android.systemui.statusbar.policy.ZenModeController; import com.android.systemui.util.wakelock.SettableWakeLock; import com.android.systemui.util.wakelock.WakeLock; @@ -68,6 +68,8 @@ import java.util.Locale; import java.util.TimeZone; import java.util.concurrent.TimeUnit; +import javax.inject.Inject; + /** * Simple Slice provider that shows the current date. */ @@ -108,26 +110,31 @@ public class KeyguardSliceProvider extends SliceProvider implements private final Handler mHandler; private final Handler mMediaHandler; private final AlarmManager.OnAlarmListener mUpdateNextAlarm = this::updateNextAlarm; - private DozeParameters mDozeParameters; + @Inject + public DozeParameters mDozeParameters; @VisibleForTesting protected SettableWakeLock mMediaWakeLock; - @VisibleForTesting - protected ZenModeController mZenModeController; + @Inject + public ZenModeController mZenModeController; private String mDatePattern; private DateFormat mDateFormat; private String mLastText; private boolean mRegistered; private String mNextAlarm; - private NextAlarmController mNextAlarmController; - @VisibleForTesting - protected AlarmManager mAlarmManager; - @VisibleForTesting - protected ContentResolver mContentResolver; + @Inject + public NextAlarmController mNextAlarmController; + @Inject + public AlarmManager mAlarmManager; + @Inject + public ContentResolver mContentResolver; private AlarmManager.AlarmClockInfo mNextAlarmInfo; private PendingIntent mPendingIntent; - protected NotificationMediaManager mMediaManager; - private StatusBarStateController mStatusBarStateController; - private KeyguardBypassController mKeyguardBypassController; + @Inject + public NotificationMediaManager mMediaManager; + @Inject + public StatusBarStateController mStatusBarStateController; + @Inject + public KeyguardBypassController mKeyguardBypassController; private CharSequence mMediaTitle; private CharSequence mMediaArtist; protected boolean mDozing; @@ -188,26 +195,6 @@ public class KeyguardSliceProvider extends SliceProvider implements mMediaUri = Uri.parse(KEYGUARD_MEDIA_URI); } - /** - * Initialize dependencies that don't exist during {@link android.content.ContentProvider} - * instantiation. - * - * @param mediaManager {@link NotificationMediaManager} singleton. - * @param statusBarStateController {@link StatusBarStateController} singleton. - */ - public void initDependencies( - NotificationMediaManager mediaManager, - StatusBarStateController statusBarStateController, - KeyguardBypassController keyguardBypassController, - DozeParameters dozeParameters) { - mMediaManager = mediaManager; - mMediaManager.addCallback(this); - mStatusBarStateController = statusBarStateController; - mStatusBarStateController.addCallback(this); - mKeyguardBypassController = keyguardBypassController; - mDozeParameters = dozeParameters; - } - @AnyThread @Override public Slice onBindSlice(Uri sliceUri) { @@ -310,25 +297,19 @@ public class KeyguardSliceProvider extends SliceProvider implements @Override public boolean onCreateSliceProvider() { - if (mContextAvailableCallback != null) { - mContextAvailableCallback.onContextAvailable(getContext()); - } + mContextAvailableCallback.onContextAvailable(getContext()); + inject(); synchronized (KeyguardSliceProvider.sInstanceLock) { KeyguardSliceProvider oldInstance = KeyguardSliceProvider.sInstance; if (oldInstance != null) { oldInstance.onDestroy(); } - - mAlarmManager = getContext().getSystemService(AlarmManager.class); - mContentResolver = getContext().getContentResolver(); - mNextAlarmController = new NextAlarmControllerImpl(getContext()); - mNextAlarmController.addCallback(this); - mZenModeController = Dependency.get(ZenModeController.class); - mZenModeController.addCallback(this); mDatePattern = getContext().getString(R.string.system_ui_aod_date_pattern); mPendingIntent = PendingIntent.getActivity(getContext(), 0, new Intent(), 0); - mMediaWakeLock = new SettableWakeLock(WakeLock.createPartial(getContext(), "media"), - "media"); + mMediaManager.addCallback(this); + mStatusBarStateController.addCallback(this); + mNextAlarmController.addCallback(this); + mZenModeController.addCallback(this); KeyguardSliceProvider.sInstance = this; registerClockUpdate(); updateClockLocked(); @@ -337,6 +318,13 @@ public class KeyguardSliceProvider extends SliceProvider implements } @VisibleForTesting + protected void inject() { + SystemUIFactory.getInstance().getRootComponent().inject(this); + mMediaWakeLock = new SettableWakeLock(WakeLock.createPartial(getContext(), "media"), + "media"); + } + + @VisibleForTesting protected void onDestroy() { synchronized (KeyguardSliceProvider.sInstanceLock) { mNextAlarmController.removeCallback(this); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java index 976531d8b49d..d38f1b99cb9a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java @@ -79,6 +79,7 @@ public class NotificationLockscreenUserManagerImpl implements private final DeviceProvisionedController mDeviceProvisionedController; private final KeyguardStateController mKeyguardStateController; + private final Object mLock = new Object(); // Lazy private NotificationEntryManager mEntryManager; @@ -181,6 +182,7 @@ public class NotificationLockscreenUserManagerImpl implements protected final Context mContext; private final Handler mMainHandler; protected final SparseArray<UserInfo> mCurrentProfiles = new SparseArray<>(); + protected final ArrayList<UserInfo> mCurrentManagedProfiles = new ArrayList<>(); protected int mCurrentUserId = 0; protected NotificationPresenter mPresenter; @@ -300,7 +302,7 @@ public class NotificationLockscreenUserManagerImpl implements } public boolean isCurrentProfile(int userId) { - synchronized (mCurrentProfiles) { + synchronized (mLock) { return userId == UserHandle.USER_ALL || mCurrentProfiles.get(userId) != null; } } @@ -417,6 +419,20 @@ public class NotificationLockscreenUserManagerImpl implements return mUsersAllowingPrivateNotifications.get(userHandle); } + /** + * If all managed profiles (work profiles) can show private data in public (secure & locked.) + */ + public boolean allowsManagedPrivateNotificationsInPublic() { + synchronized (mLock) { + for (UserInfo profile : mCurrentManagedProfiles) { + if (!userAllowsPrivateNotificationsInPublic(profile.id)) { + return false; + } + } + } + return true; + } + private boolean adminAllowsKeyguardFeature(int userHandle, int feature) { if (userHandle == UserHandle.USER_ALL) { return true; @@ -495,11 +511,15 @@ public class NotificationLockscreenUserManagerImpl implements } private void updateCurrentProfilesCache() { - synchronized (mCurrentProfiles) { + synchronized (mLock) { mCurrentProfiles.clear(); + mCurrentManagedProfiles.clear(); if (mUserManager != null) { for (UserInfo user : mUserManager.getProfiles(mCurrentUserId)) { mCurrentProfiles.put(user.id, user); + if (UserManager.USER_TYPE_PROFILE_MANAGED.equals(user.userType)) { + mCurrentManagedProfiles.add(user); + } } } } @@ -510,10 +530,29 @@ public class NotificationLockscreenUserManagerImpl implements }); } + /** + * If any of the profiles are in public mode. + */ public boolean isAnyProfilePublicMode() { - for (int i = mCurrentProfiles.size() - 1; i >= 0; i--) { - if (isLockscreenPublicMode(mCurrentProfiles.valueAt(i).id)) { - return true; + synchronized (mLock) { + for (int i = mCurrentProfiles.size() - 1; i >= 0; i--) { + if (isLockscreenPublicMode(mCurrentProfiles.valueAt(i).id)) { + return true; + } + } + } + return false; + } + + /** + * If any managed/work profiles are in public mode. + */ + public boolean isAnyManagedProfilePublicMode() { + synchronized (mLock) { + for (int i = mCurrentManagedProfiles.size() - 1; i >= 0; i--) { + if (isLockscreenPublicMode(mCurrentManagedProfiles.get(i).id)) { + return true; + } } } return false; @@ -620,9 +659,17 @@ public class NotificationLockscreenUserManagerImpl implements pw.print(" mAllowLockscreenRemoteInput="); pw.println(mAllowLockscreenRemoteInput); pw.print(" mCurrentProfiles="); - for (int i = mCurrentProfiles.size() - 1; i >= 0; i--) { - final int userId = mCurrentProfiles.valueAt(i).id; - pw.print("" + userId + " "); + synchronized (mLock) { + for (int i = mCurrentProfiles.size() - 1; i >= 0; i--) { + final int userId = mCurrentProfiles.valueAt(i).id; + pw.print("" + userId + " "); + } + } + pw.print(" mCurrentManagedProfiles="); + synchronized (mLock) { + for (UserInfo userInfo : mCurrentManagedProfiles) { + pw.print("" + userInfo.id + " "); + } } pw.println(); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBypassController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBypassController.kt index ad1aa8370495..b4d0d479ff39 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBypassController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBypassController.kt @@ -33,7 +33,7 @@ import javax.inject.Inject import javax.inject.Singleton @Singleton -class KeyguardBypassController : Dumpable { +open class KeyguardBypassController : Dumpable { private val mKeyguardStateController: KeyguardStateController private val statusBarStateController: StatusBarStateController diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index 4e8442f14dba..1726b4884aff 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -144,7 +144,6 @@ import com.android.systemui.dagger.qualifiers.UiBackground; import com.android.systemui.fragments.ExtensionFragmentListener; import com.android.systemui.fragments.FragmentHostManager; import com.android.systemui.keyguard.DismissCallbackRegistry; -import com.android.systemui.keyguard.KeyguardSliceProvider; import com.android.systemui.keyguard.KeyguardViewMediator; import com.android.systemui.keyguard.ScreenLifecycle; import com.android.systemui.keyguard.WakefulnessLifecycle; @@ -794,13 +793,6 @@ public class StatusBar extends SystemUI implements DemoMode, mBypassHeadsUpNotifier.setUp(mEntryManager); mBubbleController.setExpandListener(mBubbleExpandListener); mActivityIntentHelper = new ActivityIntentHelper(mContext); - KeyguardSliceProvider sliceProvider = KeyguardSliceProvider.getAttachedInstance(); - if (sliceProvider != null) { - sliceProvider.initDependencies(mMediaManager, mStatusBarStateController, - mKeyguardBypassController, mDozeParameters); - } else { - Log.w(TAG, "Cannot init KeyguardSliceProvider dependencies"); - } mColorExtractor.addOnColorsChangedListener(this); mStatusBarStateController.addCallback(this, diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java index c9b6790166e3..92c1d7601106 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardSliceProviderTest.java @@ -51,6 +51,7 @@ import com.android.systemui.statusbar.NotificationMediaManager; import com.android.systemui.statusbar.StatusBarState; import com.android.systemui.statusbar.phone.DozeParameters; import com.android.systemui.statusbar.phone.KeyguardBypassController; +import com.android.systemui.statusbar.policy.NextAlarmController; import com.android.systemui.statusbar.policy.ZenModeController; import com.android.systemui.util.wakelock.SettableWakeLock; @@ -87,6 +88,8 @@ public class KeyguardSliceProviderTest extends SysuiTestCase { private SettableWakeLock mMediaWakeLock; @Mock private DozeParameters mDozeParameters; + @Mock + private NextAlarmController mNextAlarmController; private KeyguardUpdateMonitor mKeyguardUpdateMonitor; private TestableKeyguardSliceProvider mProvider; private boolean mIsZenMode; @@ -97,9 +100,9 @@ public class KeyguardSliceProviderTest extends SysuiTestCase { mKeyguardUpdateMonitor = mDependency.injectMockDependency(KeyguardUpdateMonitor.class); mIsZenMode = false; mProvider = new TestableKeyguardSliceProvider(); + mProvider.setContextAvailableCallback(context -> { }); mProvider.attachInfo(getContext(), null); - mProvider.initDependencies(mNotificationMediaManager, mStatusBarStateController, - mKeyguardBypassController, mDozeParameters); + reset(mContentResolver); SliceProvider.setSpecs(new HashSet<>(Arrays.asList(SliceSpecs.LIST))); } @@ -254,13 +257,16 @@ public class KeyguardSliceProviderTest extends SysuiTestCase { } @Override - public boolean onCreateSliceProvider() { - super.onCreateSliceProvider(); + protected void inject() { mAlarmManager = KeyguardSliceProviderTest.this.mAlarmManager; mContentResolver = KeyguardSliceProviderTest.this.mContentResolver; mZenModeController = KeyguardSliceProviderTest.this.mZenModeController; mMediaWakeLock = KeyguardSliceProviderTest.this.mMediaWakeLock; - return true; + mDozeParameters = KeyguardSliceProviderTest.this.mDozeParameters; + mNextAlarmController = KeyguardSliceProviderTest.this.mNextAlarmController; + mStatusBarStateController = KeyguardSliceProviderTest.this.mStatusBarStateController; + mKeyguardBypassController = KeyguardSliceProviderTest.this.mKeyguardBypassController; + mMediaManager = KeyguardSliceProviderTest.this.mNotificationMediaManager; } @Override diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java index 3a6accea2b54..c6d57e6df028 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java @@ -95,7 +95,9 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase { @Mock private KeyguardStateController mKeyguardStateController; - private int mCurrentUserId; + private UserInfo mCurrentUser; + private UserInfo mSecondaryUser; + private UserInfo mWorkUser; private TestNotificationLockscreenUserManager mLockscreenUserManager; @Before @@ -103,10 +105,14 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase { MockitoAnnotations.initMocks(this); mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager); - mCurrentUserId = ActivityManager.getCurrentUser(); + int currentUserId = ActivityManager.getCurrentUser(); + mCurrentUser = new UserInfo(currentUserId, "", 0); + mSecondaryUser = new UserInfo(currentUserId + 1, "", 0); + mWorkUser = new UserInfo(currentUserId + 2, "" /* name */, null /* iconPath */, 0, + UserManager.USER_TYPE_PROFILE_MANAGED); - when(mUserManager.getProfiles(mCurrentUserId)).thenReturn(Lists.newArrayList( - new UserInfo(mCurrentUserId, "", 0), new UserInfo(mCurrentUserId + 1, "", 0))); + when(mUserManager.getProfiles(currentUserId)).thenReturn(Lists.newArrayList( + mCurrentUser, mSecondaryUser, mWorkUser)); mDependency.injectTestDependency(Dependency.MAIN_HANDLER, Handler.createAsync(Looper.myLooper())); @@ -141,15 +147,31 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase { Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1); mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false); - assertTrue(mLockscreenUserManager.userAllowsPrivateNotificationsInPublic(mCurrentUserId)); + assertTrue(mLockscreenUserManager.userAllowsPrivateNotificationsInPublic(mCurrentUser.id)); } @Test public void testLockScreenAllowPrivateNotificationsFalse() { - Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0); + Settings.Secure.putIntForUser(mContext.getContentResolver(), + Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0, mCurrentUser.id); + mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false); + assertFalse(mLockscreenUserManager.userAllowsNotificationsInPublic(mCurrentUser.id)); + } + + @Test + public void testLockScreenAllowsWorkPrivateNotificationsFalse() { + Settings.Secure.putIntForUser(mContext.getContentResolver(), + Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0, mWorkUser.id); + mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false); + assertFalse(mLockscreenUserManager.allowsManagedPrivateNotificationsInPublic()); + } + + @Test + public void testLockScreenAllowsWorkPrivateNotificationsTrue() { + Settings.Secure.putIntForUser(mContext.getContentResolver(), + Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, mWorkUser.id); mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false); - assertFalse(mLockscreenUserManager.userAllowsPrivateNotificationsInPublic(mCurrentUserId)); + assertTrue(mLockscreenUserManager.allowsManagedPrivateNotificationsInPublic()); } @Test @@ -163,16 +185,16 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase { public void testActionUserSwitchedCallsOnUserSwitched() { Intent intent = new Intent() .setAction(ACTION_USER_SWITCHED) - .putExtra(Intent.EXTRA_USER_HANDLE, mCurrentUserId + 1); + .putExtra(Intent.EXTRA_USER_HANDLE, mSecondaryUser.id); mLockscreenUserManager.getBaseBroadcastReceiverForTest().onReceive(mContext, intent); - verify(mPresenter, times(1)).onUserSwitched(mCurrentUserId + 1); + verify(mPresenter, times(1)).onUserSwitched(mSecondaryUser.id); } @Test public void testIsLockscreenPublicMode() { - assertFalse(mLockscreenUserManager.isLockscreenPublicMode(mCurrentUserId)); - mLockscreenUserManager.setLockscreenPublicMode(true, mCurrentUserId); - assertTrue(mLockscreenUserManager.isLockscreenPublicMode(mCurrentUserId)); + assertFalse(mLockscreenUserManager.isLockscreenPublicMode(mCurrentUser.id)); + mLockscreenUserManager.setLockscreenPublicMode(true, mCurrentUser.id); + assertTrue(mLockscreenUserManager.isLockscreenPublicMode(mCurrentUser.id)); } @Test |