Merge "Implement per-app sensitivity settings toggle." into lmp-dev
diff --git a/res/xml/app_notification_settings.xml b/res/xml/app_notification_settings.xml
index 1d8ae45..a65b98d 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" />
</PreferenceScreen>
diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java
index 050008d..1dd3bdc 100644
--- a/src/com/android/settings/notification/AppNotificationSettings.java
+++ b/src/com/android/settings/notification/AppNotificationSettings.java
@@ -137,7 +137,9 @@
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);
}
@@ -193,6 +195,16 @@
}
}
+ 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 ad6956b..1f63084 100644
--- a/src/com/android/settings/notification/NotificationAppList.java
+++ b/src/com/android/settings/notification/NotificationAppList.java
@@ -41,6 +41,7 @@
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
+import android.service.notification.NotificationListenerService;
import android.util.ArrayMap;
import android.util.Log;
import android.util.TypedValue;
@@ -568,13 +569,28 @@
}
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.getPackageVisibilityOverride(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.setPackageVisibilityOverride(pkg, uid,
+ sensitive ? Notification.VISIBILITY_PRIVATE
+ : NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE);
+ return true;
+ } catch (Exception e) {
+ Log.w(TAG, "Error calling NoMan", e);
+ return false;
+ }
}
}
}