Merge "Apply package visibility to PACKAGE_DATA_CLEARED"

This commit is contained in:
Jackal Guo
2021-07-21 04:50:04 +00:00
committed by Android (Google) Code Review
5 changed files with 45 additions and 9 deletions

View File

@@ -377,7 +377,7 @@ public abstract class ActivityManagerInternal {
IIntentReceiver resultTo, int resultCode, String resultData, Bundle resultExtras,
String requiredPermission, Bundle bOptions, boolean serialized, boolean sticky,
@UserIdInt int userId, boolean allowBackgroundActivityStarts,
@Nullable IBinder backgroundActivityStartsToken);
@Nullable IBinder backgroundActivityStartsToken, @Nullable int[] broadcastAllowList);
public abstract ComponentName startServiceInPackage(int uid, Intent service,
String resolvedType, boolean fgRequired, String callingPackage,

View File

@@ -39,6 +39,7 @@ import android.os.HandlerExecutor;
import android.os.IBinder;
import android.os.Looper;
import android.os.PersistableBundle;
import android.os.Process;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.SparseArray;
@@ -719,6 +720,20 @@ public abstract class PackageManagerInternal implements PackageSettingsSnapshotP
*/
public abstract boolean filterAppAccess(int uid, int callingUid);
/**
* Fetches all app Ids that a given application is currently visible to the provided user.
*
* <p>
* <strong>Note: </strong>This only includes UIDs >= {@link Process#FIRST_APPLICATION_UID}
* as all other UIDs can already see all applications.
* </p>
*
* If the app is visible to all UIDs, null is returned. If the app is not visible to any
* applications, the int array will be empty.
*/
@Nullable
public abstract int[] getVisibilityAllowList(@NonNull String packageName, int userId);
/** Returns whether the given package was signed by the platform */
public abstract boolean isPlatformSigned(String pkg);

View File

@@ -3536,15 +3536,17 @@ public class ActivityManagerService extends IActivityManager.Stub
intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
intent.putExtra(Intent.EXTRA_UID, (appInfo != null) ? appInfo.uid : -1);
intent.putExtra(Intent.EXTRA_USER_HANDLE, resolvedUserId);
final int[] visibilityAllowList =
mPackageManagerInt.getVisibilityAllowList(packageName, resolvedUserId);
if (isInstantApp) {
intent.putExtra(Intent.EXTRA_PACKAGE_NAME, packageName);
broadcastIntentInPackage("android", null, SYSTEM_UID, uid, pid, intent,
null, null, 0, null, null, permission.ACCESS_INSTANT_APPS, null,
false, false, resolvedUserId, false, null);
false, false, resolvedUserId, false, null, visibilityAllowList);
} else {
broadcastIntentInPackage("android", null, SYSTEM_UID, uid, pid, intent,
null, null, 0, null, null, null, null, false, false, resolvedUserId,
false, null);
false, null, visibilityAllowList);
}
if (observer != null) {
@@ -13647,7 +13649,8 @@ public class ActivityManagerService extends IActivityManager.Stub
IIntentReceiver resultTo, int resultCode, String resultData, Bundle resultExtras,
String requiredPermission, Bundle bOptions, boolean serialized, boolean sticky,
int userId, boolean allowBackgroundActivityStarts,
@Nullable IBinder backgroundActivityStartsToken) {
@Nullable IBinder backgroundActivityStartsToken,
@Nullable int[] broadcastAllowList) {
synchronized(this) {
intent = verifyBroadcastLocked(intent);
@@ -13659,8 +13662,7 @@ public class ActivityManagerService extends IActivityManager.Stub
resultTo, resultCode, resultData, resultExtras, requiredPermissions, null,
OP_NONE, bOptions, serialized, sticky, -1, uid, realCallingUid,
realCallingPid, userId, allowBackgroundActivityStarts,
backgroundActivityStartsToken,
null /* broadcastAllowList */);
backgroundActivityStartsToken, broadcastAllowList);
} finally {
Binder.restoreCallingIdentity(origId);
}
@@ -15845,13 +15847,14 @@ public class ActivityManagerService extends IActivityManager.Stub
IIntentReceiver resultTo, int resultCode, String resultData, Bundle resultExtras,
String requiredPermission, Bundle bOptions, boolean serialized, boolean sticky,
int userId, boolean allowBackgroundActivityStarts,
@Nullable IBinder backgroundActivityStartsToken) {
@Nullable IBinder backgroundActivityStartsToken,
@Nullable int[] broadcastAllowList) {
synchronized (ActivityManagerService.this) {
return ActivityManagerService.this.broadcastIntentInPackage(packageName, featureId,
uid, realCallingUid, realCallingPid, intent, resolvedType, resultTo,
resultCode, resultData, resultExtras, requiredPermission, bOptions,
serialized, sticky, userId, allowBackgroundActivityStarts,
backgroundActivityStartsToken);
backgroundActivityStartsToken, broadcastAllowList);
}
}

View File

@@ -481,7 +481,8 @@ public final class PendingIntentRecord extends IIntentSender.Stub {
key.featureId, uid, callingUid, callingPid, finalIntent,
resolvedType, finishedReceiver, code, null, null,
requiredPermission, options, (finishedReceiver != null), false,
userId, allowedByToken || allowTrampoline, bgStartsToken);
userId, allowedByToken || allowTrampoline, bgStartsToken,
null /* broadcastAllowList */);
if (sent == ActivityManager.BROADCAST_SUCCESS) {
sendFinish = false;
}

View File

@@ -27125,6 +27125,18 @@ public class PackageManagerService extends IPackageManager.Stub
return mComputer.filterAppAccess(uid, callingUid);
}
private int[] getVisibilityAllowList(@NonNull String packageName, int userId) {
synchronized (mLock) {
final PackageSetting ps = getPackageSettingInternal(packageName, Process.SYSTEM_UID);
if (ps == null) {
return null;
}
final SparseArray<int[]> visibilityAllowList = mAppsFilter.getVisibilityAllowList(ps,
new int[]{userId}, mSettings.getPackagesLocked());
return visibilityAllowList != null ? visibilityAllowList.get(userId) : null;
}
}
private class PackageManagerInternalImpl extends PackageManagerInternal {
@Override
public List<ApplicationInfo> getInstalledApplications(int flags, int userId,
@@ -27212,6 +27224,11 @@ public class PackageManagerService extends IPackageManager.Stub
return PackageManagerService.this.filterAppAccess(uid, callingUid);
}
@Nullable
public int[] getVisibilityAllowList(@NonNull String packageName, int userId) {
return PackageManagerService.this.getVisibilityAllowList(packageName, userId);
}
@Override
public AndroidPackage getPackage(String packageName) {
return PackageManagerService.this.getPackage(packageName);