summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/app/Notification.java13
-rw-r--r--core/java/android/app/NotificationManager.java3
-rw-r--r--core/res/res/values/config.xml3
-rw-r--r--core/res/res/values/symbols.xml2
-rw-r--r--services/core/java/com/android/server/notification/ManagedServices.java14
-rw-r--r--services/core/java/com/android/server/notification/NotificationManagerService.java46
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java4
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java2
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/NotificationComparatorTest.java22
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java84
-rw-r--r--services/tests/uiservicestests/src/com/android/server/notification/NotificationTest.java51
11 files changed, 195 insertions, 49 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index eeec7caad7ee..c5b80196cf26 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -5553,7 +5553,8 @@ public class Notification implements Parcelable
*
* @hide
*/
- public static Notification maybeCloneStrippedForDelivery(Notification n, boolean isLowRam) {
+ public static Notification maybeCloneStrippedForDelivery(Notification n, boolean isLowRam,
+ Context context) {
String templateClass = n.extras.getString(EXTRA_TEMPLATE);
// Only strip views for known Styles because we won't know how to
@@ -5595,9 +5596,13 @@ public class Notification implements Parcelable
clone.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT);
}
if (isLowRam) {
- clone.extras.remove(Notification.TvExtender.EXTRA_TV_EXTENDER);
- clone.extras.remove(WearableExtender.EXTRA_WEARABLE_EXTENSIONS);
- clone.extras.remove(CarExtender.EXTRA_CAR_EXTENDER);
+ String[] allowedServices = context.getResources().getStringArray(
+ R.array.config_allowedManagedServicesOnLowRamDevices);
+ if (allowedServices.length == 0) {
+ clone.extras.remove(Notification.TvExtender.EXTRA_TV_EXTENDER);
+ clone.extras.remove(WearableExtender.EXTRA_WEARABLE_EXTENSIONS);
+ clone.extras.remove(CarExtender.EXTRA_CAR_EXTENDER);
+ }
}
return clone;
}
diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java
index 93be932b7fd0..f6dc5d15f385 100644
--- a/core/java/android/app/NotificationManager.java
+++ b/core/java/android/app/NotificationManager.java
@@ -399,7 +399,8 @@ public class NotificationManager {
ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
boolean isLowRam = am.isLowRamDevice();
- final Notification copy = Builder.maybeCloneStrippedForDelivery(notification, isLowRam);
+ final Notification copy = Builder.maybeCloneStrippedForDelivery(notification, isLowRam,
+ mContext);
try {
service.enqueueNotificationWithTag(pkg, mContext.getOpPackageName(), tag, id,
copy, user.getIdentifier());
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 62440880eb26..54864f36c40a 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -3181,6 +3181,9 @@
<!-- An array of packages for which notifications cannot be blocked. -->
<string-array translatable="false" name="config_nonBlockableNotificationPackages" />
+ <!-- An array of packages which can listen for notifications on low ram devices. -->
+ <string-array translatable="false" name="config_allowedManagedServicesOnLowRamDevices" />
+
<!-- The default value for transition animation scale found in developer settings.
1.0 corresponds to 1x animator scale, 0 means that there will be no transition
animations. Note that this is only a default and will be overridden by a
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 0800f510dd78..d155771fe79f 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -2979,6 +2979,8 @@
<java-symbol type="array" name="config_nonBlockableNotificationPackages" />
+ <java-symbol type="array" name="config_allowedManagedServicesOnLowRamDevices" />
+
<!-- Screen-size-dependent modes for picker dialogs. -->
<java-symbol type="integer" name="time_picker_mode" />
<java-symbol type="integer" name="date_picker_mode" />
diff --git a/services/core/java/com/android/server/notification/ManagedServices.java b/services/core/java/com/android/server/notification/ManagedServices.java
index 269a0dac41ab..f7becd518861 100644
--- a/services/core/java/com/android/server/notification/ManagedServices.java
+++ b/services/core/java/com/android/server/notification/ManagedServices.java
@@ -72,6 +72,8 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
/**
* Manages the lifecycle of application-provided services bound by system server.
@@ -336,7 +338,7 @@ abstract public class ManagedServices {
loadAllowedComponentsFromSettings();
}
- public void readXml(XmlPullParser parser)
+ public void readXml(XmlPullParser parser, Predicate<String> allowedManagedServicePackages)
throws XmlPullParserException, IOException {
// upgrade xml
int xmlVersion = XmlUtils.readIntAttribute(parser, ATT_VERSION, 0);
@@ -361,10 +363,14 @@ abstract public class ManagedServices {
final int userId = XmlUtils.readIntAttribute(parser, ATT_USER_ID, 0);
final boolean isPrimary =
XmlUtils.readBooleanAttribute(parser, ATT_IS_PRIMARY, true);
- if (mUm.getUserInfo(userId) != null) {
- addApprovedList(approved, userId, isPrimary);
+
+ if (allowedManagedServicePackages == null ||
+ allowedManagedServicePackages.test(getPackageName(approved))) {
+ if (mUm.getUserInfo(userId) != null) {
+ addApprovedList(approved, userId, isPrimary);
+ }
+ mUseXml = true;
}
- mUseXml = true;
}
}
}
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 594886458b6e..ec3949f9a441 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -233,6 +233,7 @@ import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.TimeUnit;
+import java.util.function.Predicate;
/** {@hide} */
public class NotificationManagerService extends SystemService {
@@ -397,6 +398,7 @@ public class NotificationManagerService extends SystemService {
private boolean mIsTelevision;
private MetricsLogger mMetricsLogger;
+ private Predicate<String> mAllowedManagedServicePackages;
private static class Archive {
final int mBufferSize;
@@ -518,18 +520,15 @@ public class NotificationManagerService extends SystemService {
} else if (RankingHelper.TAG_RANKING.equals(parser.getName())){
mRankingHelper.readXml(parser, forRestore);
}
- // No non-system managed services are allowed on low ram devices
- if (canUseManagedServices()) {
- if (mListeners.getConfig().xmlTag.equals(parser.getName())) {
- mListeners.readXml(parser);
- migratedManagedServices = true;
- } else if (mAssistants.getConfig().xmlTag.equals(parser.getName())) {
- mAssistants.readXml(parser);
- migratedManagedServices = true;
- } else if (mConditionProviders.getConfig().xmlTag.equals(parser.getName())) {
- mConditionProviders.readXml(parser);
- migratedManagedServices = true;
- }
+ if (mListeners.getConfig().xmlTag.equals(parser.getName())) {
+ mListeners.readXml(parser, mAllowedManagedServicePackages);
+ migratedManagedServices = true;
+ } else if (mAssistants.getConfig().xmlTag.equals(parser.getName())) {
+ mAssistants.readXml(parser, mAllowedManagedServicePackages);
+ migratedManagedServices = true;
+ } else if (mConditionProviders.getConfig().xmlTag.equals(parser.getName())) {
+ mConditionProviders.readXml(parser, mAllowedManagedServicePackages);
+ migratedManagedServices = true;
}
}
@@ -1429,6 +1428,9 @@ public class NotificationManagerService extends SystemService {
// This is a MangedServices object that keeps track of the assistant.
mAssistants = notificationAssistants;
+ // Needs to be set before loadPolicyFile
+ mAllowedManagedServicePackages = this::canUseManagedServices;
+
mPolicyFile = policyFile;
loadPolicyFile();
@@ -3218,7 +3220,7 @@ public class NotificationManagerService extends SystemService {
checkCallerIsSystemOrShell();
final long identity = Binder.clearCallingIdentity();
try {
- if (canUseManagedServices()) {
+ if (mAllowedManagedServicePackages.test(pkg)) {
mConditionProviders.setPackageOrComponentEnabled(
pkg, userId, true, granted);
@@ -3349,7 +3351,7 @@ public class NotificationManagerService extends SystemService {
checkCallerIsSystemOrShell();
final long identity = Binder.clearCallingIdentity();
try {
- if (canUseManagedServices()) {
+ if (mAllowedManagedServicePackages.test(listener.getPackageName())) {
mConditionProviders.setPackageOrComponentEnabled(listener.flattenToString(),
userId, false, granted);
mListeners.setPackageOrComponentEnabled(listener.flattenToString(),
@@ -3375,7 +3377,7 @@ public class NotificationManagerService extends SystemService {
checkCallerIsSystemOrShell();
final long identity = Binder.clearCallingIdentity();
try {
- if (canUseManagedServices()) {
+ if (mAllowedManagedServicePackages.test(assistant.getPackageName())) {
mConditionProviders.setPackageOrComponentEnabled(assistant.flattenToString(),
userId, false, granted);
mAssistants.setPackageOrComponentEnabled(assistant.flattenToString(),
@@ -6183,9 +6185,19 @@ public class NotificationManagerService extends SystemService {
}
}
- private boolean canUseManagedServices() {
- return !mActivityManager.isLowRamDevice()
+ @VisibleForTesting
+ boolean canUseManagedServices(String pkg) {
+ boolean canUseManagedServices = !mActivityManager.isLowRamDevice()
|| mPackageManagerClient.hasSystemFeature(PackageManager.FEATURE_WATCH);
+
+ for (String whitelisted : getContext().getResources().getStringArray(
+ R.array.config_allowedManagedServicesOnLowRamDevices)) {
+ if (whitelisted.equals(pkg)) {
+ canUseManagedServices = true;
+ }
+ }
+
+ return canUseManagedServices;
}
private class TrimCache {
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java b/services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java
index 4668ed42b11e..d0a656c69f43 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/ManagedServicesTest.java
@@ -343,7 +343,7 @@ public class ManagedServicesTest extends UiServiceTestCase {
parser.setInput(new BufferedInputStream(
new ByteArrayInputStream(baos.toByteArray())), null);
parser.nextTag();
- service.readXml(parser);
+ service.readXml(parser, null);
verifyExpectedApprovedEntries(service);
assertFalse(service.isPackageOrComponentAllowed("this.is.a.package.name", 0));
@@ -665,7 +665,7 @@ public class ManagedServicesTest extends UiServiceTestCase {
parser.setInput(new BufferedInputStream(
new ByteArrayInputStream(xml.toString().getBytes())), null);
parser.nextTag();
- service.readXml(parser);
+ service.readXml(parser, null);
}
private void addExpectedServices(final ManagedServices service, final List<String> packages,
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java
index a8b9dff7b3e2..f9a4f784bf4f 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationAssistantsTest.java
@@ -124,7 +124,7 @@ public class NotificationAssistantsTest extends UiServiceTestCase {
parser.setInput(new BufferedInputStream(
new ByteArrayInputStream(xml.toString().getBytes())), null);
parser.nextTag();
- mAssistants.readXml(parser);
+ mAssistants.readXml(parser, null);
verify(mNm, never()).readDefaultAssistant(anyInt());
verify(mAssistants, times(1)).addApprovedList(
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationComparatorTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationComparatorTest.java
index 30fae01f3036..7ee050174d3c 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationComparatorTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationComparatorTest.java
@@ -138,12 +138,14 @@ public class NotificationComparatorTest extends UiServiceTestCase {
mRecordInlineReply.setUserImportance(NotificationManager.IMPORTANCE_HIGH);
mRecordInlineReply.setPackagePriority(Notification.PRIORITY_MAX);
- Notification n5 = new Notification.Builder(mContext, TEST_CHANNEL_ID)
- .setCategory(Notification.CATEGORY_MESSAGE).build();
- mRecordSms = new NotificationRecord(mContext, new StatusBarNotification(smsPkg,
- smsPkg, 1, "sms", smsUid, smsUid, n5, new UserHandle(userId),
- "", 1299), getDefaultChannel());
- mRecordSms.setUserImportance(NotificationManager.IMPORTANCE_DEFAULT);
+ if (smsPkg != null) {
+ Notification n5 = new Notification.Builder(mContext, TEST_CHANNEL_ID)
+ .setCategory(Notification.CATEGORY_MESSAGE).build();
+ mRecordSms = new NotificationRecord(mContext, new StatusBarNotification(smsPkg,
+ smsPkg, 1, "sms", smsUid, smsUid, n5, new UserHandle(userId),
+ "", 1299), getDefaultChannel());
+ mRecordSms.setUserImportance(NotificationManager.IMPORTANCE_DEFAULT);
+ }
Notification n6 = new Notification.Builder(mContext, TEST_CHANNEL_ID).build();
mRecordStarredContact = new NotificationRecord(mContext, new StatusBarNotification(pkg2,
@@ -230,7 +232,9 @@ public class NotificationComparatorTest extends UiServiceTestCase {
expected.add(mRecordColorized);
expected.add(mRecordHighCall);
expected.add(mRecordInlineReply);
- expected.add(mRecordSms);
+ if (mRecordSms != null) {
+ expected.add(mRecordSms);
+ }
expected.add(mRecordStarredContact);
expected.add(mRecordContact);
expected.add(mRecordEmail);
@@ -253,7 +257,9 @@ public class NotificationComparatorTest extends UiServiceTestCase {
public void testMessaging() throws Exception {
NotificationComparator comp = new NotificationComparator(mContext);
assertTrue(comp.isImportantMessaging(mRecordInlineReply));
- assertTrue(comp.isImportantMessaging(mRecordSms));
+ if (mRecordSms != null) {
+ assertTrue(comp.isImportantMessaging(mRecordSms));
+ }
assertFalse(comp.isImportantMessaging(mRecordEmail));
assertFalse(comp.isImportantMessaging(mRecordCheater));
}
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
index 0c2928a9051f..eb1c9975cb7e 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
@@ -80,6 +80,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
+import android.content.res.Resources;
import android.graphics.Color;
import android.media.AudioAttributes;
import android.media.AudioManager;
@@ -105,6 +106,7 @@ import android.testing.TestableLooper.RunWithLooper;
import android.util.ArrayMap;
import android.util.AtomicFile;
+import com.android.internal.R;
import com.android.internal.statusbar.NotificationVisibility;
import com.android.server.UiServiceTestCase;
import com.android.server.lights.Light;
@@ -160,6 +162,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
@Mock
ActivityManager mActivityManager;
NotificationManagerService.WorkerHandler mHandler;
+ @Mock
+ Resources mResources;
private NotificationChannel mTestNotificationChannel = new NotificationChannel(
TEST_CHANNEL_ID, TEST_CHANNEL_ID, NotificationManager.IMPORTANCE_DEFAULT);
@@ -391,7 +395,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
public void testCreateNotificationChannels_NullChannelThrowsException() throws Exception {
try {
mBinderService.createNotificationChannels(PKG,
- new ParceledListSlice(Arrays.asList(null)));
+ new ParceledListSlice(Arrays.asList((Object[])null)));
fail("Exception should be thrown immediately.");
} catch (NullPointerException e) {
// pass
@@ -2197,9 +2201,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
+ "</notification-policy>";
mService.readPolicyXml(
new BufferedInputStream(new ByteArrayInputStream(upgradeXml.getBytes())), false);
- verify(mListeners, times(1)).readXml(any());
- verify(mConditionProviders, times(1)).readXml(any());
- verify(mAssistants, times(1)).readXml(any());
+ verify(mListeners, times(1)).readXml(any(), any());
+ verify(mConditionProviders, times(1)).readXml(any(), any());
+ verify(mAssistants, times(1)).readXml(any(), any());
// numbers are inflated for setup
verify(mListeners, times(1)).migrateToXml();
@@ -2216,9 +2220,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
+ "</notification-policy>";
mService.readPolicyXml(
new BufferedInputStream(new ByteArrayInputStream(preupgradeXml.getBytes())), false);
- verify(mListeners, never()).readXml(any());
- verify(mConditionProviders, never()).readXml(any());
- verify(mAssistants, never()).readXml(any());
+ verify(mListeners, never()).readXml(any(), any());
+ verify(mConditionProviders, never()).readXml(any(), any());
+ verify(mAssistants, never()).readXml(any(), any());
// numbers are inflated for setup
verify(mListeners, times(2)).migrateToXml();
@@ -2780,4 +2784,70 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
verify(mListeners, times(1)).notifyHiddenLocked(captor.capture());
assertEquals(0, captor.getValue().size());
}
+
+ @Test
+ public void testCanUseManagedServicesLowRamNoWatchNullPkg() {
+ when(mPackageManagerClient.hasSystemFeature(FEATURE_WATCH)).thenReturn(false);
+ when(mActivityManager.isLowRamDevice()).thenReturn(true);
+ when(mResources.getStringArray(R.array.config_allowedManagedServicesOnLowRamDevices))
+ .thenReturn(new String[] {"a", "b", "c"});
+ when(mContext.getResources()).thenReturn(mResources);
+
+ assertEquals(false, mService.canUseManagedServices(null));
+ }
+
+ @Test
+ public void testCanUseManagedServicesLowRamNoWatchValidPkg() {
+ when(mPackageManagerClient.hasSystemFeature(FEATURE_WATCH)).thenReturn(false);
+ when(mActivityManager.isLowRamDevice()).thenReturn(true);
+ when(mResources.getStringArray(R.array.config_allowedManagedServicesOnLowRamDevices))
+ .thenReturn(new String[] {"a", "b", "c"});
+ when(mContext.getResources()).thenReturn(mResources);
+
+ assertEquals(true, mService.canUseManagedServices("b"));
+ }
+
+ @Test
+ public void testCanUseManagedServicesLowRamNoWatchNoValidPkg() {
+ when(mPackageManagerClient.hasSystemFeature(FEATURE_WATCH)).thenReturn(false);
+ when(mActivityManager.isLowRamDevice()).thenReturn(true);
+ when(mResources.getStringArray(R.array.config_allowedManagedServicesOnLowRamDevices))
+ .thenReturn(new String[] {"a", "b", "c"});
+ when(mContext.getResources()).thenReturn(mResources);
+
+ assertEquals(false, mService.canUseManagedServices("d"));
+ }
+
+ @Test
+ public void testCanUseManagedServicesLowRamWatchNoValidPkg() {
+ when(mPackageManagerClient.hasSystemFeature(FEATURE_WATCH)).thenReturn(true);
+ when(mActivityManager.isLowRamDevice()).thenReturn(true);
+ when(mResources.getStringArray(R.array.config_allowedManagedServicesOnLowRamDevices))
+ .thenReturn(new String[] {"a", "b", "c"});
+ when(mContext.getResources()).thenReturn(mResources);
+
+ assertEquals(true, mService.canUseManagedServices("d"));
+ }
+
+ @Test
+ public void testCanUseManagedServicesNoLowRamNoWatchValidPkg() {
+ when(mPackageManagerClient.hasSystemFeature(FEATURE_WATCH)).thenReturn(false);
+ when(mActivityManager.isLowRamDevice()).thenReturn(false);
+ when(mResources.getStringArray(R.array.config_allowedManagedServicesOnLowRamDevices))
+ .thenReturn(new String[] {"a", "b", "c"});
+ when(mContext.getResources()).thenReturn(mResources);
+
+ assertEquals(true, mService.canUseManagedServices("d"));
+ }
+
+ @Test
+ public void testCanUseManagedServicesNoLowRamWatchValidPkg() {
+ when(mPackageManagerClient.hasSystemFeature(FEATURE_WATCH)).thenReturn(true);
+ when(mActivityManager.isLowRamDevice()).thenReturn(false);
+ when(mResources.getStringArray(R.array.config_allowedManagedServicesOnLowRamDevices))
+ .thenReturn(new String[] {"a", "b", "c"});
+ when(mContext.getResources()).thenReturn(mResources);
+
+ assertEquals(true, mService.canUseManagedServices("d"));
+ }
}
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationTest.java
index 9f7205b8efc8..d846d213c5b6 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationTest.java
@@ -25,6 +25,8 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
import android.app.ActivityManager;
import android.app.Notification;
@@ -33,6 +35,8 @@ import android.app.PendingIntent;
import android.app.RemoteInput;
import android.content.Context;
import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.Icon;
@@ -57,20 +61,29 @@ public class NotificationTest extends UiServiceTestCase {
@Mock
ActivityManager mAm;
+ @Mock
+ Resources mResources;
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}
@Test
- public void testStripsExtendersInLowRamMode() {
+ public void testStripsExtendersInLowRamModeNoWhitelistNoTv() {
Notification.Builder nb = new Notification.Builder(mContext, "channel");
nb.extend(new Notification.CarExtender().setColor(Color.RED));
nb.extend(new Notification.TvExtender().setChannelId("different channel"));
nb.extend(new Notification.WearableExtender().setDismissalId("dismiss"));
Notification before = nb.build();
- Notification after = Notification.Builder.maybeCloneStrippedForDelivery(before, true);
+ // No whitelist
+ Context context = spy(getContext());
+ when(context.getResources()).thenReturn(mResources);
+ when(mResources.getStringArray(anyInt())).thenReturn(new String[0]);
+
+ Notification after = Notification.Builder.maybeCloneStrippedForDelivery(before, true,
+ context);
assertEquals("different channel", new Notification.TvExtender(before).getChannelId());
assertNull(new Notification.TvExtender(after).getChannelId());
@@ -83,8 +96,34 @@ public class NotificationTest extends UiServiceTestCase {
}
@Test
+ public void testStripsExtendersInLowRamModeHasWhitelist() {
+ Notification.Builder nb = new Notification.Builder(mContext, "channel");
+ nb.extend(new Notification.CarExtender().setColor(Color.RED));
+ nb.extend(new Notification.TvExtender().setChannelId("different channel"));
+ nb.extend(new Notification.WearableExtender().setDismissalId("dismiss"));
+ Notification before = nb.build();
+
+ // Has whitelist
+ Context context = spy(mContext);
+ when(context.getResources()).thenReturn(mResources);
+ when(mResources.getStringArray(anyInt())).thenReturn(new String[1]);
+
+ Notification after = Notification.Builder.maybeCloneStrippedForDelivery(before, true,
+ context);
+
+ assertEquals("different channel", new Notification.TvExtender(before).getChannelId());
+ assertEquals("different channel", new Notification.TvExtender(after).getChannelId());
+
+ assertEquals(Color.RED, new Notification.CarExtender(before).getColor());
+ assertEquals(Color.RED, new Notification.CarExtender(after).getColor());
+
+ assertEquals("dismiss", new Notification.WearableExtender(before).getDismissalId());
+ assertEquals("dismiss", new Notification.WearableExtender(after).getDismissalId());
+ }
+
+ @Test
public void testStripsRemoteViewsInLowRamMode() {
- Context context = spy(getContext());
+ Context context = spy(mContext);
ApplicationInfo ai = new ApplicationInfo();
ai.targetSdkVersion = Build.VERSION_CODES.M;
when(context.getApplicationInfo()).thenReturn(ai);
@@ -97,7 +136,8 @@ public class NotificationTest extends UiServiceTestCase {
.setStyle(style)
.build();
- Notification after = Notification.Builder.maybeCloneStrippedForDelivery(before, true);
+ Notification after = Notification.Builder.maybeCloneStrippedForDelivery(before, true,
+ mContext);
assertNotNull(before.contentView);
assertNotNull(before.bigContentView);
assertNotNull(before.headsUpContentView);
@@ -113,7 +153,8 @@ public class NotificationTest extends UiServiceTestCase {
nb.extend(new Notification.TvExtender().setChannelId("different channel"));
nb.extend(new Notification.WearableExtender().setDismissalId("dismiss"));
Notification before = nb.build();
- Notification after = Notification.Builder.maybeCloneStrippedForDelivery(before, false);
+ Notification after = Notification.Builder.maybeCloneStrippedForDelivery(before, false,
+ mContext);
assertTrue(before == after);