Merge "Notification settings updates" into pi-dev

am: d7a1c39694

Change-Id: Ic458150338fe20e3ee2125b1419b1741754d42a9
This commit is contained in:
Julia Reynolds
2018-04-10 07:01:53 -07:00
committed by android-build-merger
14 changed files with 62 additions and 20 deletions

View File

@@ -95,8 +95,8 @@
android:id="@android:id/widget_frame" android:id="@android:id/widget_frame"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="end|center_vertical" android:gravity="center"
android:paddingStart="16dp" android:minWidth="64dp"
android:orientation="vertical" /> android:orientation="vertical" />
</LinearLayout> </LinearLayout>

View File

@@ -7515,9 +7515,9 @@
<string name="default_notification_assistant">Notification assistant</string> <string name="default_notification_assistant">Notification assistant</string>
<!-- app summary of notification app list screen [CHAR LIMIT=100] --> <!-- app summary of notification app list screen [CHAR LIMIT=100] -->
<string name="notifications_sent_daily">~<xliff:g id="number">%1$s</xliff:g> sent daily</string> <string name="notifications_sent_daily">~<xliff:g id="number">%1$s</xliff:g> per day</string>
<!-- app summary of notification app list screen [CHAR LIMIT=100] --> <!-- app summary of notification app list screen [CHAR LIMIT=100] -->
<string name="notifications_sent_weekly">~<xliff:g id="number">%1$s</xliff:g> sent weekly</string> <string name="notifications_sent_weekly">~<xliff:g id="number">%1$s</xliff:g> per week</string>
<!-- app summary of notification app list screen [CHAR LIMIT=100] --> <!-- app summary of notification app list screen [CHAR LIMIT=100] -->
<string name="notifications_sent_never">Never</string> <string name="notifications_sent_never">Never</string>

View File

@@ -167,9 +167,9 @@ public class AppNotificationSettings extends NotificationSettingsBase {
getPreferenceScreen().addPreference(groupCategory); getPreferenceScreen().addPreference(groupCategory);
mDynamicPreferences.add(groupCategory); mDynamicPreferences.add(groupCategory);
if (group.getId() == null) { if (group.getId() == null) {
groupCategory.setTitle(mChannelGroupList.size() > 1 if (mChannelGroupList.size() > 1) {
? R.string.notification_channels_other groupCategory.setTitle(R.string.notification_channels_other);
: R.string.notification_channels); }
groupCategory.setKey(KEY_GENERAL_CATEGORY); groupCategory.setKey(KEY_GENERAL_CATEGORY);
} else { } else {
groupCategory.setTitle(group.getName()); groupCategory.setTitle(group.getName());

View File

@@ -57,7 +57,7 @@ public class BadgePreferenceController extends NotificationPreferenceController
return false; return false;
} }
if (mChannel != null) { if (mChannel != null) {
if (NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId())) { if (isDefaultChannel()) {
return true; return true;
} else { } else {
return mAppRow.showBadge; return mAppRow.showBadge;

View File

@@ -98,8 +98,7 @@ public class BlockPreferenceController extends NotificationPreferenceController
// it was blocked and we are unblocking it. // it was blocked and we are unblocking it.
if (blocked || originalImportance == IMPORTANCE_NONE) { if (blocked || originalImportance == IMPORTANCE_NONE) {
final int importance = blocked ? IMPORTANCE_NONE final int importance = blocked ? IMPORTANCE_NONE
: DEFAULT_CHANNEL_ID.equals(mChannel.getId()) : isDefaultChannel() ? IMPORTANCE_UNSPECIFIED : IMPORTANCE_DEFAULT;
? IMPORTANCE_UNSPECIFIED : IMPORTANCE_DEFAULT;
mChannel.setImportance(importance); mChannel.setImportance(importance);
saveChannel(); saveChannel();
} }

View File

@@ -31,6 +31,8 @@ import com.android.settings.applications.LayoutPreference;
import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.widget.EntityHeaderController; import com.android.settings.widget.EntityHeaderController;
import java.util.Objects;
public class HeaderPreferenceController extends NotificationPreferenceController public class HeaderPreferenceController extends NotificationPreferenceController
implements PreferenceControllerMixin { implements PreferenceControllerMixin {
@@ -72,7 +74,7 @@ public class HeaderPreferenceController extends NotificationPreferenceController
} }
CharSequence getLabel() { CharSequence getLabel() {
return mChannel != null ? mChannel.getName() return (mChannel != null && !isDefaultChannel()) ? mChannel.getName()
: mChannelGroup != null : mChannelGroup != null
? mChannelGroup.getName() ? mChannelGroup.getName()
: mAppRow.label; : mAppRow.label;
@@ -80,7 +82,7 @@ public class HeaderPreferenceController extends NotificationPreferenceController
@Override @Override
public CharSequence getSummary() { public CharSequence getSummary() {
if (mChannel != null) { if (mChannel != null && !isDefaultChannel()) {
if (mChannelGroup != null if (mChannelGroup != null
&& !TextUtils.isEmpty(mChannelGroup.getName())) { && !TextUtils.isEmpty(mChannelGroup.getName())) {
final SpannableStringBuilder summary = new SpannableStringBuilder(); final SpannableStringBuilder summary = new SpannableStringBuilder();

View File

@@ -58,7 +58,7 @@ public class ImportancePreferenceController extends NotificationPreferenceContro
if (mChannel == null) { if (mChannel == null) {
return false; return false;
} }
return !NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId()); return !isDefaultChannel();
} }
@Override @Override

View File

@@ -50,8 +50,9 @@ public class LightsPreferenceController extends NotificationPreferenceController
if (mChannel == null) { if (mChannel == null) {
return false; return false;
} }
return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) && canPulseLight() return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT)
&& !NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId()); && canPulseLight()
&& !isDefaultChannel();
} }
public void updateState(Preference preference) { public void updateState(Preference preference) {

View File

@@ -184,4 +184,11 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc
protected boolean hasValidGroup() { protected boolean hasValidGroup() {
return mChannelGroup != null; return mChannelGroup != null;
} }
protected final boolean isDefaultChannel() {
if (mChannel == null) {
return false;
}
return Objects.equals(NotificationChannel.DEFAULT_CHANNEL_ID, mChannel.getId());
}
} }

View File

@@ -37,14 +37,13 @@ import android.util.Log;
import com.android.internal.logging.nano.MetricsProto; import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.applications.AppInfoBase; import com.android.settings.applications.AppInfoBase;
import com.android.settings.applications.InstalledAppCounter;
import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.SubSettingLauncher; import com.android.settings.core.SubSettingLauncher;
import com.android.settingslib.TwoTargetPreference;
import com.android.settingslib.applications.AppUtils; import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.applications.ApplicationsState; import com.android.settingslib.applications.ApplicationsState;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.utils.StringUtil; import com.android.settingslib.utils.StringUtil;
import com.android.settingslib.wrapper.PackageManagerWrapper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@@ -211,6 +210,7 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
pref.setKey(pkgName); pref.setKey(pkgName);
pref.setTitle(appEntry.label); pref.setTitle(appEntry.label);
pref.setIcon(mIconDrawableFactory.getBadgedIcon(appEntry.info)); pref.setIcon(mIconDrawableFactory.getBadgedIcon(appEntry.info));
pref.setIconSize(TwoTargetPreference.ICON_SIZE_SMALL);
pref.setSummary(StringUtil.formatRelativeTime(mContext, pref.setSummary(StringUtil.formatRelativeTime(mContext,
System.currentTimeMillis() - app.getLastNotified(), true)); System.currentTimeMillis() - app.getLastNotified(), true));
pref.setOrder(i); pref.setOrder(i);

View File

@@ -59,8 +59,7 @@ public class SoundPreferenceController extends NotificationPreferenceController
if (mChannel == null) { if (mChannel == null) {
return false; return false;
} }
return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) && !isDefaultChannel();
&& !NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId());
} }
@Override @Override

