OSDN Git Service

Differentiate between apps that use topics and those that don't.
authorJulia Reynolds <juliacr@google.com>
Fri, 18 Dec 2015 14:04:34 +0000 (09:04 -0500)
committerJulia Reynolds <juliacr@google.com>
Fri, 18 Dec 2015 20:57:43 +0000 (15:57 -0500)
Bug: 22451710
Change-Id: Idb567a4fc511a03cb999179765cfa4cbeb63dcb7

core/java/android/app/INotificationManager.aidl
core/res/res/values/strings.xml
core/res/res/values/symbols.xml
packages/SystemUI/AndroidManifest.xml
packages/SystemUI/res/layout/notification_guts.xml
packages/SystemUI/src/com/android/systemui/statusbar/NotificationGuts.java
services/core/java/com/android/server/notification/NotificationManagerService.java
services/core/java/com/android/server/notification/RankingConfig.java
services/core/java/com/android/server/notification/RankingHelper.java

index bce5bf3..abe9822 100644 (file)
@@ -55,6 +55,7 @@ interface INotificationManager
     void setTopicImportance(String pkg, int uid, in Notification.Topic topic, int importance);
     int getTopicImportance(String pkg, int uid, in Notification.Topic topic);
     void setAppImportance(String pkg, int uid, int importance);
+    boolean doesAppUseTopics(String pkg, int uid);
 
     // TODO: Remove this when callers have been migrated to the equivalent
     // INotificationListener method.
index 4843879..a127d94 100644 (file)
     <!-- [CHAR_LIMIT=NONE] Battery saver: Feature description -->
     <string name="battery_saver_description">To help improve battery life, battery saver reduces your device’s performance and limits vibration, location services, and most background data. Email, messaging, and other apps that rely on syncing may not update unless you open them.\n\nBattery saver turns off automatically when your device is charging.</string>
 
-
-    <!-- [CHAR LIMIT=100] Notification importance slider title -->
-    <string name="notification_importance_title">Importance</string>
-
-    <!-- [CHAR LIMIT=100] Notification Importance slider: blocked importance level description -->
-    <string name="notification_importance_blocked">Blocked: Never show these notifications</string>
-
-    <!-- [CHAR LIMIT=100] Notification Importance slider: low importance level description -->
-    <string name="notification_importance_low">Low: Silently show at the bottom of the notification list</string>
-
-    <!-- [CHAR LIMIT=100] Notification Importance slider: normal importance level description -->
-    <string name="notification_importance_default">Normal: Silently show these notifications</string>
-
-    <!-- [CHAR LIMIT=100] Notification Importance slider: high importance level description -->
-    <string name="notification_importance_high">High: Show at the top of the notifications list and make sound</string>
-
-    <!-- [CHAR LIMIT=100] Notification Importance slider: max importance level description -->
-    <string name="notification_importance_max">Urgent: Peek onto the screen and make sound</string>
-
     <!-- Zen mode condition - summary: time duration in minutes. [CHAR LIMIT=NONE] -->
     <plurals name="zen_mode_duration_minutes_summary">
         <item quantity="one">For one minute (until <xliff:g id="formattedTime" example="10:00 PM">%2$s</xliff:g>)</item>
index f257f14..16c610e 100644 (file)
   <java-symbol type="array" name="config_system_condition_providers" />
   <java-symbol type="string" name="muted_by" />
   <java-symbol type="string" name="zen_mode_alarm" />
-  <java-symbol type="string" name="notification_importance_blocked" />
-  <java-symbol type="string" name="notification_importance_low" />
-  <java-symbol type="string" name="notification_importance_default" />
-  <java-symbol type="string" name="notification_importance_high" />
-  <java-symbol type="string" name="notification_importance_max" />
-  <java-symbol type="string" name="notification_importance_title" />
 
   <java-symbol type="string" name="select_day" />
   <java-symbol type="string" name="select_year" />
index 02ddae6..9546c8d 100644 (file)
     <!-- Adding Quick Settings tiles -->
     <uses-permission android:name="android.permission.BIND_QUICK_SETTINGS_TILE" />
 
+    <!-- Block notifications inline notifications -->
+    <uses-permission android:name="android.permission.UPDATE_APP_OPS_STATS" />
+
     <application
         android:name=".SystemUIApplication"
         android:persistent="true"
index f15c97e..3cdee64 100644 (file)
 
         </FrameLayout>
 
-        <RadioGroup android:layout_width="wrap_content"
+        <RadioGroup
+                    android:id="@+id/apply_to"
+                    android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:paddingTop="8dp">
             <RadioButton android:id="@+id/apply_to_topic"
index 57db80a..79236be 100644 (file)
@@ -16,6 +16,7 @@
 
 package com.android.systemui.statusbar;
 
+import android.annotation.IdRes;
 import android.app.INotificationManager;
 import android.app.Notification;
 import android.content.Context;
@@ -30,6 +31,7 @@ import android.view.View;
 import android.widget.FrameLayout;
 import android.widget.LinearLayout;
 import android.widget.RadioButton;
