Merge "Remove IPC from critical path" into tm-dev

This commit is contained in:
Lucas Dupin
2022-04-06 22:50:11 +00:00
committed by Android (Google) Code Review
3 changed files with 79 additions and 70 deletions

View File

@@ -60,6 +60,7 @@ import com.android.systemui.statusbar.notification.collection.notifcollection.Co
import com.android.systemui.statusbar.notification.collection.render.NotificationVisibilityProvider; import com.android.systemui.statusbar.notification.collection.render.NotificationVisibilityProvider;
import com.android.systemui.statusbar.policy.DeviceProvisionedController; import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.util.settings.SecureSettings;
import java.io.FileDescriptor; import java.io.FileDescriptor;
import java.io.PrintWriter; import java.io.PrintWriter;
@@ -84,6 +85,7 @@ public class NotificationLockscreenUserManagerImpl implements
private final DeviceProvisionedController mDeviceProvisionedController; private final DeviceProvisionedController mDeviceProvisionedController;
private final KeyguardStateController mKeyguardStateController; private final KeyguardStateController mKeyguardStateController;
private final SecureSettings mSecureSettings;
private final Object mLock = new Object(); private final Object mLock = new Object();
// Lazy // Lazy
@@ -187,6 +189,7 @@ public class NotificationLockscreenUserManagerImpl implements
protected NotificationPresenter mPresenter; protected NotificationPresenter mPresenter;
protected ContentObserver mLockscreenSettingsObserver; protected ContentObserver mLockscreenSettingsObserver;
protected ContentObserver mSettingsObserver; protected ContentObserver mSettingsObserver;
private boolean mHideSilentNotificationsOnLockscreen;
private NotificationEntryManager getEntryManager() { private NotificationEntryManager getEntryManager() {
if (mEntryManager == null) { if (mEntryManager == null) {
@@ -208,6 +211,7 @@ public class NotificationLockscreenUserManagerImpl implements
@Main Handler mainHandler, @Main Handler mainHandler,
DeviceProvisionedController deviceProvisionedController, DeviceProvisionedController deviceProvisionedController,
KeyguardStateController keyguardStateController, KeyguardStateController keyguardStateController,
SecureSettings secureSettings,
DumpManager dumpManager) { DumpManager dumpManager) {
mContext = context; mContext = context;
mMainHandler = mainHandler; mMainHandler = mainHandler;
@@ -222,6 +226,7 @@ public class NotificationLockscreenUserManagerImpl implements
mKeyguardManager = keyguardManager; mKeyguardManager = keyguardManager;
mBroadcastDispatcher = broadcastDispatcher; mBroadcastDispatcher = broadcastDispatcher;
mDeviceProvisionedController = deviceProvisionedController; mDeviceProvisionedController = deviceProvisionedController;
mSecureSettings = secureSettings;
mKeyguardStateController = keyguardStateController; mKeyguardStateController = keyguardStateController;
dumpManager.registerDumpable(this); dumpManager.registerDumpable(this);
@@ -256,12 +261,18 @@ public class NotificationLockscreenUserManagerImpl implements
}; };
mContext.getContentResolver().registerContentObserver( mContext.getContentResolver().registerContentObserver(
Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS), false, mSecureSettings.getUriFor(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS), false,
mLockscreenSettingsObserver, mLockscreenSettingsObserver,
UserHandle.USER_ALL); UserHandle.USER_ALL);
mContext.getContentResolver().registerContentObserver( mContext.getContentResolver().registerContentObserver(
Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS), mSecureSettings.getUriFor(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS),
true,
mLockscreenSettingsObserver,
UserHandle.USER_ALL);
mContext.getContentResolver().registerContentObserver(
mSecureSettings.getUriFor(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS),
true, true,
mLockscreenSettingsObserver, mLockscreenSettingsObserver,
UserHandle.USER_ALL); UserHandle.USER_ALL);
@@ -272,7 +283,7 @@ public class NotificationLockscreenUserManagerImpl implements
if (ENABLE_LOCK_SCREEN_ALLOW_REMOTE_INPUT) { if (ENABLE_LOCK_SCREEN_ALLOW_REMOTE_INPUT) {
mContext.getContentResolver().registerContentObserver( mContext.getContentResolver().registerContentObserver(
Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_ALLOW_REMOTE_INPUT), mSecureSettings.getUriFor(Settings.Secure.LOCK_SCREEN_ALLOW_REMOTE_INPUT),
false, false,
mSettingsObserver, mSettingsObserver,
UserHandle.USER_ALL); UserHandle.USER_ALL);
@@ -366,7 +377,7 @@ public class NotificationLockscreenUserManagerImpl implements
} }
} }
boolean exceedsPriorityThreshold; boolean exceedsPriorityThreshold;
if (hideSilentNotificationsOnLockscreen()) { if (mHideSilentNotificationsOnLockscreen) {
exceedsPriorityThreshold = exceedsPriorityThreshold =
entry.getBucket() == BUCKET_MEDIA_CONTROLS entry.getBucket() == BUCKET_MEDIA_CONTROLS
|| (entry.getBucket() != BUCKET_SILENT || (entry.getBucket() != BUCKET_SILENT
@@ -377,11 +388,6 @@ public class NotificationLockscreenUserManagerImpl implements
return mShowLockscreenNotifications && exceedsPriorityThreshold; return mShowLockscreenNotifications && exceedsPriorityThreshold;
} }
private boolean hideSilentNotificationsOnLockscreen() {
return whitelistIpcs(() -> Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1) == 0);
}
private void setShowLockscreenNotifications(boolean show) { private void setShowLockscreenNotifications(boolean show) {
mShowLockscreenNotifications = show; mShowLockscreenNotifications = show;
} }
@@ -391,7 +397,7 @@ public class NotificationLockscreenUserManagerImpl implements
} }
protected void updateLockscreenNotificationSetting() { protected void updateLockscreenNotificationSetting() {
final boolean show = Settings.Secure.getIntForUser(mContext.getContentResolver(), final boolean show = mSecureSettings.getIntForUser(
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
1, 1,
mCurrentUserId) != 0; mCurrentUserId) != 0;
@@ -400,10 +406,13 @@ public class NotificationLockscreenUserManagerImpl implements
final boolean allowedByDpm = (dpmFlags final boolean allowedByDpm = (dpmFlags
& DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS) == 0; & DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS) == 0;
mHideSilentNotificationsOnLockscreen = mSecureSettings.getIntForUser(
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1, mCurrentUserId) == 0;
setShowLockscreenNotifications(show && allowedByDpm); setShowLockscreenNotifications(show && allowedByDpm);
if (ENABLE_LOCK_SCREEN_ALLOW_REMOTE_INPUT) { if (ENABLE_LOCK_SCREEN_ALLOW_REMOTE_INPUT) {
final boolean remoteInput = Settings.Secure.getIntForUser(mContext.getContentResolver(), final boolean remoteInput = mSecureSettings.getIntForUser(
Settings.Secure.LOCK_SCREEN_ALLOW_REMOTE_INPUT, Settings.Secure.LOCK_SCREEN_ALLOW_REMOTE_INPUT,
0, 0,
mCurrentUserId) != 0; mCurrentUserId) != 0;
@@ -426,8 +435,7 @@ public class NotificationLockscreenUserManagerImpl implements
} }
if (mUsersAllowingPrivateNotifications.indexOfKey(userHandle) < 0) { if (mUsersAllowingPrivateNotifications.indexOfKey(userHandle) < 0) {
final boolean allowedByUser = 0 != Settings.Secure.getIntForUser( final boolean allowedByUser = 0 != mSecureSettings.getIntForUser(
mContext.getContentResolver(),
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0, userHandle); Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0, userHandle);
final boolean allowedByDpm = adminAllowsKeyguardFeature(userHandle, final boolean allowedByDpm = adminAllowsKeyguardFeature(userHandle,
DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS); DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
@@ -492,8 +500,7 @@ public class NotificationLockscreenUserManagerImpl implements
} }
if (mUsersAllowingNotifications.indexOfKey(userHandle) < 0) { if (mUsersAllowingNotifications.indexOfKey(userHandle) < 0) {
final boolean allowedByUser = 0 != Settings.Secure.getIntForUser( final boolean allowedByUser = 0 != mSecureSettings.getIntForUser(
mContext.getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0, userHandle); Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0, userHandle);
final boolean allowedByDpm = adminAllowsKeyguardFeature(userHandle, final boolean allowedByDpm = adminAllowsKeyguardFeature(userHandle,
DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS); DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);

View File

@@ -66,6 +66,7 @@ import com.android.systemui.statusbar.notification.collection.notifcollection.Co
import com.android.systemui.statusbar.notification.collection.render.NotificationVisibilityProvider; import com.android.systemui.statusbar.notification.collection.render.NotificationVisibilityProvider;
import com.android.systemui.statusbar.policy.DeviceProvisionedController; import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import com.android.systemui.statusbar.policy.KeyguardStateController; import com.android.systemui.statusbar.policy.KeyguardStateController;
import com.android.systemui.util.settings.FakeSettings;
import com.google.android.collect.Lists; import com.google.android.collect.Lists;
@@ -109,6 +110,7 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
private UserInfo mCurrentUser; private UserInfo mCurrentUser;
private UserInfo mSecondaryUser; private UserInfo mSecondaryUser;
private UserInfo mWorkUser; private UserInfo mWorkUser;
private FakeSettings mSettings;
private TestNotificationLockscreenUserManager mLockscreenUserManager; private TestNotificationLockscreenUserManager mLockscreenUserManager;
private NotificationEntry mCurrentUserNotif; private NotificationEntry mCurrentUserNotif;
private NotificationEntry mSecondaryUserNotif; private NotificationEntry mSecondaryUserNotif;
@@ -120,6 +122,8 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager); mDependency.injectTestDependency(NotificationEntryManager.class, mEntryManager);
int currentUserId = ActivityManager.getCurrentUser(); int currentUserId = ActivityManager.getCurrentUser();
mSettings = new FakeSettings();
mSettings.setUserId(ActivityManager.getCurrentUser());
mCurrentUser = new UserInfo(currentUserId, "", 0); mCurrentUser = new UserInfo(currentUserId, "", 0);
mSecondaryUser = new UserInfo(currentUserId + 1, "", 0); mSecondaryUser = new UserInfo(currentUserId + 1, "", 0);
mWorkUser = new UserInfo(currentUserId + 2, "" /* name */, null /* iconPath */, 0, mWorkUser = new UserInfo(currentUserId + 2, "" /* name */, null /* iconPath */, 0,
@@ -157,48 +161,45 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
@Test @Test
public void testLockScreenShowNotificationsFalse() { public void testLockScreenShowNotificationsFalse() {
Settings.Secure.putInt(mContext.getContentResolver(), mSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0);
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0);
mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false); mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);
assertFalse(mLockscreenUserManager.shouldShowLockscreenNotifications()); assertFalse(mLockscreenUserManager.shouldShowLockscreenNotifications());
} }
@Test @Test
public void testLockScreenShowNotificationsTrue() { public void testLockScreenShowNotificationsTrue() {
Settings.Secure.putInt(mContext.getContentResolver(), mSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1);
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1);
mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false); mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);
assertTrue(mLockscreenUserManager.shouldShowLockscreenNotifications()); assertTrue(mLockscreenUserManager.shouldShowLockscreenNotifications());
} }
@Test @Test
public void testLockScreenAllowPrivateNotificationsTrue() { public void testLockScreenAllowPrivateNotificationsTrue() {
Settings.Secure.putInt(mContext.getContentResolver(), mSettings.putInt(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1);
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1);
mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false); mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);
assertTrue(mLockscreenUserManager.userAllowsPrivateNotificationsInPublic(mCurrentUser.id)); assertTrue(mLockscreenUserManager.userAllowsPrivateNotificationsInPublic(mCurrentUser.id));
} }
@Test @Test
public void testLockScreenAllowPrivateNotificationsFalse() { public void testLockScreenAllowPrivateNotificationsFalse() {
Settings.Secure.putIntForUser(mContext.getContentResolver(), mSettings.putIntForUser(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0,
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0, mCurrentUser.id); mCurrentUser.id);
mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false); mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);
assertFalse(mLockscreenUserManager.userAllowsPrivateNotificationsInPublic(mCurrentUser.id)); assertFalse(mLockscreenUserManager.userAllowsPrivateNotificationsInPublic(mCurrentUser.id));
} }
@Test @Test
public void testLockScreenAllowsWorkPrivateNotificationsFalse() { public void testLockScreenAllowsWorkPrivateNotificationsFalse() {
Settings.Secure.putIntForUser(mContext.getContentResolver(), mSettings.putIntForUser(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0,
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0, mWorkUser.id); mWorkUser.id);
mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false); mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);
assertFalse(mLockscreenUserManager.userAllowsPrivateNotificationsInPublic(mWorkUser.id)); assertFalse(mLockscreenUserManager.userAllowsPrivateNotificationsInPublic(mWorkUser.id));
} }
@Test @Test
public void testLockScreenAllowsWorkPrivateNotificationsTrue() { public void testLockScreenAllowsWorkPrivateNotificationsTrue() {
Settings.Secure.putIntForUser(mContext.getContentResolver(), mSettings.putIntForUser(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1,
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, mWorkUser.id); mWorkUser.id);
mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false); mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);
assertTrue(mLockscreenUserManager.userAllowsPrivateNotificationsInPublic(mWorkUser.id)); assertTrue(mLockscreenUserManager.userAllowsPrivateNotificationsInPublic(mWorkUser.id));
} }
@@ -206,8 +207,8 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
@Test @Test
public void testCurrentUserPrivateNotificationsNotRedacted() { public void testCurrentUserPrivateNotificationsNotRedacted() {
// GIVEN current user doesn't allow private notifications to show // GIVEN current user doesn't allow private notifications to show
Settings.Secure.putIntForUser(mContext.getContentResolver(), mSettings.putIntForUser(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0,
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0, mCurrentUser.id); mCurrentUser.id);
mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false); mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);
// THEN current user's notification is redacted // THEN current user's notification is redacted
@@ -217,8 +218,8 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
@Test @Test
public void testCurrentUserPrivateNotificationsRedacted() { public void testCurrentUserPrivateNotificationsRedacted() {
// GIVEN current user allows private notifications to show // GIVEN current user allows private notifications to show
Settings.Secure.putIntForUser(mContext.getContentResolver(), mSettings.putIntForUser(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1,
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, mCurrentUser.id); mCurrentUser.id);
mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false); mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);
// THEN current user's notification isn't redacted // THEN current user's notification isn't redacted
@@ -228,8 +229,8 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
@Test @Test
public void testWorkPrivateNotificationsRedacted() { public void testWorkPrivateNotificationsRedacted() {
// GIVEN work profile doesn't private notifications to show // GIVEN work profile doesn't private notifications to show
Settings.Secure.putIntForUser(mContext.getContentResolver(), mSettings.putIntForUser(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0,
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0, mWorkUser.id); mWorkUser.id);
mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false); mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);
// THEN work profile notification is redacted // THEN work profile notification is redacted
@@ -239,8 +240,8 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
@Test @Test
public void testWorkPrivateNotificationsNotRedacted() { public void testWorkPrivateNotificationsNotRedacted() {
// GIVEN work profile allows private notifications to show // GIVEN work profile allows private notifications to show
Settings.Secure.putIntForUser(mContext.getContentResolver(), mSettings.putIntForUser(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1,
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, mWorkUser.id); mWorkUser.id);
mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false); mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);
// THEN work profile notification isn't redacted // THEN work profile notification isn't redacted
@@ -250,12 +251,11 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
@Test @Test
public void testWorkPrivateNotificationsNotRedacted_otherUsersRedacted() { public void testWorkPrivateNotificationsNotRedacted_otherUsersRedacted() {
// GIVEN work profile allows private notifications to show but the other users don't // GIVEN work profile allows private notifications to show but the other users don't
Settings.Secure.putIntForUser(mContext.getContentResolver(), mSettings.putIntForUser(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1,
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, mWorkUser.id); mWorkUser.id);
Settings.Secure.putIntForUser(mContext.getContentResolver(), mSettings.putIntForUser(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0,
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0, mCurrentUser.id); mCurrentUser.id);
Settings.Secure.putIntForUser(mContext.getContentResolver(), mSettings.putIntForUser(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0,
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0,
mSecondaryUser.id); mSecondaryUser.id);
mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false); mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);
@@ -270,12 +270,11 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
@Test @Test
public void testWorkProfileRedacted_otherUsersNotRedacted() { public void testWorkProfileRedacted_otherUsersNotRedacted() {
// GIVEN work profile doesn't allow private notifications to show but the other users do // GIVEN work profile doesn't allow private notifications to show but the other users do
Settings.Secure.putIntForUser(mContext.getContentResolver(), mSettings.putIntForUser(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0,
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0, mWorkUser.id); mWorkUser.id);
Settings.Secure.putIntForUser(mContext.getContentResolver(), mSettings.putIntForUser(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1,
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, mCurrentUser.id); mCurrentUser.id);
Settings.Secure.putIntForUser(mContext.getContentResolver(), mSettings.putIntForUser(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1,
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1,
mSecondaryUser.id); mSecondaryUser.id);
mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false); mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);
@@ -291,10 +290,9 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
public void testSecondaryUserNotRedacted_currentUserRedacted() { public void testSecondaryUserNotRedacted_currentUserRedacted() {
// GIVEN secondary profile allows private notifications to show but the current user // GIVEN secondary profile allows private notifications to show but the current user
// doesn't allow private notifications to show // doesn't allow private notifications to show
Settings.Secure.putIntForUser(mContext.getContentResolver(), mSettings.putIntForUser(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0,
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0, mCurrentUser.id); mCurrentUser.id);
Settings.Secure.putIntForUser(mContext.getContentResolver(), mSettings.putIntForUser(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1,
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1,
mSecondaryUser.id); mSecondaryUser.id);
mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false); mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);
@@ -328,10 +326,9 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
@Test @Test
public void testShowSilentNotifications_settingSaysShow() { public void testShowSilentNotifications_settingSaysShow() {
Settings.Secure.putInt(mContext.getContentResolver(), mSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1);
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1); mSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1);
Settings.Secure.putInt(mContext.getContentResolver(), mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1);
NotificationEntry entry = new NotificationEntryBuilder() NotificationEntry entry = new NotificationEntryBuilder()
.setImportance(IMPORTANCE_LOW) .setImportance(IMPORTANCE_LOW)
@@ -343,10 +340,9 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
@Test @Test
public void testShowSilentNotifications_settingSaysHide() { public void testShowSilentNotifications_settingSaysHide() {
Settings.Secure.putInt(mContext.getContentResolver(), mSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1);
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1); mSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0);
Settings.Secure.putInt(mContext.getContentResolver(), mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0);
final Notification notification = mock(Notification.class); final Notification notification = mock(Notification.class);
when(notification.isForegroundService()).thenReturn(true); when(notification.isForegroundService()).thenReturn(true);
@@ -360,10 +356,9 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
@Test @Test
public void testShowSilentNotificationsPeopleBucket_settingSaysHide() { public void testShowSilentNotificationsPeopleBucket_settingSaysHide() {
Settings.Secure.putInt(mContext.getContentResolver(), mSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1);
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1); mSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0);
Settings.Secure.putInt(mContext.getContentResolver(), mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0);
final Notification notification = mock(Notification.class); final Notification notification = mock(Notification.class);
when(notification.isForegroundService()).thenReturn(true); when(notification.isForegroundService()).thenReturn(true);
@@ -377,10 +372,9 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
@Test @Test
public void testShowSilentNotificationsMediaBucket_settingSaysHide() { public void testShowSilentNotificationsMediaBucket_settingSaysHide() {
Settings.Secure.putInt(mContext.getContentResolver(), mSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1);
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1); mSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0);
Settings.Secure.putInt(mContext.getContentResolver(), mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0);
final Notification notification = mock(Notification.class); final Notification notification = mock(Notification.class);
when(notification.isForegroundService()).thenReturn(true); when(notification.isForegroundService()).thenReturn(true);
@@ -396,8 +390,8 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
@Test @Test
public void testKeyguardNotificationSuppressors() { public void testKeyguardNotificationSuppressors() {
// GIVEN a notification that should be shown on the lockscreen // GIVEN a notification that should be shown on the lockscreen
Settings.Secure.putInt(mContext.getContentResolver(), mSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1);
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1); mLockscreenUserManager.getLockscreenSettingsObserverForTest().onChange(false);
final NotificationEntry entry = new NotificationEntryBuilder() final NotificationEntry entry = new NotificationEntryBuilder()
.setImportance(IMPORTANCE_HIGH) .setImportance(IMPORTANCE_HIGH)
.build(); .build();
@@ -433,6 +427,7 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
Handler.createAsync(Looper.myLooper()), Handler.createAsync(Looper.myLooper()),
mDeviceProvisionedController, mDeviceProvisionedController,
mKeyguardStateController, mKeyguardStateController,
mSettings,
mock(DumpManager.class)); mock(DumpManager.class));
} }

