From 3fb88d743edeb7841306cbfd8745d34fbd9ec93b Mon Sep 17 00:00:00 2001 From: John Spurlock Date: Wed, 18 Mar 2015 15:33:29 -0400 Subject: [PATCH] Settings: App notification settings updates. - Tweak language. - Add new heads-up configuration setting. - Remove instead of disable settings dependent on the banhammer. Bug: 19776495 Change-Id: I3fac1a61bd66acd6db70b461e414c4e55dee9296 --- res/values/strings.xml | 16 ++-- res/xml/app_notification_settings.xml | 13 +++- .../notification/AppNotificationSettings.java | 74 ++++++++++++------- .../notification/NotificationAppList.java | 21 ++++++ 4 files changed, 92 insertions(+), 32 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 14670a7bd5e..dbe61b9b463 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -5815,22 +5815,28 @@ Loading apps... - Block + Block all Never show notifications from this app - Priority + Treat as priority - Show notifications at the top of the list and keep them coming when the device is set to priority interruptions only + Let this app\'s notifications be heard when Do not disturb is set to Priority only + + + Allow peeking + + + Let this app emphasize certain notifications by sliding them briefly into view on the current screen - Sensitive + Hide sensitive content - When the device is locked, hide any sensitive content from this app\'s notifications + When the device is locked, hide content in this app\'s notifications that might reveal private information Blocked diff --git a/res/xml/app_notification_settings.xml b/res/xml/app_notification_settings.xml index a65b98dbbd0..9aebb39c3e7 100644 --- a/res/xml/app_notification_settings.xml +++ b/res/xml/app_notification_settings.xml @@ -23,7 +23,7 @@ android:key="block" android:title="@string/app_notification_block_title" android:summary="@string/app_notification_block_summary" - android:disableDependentsState="true" + android:order="1" android:persistent="false" /> @@ -31,7 +31,15 @@ android:key="priority" android:title="@string/app_notification_priority_title" android:summary="@string/app_notification_priority_summary" - android:dependency="block" + android:order="2" + android:persistent="false" /> + + + @@ -39,6 +47,7 @@ android:key="sensitive" android:title="@string/app_notification_sensitive_title" android:summary="@string/app_notification_sensitive_summary" + android:order="4" android:persistent="false" /> diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java index bad43cc4b1e..c0fe8021a11 100644 --- a/src/com/android/settings/notification/AppNotificationSettings.java +++ b/src/com/android/settings/notification/AppNotificationSettings.java @@ -46,6 +46,7 @@ public class AppNotificationSettings extends SettingsPreferenceFragment { private static final String KEY_BLOCK = "block"; private static final String KEY_PRIORITY = "priority"; + private static final String KEY_PEEKABLE = "peekable"; private static final String KEY_SENSITIVE = "sensitive"; static final String EXTRA_HAS_SETTINGS_INTENT = "has_settings_intent"; @@ -56,9 +57,11 @@ public class AppNotificationSettings extends SettingsPreferenceFragment { private Context mContext; private SwitchPreference mBlock; private SwitchPreference mPriority; + private SwitchPreference mPeekable; private SwitchPreference mSensitive; private AppRow mAppRow; private boolean mCreated; + private boolean mIsSystemPackage; @Override public void onActivityCreated(Bundle savedInstanceState) { @@ -104,19 +107,14 @@ public class AppNotificationSettings extends SettingsPreferenceFragment { toastAndFinish(); return; } + mIsSystemPackage = Utils.isSystemPackage(pm, info); addPreferencesFromResource(R.xml.app_notification_settings); mBlock = (SwitchPreference) findPreference(KEY_BLOCK); mPriority = (SwitchPreference) findPreference(KEY_PRIORITY); + mPeekable = (SwitchPreference) findPreference(KEY_PEEKABLE); mSensitive = (SwitchPreference) findPreference(KEY_SENSITIVE); - final boolean secure = new LockPatternUtils(getActivity()).isSecure(); - final boolean enabled = getLockscreenNotificationsEnabled(); - final boolean allowPrivate = getLockscreenAllowPrivateNotifications(); - if (!secure || !enabled || !allowPrivate) { - getPreferenceScreen().removePreference(mSensitive); - } - mAppRow = NotificationAppList.loadAppRow(pm, info.applicationInfo, mBackend); if (intent.hasExtra(EXTRA_HAS_SETTINGS_INTENT)) { // use settings intent from extra @@ -131,16 +129,20 @@ public class AppNotificationSettings extends SettingsPreferenceFragment { } mBlock.setChecked(mAppRow.banned); + updateDependents(mAppRow.banned); mPriority.setChecked(mAppRow.priority); - if (mSensitive != null) { - mSensitive.setChecked(mAppRow.sensitive); - } + mPeekable.setChecked(mAppRow.peekable); + mSensitive.setChecked(mAppRow.sensitive); mBlock.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { - final boolean block = (Boolean) newValue; - return mBackend.setNotificationsBanned(pkg, uid, block); + final boolean banned = (Boolean) newValue; + final boolean success = mBackend.setNotificationsBanned(pkg, uid, banned); + if (success) { + updateDependents(banned); + } + return success; } }); @@ -152,20 +154,42 @@ public class AppNotificationSettings extends SettingsPreferenceFragment { } }); - if (mSensitive != null) { - mSensitive.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - final boolean sensitive = (Boolean) newValue; - return mBackend.setSensitive(pkg, uid, sensitive); - } - }); - } + mPeekable.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + final boolean peekable = (Boolean) newValue; + return mBackend.setPeekable(pkg, uid, peekable); + } + }); - // Users cannot block notifications from system/signature packages - if (Utils.isSystemPackage(pm, info)) { - getPreferenceScreen().removePreference(mBlock); - mPriority.setDependency(null); // don't have it depend on a preference that's gone + mSensitive.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + final boolean sensitive = (Boolean) newValue; + return mBackend.setSensitive(pkg, uid, sensitive); + } + }); + } + + private void updateDependents(boolean banned) { + final boolean lockscreenSecure = new LockPatternUtils(getActivity()).isSecure(); + final boolean lockscreenNotificationsEnabled = getLockscreenNotificationsEnabled(); + final boolean allowPrivate = getLockscreenAllowPrivateNotifications(); + + setVisible(mBlock, !mIsSystemPackage); + setVisible(mPriority, mIsSystemPackage || !banned); + setVisible(mPeekable, mIsSystemPackage || !banned); + setVisible(mSensitive, mIsSystemPackage || !banned && lockscreenSecure + && lockscreenNotificationsEnabled && allowPrivate); + } + + private void setVisible(Preference p, boolean visible) { + final boolean isVisible = getPreferenceScreen().findPreference(p.getKey()) != null; + if (isVisible == visible) return; + if (visible) { + getPreferenceScreen().addPreference(p); + } else { + getPreferenceScreen().removePreference(p); } } diff --git a/src/com/android/settings/notification/NotificationAppList.java b/src/com/android/settings/notification/NotificationAppList.java index 311ec59041d..27eb9145ec3 100644 --- a/src/com/android/settings/notification/NotificationAppList.java +++ b/src/com/android/settings/notification/NotificationAppList.java @@ -364,6 +364,7 @@ public class NotificationAppList extends PinnedHeaderListFragment public Intent settingsIntent; public boolean banned; public boolean priority; + public boolean peekable; public boolean sensitive; public boolean first; // first app in section } @@ -391,6 +392,7 @@ public class NotificationAppList extends PinnedHeaderListFragment row.icon = app.loadIcon(pm); row.banned = backend.getNotificationsBanned(row.pkg, row.uid); row.priority = backend.getHighPriority(row.pkg, row.uid); + row.peekable = backend.getPeekable(row.pkg, row.uid); row.sensitive = backend.getSensitive(row.pkg, row.uid); return row; } @@ -578,6 +580,25 @@ public class NotificationAppList extends PinnedHeaderListFragment } } + public boolean getPeekable(String pkg, int uid) { + try { + return sINM.getPackagePeekable(pkg, uid); + } catch (Exception e) { + Log.w(TAG, "Error calling NoMan", e); + return false; + } + } + + public boolean setPeekable(String pkg, int uid, boolean peekable) { + try { + sINM.setPackagePeekable(pkg, uid, peekable); + return true; + } catch (Exception e) { + Log.w(TAG, "Error calling NoMan", e); + return false; + } + } + public boolean getSensitive(String pkg, int uid) { try { return sINM.getPackageVisibilityOverride(pkg, uid) == Notification.VISIBILITY_PRIVATE;