Thread WatchedIntentFilter in PackageManagerService
Bug: 181964615 Replace most occurrences of IntentFilter with WatchedIntentFilter, so that any changes to the objects will invalidate the PM snapshot. Test: atest * FrameworksServicesTests:WatchedIntentHandlingTest * FrameworksServicesTests:AppsFilterTest * FrameworksServicesTests:PackageInstallerSessionTest * FrameworksServicesTests:PackageManagerServiceTest * FrameworksServicesTests:PackageManagerSettingsTests * FrameworksServicesTests:ScanTests * FrameworksServicesTests:UserSystemPackageInstallerTest * PackageManagerServiceBootTest * UserLifecycleTests#startUser * UserLifecycleTests#stopUser * UserLifecycleTests#switchUser * android.appsecurity.cts.EphemeralTest * android.appsecurity.cts.InstantAppUserTest * FrameworksServicesTests:WatcherTest * CtsContentTestCases:IntentFilterTest * CtsDynamicMimeHostTestCases Change-Id: Ibc931daba594038929bafeff9cc2515d770ff60c
This commit is contained in:
@@ -43,7 +43,7 @@ final class DefaultCrossProfileIntentFilter {
|
||||
}
|
||||
|
||||
/** The intent filter that's used */
|
||||
public final IntentFilter filter;
|
||||
public final WatchedIntentFilter filter;
|
||||
|
||||
/**
|
||||
* The flags related to the forwarding, e.g.
|
||||
@@ -66,7 +66,7 @@ final class DefaultCrossProfileIntentFilter {
|
||||
*/
|
||||
public final boolean letsPersonalDataIntoProfile;
|
||||
|
||||
private DefaultCrossProfileIntentFilter(IntentFilter filter, int flags,
|
||||
private DefaultCrossProfileIntentFilter(WatchedIntentFilter filter, int flags,
|
||||
@Direction int direction, boolean letsPersonalDataIntoProfile) {
|
||||
this.filter = requireNonNull(filter);
|
||||
this.flags = flags;
|
||||
@@ -75,7 +75,7 @@ final class DefaultCrossProfileIntentFilter {
|
||||
}
|
||||
|
||||
static final class Builder {
|
||||
private IntentFilter mFilter = new IntentFilter();
|
||||
private WatchedIntentFilter mFilter = new WatchedIntentFilter();
|
||||
private int mFlags;
|
||||
private @Direction int mDirection;
|
||||
private boolean mLetsPersonalDataIntoProfile;
|
||||
|
||||
@@ -1984,8 +1984,8 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
int callingUid);
|
||||
ResolveInfo createForwardingResolveInfo(CrossProfileIntentFilter filter, Intent intent,
|
||||
String resolvedType, int flags, int sourceUserId);
|
||||
ResolveInfo createForwardingResolveInfoUnchecked(IntentFilter filter, int sourceUserId,
|
||||
int targetUserId);
|
||||
ResolveInfo createForwardingResolveInfoUnchecked(WatchedIntentFilter filter,
|
||||
int sourceUserId, int targetUserId);
|
||||
ResolveInfo queryCrossProfileIntents(List<CrossProfileIntentFilter> matchingFilters,
|
||||
Intent intent, String resolvedType, int flags, int sourceUserId,
|
||||
boolean matchInCurrentProfile);
|
||||
@@ -2888,8 +2888,8 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
}
|
||||
if (result == null) {
|
||||
result = new CrossProfileDomainInfo();
|
||||
result.resolveInfo = createForwardingResolveInfoUnchecked(new IntentFilter(),
|
||||
sourceUserId, parentUserId);
|
||||
result.resolveInfo = createForwardingResolveInfoUnchecked(
|
||||
new WatchedIntentFilter(), sourceUserId, parentUserId);
|
||||
}
|
||||
|
||||
result.highestApprovalLevel = Math.max(mDomainVerificationManager
|
||||
@@ -3484,7 +3484,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
for (int i = resultTargetUser.size() - 1; i >= 0; i--) {
|
||||
if ((resultTargetUser.get(i).activityInfo.applicationInfo.flags
|
||||
& ApplicationInfo.FLAG_SUSPENDED) == 0) {
|
||||
return createForwardingResolveInfoUnchecked(filter.getIntentFilter(),
|
||||
return createForwardingResolveInfoUnchecked(filter,
|
||||
sourceUserId, targetUserId);
|
||||
}
|
||||
}
|
||||
@@ -3492,7 +3492,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public ResolveInfo createForwardingResolveInfoUnchecked(IntentFilter filter,
|
||||
public ResolveInfo createForwardingResolveInfoUnchecked(WatchedIntentFilter filter,
|
||||
int sourceUserId, int targetUserId) {
|
||||
ResolveInfo forwardingResolveInfo = new ResolveInfo();
|
||||
final long ident = Binder.clearCallingIdentity();
|
||||
@@ -3522,7 +3522,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
forwardingResolveInfo.preferredOrder = 0;
|
||||
forwardingResolveInfo.match = 0;
|
||||
forwardingResolveInfo.isDefault = true;
|
||||
forwardingResolveInfo.filter = filter;
|
||||
forwardingResolveInfo.filter = new IntentFilter(filter.getIntentFilter());
|
||||
forwardingResolveInfo.targetUserId = targetUserId;
|
||||
return forwardingResolveInfo;
|
||||
}
|
||||
@@ -9472,6 +9472,15 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
@Override
|
||||
public void setLastChosenActivity(Intent intent, String resolvedType, int flags,
|
||||
IntentFilter filter, int match, ComponentName activity) {
|
||||
setLastChosenActivity(intent, resolvedType, flags,
|
||||
new WatchedIntentFilter(filter), match, activity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Variant that takes a {@link WatchedIntentFilter}
|
||||
*/
|
||||
public void setLastChosenActivity(Intent intent, String resolvedType, int flags,
|
||||
WatchedIntentFilter filter, int match, ComponentName activity) {
|
||||
if (getInstantAppPackageName(Binder.getCallingUid()) != null) {
|
||||
return;
|
||||
}
|
||||
@@ -9492,7 +9501,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
findPreferredActivityNotLocked(
|
||||
intent, resolvedType, flags, query, 0, false, true, false, userId);
|
||||
// Add the new activity as the last chosen for this filter
|
||||
addPreferredActivityInternal(filter, match, null, activity, false, userId,
|
||||
addPreferredActivity(filter, match, null, activity, false, userId,
|
||||
"Setting last chosen", false);
|
||||
}
|
||||
|
||||
@@ -10210,12 +10219,6 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
resolvedType, flags, sourceUserId);
|
||||
}
|
||||
|
||||
private ResolveInfo createForwardingResolveInfoUnchecked(IntentFilter filter,
|
||||
int sourceUserId, int targetUserId) {
|
||||
return liveComputer().createForwardingResolveInfoUnchecked(filter,
|
||||
sourceUserId, targetUserId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull ParceledListSlice<ResolveInfo> queryIntentActivityOptions(ComponentName caller,
|
||||
Intent[] specifics, String[] specificTypes, Intent intent,
|
||||
@@ -16491,7 +16494,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
return new ParceledListSlice<IntentFilter>(result) {
|
||||
@Override
|
||||
protected void writeElement(IntentFilter parcelable, Parcel dest, int callFlags) {
|
||||
// IntentFilter has final Parcelable methods, so redirect to the subclass
|
||||
// WatchedIntentFilter has final Parcelable methods, so redirect to the subclass
|
||||
((ParsedIntentInfo) parcelable).writeIntentInfoToParcel(dest,
|
||||
callFlags);
|
||||
}
|
||||
@@ -21978,11 +21981,14 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
@Override
|
||||
public void addPreferredActivity(IntentFilter filter, int match,
|
||||
ComponentName[] set, ComponentName activity, int userId, boolean removeExisting) {
|
||||
addPreferredActivityInternal(filter, match, set, activity, true, userId,
|
||||
addPreferredActivity(new WatchedIntentFilter(filter), match, set, activity, true, userId,
|
||||
"Adding preferred", removeExisting);
|
||||
}
|
||||
|
||||
private void addPreferredActivityInternal(IntentFilter filter, int match,
|
||||
/**
|
||||
* Variant that takes a {@link WatchedIntentFilter}
|
||||
*/
|
||||
public void addPreferredActivity(WatchedIntentFilter filter, int match,
|
||||
ComponentName[] set, ComponentName activity, boolean always, int userId,
|
||||
String opname, boolean removeExisting) {
|
||||
// writer
|
||||
@@ -22048,6 +22054,15 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
@Override
|
||||
public void replacePreferredActivity(IntentFilter filter, int match,
|
||||
ComponentName[] set, ComponentName activity, int userId) {
|
||||
replacePreferredActivity(new WatchedIntentFilter(filter), match,
|
||||
set, activity, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Variant that takes a {@link WatchedIntentFilter}
|
||||
*/
|
||||
public void replacePreferredActivity(WatchedIntentFilter filter, int match,
|
||||
ComponentName[] set, ComponentName activity, int userId) {
|
||||
if (filter.countActions() != 1) {
|
||||
throw new IllegalArgumentException(
|
||||
"replacePreferredActivity expects filter to have only 1 action.");
|
||||
@@ -22120,7 +22135,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
}
|
||||
}
|
||||
}
|
||||
addPreferredActivityInternal(filter, match, set, activity, true, userId,
|
||||
addPreferredActivity(filter, match, set, activity, true, userId,
|
||||
"Replacing preferred", false);
|
||||
}
|
||||
|
||||
@@ -22227,6 +22242,22 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
@Override
|
||||
public int getPreferredActivities(List<IntentFilter> outFilters,
|
||||
List<ComponentName> outActivities, String packageName) {
|
||||
List<WatchedIntentFilter> temp =
|
||||
WatchedIntentFilter.toWatchedIntentFilterList(outFilters);
|
||||
final int result = getPreferredActivitiesInternal(
|
||||
temp, outActivities, packageName);
|
||||
outFilters.clear();
|
||||
for (int i = 0; i < temp.size(); i++) {
|
||||
outFilters.add(temp.get(i).getIntentFilter());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Variant that takes a {@link WatchedIntentFilter}
|
||||
*/
|
||||
public int getPreferredActivitiesInternal(List<WatchedIntentFilter> outFilters,
|
||||
List<ComponentName> outActivities, String packageName) {
|
||||
if (getInstantAppPackageName(Binder.getCallingUid()) != null) {
|
||||
return 0;
|
||||
}
|
||||
@@ -22243,7 +22274,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
|| (pa.mPref.mComponent.getPackageName().equals(packageName)
|
||||
&& pa.mPref.mAlways)) {
|
||||
if (outFilters != null) {
|
||||
outFilters.add(new IntentFilter(pa.getIntentFilter()));
|
||||
outFilters.add(new WatchedIntentFilter(pa.getIntentFilter()));
|
||||
}
|
||||
if (outActivities != null) {
|
||||
outActivities.add(pa.mPref.mComponent);
|
||||
@@ -22259,6 +22290,14 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
@Override
|
||||
public void addPersistentPreferredActivity(IntentFilter filter, ComponentName activity,
|
||||
int userId) {
|
||||
addPersistentPreferredActivity(new WatchedIntentFilter(filter), activity, userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Variant that takes a {@link WatchedIntentFilter}
|
||||
*/
|
||||
public void addPersistentPreferredActivity(WatchedIntentFilter filter, ComponentName activity,
|
||||
int userId) {
|
||||
int callingUid = Binder.getCallingUid();
|
||||
if (callingUid != Process.SYSTEM_UID) {
|
||||
throw new SecurityException(
|
||||
@@ -22479,6 +22518,15 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
@Override
|
||||
public void addCrossProfileIntentFilter(IntentFilter intentFilter, String ownerPackage,
|
||||
int sourceUserId, int targetUserId, int flags) {
|
||||
addCrossProfileIntentFilter(new WatchedIntentFilter(intentFilter), ownerPackage,
|
||||
sourceUserId, targetUserId, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Variant that takes a {@link WatchedIntentFilter}
|
||||
*/
|
||||
public void addCrossProfileIntentFilter(WatchedIntentFilter intentFilter, String ownerPackage,
|
||||
int sourceUserId, int targetUserId, int flags) {
|
||||
mContext.enforceCallingOrSelfPermission(
|
||||
android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, null);
|
||||
int callingUid = Binder.getCallingUid();
|
||||
@@ -22608,8 +22656,8 @@ public class PackageManagerService extends IPackageManager.Stub
|
||||
return liveComputer().getHomeIntent();
|
||||
}
|
||||
|
||||
private IntentFilter getHomeFilter() {
|
||||
IntentFilter filter = new IntentFilter(Intent.ACTION_MAIN);
|
||||
private WatchedIntentFilter getHomeFilter() {
|
||||
WatchedIntentFilter filter = new WatchedIntentFilter(Intent.ACTION_MAIN);
|
||||
filter.addCategory(Intent.CATEGORY_HOME);
|
||||
filter.addCategory(Intent.CATEGORY_DEFAULT);
|
||||
return filter;
|
||||
|
||||
@@ -3087,7 +3087,7 @@ public final class Settings implements Watchable, Snappable {
|
||||
}
|
||||
|
||||
static void removeFilters(@NonNull PreferredIntentResolver pir,
|
||||
@NonNull IntentFilter filter, @NonNull List<PreferredActivity> existing) {
|
||||
@NonNull WatchedIntentFilter filter, @NonNull List<PreferredActivity> existing) {
|
||||
if (PackageManagerService.DEBUG_PREFERRED) {
|
||||
Slog.i(TAG, existing.size() + " preferred matches for:");
|
||||
filter.dump(new LogPrinter(Log.INFO, TAG), " ");
|
||||
@@ -3274,7 +3274,7 @@ public final class Settings implements Watchable, Snappable {
|
||||
haveNonSys = null;
|
||||
}
|
||||
if (haveAct && haveNonSys == null) {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
WatchedIntentFilter filter = new WatchedIntentFilter();
|
||||
if (intent.getAction() != null) {
|
||||
filter.addAction(intent.getAction());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user