Merge "Re-add default channel on app targetsdk downgrade." into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
4c11bde01d
@@ -3236,6 +3236,8 @@ public class NotificationManagerService extends SystemService {
|
||||
final String noChannelStr = "No Channel found for "
|
||||
+ "pkg=" + pkg
|
||||
+ ", channelId=" + channelId
|
||||
+ ", id=" + id
|
||||
+ ", tag=" + tag
|
||||
+ ", opPkg=" + opPkg
|
||||
+ ", callingUid=" + callingUid
|
||||
+ ", userId=" + userId
|
||||
|
||||
@@ -1115,6 +1115,7 @@ public class RankingHelper implements RankingConfig {
|
||||
Record fullRecord = getRecord(pkg,
|
||||
mPm.getPackageUidAsUser(pkg, changeUserId));
|
||||
if (fullRecord != null) {
|
||||
createDefaultChannelIfNeeded(fullRecord);
|
||||
deleteDefaultChannelIfNeeded(fullRecord);
|
||||
}
|
||||
} catch (NameNotFoundException e) {}
|
||||
|
||||
@@ -123,6 +123,7 @@ public class RankingHelperTest extends NotificationTestCase {
|
||||
when(mPm.getApplicationInfoAsUser(eq(PKG), anyInt(), anyInt())).thenReturn(legacy);
|
||||
when(mPm.getApplicationInfoAsUser(eq(UPDATED_PKG), anyInt(), anyInt())).thenReturn(upgrade);
|
||||
when(mPm.getPackageUidAsUser(eq(PKG), anyInt())).thenReturn(UID);
|
||||
when(mPm.getPackageUidAsUser(eq(UPDATED_PKG), anyInt())).thenReturn(UID2);
|
||||
when(mContext.getResources()).thenReturn(
|
||||
InstrumentationRegistry.getContext().getResources());
|
||||
when(mContext.getPackageManager()).thenReturn(mPm);
|
||||
@@ -1045,6 +1046,24 @@ public class RankingHelperTest extends NotificationTestCase {
|
||||
assertEquals(0, mHelper.getNotificationChannelGroups(PKG, UID, true).getList().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnPackageChange_downgradeTargetSdk() throws Exception {
|
||||
// create channel as api 26
|
||||
mHelper.createNotificationChannel(UPDATED_PKG, UID2, getChannel(), true);
|
||||
|
||||
// install new app version targeting 25
|
||||
final ApplicationInfo legacy = new ApplicationInfo();
|
||||
legacy.targetSdkVersion = Build.VERSION_CODES.N_MR1;
|
||||
when(mPm.getApplicationInfoAsUser(eq(UPDATED_PKG), anyInt(), anyInt())).thenReturn(legacy);
|
||||
mHelper.onPackagesChanged(
|
||||
false, UserHandle.USER_SYSTEM, new String[]{UPDATED_PKG}, new int[]{UID2});
|
||||
|
||||
// make sure the default channel was readded
|
||||
//assertEquals(2, mHelper.getNotificationChannels(UPDATED_PKG, UID2, false).getList().size());
|
||||
assertNotNull(mHelper.getNotificationChannel(
|
||||
UPDATED_PKG, UID2, NotificationChannel.DEFAULT_CHANNEL_ID, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRecordDefaults() throws Exception {
|
||||
assertEquals(NotificationManager.IMPORTANCE_UNSPECIFIED, mHelper.getImportance(PKG, UID));
|
||||
|
||||
Reference in New Issue
Block a user