Merge "System apps cannot create channels that bypass dnd" into pi-dev

This commit is contained in:
android-build-team Robot
2018-05-01 20:46:42 +00:00
committed by Android (Google) Code Review
2 changed files with 6 additions and 75 deletions

View File

@@ -116,17 +116,12 @@ public class RankingHelper implements RankingConfig {
private final ArrayMap<String, Record> mRecords = new ArrayMap<>(); // pkg|uid => Record
private final ArrayMap<String, NotificationRecord> mProxyByGroupTmp = new ArrayMap<>();
private final ArrayMap<String, Record> mRestoredWithoutUids = new ArrayMap<>(); // pkg => Record
private final ArrayMap<Pair<String, Integer>, 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<String, Integer> 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) {

View File

@@ -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