View File

@@ -47,7 +47,7 @@ public class VibrationPreferenceController extends NotificationPreferenceControl
return false; return false;
} }
return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT)
&& !NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId()) && !isDefaultChannel()
&& mVibrator != null && mVibrator != null
&& mVibrator.hasVibrator(); && mVibrator.hasVibrator();
} }

View File

@@ -109,6 +109,11 @@ public class HeaderPreferenceControllerTest {
NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE); NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE);
mController.onResume(appRow, channel, group, null); mController.onResume(appRow, channel, group, null);
assertEquals(channel.getName(), mController.getLabel()); assertEquals(channel.getName(), mController.getLabel());
NotificationChannel defaultChannel = new NotificationChannel(
NotificationChannel.DEFAULT_CHANNEL_ID, "", IMPORTANCE_NONE);
mController.onResume(appRow, defaultChannel, null, null);
assertEquals(appRow.label, mController.getLabel());
} }
@Test @Test
@@ -130,5 +135,10 @@ public class HeaderPreferenceControllerTest {
mController.onResume(appRow, channel, null, null); mController.onResume(appRow, channel, null, null);
assertFalse(mController.getSummary().toString().contains(group.getName())); assertFalse(mController.getSummary().toString().contains(group.getName()));
assertTrue(mController.getSummary().toString().contains(appRow.label)); assertTrue(mController.getSummary().toString().contains(appRow.label));
NotificationChannel defaultChannel = new NotificationChannel(
NotificationChannel.DEFAULT_CHANNEL_ID, "", IMPORTANCE_NONE);
mController.onResume(appRow, defaultChannel, null, null);
assertEquals("", mController.getSummary());
} }
} }

View File

@@ -294,6 +294,30 @@ public class NotificationPreferenceControllerTest {
assertTrue(mController.isChannelGroupBlockable()); assertTrue(mController.isChannelGroupBlockable());
} }
@Test
public void testIsDefaultChannel_noChannel() {
mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null);
assertFalse(mController.isDefaultChannel());
}
@Test
public void testIsDefaultChannel_nonDefaultChannel() {
NotificationChannel channel = mock(NotificationChannel.class);
mController.onResume(mock(NotificationBackend.AppRow.class), channel, null, null);
assertFalse(mController.isDefaultChannel());
}
@Test
public void testIsDefaultChannel() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn(NotificationChannel.DEFAULT_CHANNEL_ID);
mController.onResume(mock(NotificationBackend.AppRow.class), channel, null, null);
assertTrue(mController.isDefaultChannel());
}
private final class TestPreferenceController extends NotificationPreferenceController { private final class TestPreferenceController extends NotificationPreferenceController {
private TestPreferenceController(Context context, NotificationBackend backend) { private TestPreferenceController(Context context, NotificationBackend backend) {