Fix visibility of settings on channel page

Properly hide fields if the parent app or group
is blocked. This is needed because apps can link
directly to this screen.

Test: atest
Fixes: 130184191
Change-Id: I8c39410574940615fbb607a201e20e480ec02d87
This commit is contained in:
Julia Reynolds
2019-04-10 09:57:02 -04:00
parent 3c2d168026
commit 2290e284ec
4 changed files with 24 additions and 4 deletions

View File

@@ -50,12 +50,18 @@ public class ImportancePreferenceController extends NotificationPreferenceContro
if (mAppRow == null) { if (mAppRow == null) {
return false; return false;
} }
if (mAppRow.banned) {
return false;
}
if (mChannel == null) { if (mChannel == null) {
return false; return false;
} }
if (isDefaultChannel()) { if (isDefaultChannel()) {
return false; return false;
} }
if (mChannelGroup != null && mChannelGroup.isBlocked()) {
return false;
}
return true; return true;
} }

View File

@@ -73,12 +73,12 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc
if (mAppRow.banned) { if (mAppRow.banned) {
return false; return false;
} }
if (mChannel != null) {
return mChannel.getImportance() != IMPORTANCE_NONE;
}
if (mChannelGroup != null) { if (mChannelGroup != null) {
return !mChannelGroup.isBlocked(); return !mChannelGroup.isBlocked();
} }
if (mChannel != null) {
return mChannel.getImportance() != IMPORTANCE_NONE;
}
return true; return true;
} }

View File

@@ -17,6 +17,7 @@
package com.android.settings.notification; package com.android.settings.notification;
import static android.app.NotificationChannel.DEFAULT_CHANNEL_ID; import static android.app.NotificationChannel.DEFAULT_CHANNEL_ID;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH; 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;
@@ -36,6 +37,7 @@ import static org.mockito.Mockito.when;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationChannel; import android.app.NotificationChannel;
import android.app.NotificationChannelGroup;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.Context; import android.content.Context;
import android.os.UserManager; import android.os.UserManager;
@@ -100,7 +102,18 @@ public class ImportancePreferenceControllerTest {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true; appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class), null, null); mController.onResume(appRow, mock(NotificationChannel.class), null, null);
assertTrue(mController.isAvailable()); assertFalse(mController.isAvailable());
}
@Test
public void testIsAvailable_isGroupBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
NotificationChannelGroup group = mock(NotificationChannelGroup.class);
when(group.isBlocked()).thenReturn(true);
mController.onResume(appRow, channel, group, null);
assertFalse(mController.isAvailable());
} }
@Test @Test

View File

@@ -117,6 +117,7 @@ public class NotificationPreferenceControllerTest {
public void isAvailable_notIfChannelGroupBlocked() { public void isAvailable_notIfChannelGroupBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class); NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT);
NotificationChannelGroup group = mock(NotificationChannelGroup.class); NotificationChannelGroup group = mock(NotificationChannelGroup.class);
mController.onResume(appRow, channel, group, null); mController.onResume(appRow, channel, group, null);