diff options
4 files changed, 110 insertions, 24 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java index 178838ea939d..f63e97a11430 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java @@ -194,6 +194,7 @@ public abstract class BaseStatusBar extends SystemUI implements // public mode, private notifications, etc private boolean mLockscreenPublicMode = false; private final SparseBooleanArray mUsersAllowingPrivateNotifications = new SparseBooleanArray(); + private final SparseBooleanArray mUsersAllowingNotifications = new SparseBooleanArray(); private UserManager mUserManager; private int mDensity; @@ -1302,6 +1303,26 @@ public abstract class BaseStatusBar extends SystemUI implements } /** + * Has the given user chosen to allow notifications to be shown even when the lockscreen is in + * "public" (secure & locked) mode? + */ + public boolean userAllowsNotificationsInPublic(int userHandle) { + if (userHandle == UserHandle.USER_ALL) { + return true; + } + + if (mUsersAllowingNotifications.indexOfKey(userHandle) < 0) { + final boolean allowed = 0 != Settings.Secure.getIntForUser( + mContext.getContentResolver(), + Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0, userHandle); + mUsersAllowingNotifications.append(userHandle, allowed); + return allowed; + } + + return mUsersAllowingNotifications.get(userHandle); + } + + /** * Has the given user chosen to allow their private (full) notifications to be shown even * when the lockscreen is in "public" (secure & locked) mode? */ @@ -1333,13 +1354,30 @@ public abstract class BaseStatusBar extends SystemUI implements } /** - * Returns true if we're on a secure lockscreen and the user wants to hide "sensitive" - * notification data. If so, private notifications should show their (possibly - * auto-generated) publicVersion, and secret notifications should be totally invisible. + * Returns true if we're on a secure lockscreen and the user wants to hide notification data. + * If so, notifications should be hidden. + */ + @Override // NotificationData.Environment + public boolean shouldHideNotifications(int userid) { + return isLockscreenPublicMode() && !userAllowsNotificationsInPublic(userid); + } + + /** + * Returns true if we're on a secure lockscreen and the user wants to hide notifications via + * package-specific override. + */ + @Override // NotificationDate.Environment + public boolean shouldHideNotifications(String key) { + return isLockscreenPublicMode() + && mNotificationData.getVisibilityOverride(key) == Notification.VISIBILITY_SECRET; + } + + /** + * Returns true if we're on a secure lockscreen. */ @Override // NotificationData.Environment - public boolean shouldHideSensitiveContents(int userid) { - return isLockscreenPublicMode() && !userAllowsPrivateNotificationsInPublic(userid); + public boolean onSecureLockScreen() { + return isLockscreenPublicMode(); } public void onNotificationClear(StatusBarNotification notification) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java index 7cb91279b00a..c9fe2bded106 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java @@ -353,8 +353,10 @@ public class NotificationData { return true; } - if (sbn.getNotification().visibility == Notification.VISIBILITY_SECRET && - mEnvironment.shouldHideSensitiveContents(sbn.getUserId())) { + if (mEnvironment.onSecureLockScreen() && + (sbn.getNotification().visibility == Notification.VISIBILITY_SECRET + || mEnvironment.shouldHideNotifications(sbn.getUserId()) + || mEnvironment.shouldHideNotifications(sbn.getKey()))) { return true; } @@ -433,7 +435,9 @@ public class NotificationData { * Provides access to keyguard state and user settings dependent data. */ public interface Environment { - public boolean shouldHideSensitiveContents(int userid); + public boolean onSecureLockScreen(); + public boolean shouldHideNotifications(int userid); + public boolean shouldHideNotifications(String key); public boolean isDeviceProvisioned(); public boolean isNotificationForCurrentProfiles(StatusBarNotification sbn); public String getCurrentMediaNotificationKey(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index e73994443491..c152171f77cf 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -1597,8 +1597,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, } private boolean packageHasVisibilityOverride(String key) { - return mNotificationData.getVisibilityOverride(key) - != NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE; + return mNotificationData.getVisibilityOverride(key) == Notification.VISIBILITY_PRIVATE; } private void updateClearAll() { diff --git a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java index 2a3f14340a39..0da1bb193c98 100644 --- a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java +++ b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java @@ -93,11 +93,7 @@ public class NotificationTestList extends TestActivity .setSmallIcon(R.drawable.icon2) .setContentTitle("Min priority") .setLights(0xff0000ff, 1, 0) - .setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE) - .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + - getPackageName() + "/raw/ringer")) .setPriority(Notification.PRIORITY_MIN) - .setFullScreenIntent(makeIntent2(), false) .build(); mNM.notify(7000, n); } @@ -125,11 +121,7 @@ public class NotificationTestList extends TestActivity .setSmallIcon(R.drawable.icon2) .setContentTitle("Low priority") .setLights(0xff0000ff, 1, 0) - .setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE) - .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + - getPackageName() + "/raw/ringer")) .setPriority(Notification.PRIORITY_LOW) - .setFullScreenIntent(makeIntent2(), false) .build(); mNM.notify(7002, n); } @@ -141,11 +133,7 @@ public class NotificationTestList extends TestActivity .setSmallIcon(R.drawable.icon2) .setContentTitle("Default priority") .setLights(0xff0000ff, 1, 0) - .setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE) - .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + - getPackageName() + "/raw/ringer")) .setPriority(Notification.PRIORITY_DEFAULT) - .setFullScreenIntent(makeIntent2(), false) .build(); mNM.notify(7004, n); } @@ -161,7 +149,6 @@ public class NotificationTestList extends TestActivity .setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + getPackageName() + "/raw/ringer")) .setPriority(Notification.PRIORITY_HIGH) - .setFullScreenIntent(makeIntent2(), false) .build(); mNM.notify(7006, n); } @@ -179,7 +166,7 @@ public class NotificationTestList extends TestActivity .setPriority(Notification.PRIORITY_MAX) .setFullScreenIntent(makeIntent2(), false) .build(); - mNM.notify(7008, n); + mNM.notify(7007, n); } }, new Test("Max priority with delay") { @@ -202,6 +189,64 @@ public class NotificationTestList extends TestActivity mNM.notify(7008, n); } }, + new Test("public notification") { + public void run() + { + Notification n = new Notification.Builder(NotificationTestList.this) + .setSmallIcon(R.drawable.icon2) + .setContentTitle("public notification") + .setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE) + .setPriority(Notification.PRIORITY_DEFAULT) + .setVisibility(Notification.VISIBILITY_PUBLIC) + .build(); + mNM.notify(7009, n); + } + }, + new Test("private notification, no public") { + public void run() + { + Notification n = new Notification.Builder(NotificationTestList.this) + .setSmallIcon(R.drawable.icon2) + .setContentTitle("private only notification") + .setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE) + .setPriority(Notification.PRIORITY_DEFAULT) + .setVisibility(Notification.VISIBILITY_PRIVATE) + .build(); + mNM.notify(7010, n); + } + }, + new Test("private notification, has public") { + public void run() + { + Notification n = new Notification.Builder(NotificationTestList.this) + .setSmallIcon(R.drawable.icon2) + .setContentTitle("private version of notification") + .setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE) + .setPriority(Notification.PRIORITY_DEFAULT) + .setVisibility(Notification.VISIBILITY_PRIVATE) + .setPublicVersion(new Notification.Builder(NotificationTestList.this) + .setSmallIcon(R.drawable.icon2) + .setContentTitle("public notification of private notification") + .setPriority(Notification.PRIORITY_DEFAULT) + .setVisibility(Notification.VISIBILITY_PUBLIC) + .build()) + .build(); + mNM.notify(7011, n); + } + }, + new Test("secret notification") { + public void run() + { + Notification n = new Notification.Builder(NotificationTestList.this) + .setSmallIcon(R.drawable.icon2) + .setContentTitle("secret notification") + .setDefaults(Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE) + .setPriority(Notification.PRIORITY_DEFAULT) + .setVisibility(Notification.VISIBILITY_SECRET) + .build(); + mNM.notify(7012, n); + } + }, new Test("Off") { public void run() { PowerManager pm = (PowerManager)NotificationTestList.this.getSystemService(Context.POWER_SERVICE); |