OSDN Git Service

Support showing notifications as badges.
authorJulia Reynolds <juliacr@google.com>
Fri, 16 Dec 2016 20:51:59 +0000 (15:51 -0500)
committerJulia Reynolds <juliacr@google.com>
Tue, 20 Dec 2016 18:07:04 +0000 (13:07 -0500)
And remove unneeded app level settings.

Change-Id: I88f506b0704195181d1748a3135f8ee0f39b774f
Test: manual for now. will add tests when have real mocks for the pages

res/values/strings.xml
res/xml/app_notification_settings.xml
res/xml/channel_notification_settings.xml
src/com/android/settings/applications/AppStateNotificationBridge.java
src/com/android/settings/applications/InstalledAppDetails.java
src/com/android/settings/applications/ManageApplications.java
src/com/android/settings/notification/AppNotificationSettings.java
src/com/android/settings/notification/ChannelNotificationSettings.java
src/com/android/settings/notification/ImportanceSeekBarPreference.java [deleted file]
src/com/android/settings/notification/NotificationBackend.java
src/com/android/settings/notification/NotificationSettingsBase.java

index a5248f6..c8f0baf 100644 (file)
     <string name="notification_importance_none">Not set</string>
 
     <!-- [CHAR LIMIT=100] Notification Importance slider: blocked importance level description -->
-    <string name="notification_importance_blocked">Never show notifications from this app</string>
+    <string name="notification_importance_blocked">Never show notifications</string>
 
     <!-- [CHAR LIMIT=100] Notification Importance slider: min importance level description -->
-    <string name="notification_importance_min">No full screen interruption, peeking, sound, or vibration. Show at the bottom of the notification list. Hide from lock screen and status bar.</string>
+    <string name="notification_importance_min">No sound or visual interruption</string>
 
     <!-- [CHAR LIMIT=100] Notification Importance slider: low importance level description -->
-    <string name="notification_importance_low">No full screen interruption, peeking, sound, or vibration.</string>
+    <string name="notification_importance_low">Show silently</string>
 
     <!-- [CHAR LIMIT=100] Notification Importance slider: normal importance level description -->
-    <string name="notification_importance_default">No full screen interruption or peeking.</string>
+    <string name="notification_importance_default">Make sound</string>
 
     <!-- [CHAR LIMIT=100] Notification Importance slider: high importance level description -->
-    <string name="notification_importance_high">Always peek. No full screen interruption.</string>
-
-    <!-- [CHAR LIMIT=100] Notification Importance slider: max importance level description -->
-    <string name="notification_importance_max">Always peek, and allow full screen interruption. Show at the top of the notification list.</string>
-
-    <!-- [CHAR LIMIT=100] Notification Importance slider: max importance level description -->
-    <string name="notification_importance_unspecified">App determines importance for each notification</string>
+    <string name="notification_importance_high">Make sound and pop on screen</string>
 
     <!-- [CHAR LIMIT=60] Notification importance reset button -->
     <string name="importance_reset">Reset</string>
     <string name="app_notification_block_title">Block all</string>
 
     <!-- [CHAR LIMIT=NONE] App notification settings: Block option description-->
-    <string name="app_notification_block_summary">Never show notifications from this app</string>
+    <string name="app_notification_block_summary">Never show these notifications</string>
 
     <!-- [CHAR LIMIT=NONE] Channel notification settings: Block option title -->
-    <string name="channel_notification_block_title">Block all</string>
+    <string name="notification_content_block_title">Show notifications</string>
 
     <!-- [CHAR LIMIT=NONE] Channel notification settings: Block option description-->
-    <string name="channel_notification_block_summary">Never show notifications from this channel</string>
+    <string name="notification_content_block_summary">Never show notifications in the shade or on peripheral devices</string>
+
+    <!-- [CHAR LIMIT=NONE] Channel notification settings: Badging option title -->
+    <string name="notification_badge_title">Show badge</string>
+
+    <!-- [CHAR LIMIT=NONE] Channel notification settings: Badge option description-->
+    <string name="notification_badge_summary">Show notifications as badges on the Home app, if supported.</string>
 
     <!-- [CHAR LIMIT=NONE] App notification settings: Override DND option title -->
     <string name="app_notification_override_dnd_title">Override Do Not Disturb</string>
     <!-- [CHAR LIMIT=NONE] App notification settings: Visibility override option title -->
     <string name="app_notification_visibility_override_title">On the lock screen</string>
 
-    <!-- [CHAR LIMIT=20] Notification settings: App notifications row summary when banned -->
+    <!-- [CHAR LIMIT=20] Notification settings: App notifications row summary when allowed -->
     <string name="app_notification_row_banned">Blocked</string>
 
     <!-- [CHAR LIMIT=40] Notification settings: App notifications row summary when high priority -->
     <string name="filter_notif_blocked_apps">Blocked</string>
     <!-- Label for showing apps with domain URLs (data URI with http or https) in list [CHAR LIMIT=30] -->
     <string name="filter_with_domain_urls_apps">With domain URLs</string>
-    <!-- Label for showing apps with priority notifications in list [CHAR LIMIT=50] -->
-    <string name="filter_notif_priority_apps">Overrides Do Not Disturb</string>
-    <!-- Label for showing apps redacting sensitive notifications in list [CHAR LIMIT=50] -->
-    <string name="filter_notif_sensitive_apps">No sensitive content on lock screen</string>
-    <!-- Label for showing apps hiding notifications from lockscreen [CHAR LIMIT=50] -->
-    <string name="filter_notif_hide_notifications_apps">Never shown on lock screen</string>
-    <!-- Filter label for apps that the user has silenced [CHAR LIMIT=40] -->
-    <string name="filter_notif_silent">Shown silently</string>
 
     <!-- Title for advanced application management settings [CHAR LIMIT=30] -->
     <string name="advanced_apps">Advanced</string>
index 2b2fc31..82660dc 100644 (file)
         xmlns:settings="http://schemas.android.com/apk/res/com.android.settings"
         android:title="@string/app_notifications_title"
         android:key="app_notification_settings">
-
-    <!-- Importance -->
     <!-- Block -->
     <com.android.settingslib.RestrictedSwitchPreference
-            android:key="block"
-            android:title="@string/app_notification_block_title"
-            android:summary="@string/app_notification_block_summary"
-            android:order="2"
-            settings:useAdditionalSummary="true"
-            settings:restrictedSwitchSummary="@string/enabled_by_admin" />
-    <!-- Silent -->
-    <com.android.settingslib.RestrictedSwitchPreference
-            android:key="silent"
-            android:title="@string/show_silently"
-            android:summary="@string/show_silently_summary"
-            android:order="3"
-            settings:useAdditionalSummary="true" />
-    <!-- Slider -->
-    <com.android.settings.notification.ImportanceSeekBarPreference
-            android:key="importance"
-            android:title="@string/notification_importance_title"
-            android:order="4"/>
-
-    <!-- Visibility Override -->
-    <com.android.settings.notification.RestrictedDropDownPreference
-            android:key="visibility_override"
-            android:title="@string/app_notification_visibility_override_title"
-            android:order="5" />
-
-    <!-- Bypass DND -->
-    <com.android.settingslib.RestrictedSwitchPreference
-            android:key="bypass_dnd"
-            android:title="@string/app_notification_override_dnd_title"
-            android:summary="@string/app_notification_override_dnd_summary"
-            android:order="6"
-            settings:useAdditionalSummary="true" />
+        android:key="block"
+        android:title="@string/app_notification_block_title"
+        android:summary="@string/app_notification_block_summary"
+        android:order="2"
+        settings:useAdditionalSummary="true"
+        settings:restrictedSwitchSummary="@string/enabled_by_admin" />
 
     <PreferenceCategory
             android:key="channels"
             android:title="@string/notification_channels"