View File

@@ -16,6 +16,7 @@
package com.android.systemui.util.settings; package com.android.systemui.util.settings;
import android.annotation.UserIdInt;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.database.ContentObserver; import android.database.ContentObserver;
import android.net.Uri; import android.net.Uri;
@@ -34,6 +35,8 @@ public class FakeSettings implements SecureSettings, GlobalSettings, SystemSetti
private final Map<String, List<ContentObserver>> mContentObserversAllUsers = new HashMap<>(); private final Map<String, List<ContentObserver>> mContentObserversAllUsers = new HashMap<>();
public static final Uri CONTENT_URI = Uri.parse("content://settings/fake"); public static final Uri CONTENT_URI = Uri.parse("content://settings/fake");
@UserIdInt
private int mUserId = UserHandle.USER_CURRENT;
public FakeSettings() { public FakeSettings() {
} }
@@ -85,9 +88,13 @@ public class FakeSettings implements SecureSettings, GlobalSettings, SystemSetti
return Uri.withAppendedPath(CONTENT_URI, name); return Uri.withAppendedPath(CONTENT_URI, name);
} }
public void setUserId(@UserIdInt int userId) {
mUserId = userId;
}
@Override @Override
public int getUserId() { public int getUserId() {
return UserHandle.USER_CURRENT; return mUserId;
} }
@Override @Override