From 56131de7412edaab9f3e5834fe3888ac8588ec79 Mon Sep 17 00:00:00 2001 From: Chris Wren Date: Tue, 2 Sep 2014 17:26:17 -0400 Subject: [PATCH] Implement per-app sensitivity settings toggle. Change-Id: I0e70e6ce5c4a56d738c1850c50c2e268296d9d92 Depends-On: I2d5cf6782273744cbf9b309dec76780cc0a4c39e Bug: 16324353 --- res/xml/app_notification_settings.xml | 1 - .../notification/AppNotificationSettings.java | 14 ++++++++++- .../notification/NotificationAppList.java | 23 +++++++++++++++---- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/res/xml/app_notification_settings.xml b/res/xml/app_notification_settings.xml index 1d8ae4561a6..a65b98dbbd0 100644 --- a/res/xml/app_notification_settings.xml +++ b/res/xml/app_notification_settings.xml @@ -39,7 +39,6 @@ android:key="sensitive" android:title="@string/app_notification_sensitive_title" android:summary="@string/app_notification_sensitive_summary" - android:enabled="false" android:persistent="false" /> diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java index efa43cd033c..09271bfc31d 100644 --- a/src/com/android/settings/notification/AppNotificationSettings.java +++ b/src/com/android/settings/notification/AppNotificationSettings.java @@ -136,7 +136,9 @@ public class AppNotificationSettings extends SettingsPreferenceFragment { mSensitive = (SwitchPreference) findPreference(KEY_SENSITIVE); final boolean secure = new LockPatternUtils(getActivity()).isSecure(); - if (!secure) { + final boolean enabled = getLockscreenNotificationsEnabled(); + final boolean allowPrivate = getLockscreenAllowPrivateNotifications(); + if (!secure || !enabled || !allowPrivate) { getPreferenceScreen().removePreference(mSensitive); } @@ -186,6 +188,16 @@ public class AppNotificationSettings extends SettingsPreferenceFragment { } } + private boolean getLockscreenNotificationsEnabled() { + return Settings.Secure.getInt(getContentResolver(), + Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0; + } + + private boolean getLockscreenAllowPrivateNotifications() { + return Settings.Secure.getInt(getContentResolver(), + Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0) != 0; + } + private void toastAndFinish() { Toast.makeText(mContext, R.string.app_not_found_dlg_text, Toast.LENGTH_SHORT).show(); getActivity().finish(); diff --git a/src/com/android/settings/notification/NotificationAppList.java b/src/com/android/settings/notification/NotificationAppList.java index 3879bef67e6..d6babea935b 100644 --- a/src/com/android/settings/notification/NotificationAppList.java +++ b/src/com/android/settings/notification/NotificationAppList.java @@ -557,13 +557,28 @@ public class NotificationAppList extends PinnedHeaderListFragment } public boolean getSensitive(String pkg, int uid) { - // TODO get visibility state from NoMan - return false; + INotificationManager nm = INotificationManager.Stub.asInterface( + ServiceManager.getService(Context.NOTIFICATION_SERVICE)); + try { + return nm.getPackageVisibility(pkg, uid) == Notification.VISIBILITY_PRIVATE; + } catch (Exception e) { + Log.w(TAG, "Error calling NoMan", e); + return false; + } } public boolean setSensitive(String pkg, int uid, boolean sensitive) { - // TODO save visibility state to NoMan - return true; + INotificationManager nm = INotificationManager.Stub.asInterface( + ServiceManager.getService(Context.NOTIFICATION_SERVICE)); + try { + nm.setPackageVisibility(pkg, uid, + sensitive ? Notification.VISIBILITY_PRIVATE + : Notification.VISIBILITY_NO_OVERRIDE); + return true; + } catch (Exception e) { + Log.w(TAG, "Error calling NoMan", e); + return false; + } } } }