-            android:order="7" />
+            android:order="3" />
 
 </PreferenceScreen>
index de0b9c7..c2d1f73 100644 (file)
     <!-- Importance -->
     <!-- Block -->
     <com.android.settingslib.RestrictedSwitchPreference
-            android:key="block"
-            android:title="@string/channel_notification_block_title"
-            android:summary="@string/app_notification_block_summary"
-            android:order="2"
-            settings:useAdditionalSummary="true"
-            settings:restrictedSwitchSummary="@string/enabled_by_admin" />
-    <!-- Silent -->
+        android:key="block"
+        android:title="@string/app_notification_block_title"
+        android:summary="@string/app_notification_block_summary"
+        android:order="1"
+        settings:useAdditionalSummary="true"
+        settings:restrictedSwitchSummary="@string/enabled_by_admin" />
+
+    <!-- Show notification -->
     <com.android.settingslib.RestrictedSwitchPreference
-            android:key="silent"
-            android:title="@string/show_silently"
-            android:summary="@string/show_silently_summary"
-            android:order="3"
-            settings:useAdditionalSummary="true" />
-    <!-- Slider -->
-    <com.android.settings.notification.ImportanceSeekBarPreference
+        android:key="show"
+        android:title="@string/notification_content_block_title"
+        android:summary="@string/notification_content_block_summary"
+        android:order="2"
+        settings:useAdditionalSummary="true"
+        settings:restrictedSwitchSummary="@string/enabled_by_admin" />
+
+    <!-- Show badge -->
+    <com.android.settingslib.RestrictedSwitchPreference
+        android:key="badge"
+        android:title="@string/notification_badge_title"
+        android:summary="@string/notification_badge_summary"
+        android:order="3"
+        settings:useAdditionalSummary="true"
+        settings:restrictedSwitchSummary="@string/enabled_by_admin" />
+
+    <!-- Importance -->
+    <com.android.settings.notification.RestrictedDropDownPreference
             android:key="importance"
             android:title="@string/notification_importance_title"
             android:order="4"/>
index 5fff175..b0c065a 100644 (file)
@@ -81,64 +81,4 @@ public class AppStateNotificationBridge extends AppStateBaseBridge {
             return false;
         }
     };
-
-    public static final AppFilter FILTER_APP_NOTIFICATION_SILENCED = new AppFilter() {
-        @Override
-        public void init() {
-        }
-
-        @Override
-        public boolean filterApp(AppEntry info) {
-            if (info == null || info.extraInfo == null) {
-                return false;
-            }
-            AppRow row = (AppRow) info.extraInfo;
-            return row.appImportance > NotificationManager.IMPORTANCE_NONE
-                    && row.appImportance < NotificationManager.IMPORTANCE_DEFAULT;
-        }
-    };
-
-    public static final AppFilter FILTER_APP_NOTIFICATION_PRIORITY = new AppFilter() {
-        @Override
-        public void init() {
-        }
-
-        @Override
-        public boolean filterApp(AppEntry info) {
-            if (info == null || info.extraInfo == null) {
-                return false;
-            }
-            return ((AppRow) info.extraInfo).appBypassDnd;
-        }
-    };
-
-    public static final AppFilter FILTER_APP_NOTIFICATION_HIDE_SENSITIVE = new AppFilter() {
-        @Override
-        public void init() {
-        }
-
-        @Override
-        public boolean filterApp(AppEntry info) {
-            if (info == null || info.extraInfo == null) {
-                return false;
-            }
-            return ((AppRow) info.extraInfo).lockScreenSecure
-                    && ((AppRow) info.extraInfo).appVisOverride == Notification.VISIBILITY_PRIVATE;
-        }
-    };
-
-    public static final AppFilter FILTER_APP_NOTIFICATION_HIDE_ALL = new AppFilter() {
-        @Override
-        public void init() {
-        }
-
-        @Override
-        public boolean filterApp(AppEntry info) {
-            if (info == null || info.extraInfo == null) {
-                return false;
-            }
-            return ((AppRow) info.extraInfo).lockScreenSecure
-                    && ((AppRow) info.extraInfo).appVisOverride == Notification.VISIBILITY_SECRET;
-        }
-    };
 }
index 2569eac..d689ee4 100755 (executable)
@@ -1088,10 +1088,6 @@ public class InstalledAppDetails extends AppInfoBase
         return NetworkTemplate.buildTemplateEthernet();
     }
 
-    public static CharSequence getNotificationSummary(AppEntry appEntry, Context context) {
-        return getNotificationSummary(appEntry, context, new NotificationBackend());
-    }
-
     public static CharSequence getNotificationSummary(AppEntry appEntry, Context context,
             NotificationBackend backend) {
         AppRow appRow = backend.loadAppRow(context, context.getPackageManager(), appEntry.info);
@@ -1099,43 +1095,8 @@ public class InstalledAppDetails extends AppInfoBase
     }
 
     public static CharSequence getNotificationSummary(AppRow appRow, Context context) {
-        boolean showSlider = Settings.Secure.getInt(
-                context.getContentResolver(), NOTIFICATION_TUNER_SETTING, 0) == 1;
-        List<String> summaryAttributes = new ArrayList<>();
-        StringBuffer summary = new StringBuffer();
-        if (showSlider) {
-            if (appRow.appImportance != NotificationManager.IMPORTANCE_UNSPECIFIED) {
-                summaryAttributes.add(context.getString(
-                        R.string.notification_summary_level, appRow.appImportance));
-            }
-        } else {
-            if (appRow.banned) {
-                summaryAttributes.add(context.getString(R.string.notifications_disabled));
-            } else if (appRow.appImportance > NotificationManager.IMPORTANCE_NONE
-                    && appRow.appImportance < NotificationManager.IMPORTANCE_DEFAULT) {
-                summaryAttributes.add(context.getString(R.string.notifications_silenced));
-            }
-        }
-        final boolean lockscreenSecure = new LockPatternUtils(context).isSecure(
-                UserHandle.myUserId());
-        if (lockscreenSecure) {
-            if (appRow.appVisOverride == Notification.VISIBILITY_PRIVATE) {
-                summaryAttributes.add(context.getString(R.string.notifications_redacted));
-            } else if (appRow.appVisOverride == Notification.VISIBILITY_SECRET) {
-                summaryAttributes.add(context.getString(R.string.notifications_hidden));
-            }
-        }
-        if (appRow.appBypassDnd) {
-            summaryAttributes.add(context.getString(R.string.notifications_priority));
-        }
-        final int N = summaryAttributes.size();
-        for (int i = 0; i < N; i++) {
-            if (i > 0) {
-                summary.append(context.getString(R.string.notifications_summary_divider));
-            }
-            summary.append(summaryAttributes.get(i));
-        }
-        return summary.toString();
+        // TODO: implement summary when it is known what it should say
+        return "";
     }
 
     @Override
index 099d30e..d8ee6b7 100644 (file)
@@ -131,15 +131,11 @@ public class ManageApplications extends InstrumentedPreferenceFragment
     public static final int FILTER_APPS_ENABLED = 3;
     public static final int FILTER_APPS_DISABLED = 4;
     public static final int FILTER_APPS_BLOCKED = 5;
