Notification settings updates
- Footer preferences were too dim
- Fix text and target on recently sent apps
- Make 'behavior' a dialog
- reorder settings on apps page
Change-Id: Idf8056bc77ead89fe2025bbde3346861e23a3c8d
Fixes: 72652526
Fixes: 72651810
Fixes: 72652024
Bug: 72651953
Test: make RunSettingsRoboTests
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index f9e123a..1766ffb 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2645,19 +2645,6 @@
android:value="com.android.settings.notification.SoundSettings" />
</activity-alias>
- <!-- Show apps for which application-level notification settings are applicable -->
- <activity android:name="Settings$NotificationAppListActivity"
- android:label="@string/app_notifications_title"
- android:icon="@drawable/ic_notifications"
- android:exported="true"
- android:taskAffinity="">
- <intent-filter android:priority="150">
- <action android:name="com.android.settings.action.SETTINGS" />
- </intent-filter>
- <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.applications.NotificationApps" />
- </activity>
-
<!-- Show application-level notification settings (app passed in as extras) -->
<activity android:name="Settings$AppNotificationSettingsActivity"
android:exported="true">
diff --git a/res/values/strings.xml b/res/values/strings.xml
index fe32e9d..f86cc56 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -6983,6 +6983,9 @@
<!-- notification header - apps that have recently sent notifications -->
<string name="recent_notifications">Recently sent</string>
+ <!-- Preference title for showing all apps on device [CHAR_LIMIT=50]-->
+ <string name="recent_notifications_see_all_title">See all apps</string>
+
<!-- Configure Notifications: Advanced section header [CHAR LIMIT=30] -->
<string name="advanced_section_header">Advanced</string>
diff --git a/res/xml/app_notification_settings.xml b/res/xml/app_notification_settings.xml
index b21d168..2d5dc57 100644
--- a/res/xml/app_notification_settings.xml
+++ b/res/xml/app_notification_settings.xml
@@ -15,7 +15,8 @@
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:settings="http://schemas.android.com/apk/res-auto">
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ settings:initialExpandedChildrenCount="500">
<com.android.settings.applications.LayoutPreference
android:key="pref_app_header"
@@ -25,24 +26,24 @@
android:key="block"
android:layout="@layout/styled_switch_bar" />
+ <com.android.settings.notification.NotificationFooterPreference
+ android:key="block_desc" />
+
+ <!-- Channels/Channel groups added here -->
+
<!-- Show badge -->
<com.android.settingslib.RestrictedSwitchPreference
android:key="badge"
android:title="@string/notification_badge_title"
+ android:order="501"
settings:useAdditionalSummary="true"
+ settings:allowDividerAbove="true"
settings:restrictedSwitchSummary="@string/enabled_by_admin" />
- <!-- Channels/Channel groups added here -->
-
<Preference
android:key="app_link"
android:title="@string/app_settings_link"
- android:order="500"
- settings:allowDividerAbove="true"/>
-
- <com.android.settings.notification.NotificationFooterPreference
- android:key="block_desc"
- android:order="1000" />
+ android:order="502" />
<com.android.settings.notification.NotificationFooterPreference
android:key="desc"
diff --git a/res/xml/channel_notification_settings.xml b/res/xml/channel_notification_settings.xml
index 6d20571..9d0398d 100644
--- a/res/xml/channel_notification_settings.xml
+++ b/res/xml/channel_notification_settings.xml
@@ -27,7 +27,7 @@
android:layout="@layout/styled_switch_bar" />
<!-- Importance -->
- <Preference
+ <com.android.settings.RestrictedListPreference
android:key="importance"
android:title="@string/notification_importance_title" />
diff --git a/res/xml/configure_notification_settings.xml b/res/xml/configure_notification_settings.xml
index e080be4..9d72441 100644
--- a/res/xml/configure_notification_settings.xml
+++ b/res/xml/configure_notification_settings.xml
@@ -79,7 +79,7 @@
<intent
android:action="android.intent.action.MAIN"
android:targetPackage="com.android.settings"
- android:targetClass="com.android.settings.Settings$NotificationAppListActivity">
+ android:targetClass="com.android.settings.Settings$ManageApplicationsActivity">
</intent>
</Preference>
</PreferenceCategory>
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index b4908dd..7bd85cd 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -108,7 +108,6 @@
public static class ZenModeExternalRuleSettingsActivity extends SettingsActivity { /* empty */ }
public static class SoundSettingsActivity extends SettingsActivity { /* empty */ }
public static class ConfigureNotificationSettingsActivity extends SettingsActivity { /* empty */ }
- public static class NotificationAppListActivity extends SettingsActivity { /* empty */ }
public static class AppNotificationSettingsActivity extends SettingsActivity { /* empty */ }
public static class ChannelNotificationSettingsActivity extends SettingsActivity { /* empty */ }
public static class ChannelGroupNotificationSettingsActivity extends SettingsActivity { /* empty */ }
diff --git a/src/com/android/settings/applications/NotificationApps.java b/src/com/android/settings/applications/NotificationApps.java
deleted file mode 100644
index f921092..0000000
--- a/src/com/android/settings/applications/NotificationApps.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2016 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.applications;
-
-import android.app.Activity;
-import android.content.Context;
-import android.content.pm.ApplicationInfo;
-
-import com.android.settings.R;
-import com.android.settings.applications.manageapplications.ManageApplications;
-import com.android.settings.dashboard.SummaryLoader;
-import com.android.settings.notification.NotificationBackend;
-import com.android.settingslib.wrapper.PackageManagerWrapper;
-
-/**
- * Extension of ManageApplications with no changes other than having its own
- * SummaryProvider.
- */
-public class NotificationApps extends ManageApplications {
-
- public static class SummaryProvider implements SummaryLoader.SummaryProvider {
-
- private final Context mContext;
- private final SummaryLoader mLoader;
- private final NotificationBackend mNotificationBackend;
- private final PackageManagerWrapper mPackageManager;
-
- public SummaryProvider(Context context, SummaryLoader loader) {
- mContext = context;
- mLoader = loader;
- mNotificationBackend = new NotificationBackend();
- mPackageManager = new PackageManagerWrapper(mContext.getPackageManager());
- }
-
- @Override
- public void setListening(boolean listening) {
- if (listening) {
- new AppCounter(mContext, mPackageManager) {
- @Override
- protected void onCountComplete(int num) {
- updateSummary(num);
- }
-
- @Override
- protected boolean includeInCount(ApplicationInfo info) {
- return mNotificationBackend.getNotificationsBanned(info.packageName,
- info.uid);
- }
- }.execute();
- }
- }
-
- private void updateSummary(int count) {
- if (count == 0) {
- mLoader.setSummary(this, mContext.getString(R.string.notification_summary_none));
- } else {
- mLoader.setSummary(this, mContext.getResources().getQuantityString(
- R.plurals.notification_summary, count, count));
- }
- }
- }
-
- public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
- = new SummaryLoader.SummaryProviderFactory() {
- @Override
- public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
- SummaryLoader summaryLoader) {
- return new SummaryProvider(activity, summaryLoader);
- }
- };
-}
diff --git a/src/com/android/settings/applications/manageapplications/ManageApplications.java b/src/com/android/settings/applications/manageapplications/ManageApplications.java
index 06ba86e..b0949ea 100644
--- a/src/com/android/settings/applications/manageapplications/ManageApplications.java
+++ b/src/com/android/settings/applications/manageapplications/ManageApplications.java
@@ -70,7 +70,6 @@
import com.android.settings.Settings.HighPowerApplicationsActivity;
import com.android.settings.Settings.ManageExternalSourcesActivity;
import com.android.settings.Settings.MoviesStorageActivity;
-import com.android.settings.Settings.NotificationAppListActivity;
import com.android.settings.Settings.OverlaySettingsActivity;
import com.android.settings.Settings.StorageUseActivity;
import com.android.settings.Settings.UsageAccessSettingsActivity;
@@ -90,7 +89,6 @@
import com.android.settings.applications.AppStorageSettings;
import com.android.settings.applications.DefaultAppSettings;
import com.android.settings.applications.InstalledAppCounter;
-import com.android.settings.applications.NotificationApps;
import com.android.settings.applications.DirectoryAccessDetails;
import com.android.settings.applications.UsageAccessDetails;
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
@@ -238,12 +236,7 @@
if (className == null) {
className = intent.getComponent().getClassName();
}
- if (className.equals(NotificationAppListActivity.class.getName())
- || this instanceof NotificationApps) {
- mListType = LIST_TYPE_NOTIFICATION;
- mNotifBackend = new NotificationBackend();
- screenTitle = R.string.app_notifications_title;
- } else if (className.equals(StorageUseActivity.class.getName())) {
+ if (className.equals(StorageUseActivity.class.getName())) {
if (args != null && args.containsKey(EXTRA_VOLUME_UUID)) {
mVolumeUuid = args.getString(EXTRA_VOLUME_UUID);
mStorageType = args.getInt(EXTRA_STORAGE_TYPE, STORAGE_TYPE_DEFAULT);
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index 91fc108..af85ac9 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -40,7 +40,6 @@
import com.android.settings.applications.AppAndNotificationDashboardFragment;
import com.android.settings.applications.DefaultAppSettings;
import com.android.settings.applications.ManageDomainUrls;
-import com.android.settings.applications.NotificationApps;
import com.android.settings.applications.ProcessStatsSummary;
import com.android.settings.applications.ProcessStatsUi;
import com.android.settings.applications.DirectoryAccessDetails;
@@ -157,7 +156,6 @@
DisplaySettings.class.getName(),
DeviceInfoSettings.class.getName(),
ManageApplications.class.getName(),
- NotificationApps.class.getName(),
ManageAssist.class.getName(),
ProcessStatsUi.class.getName(),
NotificationStation.class.getName(),
diff --git a/src/com/android/settings/notification/AllowSoundPreferenceController.java b/src/com/android/settings/notification/AllowSoundPreferenceController.java
index dcd5e45..7186be1 100644
--- a/src/com/android/settings/notification/AllowSoundPreferenceController.java
+++ b/src/com/android/settings/notification/AllowSoundPreferenceController.java
@@ -56,6 +56,7 @@
}
+ @Override
public void updateState(Preference preference) {
if (mChannel != null) {
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java
index 333e060..14ccf23 100644
--- a/src/com/android/settings/notification/AppNotificationSettings.java
+++ b/src/com/android/settings/notification/AppNotificationSettings.java
@@ -120,7 +120,8 @@
mControllers.add(new BadgePreferenceController(context, mBackend));
mControllers.add(new AllowSoundPreferenceController(
context, mImportanceListener, mBackend));
- mControllers.add(new ImportancePreferenceController(context));
+ mControllers.add(new ImportancePreferenceController(
+ context, mImportanceListener, mBackend));
mControllers.add(new SoundPreferenceController(context, this,
mImportanceListener, mBackend));
mControllers.add(new LightsPreferenceController(context, mBackend));
diff --git a/src/com/android/settings/notification/ChannelImportanceSettings.java b/src/com/android/settings/notification/ChannelImportanceSettings.java
deleted file mode 100644
index 27b23b8..0000000
--- a/src/com/android/settings/notification/ChannelImportanceSettings.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Copyright (C) 2017 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 static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE;
-import static android.app.NotificationChannel.USER_LOCKED_SOUND;
-import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
-import static android.app.NotificationManager.IMPORTANCE_HIGH;
-import static android.app.NotificationManager.IMPORTANCE_LOW;
-import static android.app.NotificationManager.IMPORTANCE_MAX;
-import static android.app.NotificationManager.IMPORTANCE_MIN;
-
-import android.content.Context;
-import android.media.RingtoneManager;
-import android.provider.SearchIndexableResource;
-import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceScreen;
-import android.text.TextUtils;
-import android.util.Log;
-
-import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-import com.android.settings.R;
-import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settings.search.Indexable;
-import com.android.settings.widget.RadioButtonPreference;
-import com.android.settingslib.core.AbstractPreferenceController;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class ChannelImportanceSettings extends NotificationSettingsBase
- implements RadioButtonPreference.OnClickListener, Indexable {
- private static final String TAG = "NotiImportance";
-
- private static final String KEY_IMPORTANCE_HIGH = "importance_high";
- private static final String KEY_IMPORTANCE_DEFAULT = "importance_default";
- private static final String KEY_IMPORTANCE_LOW = "importance_low";
- private static final String KEY_IMPORTANCE_MIN = "importance_min";
-
- List<RadioButtonPreference> mImportances = new ArrayList<>();
-
- @Override
- public int getMetricsCategory() {
- return MetricsEvent.NOTIFICATION_CHANNEL_IMPORTANCE;
- }
-
- @Override
- public void onResume() {
- super.onResume();
- if (mAppRow == null || mChannel == null) {
- Log.w(TAG, "Missing package or channel");
- finish();
- return;
- }
- createPreferenceHierarchy();
- }
-
- @Override
- protected String getLogTag() {
- return TAG;
- }
-
- @Override
- protected int getPreferenceScreenResId() {
- return R.xml.notification_importance;
- }
-
- @Override
- protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
- return null;
- }
-
- @Override
- public void onPause() {
- super.onPause();
- }
-
- private PreferenceScreen createPreferenceHierarchy() {
- PreferenceScreen root = getPreferenceScreen();
-
- for (int i = 0; i < root.getPreferenceCount(); i++) {
- Preference pref = root.getPreference(i);
- if (pref instanceof RadioButtonPreference) {
- RadioButtonPreference radioPref = (RadioButtonPreference) pref;
- radioPref.setOnClickListener(this);
- mImportances.add(radioPref);
- }
- }
-
- switch (mChannel.getImportance()) {
- case IMPORTANCE_MIN:
- updateRadioButtons(KEY_IMPORTANCE_MIN);
- break;
- case IMPORTANCE_LOW:
- updateRadioButtons(KEY_IMPORTANCE_LOW);
- break;
- case IMPORTANCE_DEFAULT:
- updateRadioButtons(KEY_IMPORTANCE_DEFAULT);
- break;
- case IMPORTANCE_HIGH:
- case IMPORTANCE_MAX:
- updateRadioButtons(KEY_IMPORTANCE_HIGH);
- break;
- }
-
- return root;
- }
-
- private void updateRadioButtons(String selectionKey) {
- for (RadioButtonPreference pref : mImportances) {
- if (selectionKey.equals(pref.getKey())) {
- pref.setChecked(true);
- } else {
- pref.setChecked(false);
- }
- }
- }
-
- @Override
- public void onRadioButtonClicked(RadioButtonPreference clicked) {
- int oldImportance = mChannel.getImportance();
- switch (clicked.getKey()) {
- case KEY_IMPORTANCE_HIGH:
- mChannel.setImportance(IMPORTANCE_HIGH);
- break;
- case KEY_IMPORTANCE_DEFAULT:
- mChannel.setImportance(IMPORTANCE_DEFAULT);
- break;
- case KEY_IMPORTANCE_LOW:
- mChannel.setImportance(IMPORTANCE_LOW);
- break;
- case KEY_IMPORTANCE_MIN:
- mChannel.setImportance(IMPORTANCE_MIN);
- break;
- }
- updateRadioButtons(clicked.getKey());
-
- // If you are moving from an importance level without sound to one with sound,
- // but the sound you had selected was "Silence",
- // then set sound for this channel to your default sound,
- // because you probably intended to cause this channel to actually start making sound.
- if (oldImportance < IMPORTANCE_DEFAULT
- && !SoundPreferenceController.hasValidSound(mChannel)
- && mChannel.getImportance() >= IMPORTANCE_DEFAULT) {
- mChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION),
- mChannel.getAudioAttributes());
- mChannel.lockFields(USER_LOCKED_SOUND);
- }
- mChannel.lockFields(USER_LOCKED_IMPORTANCE);
- mBackend.updateChannel(mAppRow.pkg, mAppRow.uid, mChannel);
- }
-}
diff --git a/src/com/android/settings/notification/ChannelNotificationSettings.java b/src/com/android/settings/notification/ChannelNotificationSettings.java
index ea17a05..23451ec 100644
--- a/src/com/android/settings/notification/ChannelNotificationSettings.java
+++ b/src/com/android/settings/notification/ChannelNotificationSettings.java
@@ -79,7 +79,8 @@
mControllers = new ArrayList<>();
mControllers.add(new HeaderPreferenceController(context, this));
mControllers.add(new BlockPreferenceController(context, mImportanceListener, mBackend));
- mControllers.add(new ImportancePreferenceController(context));
+ mControllers.add(new ImportancePreferenceController(
+ context, mImportanceListener, mBackend));
mControllers.add(new AllowSoundPreferenceController(
context, mImportanceListener, mBackend));
mControllers.add(new SoundPreferenceController(context, this,
diff --git a/src/com/android/settings/notification/ConfigureNotificationSettings.java b/src/com/android/settings/notification/ConfigureNotificationSettings.java
index 7cfa124..a3af471 100644
--- a/src/com/android/settings/notification/ConfigureNotificationSettings.java
+++ b/src/com/android/settings/notification/ConfigureNotificationSettings.java
@@ -30,9 +30,7 @@
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.RingtonePreference;
-import com.android.settings.applications.NotificationApps;
import com.android.settings.dashboard.DashboardFragment;
-import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.gestures.SwipeToNotificationPreferenceController;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
@@ -153,15 +151,6 @@
}
}
- public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
- = new SummaryLoader.SummaryProviderFactory() {
- @Override
- public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
- SummaryLoader summaryLoader) {
- return new NotificationApps.SummaryProvider(activity, summaryLoader);
- }
- };
-
/**
* For Search.
*/
diff --git a/src/com/android/settings/notification/DeletedChannelsPreferenceController.java b/src/com/android/settings/notification/DeletedChannelsPreferenceController.java
index 16eb9ed..45fb8ec 100644
--- a/src/com/android/settings/notification/DeletedChannelsPreferenceController.java
+++ b/src/com/android/settings/notification/DeletedChannelsPreferenceController.java
@@ -55,7 +55,6 @@
preference.setTitle(mContext.getResources().getQuantityString(
R.plurals.deleted_channels, deletedChannelCount, deletedChannelCount));
}
- preference.setEnabled(false);
preference.setSelectable(false);
}
}
diff --git a/src/com/android/settings/notification/ImportancePreferenceController.java b/src/com/android/settings/notification/ImportancePreferenceController.java
index 977cd9a..f95c34a 100644
--- a/src/com/android/settings/notification/ImportancePreferenceController.java
+++ b/src/com/android/settings/notification/ImportancePreferenceController.java
@@ -16,41 +16,39 @@
package com.android.settings.notification;
+import static android.app.NotificationChannel.USER_LOCKED_SOUND;
+import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
+import static android.app.NotificationManager.IMPORTANCE_HIGH;
+import static android.app.NotificationManager.IMPORTANCE_MIN;
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-import android.provider.Settings;
+import android.media.RingtoneManager;
import android.support.v7.preference.Preference;
-import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
-import com.android.settings.Utils;
-import com.android.settings.applications.AppInfoBase;
+import com.android.settings.RestrictedListPreference;
import com.android.settings.core.PreferenceControllerMixin;
public class ImportancePreferenceController extends NotificationPreferenceController
- implements PreferenceControllerMixin {
+ implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
private static final String KEY_IMPORTANCE = "importance";
+ private NotificationSettingsBase.ImportanceListener mImportanceListener;
- // Ironically doesn't take an importance listener because the importance is not changed
- // by this controller's preference but by the screen it links to.
- public ImportancePreferenceController(Context context) {
- super(context, null);
+ public ImportancePreferenceController(Context context,
+ NotificationSettingsBase.ImportanceListener importanceListener,
+ NotificationBackend backend) {
+ super(context, backend);
+ mImportanceListener = importanceListener;
}
@Override
public String getPreferenceKey() {
return KEY_IMPORTANCE;
}
-
- private int getMetricsCategory() {
- return MetricsProto.MetricsEvent.NOTIFICATION_TOPIC_NOTIFICATION;
- }
@Override
public boolean isAvailable() {
@@ -63,51 +61,82 @@
return !NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId());
}
+ @Override
public void updateState(Preference preference) {
if (mAppRow!= null && mChannel != null) {
preference.setEnabled(mAdmin == null && isChannelConfigurable());
- Bundle channelArgs = new Bundle();
- channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mAppRow.uid);
- channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mAppRow.pkg);
- channelArgs.putString(Settings.EXTRA_CHANNEL_ID, mChannel.getId());
- if (preference.isEnabled()) {
- Intent channelIntent = Utils.onBuildStartFragmentIntent(mContext,
- ChannelImportanceSettings.class.getName(),
- channelArgs, null,
- R.string.notification_importance_title, null,
- false, getMetricsCategory());
- preference.setIntent(channelIntent);
- preference.setSummary(getImportanceSummary(mContext, mChannel));
+ preference.setSummary(getImportanceSummary(mChannel));
+
+ int importances = IMPORTANCE_HIGH - IMPORTANCE_MIN + 1;
+ CharSequence[] entries = new CharSequence[importances];
+ CharSequence[] values = new CharSequence[importances];
+
+ int index = 0;
+ for (int i = IMPORTANCE_HIGH; i >= IMPORTANCE_MIN; i--) {
+ NotificationChannel channel = new NotificationChannel("", "", i);
+ entries[index] = getImportanceSummary(channel);
+ values[index] = String.valueOf(i);
+ index++;
}
+
+ RestrictedListPreference pref = (RestrictedListPreference) preference;
+ pref.setEntries(entries);
+ pref.setEntryValues(values);
+ pref.setValue(String.valueOf(mChannel.getImportance()));
}
}
- protected static String getImportanceSummary(Context context, NotificationChannel channel) {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (mChannel != null) {
+ final int importance = Integer.parseInt((String) newValue);
+
+ // If you are moving from an importance level without sound to one with sound,
+ // but the sound you had selected was "Silence",
+ // then set sound for this channel to your default sound,
+ // because you probably intended to cause this channel to actually start making sound.
+ if (mChannel.getImportance() < IMPORTANCE_DEFAULT
+ && !SoundPreferenceController.hasValidSound(mChannel)
+ && importance >= IMPORTANCE_DEFAULT) {
+ mChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION),
+ mChannel.getAudioAttributes());
+ mChannel.lockFields(USER_LOCKED_SOUND);
+ }
+
+ mChannel.setImportance(importance);
+ mChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
+ saveChannel();
+ mImportanceListener.onImportanceChanged();
+ }
+ return true;
+ }
+
+ protected String getImportanceSummary(NotificationChannel channel) {
String summary = "";
int importance = channel.getImportance();
switch (importance) {
case IMPORTANCE_UNSPECIFIED:
- summary = context.getString(R.string.notification_importance_unspecified);
+ summary = mContext.getString(R.string.notification_importance_unspecified);
break;
case NotificationManager.IMPORTANCE_MIN:
- summary = context.getString(R.string.notification_importance_min);
+ summary = mContext.getString(R.string.notification_importance_min);
break;
case NotificationManager.IMPORTANCE_LOW:
- summary = context.getString(R.string.notification_importance_low);
+ summary = mContext.getString(R.string.notification_importance_low);
break;
case NotificationManager.IMPORTANCE_DEFAULT:
if (SoundPreferenceController.hasValidSound(channel)) {
- summary = context.getString(R.string.notification_importance_default);
+ summary = mContext.getString(R.string.notification_importance_default);
} else {
- summary = context.getString(R.string.notification_importance_low);
+ summary = mContext.getString(R.string.notification_importance_low);
}
break;
case NotificationManager.IMPORTANCE_HIGH:
case NotificationManager.IMPORTANCE_MAX:
if (SoundPreferenceController.hasValidSound(channel)) {
- summary = context.getString(R.string.notification_importance_high);
+ summary = mContext.getString(R.string.notification_importance_high);
} else {
- summary = context.getString(R.string.notification_importance_high_silent);
+ summary = mContext.getString(R.string.notification_importance_high_silent);
}
break;
default:
diff --git a/src/com/android/settings/notification/NotificationsOffPreferenceController.java b/src/com/android/settings/notification/NotificationsOffPreferenceController.java
index 74591cf..ba304de 100644
--- a/src/com/android/settings/notification/NotificationsOffPreferenceController.java
+++ b/src/com/android/settings/notification/NotificationsOffPreferenceController.java
@@ -57,7 +57,6 @@
preference.setTitle(R.string.app_notifications_off_desc);
}
}
- preference.setEnabled(false);
preference.setSelectable(false);
}
}
diff --git a/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java b/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java
index dbffc55..3240ae0 100644
--- a/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java
+++ b/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java
@@ -147,7 +147,8 @@
@Override
protected void onCountComplete(int num) {
if (mHasRecentApps) {
- mSeeAllPref.setTitle(mContext.getString(R.string.see_all_apps_title, num));
+ mSeeAllPref.setTitle(
+ mContext.getString(R.string.recent_notifications_see_all_title));
} else {
mSeeAllPref.setSummary(mContext.getString(R.string.apps_summary, num));
}
diff --git a/tests/robotests/assets/grandfather_not_implementing_index_provider b/tests/robotests/assets/grandfather_not_implementing_index_provider
index be910e1..43697bd 100644
--- a/tests/robotests/assets/grandfather_not_implementing_index_provider
+++ b/tests/robotests/assets/grandfather_not_implementing_index_provider
@@ -10,7 +10,6 @@
com.android.settings.development.qstile.DevelopmentTileConfigFragment
com.android.settings.deviceinfo.StorageProfileFragment
com.android.settings.notification.ChannelNotificationSettings
-com.android.settings.notification.ChannelImportanceSettings
com.android.settings.notification.ChannelGroupNotificationSettings
com.android.settings.notification.AppNotificationSettings
com.android.settings.wifi.details.WifiNetworkDetailsFragment
diff --git a/tests/robotests/src/com/android/settings/applications/NotificationAppsTest.java b/tests/robotests/src/com/android/settings/applications/NotificationAppsTest.java
deleted file mode 100644
index 11d757f..0000000
--- a/tests/robotests/src/com/android/settings/applications/NotificationAppsTest.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright (C) 2017 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.applications;
-
-import android.content.Context;
-
-import android.content.pm.ApplicationInfo;
-import android.content.pm.UserInfo;
-import android.os.UserManager;
-
-import com.android.settings.R;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settings.TestConfig;
-import com.android.settings.dashboard.SummaryLoader;
-import com.android.settings.notification.NotificationBackend;
-import com.android.settingslib.wrapper.PackageManagerWrapper;
-
-import java.util.List;
-import java.util.ArrayList;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.annotation.Config;
-import org.robolectric.shadows.ShadowApplication;
-import org.robolectric.util.ReflectionHelpers;
-
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class NotificationAppsTest {
-
- @Mock
- private PackageManagerWrapper mPackageManager;
- @Mock
- private UserManager mUserManager;
- @Mock
- private SummaryLoader mSummaryLoader;
- @Mock
- private NotificationBackend mBackend;
-
- private Context mContext;
- private NotificationApps.SummaryProvider mSummaryProvider;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- ShadowApplication shadowApplication = ShadowApplication.getInstance();
- shadowApplication.setSystemService(Context.USER_SERVICE, mUserManager);
- mContext = shadowApplication.getApplicationContext();
- mSummaryProvider = spy(new NotificationApps.SummaryProvider(mContext, mSummaryLoader));
- ReflectionHelpers.setField(mSummaryProvider, "mNotificationBackend", mBackend);
- ReflectionHelpers.setField(mSummaryProvider, "mPackageManager", mPackageManager);
- }
-
- @Test
- public void setListening_shouldSetSummary() {
- List<UserInfo> userInfos = new ArrayList<>();
- userInfos.add(new UserInfo(1, "user1", 0));
- when(mUserManager.getProfiles(anyInt())).thenReturn(userInfos);
- List<ApplicationInfo> appInfos = new ArrayList<>();
- ApplicationInfo info1 = new ApplicationInfo();
- info1.packageName = "package1";
- appInfos.add(info1);
- ApplicationInfo info2 = new ApplicationInfo();
- info2.packageName = "package2";
- appInfos.add(info2);
- when(mPackageManager.getInstalledApplicationsAsUser(anyInt(), anyInt()))
- .thenReturn(appInfos);
-
- // no notification off
- when(mBackend.getNotificationsBanned(anyString(), anyInt())).thenReturn(false);
- mSummaryProvider.setListening(true);
- ShadowApplication.runBackgroundTasks();
- verify(mSummaryLoader).setSummary(mSummaryProvider,
- mContext.getString(R.string.notification_summary_none));
-
- // some notification off
- when(mBackend.getNotificationsBanned(eq("package1"), anyInt())).thenReturn(true);
- mSummaryProvider.setListening(true);
- ShadowApplication.runBackgroundTasks();
- verify(mSummaryLoader).setSummary(mSummaryProvider,
- mContext.getResources().getQuantityString(R.plurals.notification_summary, 1, 1));
-
- when(mBackend.getNotificationsBanned(eq("package2"), anyInt())).thenReturn(true);
- mSummaryProvider.setListening(true);
- ShadowApplication.runBackgroundTasks();
- verify(mSummaryLoader).setSummary(mSummaryProvider,
- mContext.getResources().getQuantityString(R.plurals.notification_summary, 2, 2));
- }
-
-}
diff --git a/tests/robotests/src/com/android/settings/notification/DeletedChannelsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/DeletedChannelsPreferenceControllerTest.java
index fd903f9..0d8b430 100644
--- a/tests/robotests/src/com/android/settings/notification/DeletedChannelsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/DeletedChannelsPreferenceControllerTest.java
@@ -119,7 +119,6 @@
Preference pref = mock(Preference.class);
mController.updateState(pref);
- verify(pref, times(1)).setEnabled(false);
verify(pref, times(1)).setSelectable(false);
verify(mBackend, times(1)).getDeletedChannelCount(any(), anyInt());
ArgumentCaptor<CharSequence> argumentCaptor = ArgumentCaptor.forClass(CharSequence.class);
diff --git a/tests/robotests/src/com/android/settings/notification/ImportancePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ImportancePreferenceControllerTest.java
index 0065e30..229a212 100644
--- a/tests/robotests/src/com/android/settings/notification/ImportancePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ImportancePreferenceControllerTest.java
@@ -21,6 +21,7 @@
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_NONE;
+import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
@@ -30,13 +31,16 @@
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
+import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.UserManager;
import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
import android.text.TextUtils;
+import com.android.settings.RestrictedListPreference;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.RestrictedLockUtils;
@@ -44,6 +48,7 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
@@ -58,7 +63,13 @@
@Mock
private NotificationManager mNm;
@Mock
+ private NotificationBackend mBackend;
+ @Mock
+ NotificationSettingsBase.ImportanceListener mImportanceListener;
+ @Mock
private UserManager mUm;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private PreferenceScreen mScreen;
private ImportancePreferenceController mController;
@@ -69,7 +80,8 @@
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
mContext = shadowApplication.getApplicationContext();
- mController = spy(new ImportancePreferenceController(mContext));
+ mController = spy(new ImportancePreferenceController(
+ mContext, mImportanceListener, mBackend));
}
@Test
@@ -123,14 +135,15 @@
@Test
public void testUpdateState_disabledByAdmin() throws Exception {
NotificationChannel channel = mock(NotificationChannel.class);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
RestrictedLockUtils.EnforcedAdmin.class));
- Preference pref = new Preference(RuntimeEnvironment.application);
+ Preference pref = new RestrictedListPreference(RuntimeEnvironment.application, null);
mController.updateState(pref);
assertFalse(pref.isEnabled());
- assertNull(pref.getIntent());
+ assertFalse(TextUtils.isEmpty(pref.getSummary()));
}
@Test
@@ -140,13 +153,14 @@
appRow.lockedChannelId = lockedId;
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn(lockedId);
+ when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
- Preference pref = new Preference(RuntimeEnvironment.application);
+ Preference pref = new RestrictedListPreference(RuntimeEnvironment.application, null);
mController.updateState(pref);
assertFalse(pref.isEnabled());
- assertNull(pref.getIntent());
+ assertFalse(TextUtils.isEmpty(pref.getSummary()));
}
@Test
@@ -155,11 +169,50 @@
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
- Preference pref = new Preference(RuntimeEnvironment.application);
+ Preference pref = new RestrictedListPreference(RuntimeEnvironment.application, null);
mController.updateState(pref);
assertTrue(pref.isEnabled());
- assertNotNull(pref.getIntent());
assertFalse(TextUtils.isEmpty(pref.getSummary()));
}
+
+ @Test
+ public void testImportanceLowToHigh() {
+ NotificationChannel channel =
+ new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_LOW);
+ channel.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
+
+ RestrictedListPreference pref =
+ new RestrictedListPreference(RuntimeEnvironment.application, null);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
+ mController.displayPreference(mScreen);
+ mController.updateState(pref);
+
+ pref.setValue(String.valueOf(IMPORTANCE_HIGH));
+ mController.onPreferenceChange(pref, pref.getValue());
+
+ assertEquals(IMPORTANCE_HIGH, channel.getImportance());
+ assertNotNull(channel.getSound());
+ }
+
+ @Test
+ public void testImportanceHightToLow() {
+ NotificationChannel channel =
+ new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_HIGH);
+ channel.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
+ mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
+
+ RestrictedListPreference pref =
+ new RestrictedListPreference(RuntimeEnvironment.application, null);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
+ mController.displayPreference(mScreen);
+ mController.updateState(pref);
+
+ pref.setValue(String.valueOf(IMPORTANCE_LOW));
+ mController.onPreferenceChange(pref, pref.getValue());
+
+ assertEquals(IMPORTANCE_LOW, channel.getImportance());
+ assertNull(channel.getSound());
+ }
}
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationsOffPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationsOffPreferenceControllerTest.java
index 654d90c..82ef6fd 100644
--- a/tests/robotests/src/com/android/settings/notification/NotificationsOffPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/NotificationsOffPreferenceControllerTest.java
@@ -110,7 +110,6 @@
mController.updateState(pref);
assertTrue(pref.getTitle().toString().contains("category"));
- assertFalse(pref.isEnabled());
assertFalse(pref.isSelectable());
}
@@ -125,7 +124,6 @@
mController.updateState(pref);
assertTrue(pref.getTitle().toString().contains("group"));
- assertFalse(pref.isEnabled());
assertFalse(pref.isSelectable());
}
@@ -139,7 +137,6 @@
mController.updateState(pref);
assertTrue(pref.getTitle().toString().contains("app"));
- assertFalse(pref.isEnabled());
assertFalse(pref.isSelectable());
}
}