diff options
| author | 2015-12-18 09:04:34 -0500 | |
|---|---|---|
| committer | 2015-12-18 15:57:43 -0500 | |
| commit | be8fdee532cff806a7482863b7c72e907547d127 (patch) | |
| tree | 9e87e07573f01b62e916b756f0a31f37a02d4d27 | |
| parent | 87af9a03f19c5e8eb8d4aec53c320e029c873e0c (diff) | |
Differentiate between apps that use topics and those that don't.
Bug: 22451710
Change-Id: Idb567a4fc511a03cb999179765cfa4cbeb63dcb7
9 files changed, 67 insertions, 34 deletions
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index bce5bf37f0eb..abe9822e972f 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -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. diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 4843879a2dba..a127d94691eb 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -3966,25 +3966,6 @@ <!-- [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> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index f257f1455cb2..16c610ea5c23 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -2091,12 +2091,6 @@ <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" /> diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml index 02ddae6845bc..9546c8dba734 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -139,6 +139,9 @@ <!-- 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" diff --git a/packages/SystemUI/res/layout/notification_guts.xml b/packages/SystemUI/res/layout/notification_guts.xml index f15c97ef6694..3cdee640dd26 100644 --- a/packages/SystemUI/res/layout/notification_guts.xml +++ b/packages/SystemUI/res/layout/notification_guts.xml @@ -139,7 +139,9 @@ </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" diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationGuts.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationGuts.java index 57db80a0744b..79236be87e5e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationGuts.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationGuts.java @@ -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, diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 0bfbd7f5cd9f..8623d743f3ce 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -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. * diff --git a/services/core/java/com/android/server/notification/RankingConfig.java b/services/core/java/com/android/server/notification/RankingConfig.java index a6c9b0d946e2..9b10ef2f0fa3 100644 --- a/services/core/java/com/android/server/notification/RankingConfig.java +++ b/services/core/java/com/android/server/notification/RankingConfig.java @@ -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); } diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java index 32c0ce24dc20..3287f67a6b86 100644 --- a/services/core/java/com/android/server/notification/RankingHelper.java +++ b/services/core/java/com/android/server/notification/RankingHelper.java @@ -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(); |