-    public static final int FILTER_APPS_SILENT = 6;
-    public static final int FILTER_APPS_SENSITIVE = 7;
-    public static final int FILTER_APPS_HIDE_NOTIFICATIONS = 8;
-    public static final int FILTER_APPS_PRIORITY = 9;
-    public static final int FILTER_APPS_PERSONAL = 10;
-    public static final int FILTER_APPS_WORK = 11;
-    public static final int FILTER_APPS_USAGE_ACCESS = 13;
-    public static final int FILTER_APPS_WITH_OVERLAY = 14;
-    public static final int FILTER_APPS_WRITE_SETTINGS = 15;
+    public static final int FILTER_APPS_PERSONAL = 6;
+    public static final int FILTER_APPS_WORK = 7;
+    public static final int FILTER_APPS_USAGE_ACCESS = 8;
+    public static final int FILTER_APPS_WITH_OVERLAY = 9;
+    public static final int FILTER_APPS_WRITE_SETTINGS = 10;
 
     // This is the string labels for the filter modes above, the order must be kept in sync.
     public static final int[] FILTER_LABELS = new int[]{
@@ -149,10 +145,6 @@ public class ManageApplications extends InstrumentedPreferenceFragment
             R.string.filter_enabled_apps,  // Enabled
             R.string.filter_apps_disabled, // Disabled
             R.string.filter_notif_blocked_apps,   // Blocked Notifications
-            R.string.filter_notif_silent,    // Silenced Notifications
-            R.string.filter_notif_sensitive_apps, // Sensitive Notifications
-            R.string.filter_notif_hide_notifications_apps, // Sensitive Notifications
-            R.string.filter_notif_priority_apps,  // Priority Notifications
             R.string.filter_personal_apps, // Personal
             R.string.filter_work_apps,     // Work
             R.string.filter_with_domain_urls_apps,     // Domain URLs
@@ -171,10 +163,6 @@ public class ManageApplications extends InstrumentedPreferenceFragment
             ApplicationsState.FILTER_ALL_ENABLED, // Enabled
             ApplicationsState.FILTER_DISABLED,    // Disabled
             AppStateNotificationBridge.FILTER_APP_NOTIFICATION_BLOCKED,   // Blocked Notifications
-            AppStateNotificationBridge.FILTER_APP_NOTIFICATION_SILENCED,   // Silenced Notifications
-            AppStateNotificationBridge.FILTER_APP_NOTIFICATION_HIDE_SENSITIVE, // Sensitive Notifications
-            AppStateNotificationBridge.FILTER_APP_NOTIFICATION_HIDE_ALL, // Hide all Notifications
-            AppStateNotificationBridge.FILTER_APP_NOTIFICATION_PRIORITY,  // Priority Notifications
             ApplicationsState.FILTER_PERSONAL,    // Personal
             ApplicationsState.FILTER_WORK,        // Work
             ApplicationsState.FILTER_WITH_DOMAIN_URLS,   // Apps with Domain URLs
@@ -356,10 +344,6 @@ public class ManageApplications extends InstrumentedPreferenceFragment
         }
         if (mListType == LIST_TYPE_NOTIFICATION) {
             mFilterAdapter.enableFilter(FILTER_APPS_BLOCKED);
-            mFilterAdapter.enableFilter(FILTER_APPS_SILENT);
-            mFilterAdapter.enableFilter(FILTER_APPS_SENSITIVE);
-            mFilterAdapter.enableFilter(FILTER_APPS_HIDE_NOTIFICATIONS);
-            mFilterAdapter.enableFilter(FILTER_APPS_PRIORITY);
         }
         if (mListType == LIST_TYPE_HIGH_POWER) {
             mFilterAdapter.enableFilter(FILTER_APPS_POWER_WHITELIST_ALL);
index c38a72f..c720bb5 100644 (file)
@@ -54,12 +54,12 @@ public class AppNotificationSettings extends NotificationSettingsBase {
                 .addCategory(Notification.INTENT_CATEGORY_NOTIFICATION_PREFERENCES);
 
     private static final String KEY_CHANNELS = "channels";
+    private static final String KEY_BLOCK = "block";
 
     private DashboardFeatureProvider mDashboardFeatureProvider;
     private PreferenceCategory mChannels;
     private List<NotificationChannel> mChannelList;
 
-
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
         super.onActivityCreated(savedInstanceState);
@@ -84,28 +84,17 @@ public class AppNotificationSettings extends NotificationSettingsBase {
 
         addPreferencesFromResource(R.xml.app_notification_settings);
 
-        mImportance = (ImportanceSeekBarPreference) findPreference(KEY_IMPORTANCE);
-        mPriority =
-                (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BYPASS_DND);
-        mVisibilityOverride =
-                (RestrictedDropDownPreference) getPreferenceScreen().findPreference(
-                        KEY_VISIBILITY_OVERRIDE);
         mBlock = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BLOCK);
-        mSilent = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_SILENT);
         mChannels = (PreferenceCategory) findPreference(KEY_CHANNELS);
 
         if (mPkgInfo != null) {
+            setupBlock(mAppRow.systemApp, mAppRow.banned);
             // load settings intent
             ArrayMap<String, AppRow> rows = new ArrayMap<String, AppRow>();
             rows.put(mAppRow.pkg, mAppRow);
             collectConfigActivities(rows);
             mChannelList = mBackend.getChannels(mPkg, mUid).getList();
 
-            setupImportancePrefs(mAppRow.systemApp, mAppRow.appImportance, mAppRow.banned,
-                    NotificationManager.IMPORTANCE_HIGH);
-            setupPriorityPref(mAppRow.appBypassDnd);
-            setupVisOverridePref(mAppRow.appVisOverride);
-
             if (mChannelList.isEmpty()) {
                 setVisible(mChannels, false);
             } else {
@@ -129,7 +118,7 @@ public class AppNotificationSettings extends NotificationSettingsBase {
                     mChannels.addPreference(channelPref);
                 }
             }
-            updateDependents(mAppRow.appImportance);
+            updateDependents(mAppRow.banned);
         }
         if (mDashboardFeatureProvider.isEnabled()) {
             final Preference pref = FeatureFactory.getFactory(activity)
@@ -148,10 +137,40 @@ public class AppNotificationSettings extends NotificationSettingsBase {
     }
 
     @Override
-    protected void updateDependents(int importance) {
-        super.updateDependents(importance);
-        setVisible(mChannels,
-                !(mChannelList.isEmpty() || importance == NotificationManager.IMPORTANCE_NONE));
+    public void onResume() {
+        super.onResume();
+        if ((mUid != -1 && getPackageManager().getPackagesForUid(mUid) == null)) {
+            // App isn't around anymore, must have been removed.
+            finish();
+            return;
+        }
+        if (mBlock != null) {
+            mBlock.setDisabledByAdmin(mSuspendedAppsAdmin);
+        }
+    }
+
+    private void setupBlock(boolean notBlockable, boolean banned) {
+        if (notBlockable) {
+            setVisible(mBlock, false);
+        } else {
+            mBlock.setChecked(banned);
+            mBlock.setOnPreferenceChangeListener(
+                    new Preference.OnPreferenceChangeListener() {
+                        @Override
+                        public boolean onPreferenceChange(Preference preference,
+                                Object newValue) {
+                            final boolean blocked = (Boolean) newValue;
+                            mBackend.setNotificationsEnabledForPackage(mPkgInfo.packageName, mUid,
+                                    !blocked);
+                            updateDependents(blocked);
+                            return true;
+                        }
+                    });
+        }
+    }
+
+    private void updateDependents(boolean banned) {
+        setVisible(mChannels, !(mChannelList.isEmpty() || banned));
     }
 
     private List<ResolveInfo> queryNotificationConfigActivities() {
index 02cc436..77bf6be 100644 (file)
 
 package com.android.settings.notification;
 
+import static android.app.NotificationManager.IMPORTANCE_HIGH;
+import static android.app.NotificationManager.IMPORTANCE_LOW;
+import static android.app.NotificationManager.IMPORTANCE_MIN;
+import static android.app.NotificationManager.IMPORTANCE_NONE;
+
 import android.app.Activity;
+import android.app.Notification;
 import android.app.NotificationChannel;
 import android.app.NotificationManager;
+import android.app.admin.DevicePolicyManager;
 import android.content.Intent;
+import android.content.pm.UserInfo;
 import android.net.Uri;
 import android.os.Bundle;
+import android.os.UserHandle;
 import android.provider.Settings;
 import android.service.notification.NotificationListenerService.Ranking;
 import android.support.v7.preference.Preference;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.internal.widget.LockPatternUtils;
 import com.android.settings.AppHeader;
 import com.android.settings.R;
 import com.android.settings.RingtonePreference;
@@ -36,17 +46,26 @@ import com.android.settings.overlay.FeatureFactory;
 import com.android.settingslib.RestrictedLockUtils;
 import com.android.settingslib.RestrictedSwitchPreference;
 
+import java.util.ArrayList;
+
 public class ChannelNotificationSettings extends NotificationSettingsBase {
+    protected static final String KEY_BYPASS_DND = "bypass_dnd";
+    protected static final String KEY_VISIBILITY_OVERRIDE = "visibility_override";
+    protected static final String KEY_IMPORTANCE = "importance";
     protected static final String KEY_LIGHTS = "lights";
     protected static final String KEY_VIBRATE = "vibrate";
     protected static final String KEY_RINGTONE = "ringtone";
+    protected static final String KEY_SHOW = "show";
+    protected static final String KEY_BADGE = "badge";
 
     protected RestrictedSwitchPreference mLights;
     protected RestrictedSwitchPreference mVibrate;
     protected DefaultNotificationTonePreference mRingtone;
+    protected RestrictedDropDownPreference mImportance;
+    protected RestrictedSwitchPreference mPriority;
+    protected RestrictedDropDownPreference mVisibilityOverride;
 
     private DashboardFeatureProvider mDashboardFeatureProvider;
-    private int mMaxImportance;
 
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
@@ -71,34 +90,26 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
                 FeatureFactory.getFactory(activity).getDashboardFeatureProvider(activity);
         addPreferencesFromResource(R.xml.channel_notification_settings);
 
-        mImportance = (ImportanceSeekBarPreference) findPreference(KEY_IMPORTANCE);
+        mBlock = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BLOCK);
+        mShow = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_SHOW);
+        mBadge = (RestrictedSwitchPreference) getPreferenceScreen().findPreference(KEY_BADGE);
+        mImportance = (RestrictedDropDownPreference) findPreference(KEY_IMPORTANCE);
         mPriority =
                 (RestrictedSwitchPreference) findPreference(KEY_BYPASS_DND);
         mVisibilityOverride =
                 (RestrictedDropDownPreference) findPreference(KEY_VISIBILITY_OVERRIDE);
-        mBlock = (RestrictedSwitchPreference) findPreference(KEY_BLOCK);
-        mSilent = (RestrictedSwitchPreference) findPreference(KEY_SILENT);
         mLights = (RestrictedSwitchPreference) findPreference(KEY_LIGHTS);
         mVibrate = (RestrictedSwitchPreference) findPreference(KEY_VIBRATE);
         mRingtone = (DefaultNotificationTonePreference) findPreference(KEY_RINGTONE);
 
         if (mPkgInfo != null) {
             setupPriorityPref(mChannel.canBypassDnd());
-            if (mAppRow.appBypassDnd) {
-                mPriority.setShouldDisableView(true);
-            }
             setupVisOverridePref(mChannel.getLockscreenVisibility());
-            if (mAppRow.appVisOverride != Ranking.VISIBILITY_NO_OVERRIDE) {
-                mVisibilityOverride.setShouldDisableView(true);
-            }
             setupLights();
             setupVibrate();
             setupRingtone();
-            mMaxImportance = mAppRow.appImportance == NotificationManager.IMPORTANCE_UNSPECIFIED
-                    ? NotificationManager.IMPORTANCE_HIGH : mAppRow.appImportance;
-            setupImportancePrefs(false, mChannel.getImportance(),
-                    mChannel.getImportance() == NotificationManager.IMPORTANCE_NONE,
-                    mMaxImportance);
+            setupBlockAndImportance();
+            updateDependents();
         }
         if (mDashboardFeatureProvider.isEnabled()) {
             final Preference pref = FeatureFactory.getFactory(activity)
@@ -124,14 +135,14 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
             finish();
             return;
         }
-        mSuspendedAppsAdmin = RestrictedLockUtils.checkIfApplicationIsSuspended(
-                mContext, mPkg, mUserId);
-        if (mLights != null) {
-            mLights.setDisabledByAdmin(mSuspendedAppsAdmin);
-        }
-        if (mVibrate != null) {
-            mVibrate.setDisabledByAdmin(mSuspendedAppsAdmin);
-        }
+        mLights.setDisabledByAdmin(mSuspendedAppsAdmin);
+        mVibrate.setDisabledByAdmin(mSuspendedAppsAdmin);
+        mImportance.setDisabledByAdmin(mSuspendedAppsAdmin);
+        mPriority.setDisabledByAdmin(mSuspendedAppsAdmin);
+        mVisibilityOverride.setDisabledByAdmin(mSuspendedAppsAdmin);
+        mBlock.setDisabledByAdmin(mSuspendedAppsAdmin);
+        mShow.setDisabledByAdmin(mSuspendedAppsAdmin);
+        mBadge.setDisabledByAdmin(mSuspendedAppsAdmin);
     }
 
     private void setupLights() {
@@ -179,6 +190,209 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
         });
     }
 
