Merge "Allow notifications to be hidden from lockscreen at a package level." into nyc-dev
am: c523dc1ff9
* commit 'c523dc1ff9454bd8cd8fc9b00c39ea02409f93c4':
Allow notifications to be hidden from lockscreen at a package level.
This commit is contained in:
@@ -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;
|
||||
@@ -1305,6 +1306,26 @@ public abstract class BaseStatusBar extends SystemUI implements
|
||||
return mLockscreenPublicMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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?
|
||||
@@ -1337,13 +1358,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 shouldHideSensitiveContents(int userid) {
|
||||
return isLockscreenPublicMode() && !userAllowsPrivateNotificationsInPublic(userid);
|
||||
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 onSecureLockScreen() {
|
||||
return isLockscreenPublicMode();
|
||||
}
|
||||
|
||||
public void onNotificationClear(StatusBarNotification notification) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user