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
This commit is contained in:
@@ -2645,19 +2645,6 @@
|
|||||||
android:value="com.android.settings.notification.SoundSettings" />
|
android:value="com.android.settings.notification.SoundSettings" />
|
||||||
</activity-alias>
|
</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) -->
|
<!-- Show application-level notification settings (app passed in as extras) -->
|
||||||
<activity android:name="Settings$AppNotificationSettingsActivity"
|
<activity android:name="Settings$AppNotificationSettingsActivity"
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
|
@@ -6983,6 +6983,9 @@
|
|||||||
<!-- notification header - apps that have recently sent notifications -->
|
<!-- notification header - apps that have recently sent notifications -->
|
||||||
<string name="recent_notifications">Recently sent</string>
|
<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] -->
|
<!-- Configure Notifications: Advanced section header [CHAR LIMIT=30] -->
|
||||||
<string name="advanced_section_header">Advanced</string>
|
<string name="advanced_section_header">Advanced</string>
|
||||||
|
|
||||||
|
@@ -15,7 +15,8 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<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
|
<com.android.settings.applications.LayoutPreference
|
||||||
android:key="pref_app_header"
|
android:key="pref_app_header"
|
||||||
@@ -25,24 +26,24 @@
|
|||||||
android:key="block"
|
android:key="block"
|
||||||
android:layout="@layout/styled_switch_bar" />
|
android:layout="@layout/styled_switch_bar" />
|
||||||
|
|
||||||
|
<com.android.settings.notification.NotificationFooterPreference
|
||||||
|
android:key="block_desc" />
|
||||||
|
|
||||||
|
<!-- Channels/Channel groups added here -->
|
||||||
|
|
||||||
<!-- Show badge -->
|
<!-- Show badge -->
|
||||||
<com.android.settingslib.RestrictedSwitchPreference
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
android:key="badge"
|
android:key="badge"
|
||||||
android:title="@string/notification_badge_title"
|
android:title="@string/notification_badge_title"
|
||||||
|
android:order="501"
|
||||||
settings:useAdditionalSummary="true"
|
settings:useAdditionalSummary="true"
|
||||||
|
settings:allowDividerAbove="true"
|
||||||
settings:restrictedSwitchSummary="@string/enabled_by_admin" />
|
settings:restrictedSwitchSummary="@string/enabled_by_admin" />
|
||||||
|
|
||||||
<!-- Channels/Channel groups added here -->
|
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="app_link"
|
android:key="app_link"
|
||||||
android:title="@string/app_settings_link"
|
android:title="@string/app_settings_link"
|
||||||
android:order="500"
|
android:order="502" />
|
||||||
settings:allowDividerAbove="true"/>
|
|
||||||
|
|
||||||
<com.android.settings.notification.NotificationFooterPreference
|
|
||||||
android:key="block_desc"
|
|
||||||
android:order="1000" />
|
|
||||||
|
|
||||||
<com.android.settings.notification.NotificationFooterPreference
|
<com.android.settings.notification.NotificationFooterPreference
|
||||||
android:key="desc"
|
android:key="desc"
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
android:layout="@layout/styled_switch_bar" />
|
android:layout="@layout/styled_switch_bar" />
|
||||||
|
|
||||||
<!-- Importance -->
|
<!-- Importance -->
|
||||||
<Preference
|
<com.android.settings.RestrictedListPreference
|
||||||
android:key="importance"
|
android:key="importance"
|
||||||
android:title="@string/notification_importance_title" />
|
android:title="@string/notification_importance_title" />
|
||||||
|
|
||||||
|
@@ -79,7 +79,7 @@
|
|||||||
<intent
|
<intent
|
||||||
android:action="android.intent.action.MAIN"
|
android:action="android.intent.action.MAIN"
|
||||||
android:targetPackage="com.android.settings"
|
android:targetPackage="com.android.settings"
|
||||||
android:targetClass="com.android.settings.Settings$NotificationAppListActivity">
|
android:targetClass="com.android.settings.Settings$ManageApplicationsActivity">
|
||||||
</intent>
|
</intent>
|
||||||
</Preference>
|
</Preference>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
@@ -108,7 +108,6 @@ public class Settings extends SettingsActivity {
|
|||||||
public static class ZenModeExternalRuleSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class ZenModeExternalRuleSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class SoundSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class SoundSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class ConfigureNotificationSettingsActivity 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 AppNotificationSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class ChannelNotificationSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class ChannelNotificationSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class ChannelGroupNotificationSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class ChannelGroupNotificationSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
|
@@ -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);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
@@ -70,7 +70,6 @@ import com.android.settings.Settings.GamesStorageActivity;
|
|||||||
import com.android.settings.Settings.HighPowerApplicationsActivity;
|
import com.android.settings.Settings.HighPowerApplicationsActivity;
|
||||||
import com.android.settings.Settings.ManageExternalSourcesActivity;
|
import com.android.settings.Settings.ManageExternalSourcesActivity;
|
||||||
import com.android.settings.Settings.MoviesStorageActivity;
|
import com.android.settings.Settings.MoviesStorageActivity;
|
||||||
import com.android.settings.Settings.NotificationAppListActivity;
|
|
||||||
import com.android.settings.Settings.OverlaySettingsActivity;
|
import com.android.settings.Settings.OverlaySettingsActivity;
|
||||||
import com.android.settings.Settings.StorageUseActivity;
|
import com.android.settings.Settings.StorageUseActivity;
|
||||||
import com.android.settings.Settings.UsageAccessSettingsActivity;
|
import com.android.settings.Settings.UsageAccessSettingsActivity;
|
||||||
@@ -90,7 +89,6 @@ import com.android.settings.applications.AppStateWriteSettingsBridge;
|
|||||||
import com.android.settings.applications.AppStorageSettings;
|
import com.android.settings.applications.AppStorageSettings;
|
||||||
import com.android.settings.applications.DefaultAppSettings;
|
import com.android.settings.applications.DefaultAppSettings;
|
||||||
import com.android.settings.applications.InstalledAppCounter;
|
import com.android.settings.applications.InstalledAppCounter;
|
||||||
import com.android.settings.applications.NotificationApps;
|
|
||||||
import com.android.settings.applications.DirectoryAccessDetails;
|
import com.android.settings.applications.DirectoryAccessDetails;
|
||||||
import com.android.settings.applications.UsageAccessDetails;
|
import com.android.settings.applications.UsageAccessDetails;
|
||||||
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
|
import com.android.settings.applications.appinfo.AppInfoDashboardFragment;
|
||||||
@@ -238,12 +236,7 @@ public class ManageApplications extends InstrumentedPreferenceFragment
|
|||||||
if (className == null) {
|
if (className == null) {
|
||||||
className = intent.getComponent().getClassName();
|
className = intent.getComponent().getClassName();
|
||||||
}
|
}
|
||||||
if (className.equals(NotificationAppListActivity.class.getName())
|
if (className.equals(StorageUseActivity.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 (args != null && args.containsKey(EXTRA_VOLUME_UUID)) {
|
if (args != null && args.containsKey(EXTRA_VOLUME_UUID)) {
|
||||||
mVolumeUuid = args.getString(EXTRA_VOLUME_UUID);
|
mVolumeUuid = args.getString(EXTRA_VOLUME_UUID);
|
||||||
mStorageType = args.getInt(EXTRA_STORAGE_TYPE, STORAGE_TYPE_DEFAULT);
|
mStorageType = args.getInt(EXTRA_STORAGE_TYPE, STORAGE_TYPE_DEFAULT);
|
||||||
|
@@ -40,7 +40,6 @@ import com.android.settings.accounts.AccountDashboardFragment;
|
|||||||
import com.android.settings.applications.AppAndNotificationDashboardFragment;
|
import com.android.settings.applications.AppAndNotificationDashboardFragment;
|
||||||
import com.android.settings.applications.DefaultAppSettings;
|
import com.android.settings.applications.DefaultAppSettings;
|
||||||
import com.android.settings.applications.ManageDomainUrls;
|
import com.android.settings.applications.ManageDomainUrls;
|
||||||
import com.android.settings.applications.NotificationApps;
|
|
||||||
import com.android.settings.applications.ProcessStatsSummary;
|
import com.android.settings.applications.ProcessStatsSummary;
|
||||||
import com.android.settings.applications.ProcessStatsUi;
|
import com.android.settings.applications.ProcessStatsUi;
|
||||||
import com.android.settings.applications.DirectoryAccessDetails;
|
import com.android.settings.applications.DirectoryAccessDetails;
|
||||||
@@ -157,7 +156,6 @@ public class SettingsGateway {
|
|||||||
DisplaySettings.class.getName(),
|
DisplaySettings.class.getName(),
|
||||||
DeviceInfoSettings.class.getName(),
|
DeviceInfoSettings.class.getName(),
|
||||||
ManageApplications.class.getName(),
|
ManageApplications.class.getName(),
|
||||||
NotificationApps.class.getName(),
|
|
||||||
ManageAssist.class.getName(),
|
ManageAssist.class.getName(),
|
||||||
ProcessStatsUi.class.getName(),
|
ProcessStatsUi.class.getName(),
|
||||||
NotificationStation.class.getName(),
|
NotificationStation.class.getName(),
|
||||||
|
@@ -56,6 +56,7 @@ public class AllowSoundPreferenceController extends NotificationPreferenceContro
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
RestrictedSwitchPreference pref = (RestrictedSwitchPreference) preference;
|
||||||
|
@@ -120,7 +120,8 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
mControllers.add(new BadgePreferenceController(context, mBackend));
|
mControllers.add(new BadgePreferenceController(context, mBackend));
|
||||||
mControllers.add(new AllowSoundPreferenceController(
|
mControllers.add(new AllowSoundPreferenceController(
|
||||||
context, mImportanceListener, mBackend));
|
context, mImportanceListener, mBackend));
|
||||||
mControllers.add(new ImportancePreferenceController(context));
|
mControllers.add(new ImportancePreferenceController(
|
||||||
|
context, mImportanceListener, mBackend));
|
||||||
mControllers.add(new SoundPreferenceController(context, this,
|
mControllers.add(new SoundPreferenceController(context, this,
|
||||||
mImportanceListener, mBackend));
|
mImportanceListener, mBackend));
|
||||||
mControllers.add(new LightsPreferenceController(context, mBackend));
|
mControllers.add(new LightsPreferenceController(context, mBackend));
|
||||||
|
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -79,7 +79,8 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
|
|||||||
mControllers = new ArrayList<>();
|
mControllers = new ArrayList<>();
|
||||||
mControllers.add(new HeaderPreferenceController(context, this));
|
mControllers.add(new HeaderPreferenceController(context, this));
|
||||||
mControllers.add(new BlockPreferenceController(context, mImportanceListener, mBackend));
|
mControllers.add(new BlockPreferenceController(context, mImportanceListener, mBackend));
|
||||||
mControllers.add(new ImportancePreferenceController(context));
|
mControllers.add(new ImportancePreferenceController(
|
||||||
|
context, mImportanceListener, mBackend));
|
||||||
mControllers.add(new AllowSoundPreferenceController(
|
mControllers.add(new AllowSoundPreferenceController(
|
||||||
context, mImportanceListener, mBackend));
|
context, mImportanceListener, mBackend));
|
||||||
mControllers.add(new SoundPreferenceController(context, this,
|
mControllers.add(new SoundPreferenceController(context, this,
|
||||||
|
@@ -30,9 +30,7 @@ import android.support.v7.preference.Preference;
|
|||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.RingtonePreference;
|
import com.android.settings.RingtonePreference;
|
||||||
import com.android.settings.applications.NotificationApps;
|
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.dashboard.SummaryLoader;
|
|
||||||
import com.android.settings.gestures.SwipeToNotificationPreferenceController;
|
import com.android.settings.gestures.SwipeToNotificationPreferenceController;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.search.Indexable;
|
import com.android.settings.search.Indexable;
|
||||||
@@ -153,15 +151,6 @@ public class ConfigureNotificationSettings extends DashboardFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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.
|
* For Search.
|
||||||
*/
|
*/
|
||||||
|
@@ -55,7 +55,6 @@ public class DeletedChannelsPreferenceController extends NotificationPreferenceC
|
|||||||
preference.setTitle(mContext.getResources().getQuantityString(
|
preference.setTitle(mContext.getResources().getQuantityString(
|
||||||
R.plurals.deleted_channels, deletedChannelCount, deletedChannelCount));
|
R.plurals.deleted_channels, deletedChannelCount, deletedChannelCount));
|
||||||
}
|
}
|
||||||
preference.setEnabled(false);
|
|
||||||
preference.setSelectable(false);
|
preference.setSelectable(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,41 +16,39 @@
|
|||||||
|
|
||||||
package com.android.settings.notification;
|
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 static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
|
||||||
|
|
||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.media.RingtoneManager;
|
||||||
import android.os.Bundle;
|
|
||||||
import android.provider.Settings;
|
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto;
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.RestrictedListPreference;
|
||||||
import com.android.settings.applications.AppInfoBase;
|
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
|
|
||||||
public class ImportancePreferenceController extends NotificationPreferenceController
|
public class ImportancePreferenceController extends NotificationPreferenceController
|
||||||
implements PreferenceControllerMixin {
|
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
private static final String KEY_IMPORTANCE = "importance";
|
private static final String KEY_IMPORTANCE = "importance";
|
||||||
|
private NotificationSettingsBase.ImportanceListener mImportanceListener;
|
||||||
|
|
||||||
// Ironically doesn't take an importance listener because the importance is not changed
|
public ImportancePreferenceController(Context context,
|
||||||
// by this controller's preference but by the screen it links to.
|
NotificationSettingsBase.ImportanceListener importanceListener,
|
||||||
public ImportancePreferenceController(Context context) {
|
NotificationBackend backend) {
|
||||||
super(context, null);
|
super(context, backend);
|
||||||
|
mImportanceListener = importanceListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return KEY_IMPORTANCE;
|
return KEY_IMPORTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getMetricsCategory() {
|
|
||||||
return MetricsProto.MetricsEvent.NOTIFICATION_TOPIC_NOTIFICATION;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
@@ -63,51 +61,82 @@ public class ImportancePreferenceController extends NotificationPreferenceContro
|
|||||||
return !NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId());
|
return !NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
if (mAppRow!= null && mChannel != null) {
|
if (mAppRow!= null && mChannel != null) {
|
||||||
preference.setEnabled(mAdmin == null && isChannelConfigurable());
|
preference.setEnabled(mAdmin == null && isChannelConfigurable());
|
||||||
Bundle channelArgs = new Bundle();
|
preference.setSummary(getImportanceSummary(mChannel));
|
||||||
channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mAppRow.uid);
|
|
||||||
channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mAppRow.pkg);
|
int importances = IMPORTANCE_HIGH - IMPORTANCE_MIN + 1;
|
||||||
channelArgs.putString(Settings.EXTRA_CHANNEL_ID, mChannel.getId());
|
CharSequence[] entries = new CharSequence[importances];
|
||||||
if (preference.isEnabled()) {
|
CharSequence[] values = new CharSequence[importances];
|
||||||
Intent channelIntent = Utils.onBuildStartFragmentIntent(mContext,
|
|
||||||
ChannelImportanceSettings.class.getName(),
|
int index = 0;
|
||||||
channelArgs, null,
|
for (int i = IMPORTANCE_HIGH; i >= IMPORTANCE_MIN; i--) {
|
||||||
R.string.notification_importance_title, null,
|
NotificationChannel channel = new NotificationChannel("", "", i);
|
||||||
false, getMetricsCategory());
|
entries[index] = getImportanceSummary(channel);
|
||||||
preference.setIntent(channelIntent);
|
values[index] = String.valueOf(i);
|
||||||
preference.setSummary(getImportanceSummary(mContext, mChannel));
|
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 = "";
|
String summary = "";
|
||||||
int importance = channel.getImportance();
|
int importance = channel.getImportance();
|
||||||
switch (importance) {
|
switch (importance) {
|
||||||
case IMPORTANCE_UNSPECIFIED:
|
case IMPORTANCE_UNSPECIFIED:
|
||||||
summary = context.getString(R.string.notification_importance_unspecified);
|
summary = mContext.getString(R.string.notification_importance_unspecified);
|
||||||
break;
|
break;
|
||||||
case NotificationManager.IMPORTANCE_MIN:
|
case NotificationManager.IMPORTANCE_MIN:
|
||||||
summary = context.getString(R.string.notification_importance_min);
|
summary = mContext.getString(R.string.notification_importance_min);
|
||||||
break;
|
break;
|
||||||
case NotificationManager.IMPORTANCE_LOW:
|
case NotificationManager.IMPORTANCE_LOW:
|
||||||
summary = context.getString(R.string.notification_importance_low);
|
summary = mContext.getString(R.string.notification_importance_low);
|
||||||
break;
|
break;
|
||||||
case NotificationManager.IMPORTANCE_DEFAULT:
|
case NotificationManager.IMPORTANCE_DEFAULT:
|
||||||
if (SoundPreferenceController.hasValidSound(channel)) {
|
if (SoundPreferenceController.hasValidSound(channel)) {
|
||||||
summary = context.getString(R.string.notification_importance_default);
|
summary = mContext.getString(R.string.notification_importance_default);
|
||||||
} else {
|
} else {
|
||||||
summary = context.getString(R.string.notification_importance_low);
|
summary = mContext.getString(R.string.notification_importance_low);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NotificationManager.IMPORTANCE_HIGH:
|
case NotificationManager.IMPORTANCE_HIGH:
|
||||||
case NotificationManager.IMPORTANCE_MAX:
|
case NotificationManager.IMPORTANCE_MAX:
|
||||||
if (SoundPreferenceController.hasValidSound(channel)) {
|
if (SoundPreferenceController.hasValidSound(channel)) {
|
||||||
summary = context.getString(R.string.notification_importance_high);
|
summary = mContext.getString(R.string.notification_importance_high);
|
||||||
} else {
|
} else {
|
||||||
summary = context.getString(R.string.notification_importance_high_silent);
|
summary = mContext.getString(R.string.notification_importance_high_silent);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@@ -57,7 +57,6 @@ public class NotificationsOffPreferenceController extends NotificationPreference
|
|||||||
preference.setTitle(R.string.app_notifications_off_desc);
|
preference.setTitle(R.string.app_notifications_off_desc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
preference.setEnabled(false);
|
|
||||||
preference.setSelectable(false);
|
preference.setSelectable(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -147,7 +147,8 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
|
|||||||
@Override
|
@Override
|
||||||
protected void onCountComplete(int num) {
|
protected void onCountComplete(int num) {
|
||||||
if (mHasRecentApps) {
|
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 {
|
} else {
|
||||||
mSeeAllPref.setSummary(mContext.getString(R.string.apps_summary, num));
|
mSeeAllPref.setSummary(mContext.getString(R.string.apps_summary, num));
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,6 @@ com.android.settings.development.featureflags.FeatureFlagsDashboard
|
|||||||
com.android.settings.development.qstile.DevelopmentTileConfigFragment
|
com.android.settings.development.qstile.DevelopmentTileConfigFragment
|
||||||
com.android.settings.deviceinfo.StorageProfileFragment
|
com.android.settings.deviceinfo.StorageProfileFragment
|
||||||
com.android.settings.notification.ChannelNotificationSettings
|
com.android.settings.notification.ChannelNotificationSettings
|
||||||
com.android.settings.notification.ChannelImportanceSettings
|
|
||||||
com.android.settings.notification.ChannelGroupNotificationSettings
|
com.android.settings.notification.ChannelGroupNotificationSettings
|
||||||
com.android.settings.notification.AppNotificationSettings
|
com.android.settings.notification.AppNotificationSettings
|
||||||
com.android.settings.wifi.details.WifiNetworkDetailsFragment
|
com.android.settings.wifi.details.WifiNetworkDetailsFragment
|
||||||
|
@@ -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));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -119,7 +119,6 @@ public class DeletedChannelsPreferenceControllerTest {
|
|||||||
Preference pref = mock(Preference.class);
|
Preference pref = mock(Preference.class);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
verify(pref, times(1)).setEnabled(false);
|
|
||||||
verify(pref, times(1)).setSelectable(false);
|
verify(pref, times(1)).setSelectable(false);
|
||||||
verify(mBackend, times(1)).getDeletedChannelCount(any(), anyInt());
|
verify(mBackend, times(1)).getDeletedChannelCount(any(), anyInt());
|
||||||
ArgumentCaptor<CharSequence> argumentCaptor = ArgumentCaptor.forClass(CharSequence.class);
|
ArgumentCaptor<CharSequence> argumentCaptor = ArgumentCaptor.forClass(CharSequence.class);
|
||||||
|
@@ -21,6 +21,7 @@ import static android.app.NotificationManager.IMPORTANCE_HIGH;
|
|||||||
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
||||||
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertEquals;
|
||||||
import static junit.framework.Assert.assertFalse;
|
import static junit.framework.Assert.assertFalse;
|
||||||
import static junit.framework.Assert.assertNull;
|
import static junit.framework.Assert.assertNull;
|
||||||
import static junit.framework.Assert.assertTrue;
|
import static junit.framework.Assert.assertTrue;
|
||||||
@@ -30,13 +31,16 @@ import static org.mockito.Mockito.mock;
|
|||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.Notification;
|
||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.android.settings.RestrictedListPreference;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
@@ -44,6 +48,7 @@ import com.android.settingslib.RestrictedLockUtils;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Answers;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
@@ -58,7 +63,13 @@ public class ImportancePreferenceControllerTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private NotificationManager mNm;
|
private NotificationManager mNm;
|
||||||
@Mock
|
@Mock
|
||||||
|
private NotificationBackend mBackend;
|
||||||
|
@Mock
|
||||||
|
NotificationSettingsBase.ImportanceListener mImportanceListener;
|
||||||
|
@Mock
|
||||||
private UserManager mUm;
|
private UserManager mUm;
|
||||||
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
|
private PreferenceScreen mScreen;
|
||||||
|
|
||||||
private ImportancePreferenceController mController;
|
private ImportancePreferenceController mController;
|
||||||
|
|
||||||
@@ -69,7 +80,8 @@ public class ImportancePreferenceControllerTest {
|
|||||||
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
|
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
|
||||||
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
|
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
|
||||||
mContext = shadowApplication.getApplicationContext();
|
mContext = shadowApplication.getApplicationContext();
|
||||||
mController = spy(new ImportancePreferenceController(mContext));
|
mController = spy(new ImportancePreferenceController(
|
||||||
|
mContext, mImportanceListener, mBackend));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -123,14 +135,15 @@ public class ImportancePreferenceControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testUpdateState_disabledByAdmin() throws Exception {
|
public void testUpdateState_disabledByAdmin() throws Exception {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
|
mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
|
||||||
RestrictedLockUtils.EnforcedAdmin.class));
|
RestrictedLockUtils.EnforcedAdmin.class));
|
||||||
|
|
||||||
Preference pref = new Preference(RuntimeEnvironment.application);
|
Preference pref = new RestrictedListPreference(RuntimeEnvironment.application, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
assertFalse(pref.isEnabled());
|
assertFalse(pref.isEnabled());
|
||||||
assertNull(pref.getIntent());
|
assertFalse(TextUtils.isEmpty(pref.getSummary()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -140,13 +153,14 @@ public class ImportancePreferenceControllerTest {
|
|||||||
appRow.lockedChannelId = lockedId;
|
appRow.lockedChannelId = lockedId;
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getId()).thenReturn(lockedId);
|
when(channel.getId()).thenReturn(lockedId);
|
||||||
|
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null);
|
mController.onResume(appRow, channel, null, null);
|
||||||
|
|
||||||
Preference pref = new Preference(RuntimeEnvironment.application);
|
Preference pref = new RestrictedListPreference(RuntimeEnvironment.application, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
assertFalse(pref.isEnabled());
|
assertFalse(pref.isEnabled());
|
||||||
assertNull(pref.getIntent());
|
assertFalse(TextUtils.isEmpty(pref.getSummary()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -155,11 +169,50 @@ public class ImportancePreferenceControllerTest {
|
|||||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
|
||||||
mController.onResume(appRow, channel, null, null);
|
mController.onResume(appRow, channel, null, null);
|
||||||
|
|
||||||
Preference pref = new Preference(RuntimeEnvironment.application);
|
Preference pref = new RestrictedListPreference(RuntimeEnvironment.application, null);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
assertTrue(pref.isEnabled());
|
assertTrue(pref.isEnabled());
|
||||||
assertNotNull(pref.getIntent());
|
|
||||||
assertFalse(TextUtils.isEmpty(pref.getSummary()));
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -110,7 +110,6 @@ public class NotificationsOffPreferenceControllerTest {
|
|||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
assertTrue(pref.getTitle().toString().contains("category"));
|
assertTrue(pref.getTitle().toString().contains("category"));
|
||||||
assertFalse(pref.isEnabled());
|
|
||||||
assertFalse(pref.isSelectable());
|
assertFalse(pref.isSelectable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +124,6 @@ public class NotificationsOffPreferenceControllerTest {
|
|||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
assertTrue(pref.getTitle().toString().contains("group"));
|
assertTrue(pref.getTitle().toString().contains("group"));
|
||||||
assertFalse(pref.isEnabled());
|
|
||||||
assertFalse(pref.isSelectable());
|
assertFalse(pref.isSelectable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +137,6 @@ public class NotificationsOffPreferenceControllerTest {
|
|||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
|
||||||
assertTrue(pref.getTitle().toString().contains("app"));
|
assertTrue(pref.getTitle().toString().contains("app"));
|
||||||
assertFalse(pref.isEnabled());
|
|
||||||
assertFalse(pref.isSelectable());
|
assertFalse(pref.isSelectable());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user