+    protected void setupBlockAndImportance() {
+        mBlock.setDisabledByAdmin(mSuspendedAppsAdmin);
+        mBlock.setChecked(!mChannel.isAllowed());
+        mBlock.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+            @Override
+            public boolean onPreferenceChange(Preference preference, Object newValue) {
+                final boolean value = (Boolean) newValue;
+                mChannel.setAllowed(!value);
+                mChannel.lockFields(NotificationChannel.USER_LOCKED_ALLOWED);
+                mBackend.updateChannel(mPkg, mUid, mChannel);
+                updateDependents();
+                return true;
+            }
+        });
+
+        mShow.setDisabledByAdmin(mSuspendedAppsAdmin);
+        mShow.setChecked(mChannel.getImportance() != NotificationManager.IMPORTANCE_NONE);
+        mShow.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+            @Override
+            public boolean onPreferenceChange(Preference preference, Object newValue) {
+                final boolean value = (Boolean) newValue;
+                int importance = value ? IMPORTANCE_LOW : IMPORTANCE_NONE;
+                mImportance.setValue(String.valueOf(importance));
+                mChannel.setImportance(importance);
+                mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
+                mBackend.updateChannel(mPkg, mUid, mChannel);
+                updateDependents();
+                return true;
+            }
+        });
+        mBadge.setDisabledByAdmin(mSuspendedAppsAdmin);
+        mBadge.setChecked(mChannel.canShowBadge());
+        mBadge.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+            @Override
+            public boolean onPreferenceChange(Preference preference, Object newValue) {
+                final boolean value = (Boolean) newValue;
+                mChannel.setShowBadge(value);
+                mChannel.lockFields(NotificationChannel.USER_LOCKED_SHOW_BADGE);
+                mBackend.updateChannel(mPkg, mUid, mChannel);
+                return true;
+            }
+        });
+
+        mImportance.setDisabledByAdmin(mSuspendedAppsAdmin);
+        final int numImportances = IMPORTANCE_HIGH - IMPORTANCE_MIN + 1;
+        String[] summaries = new String[numImportances];
+        String[] values = new String[numImportances];
+        for (int i = 0; i < numImportances; i++) {
+            int importance = i + 1;
+            summaries[i] = getSummary(importance);
+            values[i] = String.valueOf(importance);
+        }
+        mImportance.setEntryValues(values);
+        mImportance.setEntries(summaries);
+        mImportance.setValue(String.valueOf(mChannel.getImportance()));
+        mImportance.setSummary("%s");
+
+        mImportance.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+            @Override
+            public boolean onPreferenceChange(Preference preference, Object newValue) {
+                int importance = Integer.parseInt((String) newValue);
+                mChannel.setImportance(importance);
+                mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
+                mBackend.updateChannel(mPkg, mUid, mChannel);
+                updateDependents();
+                return true;
+            }
+        });
+    }
+
+    private String getSummary(int importance) {
+        switch (importance) {
+            case NotificationManager.IMPORTANCE_NONE:
+                return getContext().getString(R.string.notification_importance_blocked);
+            case NotificationManager.IMPORTANCE_MIN:
+                return getContext().getString(R.string.notification_importance_min);
+            case NotificationManager.IMPORTANCE_LOW:
+                return getContext().getString(R.string.notification_importance_low);
+            case NotificationManager.IMPORTANCE_DEFAULT:
+                return getContext().getString(R.string.notification_importance_default);
+            case NotificationManager.IMPORTANCE_HIGH:
+            case NotificationManager.IMPORTANCE_MAX:
+            default:
+                return getContext().getString(R.string.notification_importance_high);
+        }
+    }
+
+    protected void setupPriorityPref(boolean priority) {
+        mPriority.setDisabledByAdmin(mSuspendedAppsAdmin);
+        mPriority.setChecked(priority);
+        mPriority.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+            @Override
+            public boolean onPreferenceChange(Preference preference, Object newValue) {
+                final boolean bypassZenMode = (Boolean) newValue;
+                mChannel.setBypassDnd(bypassZenMode);
+                mChannel.lockFields(NotificationChannel.USER_LOCKED_PRIORITY);
+                mBackend.updateChannel(mPkg, mUid, mChannel);
+                return true;
+            }
+        });
+    }
+
+    protected void setupVisOverridePref(int sensitive) {
+        ArrayList<CharSequence> entries = new ArrayList<>();
+        ArrayList<CharSequence> values = new ArrayList<>();
+
+        mVisibilityOverride.clearRestrictedItems();
+        if (getLockscreenNotificationsEnabled() && getLockscreenAllowPrivateNotifications()) {
+            final String summaryShowEntry =
+                    getString(R.string.lock_screen_notifications_summary_show);
+            final String summaryShowEntryValue =
+                    Integer.toString(NotificationManager.VISIBILITY_NO_OVERRIDE);
+            entries.add(summaryShowEntry);
+            values.add(summaryShowEntryValue);
+            setRestrictedIfNotificationFeaturesDisabled(summaryShowEntry, summaryShowEntryValue,
+                    DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS
+                            | DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
+        }
+
+        final String summaryHideEntry = getString(R.string.lock_screen_notifications_summary_hide);
+        final String summaryHideEntryValue = Integer.toString(Notification.VISIBILITY_PRIVATE);
+        entries.add(summaryHideEntry);
+        values.add(summaryHideEntryValue);
+        setRestrictedIfNotificationFeaturesDisabled(summaryHideEntry, summaryHideEntryValue,
+                DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
+        entries.add(getString(R.string.lock_screen_notifications_summary_disable));
+        values.add(Integer.toString(Notification.VISIBILITY_SECRET));
+        mVisibilityOverride.setEntries(entries.toArray(new CharSequence[entries.size()]));
+        mVisibilityOverride.setEntryValues(values.toArray(new CharSequence[values.size()]));
+
+        if (sensitive == Ranking.VISIBILITY_NO_OVERRIDE) {
+            mVisibilityOverride.setValue(Integer.toString(getGlobalVisibility()));
+        } else {
+            mVisibilityOverride.setValue(Integer.toString(sensitive));
+        }
+        mVisibilityOverride.setSummary("%s");
+
+        mVisibilityOverride.setOnPreferenceChangeListener(
+                new Preference.OnPreferenceChangeListener() {
+                    @Override
+                    public boolean onPreferenceChange(Preference preference, Object newValue) {
+                        int sensitive = Integer.parseInt((String) newValue);
+                        if (sensitive == getGlobalVisibility()) {
+                            sensitive = Ranking.VISIBILITY_NO_OVERRIDE;
+                        }
+                        mChannel.setLockscreenVisibility(sensitive);
+                        mChannel.lockFields(NotificationChannel.USER_LOCKED_VISIBILITY);
+                        mBackend.updateChannel(mPkg, mUid, mChannel);
+                        return true;
+                    }
+                });
+    }
+
+    private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry,
+            CharSequence entryValue, int keyguardNotificationFeatures) {
+        RestrictedLockUtils.EnforcedAdmin admin =
+                RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
+                        mContext, keyguardNotificationFeatures, mUserId);
+        if (admin != null) {
+            RestrictedDropDownPreference.RestrictedItem item =
+                    new RestrictedDropDownPreference.RestrictedItem(entry, entryValue, admin);
+            mVisibilityOverride.addRestrictedItem(item);
+        }
+    }
+
+    private int getGlobalVisibility() {
+        int globalVis = Ranking.VISIBILITY_NO_OVERRIDE;
+        if (!getLockscreenNotificationsEnabled()) {
+            globalVis = Notification.VISIBILITY_SECRET;
+        } else if (!getLockscreenAllowPrivateNotifications()) {
+            globalVis = Notification.VISIBILITY_PRIVATE;
+        }
+        return globalVis;
+    }
+
+    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 boolean isLockScreenSecure() {
+        LockPatternUtils utils = new LockPatternUtils(getActivity());
+        boolean lockscreenSecure = utils.isSecure(UserHandle.myUserId());
+        UserInfo parentUser = mUm.getProfileParent(UserHandle.myUserId());
+        if (parentUser != null){
+            lockscreenSecure |= utils.isSecure(parentUser.id);
+        }
+
+        return lockscreenSecure;
+    }
+
+    protected boolean checkCanBeVisible(int minImportanceVisible, int importance) {
+        if (importance == NotificationManager.IMPORTANCE_UNSPECIFIED) {
+            return true;
+        }
+        return importance >= minImportanceVisible;
+    }
+
     @Override
     public boolean onPreferenceTreeClick(Preference preference) {
         if (preference instanceof RingtonePreference) {
@@ -205,22 +419,24 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
                 Settings.System.NOTIFICATION_LIGHT_PULSE, 0) == 1;
     }
 
