Merge "Fixes broadcast filtering for multi-user sys apps" into rvc-dev

This commit is contained in:
TreeHugger Robot
2020-06-18 05:26:16 +00:00
committed by Android (Google) Code Review
3 changed files with 27 additions and 9 deletions

View File

@@ -15788,9 +15788,10 @@ public class ActivityManagerService extends IActivityManager.Stub
}
if (receivers != null && broadcastWhitelist != null) {
for (int i = receivers.size() - 1; i >= 0; i--) {
final int uid = receivers.get(i).activityInfo.applicationInfo.uid;
if (uid >= Process.FIRST_APPLICATION_UID
&& Arrays.binarySearch(broadcastWhitelist, UserHandle.getAppId(uid)) < 0) {
final int receiverAppId = UserHandle.getAppId(
receivers.get(i).activityInfo.applicationInfo.uid);
if (receiverAppId >= Process.FIRST_APPLICATION_UID
&& Arrays.binarySearch(broadcastWhitelist, receiverAppId) < 0) {
receivers.remove(i);
}
}
@@ -16436,9 +16437,9 @@ public class ActivityManagerService extends IActivityManager.Stub
// if a uid whitelist was provided, remove anything in the application space that wasn't
// in it.
for (int i = registeredReceivers.size() - 1; i >= 0; i--) {
final int uid = registeredReceivers.get(i).owningUid;
if (uid >= Process.FIRST_APPLICATION_UID
&& Arrays.binarySearch(broadcastWhitelist, UserHandle.getAppId(uid)) < 0) {
final int owningAppId = UserHandle.getAppId(registeredReceivers.get(i).owningUid);
if (owningAppId >= Process.FIRST_APPLICATION_UID
&& Arrays.binarySearch(broadcastWhitelist, owningAppId) < 0) {
registeredReceivers.remove(i);
}
}

View File

@@ -859,8 +859,9 @@ public class AppsFilter {
PackageSetting targetPkgSetting, int userId) {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "shouldFilterApplication");
try {
if (callingUid < Process.FIRST_APPLICATION_UID
|| UserHandle.getAppId(callingUid) == targetPkgSetting.appId) {
int callingAppId = UserHandle.getAppId(callingUid);
if (callingAppId < Process.FIRST_APPLICATION_UID
|| callingAppId == targetPkgSetting.appId) {
return false;
}
if (mShouldFilterCache != null) { // use cache
@@ -885,7 +886,7 @@ public class AppsFilter {
return false;
}
}
if (DEBUG_LOGGING || mFeatureConfig.isLoggingEnabled(UserHandle.getAppId(callingUid))) {
if (DEBUG_LOGGING || mFeatureConfig.isLoggingEnabled(callingAppId)) {
log(callingSetting, targetPkgSetting, "BLOCKED");
}
return !DEBUG_ALLOW_ALL;

View File

@@ -512,6 +512,22 @@ public class AppsFilterTest {
null, target, SYSTEM_USER));
}
@Test
public void testSystemUidSecondaryUser_DoesntFilter() throws Exception {
final AppsFilter appsFilter =
new AppsFilter(mStateProvider, mFeatureConfigMock, new String[]{}, false, null);
simulateAddBasicAndroid(appsFilter);
appsFilter.onSystemReady();
PackageSetting target = simulateAddPackage(appsFilter,
pkg("com.some.package"), DUMMY_TARGET_APPID);
assertFalse(appsFilter.shouldFilterApplication(0, null, target, SECONDARY_USER));
assertFalse(appsFilter.shouldFilterApplication(
UserHandle.getUid(SECONDARY_USER, Process.FIRST_APPLICATION_UID - 1),
null, target, SECONDARY_USER));
}
@Test
public void testNonSystemUid_NoCallingSetting_Filters() throws Exception {
final AppsFilter appsFilter =