diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java index febce31c22290..7f141eeba839f 100644 --- a/services/core/java/com/android/server/notification/RankingHelper.java +++ b/services/core/java/com/android/server/notification/RankingHelper.java @@ -116,17 +116,12 @@ public class RankingHelper implements RankingConfig { private final ArrayMap mRecords = new ArrayMap<>(); // pkg|uid => Record private final ArrayMap mProxyByGroupTmp = new ArrayMap<>(); private final ArrayMap mRestoredWithoutUids = new ArrayMap<>(); // pkg => Record - private final ArrayMap, Boolean> mSystemAppCache = new ArrayMap<>(); private final Context mContext; private final RankingHandler mRankingHandler; private final PackageManager mPm; private SparseBooleanArray mBadgingEnabled; - private Signature[] mSystemSignature; - private String mPermissionControllerPackageName; - private String mServicesSystemSharedLibPackageName; - private String mSharedSystemSharedLibPackageName; private boolean mAreChannelsBypassingDnd; private ZenModeHelper mZenModeHelper; @@ -161,7 +156,6 @@ public class RankingHelper implements RankingConfig { } } - getSignatures(); updateChannelsBypassingDnd(); } @@ -623,7 +617,6 @@ public class RankingHelper implements RankingConfig { if (NotificationChannel.DEFAULT_CHANNEL_ID.equals(channel.getId())) { throw new IllegalArgumentException("Reserved id"); } - final boolean isSystemApp = isSystemPackage(pkg, uid); NotificationChannel existing = r.channels.get(channel.getId()); // Keep most of the existing settings if (existing != null && fromTargetApp) { @@ -651,7 +644,7 @@ public class RankingHelper implements RankingConfig { // system apps and dnd access apps can bypass dnd if the user hasn't changed any // fields on the channel yet - if (existing.getUserLockedFields() == 0 && (isSystemApp || hasDndAccess)) { + if (existing.getUserLockedFields() == 0 && hasDndAccess) { boolean bypassDnd = channel.canBypassDnd(); existing.setBypassDnd(bypassDnd); @@ -669,7 +662,7 @@ public class RankingHelper implements RankingConfig { } // Reset fields that apps aren't allowed to set. - if (fromTargetApp && !(isSystemApp || hasDndAccess)) { + if (fromTargetApp && !hasDndAccess) { channel.setBypassDnd(r.priority == Notification.PRIORITY_MAX); } if (fromTargetApp) { @@ -695,65 +688,6 @@ public class RankingHelper implements RankingConfig { channel.unlockFields(channel.getUserLockedFields()); } - /** - * Determine whether a package is a "system package", in which case certain things (like - * bypassing DND) should be allowed. - */ - private boolean isSystemPackage(String pkg, int uid) { - Pair app = new Pair(pkg, uid); - if (mSystemAppCache.containsKey(app)) { - return mSystemAppCache.get(app); - } - - PackageInfo pi; - try { - pi = mPm.getPackageInfoAsUser( - pkg, PackageManager.GET_SIGNATURES, UserHandle.getUserId(uid)); - } catch (NameNotFoundException e) { - Slog.w(TAG, "Can't find pkg", e); - return false; - } - boolean isSystem = (mSystemSignature[0] != null - && mSystemSignature[0].equals(getFirstSignature(pi))) - || pkg.equals(mPermissionControllerPackageName) - || pkg.equals(mServicesSystemSharedLibPackageName) - || pkg.equals(mSharedSystemSharedLibPackageName) - || pkg.equals(PrintManager.PRINT_SPOOLER_PACKAGE_NAME) - || isDeviceProvisioningPackage(pkg); - mSystemAppCache.put(app, isSystem); - return isSystem; - } - - private Signature getFirstSignature(PackageInfo pkg) { - if (pkg != null && pkg.signatures != null && pkg.signatures.length > 0) { - return pkg.signatures[0]; - } - return null; - } - - private Signature getSystemSignature() { - try { - final PackageInfo sys = mPm.getPackageInfoAsUser( - "android", PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM); - return getFirstSignature(sys); - } catch (NameNotFoundException e) { - } - return null; - } - - private boolean isDeviceProvisioningPackage(String packageName) { - String deviceProvisioningPackage = mContext.getResources().getString( - com.android.internal.R.string.config_deviceProvisioningPackage); - return deviceProvisioningPackage != null && deviceProvisioningPackage.equals(packageName); - } - - private void getSignatures() { - mSystemSignature = new Signature[]{getSystemSignature()}; - mPermissionControllerPackageName = mPm.getPermissionControllerPackageName(); - mServicesSystemSharedLibPackageName = mPm.getServicesSystemSharedLibraryPackageName(); - mSharedSystemSharedLibPackageName = mPm.getSharedSystemSharedLibraryPackageName(); - } - @Override public void updateNotificationChannel(String pkg, int uid, NotificationChannel updatedChannel, boolean fromUser) { diff --git a/services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java index 8183a74672775..890595045ae27 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java @@ -1714,13 +1714,13 @@ public class RankingHelperTest extends UiServiceTestCase { } @Test - public void testAndroidPkgCanBypassDnd_creation() { + public void testAndroidPkgCannotBypassDnd_creation() { NotificationChannel test = new NotificationChannel("A", "a", IMPORTANCE_LOW); test.setBypassDnd(true); mHelper.createNotificationChannel(SYSTEM_PKG, SYSTEM_UID, test, true, false); - assertTrue(mHelper.getNotificationChannel(SYSTEM_PKG, SYSTEM_UID, "A", false) + assertFalse(mHelper.getNotificationChannel(SYSTEM_PKG, SYSTEM_UID, "A", false) .canBypassDnd()); } @@ -1745,7 +1745,7 @@ public class RankingHelperTest extends UiServiceTestCase { } @Test - public void testAndroidPkgCanBypassDnd_update() throws Exception { + public void testAndroidPkgCannotBypassDnd_update() throws Exception { NotificationChannel test = new NotificationChannel("A", "a", IMPORTANCE_LOW); mHelper.createNotificationChannel(SYSTEM_PKG, SYSTEM_UID, test, true, false); @@ -1753,11 +1753,8 @@ public class RankingHelperTest extends UiServiceTestCase { update.setBypassDnd(true); mHelper.createNotificationChannel(SYSTEM_PKG, SYSTEM_UID, update, true, false); - assertTrue(mHelper.getNotificationChannel(SYSTEM_PKG, SYSTEM_UID, "A", false) + assertFalse(mHelper.getNotificationChannel(SYSTEM_PKG, SYSTEM_UID, "A", false) .canBypassDnd()); - - // setup + 1st check - verify(mPm, times(2)).getPackageInfoAsUser(any(), anyInt(), anyInt()); } @Test