-    @Override
-    protected void updateDependents(int importance) {
-        if (importance == NotificationManager.IMPORTANCE_UNSPECIFIED) {
-            importance = mMaxImportance;
-        }
-        importance = Math.min(mMaxImportance, importance);
-
-        super.updateDependents(importance);
-        setVisible(mLights, checkCanBeVisible(
+    private void updateDependents() {
+        boolean allowed = mChannel.isAllowed();
+        int importance = mChannel.getImportance();
+        setVisible(mShow, allowed);
+        setVisible(mBadge, allowed);
+        setVisible(mImportance, allowed && importance != NotificationManager.IMPORTANCE_NONE);
+        setVisible(mLights, allowed && checkCanBeVisible(
                 NotificationManager.IMPORTANCE_LOW, importance) && canPulseLight());
-        setVisible(mVibrate, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT, importance));
-        setVisible(mRingtone, checkCanBeVisible(
+        setVisible(mVibrate, allowed
+                && checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT, importance));
+        setVisible(mRingtone, allowed && checkCanBeVisible(
                 NotificationManager.IMPORTANCE_DEFAULT, importance));
-        if (mMaxImportance == NotificationManager.IMPORTANCE_LOW
-                && getPreferenceScreen().findPreference(mBlock.getKey()) != null) {
-            setVisible(mSilent, false);
-        }
+        setVisible(mPriority, allowed
+                && (checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT, importance)
+                || (checkCanBeVisible(NotificationManager.IMPORTANCE_LOW, importance)
+                        && mDndVisualEffectsSuppressed)));
+        setVisible(mVisibilityOverride, allowed
+                && checkCanBeVisible(NotificationManager.IMPORTANCE_MIN, importance)
+                && isLockScreenSecure());
     }
 }
diff --git a/src/com/android/settings/notification/ImportanceSeekBarPreference.java b/src/com/android/settings/notification/ImportanceSeekBarPreference.java
deleted file mode 100644 (file)
index 568dc1c..0000000
+++ /dev/null
@@ -1,204 +0,0 @@
-/**
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.notification;
-
-import com.android.settings.R;
-import com.android.settings.SeekBarPreference;
-
-import android.app.NotificationManager;
-import android.content.Context;
-import android.content.res.ColorStateList;
-import android.content.res.TypedArray;
-import android.graphics.drawable.Drawable;
-import android.os.Handler;
-import android.service.notification.NotificationListenerService;
-import android.support.v7.preference.PreferenceViewHolder;
-import android.util.AttributeSet;
-import android.view.View;
-import android.widget.ImageView;
-import android.widget.SeekBar;
-import android.widget.TextView;
-import com.android.settings.Utils;
-
-/**
- * A slider preference that controls notification importance.
- **/
-public class ImportanceSeekBarPreference extends SeekBarPreference implements
-        SeekBar.OnSeekBarChangeListener {
-    private static final String TAG = "ImportanceSeekBarPref";
-
-    private Callback mCallback;
-    private int mMinProgress;
-    private TextView mSummaryTextView;
-    private String mSummary;
-    private SeekBar mSeekBar;
-    private ColorStateList mActiveSliderTint;
-    private ColorStateList mInactiveSliderTint;
-    private float mActiveSliderAlpha = 1.0f;
-    private float mInactiveSliderAlpha;
-    private boolean mAutoOn;
-    private Handler mHandler;
-
-    public ImportanceSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr,
-            int defStyleRes) {
-        super(context, attrs, defStyleAttr, defStyleRes);
-        setLayoutResource(R.layout.preference_importance_slider);
-        mActiveSliderTint = ColorStateList.valueOf(Utils.getColorAccent(context));
-        mInactiveSliderTint = ColorStateList.valueOf(
-                context.getColor(R.color.importance_disabled_slider_color));
-        mHandler = new Handler();
-        final TypedArray ta =
-                context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Theme, 0, 0);
-        mInactiveSliderAlpha =
-                ta.getFloat(com.android.internal.R.styleable.Theme_disabledAlpha, 0.5f);
-        ta.recycle();
-    }
-
-    public ImportanceSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr) {
-        this(context, attrs, defStyleAttr, 0);
-    }
-
-    public ImportanceSeekBarPreference(Context context, AttributeSet attrs) {
-        this(context, attrs, 0);
-    }
-
-    public ImportanceSeekBarPreference(Context context) {
-        this(context, null);
-    }
-
-    public void setCallback(Callback callback) {
-        mCallback = callback;
-    }
-
-    public void setMinimumProgress(int minProgress) {
-        mMinProgress = minProgress;
-        notifyChanged();
-    }
-
-    @Override
-    public void setProgress(int progress) {
-        mSummary = getProgressSummary(progress);
-        super.setProgress(progress);
-    }
-
-    public void setAutoOn(boolean autoOn) {
-        mAutoOn = autoOn;
-        notifyChanged();
-    }
-
-    @Override
-    public void onBindViewHolder(PreferenceViewHolder view) {
-        super.onBindViewHolder(view);
-        mSummaryTextView = (TextView) view.findViewById(com.android.internal.R.id.summary);
-        mSeekBar = (SeekBar) view.findViewById(
-                com.android.internal.R.id.seekbar);
-
-        final ImageView autoButton = (ImageView) view.findViewById(R.id.auto_importance);
-        applyAutoUi(autoButton);
-        autoButton.setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View v) {
-                applyAuto(autoButton);
-            }
-        });
-    }
-
-    private void applyAuto(ImageView autoButton) {
-        mAutoOn = !mAutoOn;
-        if (!mAutoOn) {
-            setProgress(NotificationManager.IMPORTANCE_DEFAULT);
-            mCallback.onImportanceChanged(NotificationManager.IMPORTANCE_DEFAULT, true);
-        } else {
-            mCallback.onImportanceChanged(NotificationManager.IMPORTANCE_UNSPECIFIED, true);
-        }
-        applyAutoUi(autoButton);
-    }
-
-    private void applyAutoUi(ImageView autoButton) {
-        mSeekBar.setEnabled(!mAutoOn);
-
-        final float alpha = mAutoOn ? mInactiveSliderAlpha : mActiveSliderAlpha;
-        final ColorStateList starTint = mAutoOn ?  mActiveSliderTint : mInactiveSliderTint;
-        Drawable icon = autoButton.getDrawable().mutate();
-        icon.setTintList(starTint);
-        autoButton.setImageDrawable(icon);
-        mSeekBar.setAlpha(alpha);
-
-        if (mAutoOn) {
-            setProgress(NotificationManager.IMPORTANCE_DEFAULT);
-            mSummary = getProgressSummary(NotificationManager.IMPORTANCE_UNSPECIFIED);
-        }
-        mSummaryTextView.setText(mSummary);
-    }
-
-    @Override
-    public CharSequence getSummary() {
-        return mSummary;
-    }
-
-    @Override
-    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
-        super.onProgressChanged(seekBar, progress, fromTouch);
-        if (progress < mMinProgress) {
-            seekBar.setProgress(mMinProgress);
-            progress = mMinProgress;
-        }
-        if (mSummaryTextView != null) {
-            mSummary = getProgressSummary(progress);
-            mSummaryTextView.setText(mSummary);
-        }
-        mCallback.onImportanceChanged(progress, fromTouch);
-    }
-
-    private String getProgressSummary(int progress) {
-        switch (progress) {
-            case NotificationManager.IMPORTANCE_NONE:
-                return getContext().getString(R.string.notification_importance_blocked);
-            case NotificationManager.IMPORTANCE_MIN:
-                return getContext().getString(R.string.notification_importance_min);
-            case NotificationManager.IMPORTANCE_LOW:
-                return getContext().getString(R.string.notification_importance_low);
-            case NotificationManager.IMPORTANCE_DEFAULT:
-                return getContext().getString(R.string.notification_importance_default);
-            case NotificationManager.IMPORTANCE_HIGH:
-            case NotificationManager.IMPORTANCE_MAX:
-                return getContext().getString(R.string.notification_importance_high);
-            default:
-                return getContext().getString(R.string.notification_importance_unspecified);
-        }
-    }
-
-    @Override
-    protected void notifyChanged() {
-        mHandler.post(mNotifyChanged);
-    }
-
-    private void postNotifyChanged() {
-        super.notifyChanged();
-    }
-
-    private final Runnable mNotifyChanged = new Runnable() {
-        @Override
-        public void run() {
-            postNotifyChanged();
-        }
-    };
-
-    public interface Callback {
-        void onImportanceChanged(int progress, boolean fromTouch);
-    }
-}
index 5d69203..4013971 100644 (file)
@@ -16,7 +16,6 @@
 package com.android.settings.notification;
 
 import android.app.INotificationManager;