+import android.widget.RadioGroup;
 import android.widget.SeekBar;
 import android.widget.TextView;
 
@@ -101,24 +103,51 @@ public class NotificationGuts extends LinearLayout {
                 ? new Notification.Topic(Notification.TOPIC_DEFAULT, mContext.getString(
                 com.android.internal.R.string.default_notification_topic_label))
                 : sbn.getNotification().getTopic();
+        boolean doesAppUseTopics = false;
+        try {
+            doesAppUseTopics = sINM.doesAppUseTopics(sbn.getPackageName(), sbn.getUid());
+        } catch (RemoteException e) {}
+        final boolean appUsesTopics = doesAppUseTopics;
 
         final RadioButton applyToTopic = (RadioButton) row.findViewById(R.id.apply_to_topic);
-        if (sbn.getNotification().getTopic() != null) {
-            applyToTopic.setVisibility(View.VISIBLE);
-            applyToTopic.setChecked(true);
-            applyToTopic.setText(mContext.getString(R.string.apply_to_topic, topic.getLabel()));
-            row.findViewById(R.id.apply_to_app).setVisibility(View.VISIBLE);
-        }
-
+        applyToTopic.setChecked(true);
+        final View applyToApp = row.findViewById(R.id.apply_to_app);
         final TextView topicSummary = ((TextView) row.findViewById(R.id.summary));
         final TextView topicTitle = ((TextView) row.findViewById(R.id.title));
-        SeekBar seekBar = (SeekBar) row.findViewById(R.id.seekbar);
+        final SeekBar seekBar = (SeekBar) row.findViewById(R.id.seekbar);
+        final RadioGroup applyTo = (RadioGroup) row.findViewById(R.id.apply_to);
+        applyTo.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
+            @Override
+            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
+                try {
+                    switch (checkedId) {
+                        case R.id.apply_to_topic:
+                            sINM.setTopicImportance(sbn.getPackageName(), sbn.getUid(), topic,
+                                    seekBar.getProgress());
+                            break;
+                        default:
+                            sINM.setAppImportance(sbn.getPackageName(), sbn.getUid(),
+                                    seekBar.getProgress());
+                    }
+                } catch (RemoteException e) {
+                    // :(
+                }
+            }
+        });
+
         seekBar.setMax(4);
         seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
             @Override
             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                 updateTitleAndSummary(progress);
                 if (fromUser) {
+                    if (appUsesTopics) {
+                        applyToTopic.setVisibility(View.VISIBLE);
+
+                        applyToTopic.setText(
+                                mContext.getString(R.string.apply_to_topic, topic.getLabel()));
+                        applyToApp.setVisibility(View.VISIBLE);
+                    }
                     try {
                         if (applyToTopic.isChecked()) {
                             sINM.setTopicImportance(sbn.getPackageName(), sbn.getUid(), topic,
index 0bfbd7f..8623d74 100644 (file)
@@ -1251,10 +1251,18 @@ public class NotificationManagerService extends SystemService {
         @Override
         public void setAppImportance(String pkg, int uid, int importance) {
             enforceSystemOrSystemUI("Caller not system or systemui");
+            setNotificationsEnabledForPackageImpl(pkg, uid,
+                    importance != NotificationListenerService.Ranking.IMPORTANCE_NONE);
             mRankingHelper.setAppImportance(pkg, uid, importance);
             savePolicyFile();
         }
 
+        @Override
+        public boolean doesAppUseTopics(String pkg, int uid) {
+            enforceSystemOrSystemUI("Caller not system or systemui");
+            return mRankingHelper.doesAppUseTopics(pkg, uid);
+        }
+
         /**
          * System-only API for getting a list of current (i.e. not cleared) notifications.
          *
index a6c9b0d..9b10ef2 100644 (file)
@@ -37,4 +37,6 @@ public interface RankingConfig {
     int getTopicImportance(String packageName, int uid, Notification.Topic topic);
 
     void setAppImportance(String packageName, int uid, int importance);
+
+    boolean doesAppUseTopics(String packageName, int uid);
 }
index 32c0ce2..3287f67 100644 (file)
@@ -170,6 +170,7 @@ public class RankingHelper implements RankingConfig {
                         } else {
                             r = getOrCreateRecord(name, uid);
                         }
+                        r.importance = safeInt(parser, ATT_IMPORTANCE, DEFAULT_IMPORTANCE);
 
                         // Migrate package level settings to the default topic.
                         // Might be overwritten by parseTopics.
@@ -441,6 +442,18 @@ public class RankingHelper implements RankingConfig {
         updateConfig();
     }
 
+    @Override
+    public boolean doesAppUseTopics(String pkgName, int uid) {
+        final Record r = getOrCreateRecord(pkgName, uid);
+        int numTopics = r.topics.size();
+        if (numTopics == 0
+                || (numTopics == 1 && r.topics.containsKey(Notification.TOPIC_DEFAULT))) {
+            return false;
+        } else {
+            return true;
+        }
+    }
+
     private Topic getOrCreateTopic(Record r, Notification.Topic topic) {
         if (topic == null) {
             topic = createDefaultTopic();