-import android.app.Notification;
 import android.app.NotificationChannel;
 import android.app.NotificationManager;
 import android.content.Context;
@@ -27,11 +26,8 @@ import android.content.pm.PackageManager;
 import android.content.pm.ParceledListSlice;
 import android.graphics.drawable.Drawable;
 import android.os.ServiceManager;
-import android.os.UserHandle;
-import android.service.notification.NotificationListenerService;
 import android.util.Log;
 
-import com.android.internal.widget.LockPatternUtils;
 import com.android.settingslib.Utils;
 
 public class NotificationBackend {
@@ -52,11 +48,6 @@ public class NotificationBackend {
         }
         row.icon = app.loadIcon(pm);
         row.banned = getNotificationsBanned(row.pkg, row.uid);
-        row.appImportance = getImportance(row.pkg, row.uid);
-        row.appBypassDnd = getBypassZenMode(row.pkg, row.uid);
-        row.appVisOverride = getVisibilityOverride(row.pkg, row.uid);
-        row.lockScreenSecure = new LockPatternUtils(context).isSecure(
-                UserHandle.myUserId());
         return row;
     }
 
@@ -86,19 +77,9 @@ public class NotificationBackend {
         }
     }
 
-    public boolean getBypassZenMode(String pkg, int uid) {
+    public boolean setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled) {
         try {
-            return sINM.getPriority(pkg, uid) == Notification.PRIORITY_MAX;
-        } catch (Exception e) {
-            Log.w(TAG, "Error calling NoMan", e);
-            return false;
-        }
-    }
-
-    public boolean setBypassZenMode(String pkg, int uid, boolean bypassZen) {
-        try {
-            sINM.setPriority(pkg, uid,
-                    bypassZen ? Notification.PRIORITY_MAX : Notification.PRIORITY_DEFAULT);
+            sINM.setNotificationsEnabledForPackage(pkg, uid, enabled);
             return true;
         } catch (Exception e) {
             Log.w(TAG, "Error calling NoMan", e);
@@ -106,44 +87,6 @@ public class NotificationBackend {
         }
     }
 
-    public int getVisibilityOverride(String pkg, int uid) {
-        try {
-            return sINM.getVisibilityOverride(pkg, uid);
-        } catch (Exception e) {
-            Log.w(TAG, "Error calling NoMan", e);
-            return NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE;
-        }
-    }
-
-    public boolean setVisibilityOverride(String pkg, int uid, int override) {
-        try {
-            sINM.setVisibilityOverride(pkg, uid, override);
-            return true;
-        } catch (Exception e) {
-            Log.w(TAG, "Error calling NoMan", e);
-            return false;
-        }
-    }
-
-    public boolean setImportance(String pkg, int uid, int importance) {
-        try {
-            sINM.setImportance(pkg, uid, importance);
-            return true;
-        } catch (Exception e) {
-            Log.w(TAG, "Error calling NoMan", e);
-            return false;
-        }
-    }
-
-    public int getImportance(String pkg, int uid) {
-        try {
-            return sINM.getImportance(pkg, uid);
-        } catch (Exception e) {
-            Log.w(TAG, "Error calling NoMan", e);
-            return NotificationManager.IMPORTANCE_UNSPECIFIED;
-        }
-    }
-
     public NotificationChannel getChannel(String pkg, int uid, String channelId) {
         if (channelId == null) {
             return null;
@@ -186,10 +129,6 @@ public class NotificationBackend {
         public boolean banned;
         public boolean first;  // first app in section
         public boolean systemApp;
-        public int appImportance;
-        public boolean appBypassDnd;
-        public int appVisOverride;
-        public boolean lockScreenSecure;
     }
 
     public static class ChannelRow extends AppRow {
index 5d6f598..046c5e6 100644 (file)
@@ -51,15 +51,10 @@ import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
 abstract public class NotificationSettingsBase extends SettingsPreferenceFragment {
     private static final String TAG = "NotifiSettingsBase";
     private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
-    private static final String TUNER_SETTING = "show_importance_slider";
 
     protected static final String ARG_CHANNEL = "channel";
 
-    protected static final String KEY_BYPASS_DND = "bypass_dnd";
-    protected static final String KEY_VISIBILITY_OVERRIDE = "visibility_override";
-    protected static final String KEY_IMPORTANCE = "importance";
     protected static final String KEY_BLOCK = "block";
-    protected static final String KEY_SILENT = "silent";
 
     protected PackageManager mPm;
     protected UserManager mUm;
@@ -70,13 +65,10 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
     protected int mUserId;
     protected String mPkg;
     protected PackageInfo mPkgInfo;
-    protected ImportanceSeekBarPreference mImportance;
-    protected RestrictedSwitchPreference mPriority;
-    protected RestrictedDropDownPreference mVisibilityOverride;
     protected RestrictedSwitchPreference mBlock;
-    protected RestrictedSwitchPreference mSilent;
+    protected RestrictedSwitchPreference mShow;
+    protected RestrictedSwitchPreference mBadge;
     protected EnforcedAdmin mSuspendedAppsAdmin;
-    protected boolean mShowSlider = false;
     protected boolean mDndVisualEffectsSuppressed;
 
     protected NotificationChannel mChannel;
@@ -138,7 +130,6 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
 
         mSuspendedAppsAdmin = RestrictedLockUtils.checkIfApplicationIsSuspended(
                 mContext, mPkg, mUserId);
-        mShowSlider = Settings.Secure.getInt(getContentResolver(), TUNER_SETTING, 0) == 1;
         NotificationManager.Policy policy =
                 NotificationManager.from(mContext).getNotificationPolicy();
         mDndVisualEffectsSuppressed = policy == null ? false : policy.suppressedVisualEffects != 0;
@@ -154,237 +145,7 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
         }
         mSuspendedAppsAdmin = RestrictedLockUtils.checkIfApplicationIsSuspended(
                 mContext, mPkg, mUserId);
-        if (mImportance != null) {
-            mImportance.setDisabledByAdmin(mSuspendedAppsAdmin);
-        }
-        if (mPriority != null) {
-            mPriority.setDisabledByAdmin(mSuspendedAppsAdmin);
-        }
-        if (mBlock != null) {
-            mBlock.setDisabledByAdmin(mSuspendedAppsAdmin);
-        }
-        if (mSilent != null) {
-            mSilent.setDisabledByAdmin(mSuspendedAppsAdmin);
-        }
-        if (mVisibilityOverride != null) {
-            mVisibilityOverride.setDisabledByAdmin(mSuspendedAppsAdmin);
-        }
-    }
-
-    protected void setupImportancePrefs(boolean notBlockable, int importance, boolean banned,
-            int maxImportance) {
-        if (mShowSlider) {
-            setVisible(mBlock, false);
-            setVisible(mSilent, false);
-            mImportance.setDisabledByAdmin(mSuspendedAppsAdmin);
-            mImportance.setMinimumProgress(
-                    notBlockable ? NotificationManager.IMPORTANCE_MIN
-                            : NotificationManager.IMPORTANCE_NONE);
-            mImportance.setMax(maxImportance);
-            mImportance.setProgress(Math.min(importance, maxImportance));
-            mImportance.setAutoOn(importance == NotificationManager.IMPORTANCE_UNSPECIFIED);
-            mImportance.setCallback(new ImportanceSeekBarPreference.Callback() {
-                @Override
-                public void onImportanceChanged(int progress, boolean fromUser) {
-                    if (fromUser) {
-                        if (mChannel != null) {
-                            mChannel.setImportance(progress);
-                            mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
-                            mBackend.updateChannel(mPkg, mUid, mChannel);
-                        } else {
-                            mBackend.setImportance(mPkg, mUid, progress);
-                        }
-                    }
-                    updateDependents(progress);
-                }
-            });
-        } else {
-            setVisible(mImportance, false);
-            if (notBlockable) {
-                setVisible(mBlock, false);
-            } else {
-                mBlock.setChecked(banned);
-                mBlock.setOnPreferenceChangeListener(
-                        new Preference.OnPreferenceChangeListener() {
-                            @Override
-                            public boolean onPreferenceChange(Preference preference,
-                                    Object newValue) {
-                                final boolean blocked = (Boolean) newValue;
-                                final int importance = blocked
-                                        ? NotificationManager.IMPORTANCE_NONE
-                                        : NotificationManager.IMPORTANCE_UNSPECIFIED;
-                                if (mChannel != null) {
-                                    mChannel.setImportance(importance);
-                                    mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
-                                    mBackend.updateChannel(mPkg, mUid, mChannel);
-                                } else {
-                                    mBackend.setImportance(mPkgInfo.packageName, mUid,
-                                            importance);
-                                }
-                                updateDependents(importance);
-                                return true;
-                            }
-                        });
-            }
-            // app silenced; cannot un-silence a channel
-            if (maxImportance == NotificationManager.IMPORTANCE_LOW) {
-                setVisible(mSilent, false);
-                updateDependents(banned ? NotificationManager.IMPORTANCE_NONE
-                        : NotificationManager.IMPORTANCE_LOW);
-            } else {
-                mSilent.setChecked(importance == NotificationManager.IMPORTANCE_LOW);
-                mSilent.setOnPreferenceChangeListener(
-                        new Preference.OnPreferenceChangeListener() {
-                            @Override
-                            public boolean onPreferenceChange(Preference preference,
-                                    Object newValue) {
-                                final boolean silenced = (Boolean) newValue;
-                                final int importance = silenced
-                                        ? NotificationManager.IMPORTANCE_LOW
-                                        : NotificationManager.IMPORTANCE_UNSPECIFIED;
-                                if (mChannel != null) {
-                                    mChannel.setImportance(importance);
-                                    mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
-                                    mBackend.updateChannel(mPkg, mUid, mChannel);
-                                } else {
-                                    mBackend.setImportance(mPkgInfo.packageName, mUid,
-                                            importance);
-                                }
-                                updateDependents(importance);
-                                return true;
-                            }
-                        });
-                updateDependents(banned ? NotificationManager.IMPORTANCE_NONE : importance);
-            }
-        }
-    }
-
-    protected void setupPriorityPref(boolean priority) {
-        mPriority.setDisabledByAdmin(mSuspendedAppsAdmin);
-        mPriority.setChecked(priority);
-        mPriority.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
-            @Override
-            public boolean onPreferenceChange(Preference preference, Object newValue) {
-                final boolean bypassZenMode = (Boolean) newValue;
-                if (mChannel != null) {
-                    mChannel.setBypassDnd(bypassZenMode);
-                    mChannel.lockFields(NotificationChannel.USER_LOCKED_PRIORITY);
-                    mBackend.updateChannel(mPkg, mUid, mChannel);
-                    return true;
-                } else {
-                    return mBackend.setBypassZenMode(mPkgInfo.packageName, mUid, bypassZenMode);
-                }
-            }
-        });
-    }
-
-    protected void setupVisOverridePref(int sensitive) {
-        ArrayList<CharSequence> entries = new ArrayList<>();
-        ArrayList<CharSequence> values = new ArrayList<>();
-
-        mVisibilityOverride.clearRestrictedItems();
-        if (getLockscreenNotificationsEnabled() && getLockscreenAllowPrivateNotifications()) {
-            final String summaryShowEntry =
-                    getString(R.string.lock_screen_notifications_summary_show);
-            final String summaryShowEntryValue =
-                    Integer.toString(NotificationManager.VISIBILITY_NO_OVERRIDE);
-            entries.add(summaryShowEntry);
-            values.add(summaryShowEntryValue);
-            setRestrictedIfNotificationFeaturesDisabled(summaryShowEntry, summaryShowEntryValue,
-                    DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS
-                            | DevicePolicyManager.KEYGUARD_DISABLE_UNREDACTED_NOTIFICATIONS);
-        }
-
-        final String summaryHideEntry = getString(R.string.lock_screen_notifications_summary_hide);
-        final String summaryHideEntryValue = Integer.toString(Notification.VISIBILITY_PRIVATE);
-        entries.add(summaryHideEntry);
-        values.add(summaryHideEntryValue);
-        setRestrictedIfNotificationFeaturesDisabled(summaryHideEntry, summaryHideEntryValue,
-                DevicePolicyManager.KEYGUARD_DISABLE_SECURE_NOTIFICATIONS);
-        entries.add(getString(R.string.lock_screen_notifications_summary_disable));
-        values.add(Integer.toString(Notification.VISIBILITY_SECRET));
-        mVisibilityOverride.setEntries(entries.toArray(new CharSequence[entries.size()]));
-        mVisibilityOverride.setEntryValues(values.toArray(new CharSequence[values.size()]));
-
-        if (sensitive == Ranking.VISIBILITY_NO_OVERRIDE) {
-            mVisibilityOverride.setValue(Integer.toString(getGlobalVisibility()));
-        } else {
-            mVisibilityOverride.setValue(Integer.toString(sensitive));
-        }
-        mVisibilityOverride.setSummary("%s");
-
-        mVisibilityOverride.setOnPreferenceChangeListener(
-                new Preference.OnPreferenceChangeListener() {
-            @Override
-            public boolean onPreferenceChange(Preference preference, Object newValue) {
-                int sensitive = Integer.parseInt((String) newValue);
-                if (sensitive == getGlobalVisibility()) {
-                    sensitive = Ranking.VISIBILITY_NO_OVERRIDE;
-                }
-                if (mChannel != null) {
-                    mChannel.setLockscreenVisibility(sensitive);
-                    mChannel.lockFields(NotificationChannel.USER_LOCKED_VISIBILITY);
-                    mBackend.updateChannel(mPkg, mUid, mChannel);
-                } else {
-                    mBackend.setVisibilityOverride(mPkgInfo.packageName, mUid, sensitive);
-                }
-                return true;
-            }
-        });
-    }
-
-    private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry,
-            CharSequence entryValue, int keyguardNotificationFeatures) {
-        EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
-                mContext, keyguardNotificationFeatures, mUserId);
-        if (admin != null) {
-            RestrictedItem item = new RestrictedItem(entry, entryValue, admin);
-            mVisibilityOverride.addRestrictedItem(item);
-        }
-    }
-
-    private int getGlobalVisibility() {
-        int globalVis = Ranking.VISIBILITY_NO_OVERRIDE;
-        if (!getLockscreenNotificationsEnabled()) {
-            globalVis = Notification.VISIBILITY_SECRET;
-        } else if (!getLockscreenAllowPrivateNotifications()) {
-            globalVis = Notification.VISIBILITY_PRIVATE;
-        }
-        return globalVis;
-    }
-
-    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 boolean isLockScreenSecure() {
-        LockPatternUtils utils = new LockPatternUtils(getActivity());
-        boolean lockscreenSecure = utils.isSecure(UserHandle.myUserId());
-        UserInfo parentUser = mUm.getProfileParent(UserHandle.myUserId());
-        if (parentUser != null){
-            lockscreenSecure |= utils.isSecure(parentUser.id);
-        }
-
-        return lockscreenSecure;
-    }
-
-    protected void updateDependents(int importance) {
-        if (getPreferenceScreen().findPreference(mBlock.getKey()) != null) {
-            setVisible(mSilent, checkCanBeVisible(NotificationManager.IMPORTANCE_MIN, importance));
-            mSilent.setChecked(importance == NotificationManager.IMPORTANCE_LOW);
-        }
-        setVisible(mPriority, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT, importance)
-                || (checkCanBeVisible(NotificationManager.IMPORTANCE_LOW, importance)
-                && mDndVisualEffectsSuppressed));
-        setVisible(mVisibilityOverride,
-                checkCanBeVisible(NotificationManager.IMPORTANCE_MIN, importance)
-                        && isLockScreenSecure());
+        mBlock.setDisabledByAdmin(mSuspendedAppsAdmin);
     }
 
     protected void setVisible(Preference p, boolean visible) {
@@ -397,13 +158,6 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen
         }
     }
 
-    protected boolean checkCanBeVisible(int minImportanceVisible, int importance) {
-        if (importance == NotificationManager.IMPORTANCE_UNSPECIFIED) {
-            return true;
-        }
-        return importance >= minImportanceVisible;
-    }
-
     protected void toastAndFinish() {
         Toast.makeText(mContext, R.string.app_not_found_dlg_text, Toast.LENGTH_SHORT).show();
         getActivity().finish();