diff options
| author | 2024-05-01 07:03:10 +0000 | |
|---|---|---|
| committer | 2024-06-04 21:14:02 +0000 | |
| commit | 9d1f84235ca6a1565d7ea1a1df2e28fd78809969 (patch) | |
| tree | 2888dda3a4f3355b3841ca4bd9e3a4ed4d656612 | |
| parent | 2246bcc52e89d961d8d8d9bbaf708b44d1557ec8 (diff) | |
Simplify and fix resolveIntent implementation
- `exportOnly` is false only when resolving on behalf of system_server,
which is automatically handled in `filterNonExportedComponents`, so
there is no need to additionally pass this boolean.
- `resolveIntentExported` is unnecessary as functionality is duplicated
- PM#resolveIntent() should follow normal intent resolving process and
return the correct Activity. The implementation before this CL is
incorrect (`exportOnly` is set to false).
Test: TH
Change-Id: I01b3295295b4b2dbdced54971b525aaa6126ed01
9 files changed, 26 insertions, 61 deletions
diff --git a/services/core/java/android/content/pm/PackageManagerInternal.java b/services/core/java/android/content/pm/PackageManagerInternal.java index e64a87f3966b..801c7e9dce13 100644 --- a/services/core/java/android/content/pm/PackageManagerInternal.java +++ b/services/core/java/android/content/pm/PackageManagerInternal.java @@ -611,17 +611,9 @@ public abstract class PackageManagerInternal { @NonNull Set<String> outInvalidPackageNames); /** - * Resolves an activity intent, allowing instant apps to be resolved. - */ - public abstract ResolveInfo resolveIntent(Intent intent, String resolvedType, - @PackageManager.ResolveInfoFlagsBits long flags, - @PrivateResolveFlags long privateResolveFlags, int userId, boolean resolveForStart, - int filterCallingUid); - - /** * Resolves an exported activity intent, allowing instant apps to be resolved. */ - public abstract ResolveInfo resolveIntentExported(Intent intent, String resolvedType, + public abstract ResolveInfo resolveIntent(Intent intent, String resolvedType, @PackageManager.ResolveInfoFlagsBits long flags, @PrivateResolveFlags long privateResolveFlags, int userId, boolean resolveForStart, int filterCallingUid, int callingPid); diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index f7278e9f986d..25e448af569c 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -13775,7 +13775,7 @@ public class ActivityManagerService extends IActivityManager.Stub } }); } - boolean hasToBeExportedToMatch = platformCompat.isChangeEnabledByUid( + boolean hasToBeExportedToMatch = platformCompat.isChangeEnabledByUidInternal( ActivityManagerService.IMPLICIT_INTENTS_ONLY_MATCH_EXPORTED_COMPONENTS, callingUid); ActivityManagerUtils.logUnsafeIntentEvent( diff --git a/services/core/java/com/android/server/pm/IPackageManagerBase.java b/services/core/java/com/android/server/pm/IPackageManagerBase.java index f987d4ae8999..0f091b04a98f 100644 --- a/services/core/java/com/android/server/pm/IPackageManagerBase.java +++ b/services/core/java/com/android/server/pm/IPackageManagerBase.java @@ -1139,7 +1139,7 @@ public abstract class IPackageManagerBase extends IPackageManager.Stub { @PackageManager.ResolveInfoFlagsBits long flags, int userId) { return mResolveIntentHelper.resolveIntentInternal(snapshot(), intent, resolvedType, flags, 0 /*privateResolveFlags*/, userId, false, - Binder.getCallingUid()); + Binder.getCallingUid(), Binder.getCallingPid()); } @Override diff --git a/services/core/java/com/android/server/pm/PackageManagerInternalBase.java b/services/core/java/com/android/server/pm/PackageManagerInternalBase.java index d2b60a489de3..47cb42d6d084 100644 --- a/services/core/java/com/android/server/pm/PackageManagerInternalBase.java +++ b/services/core/java/com/android/server/pm/PackageManagerInternalBase.java @@ -472,24 +472,10 @@ abstract class PackageManagerInternalBase extends PackageManagerInternal { public final ResolveInfo resolveIntent(Intent intent, String resolvedType, @PackageManager.ResolveInfoFlagsBits long flags, @PackageManagerInternal.PrivateResolveFlags long privateResolveFlags, int userId, - boolean resolveForStart, int filterCallingUid) { - return getResolveIntentHelper().resolveIntentInternal(snapshot(), - intent, resolvedType, flags, privateResolveFlags, userId, resolveForStart, - filterCallingUid); - } - - /** - * @deprecated similar to {@link resolveIntent} but limits the matches to exported components. - */ - @Override - @Deprecated - public final ResolveInfo resolveIntentExported(Intent intent, String resolvedType, - @PackageManager.ResolveInfoFlagsBits long flags, - @PackageManagerInternal.PrivateResolveFlags long privateResolveFlags, int userId, boolean resolveForStart, int filterCallingUid, int callingPid) { return getResolveIntentHelper().resolveIntentInternal(snapshot(), intent, resolvedType, flags, privateResolveFlags, userId, resolveForStart, - filterCallingUid, true, callingPid); + filterCallingUid, callingPid); } @Override diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 679ab65380af..af125d99e568 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -2140,7 +2140,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService mResolveIntentHelper = new ResolveIntentHelper(mContext, mPreferredActivityHelper, injector.getCompatibility(), mUserManager, mDomainVerificationManager, mUserNeedsBadging, () -> mResolveInfo, () -> mInstantAppInstallerActivity, - injector.getBackgroundHandler()); + injector.getBackgroundHandler(), injector.getActivityManagerInternal()); mDexOptHelper = new DexOptHelper(this); mSuspendPackageHelper = new SuspendPackageHelper(this, mInjector, mBroadcastHelper, mProtectedPackages); @@ -2695,7 +2695,8 @@ public class PackageManagerService implements PackageSender, TestUtilityService final ResolveInfo resolveInfo = mResolveIntentHelper.resolveIntentInternal(computer, intent, null, MATCH_SYSTEM_ONLY | MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE, - 0 /*privateResolveFlags*/, UserHandle.USER_SYSTEM, false, Binder.getCallingUid()); + 0 /*privateResolveFlags*/, UserHandle.USER_SYSTEM, false, + Binder.getCallingUid(), Binder.getCallingPid()); if (resolveInfo == null || mResolveActivity.name.equals(resolveInfo.getComponentInfo().name)) { throw new RuntimeException("There must be exactly one uninstaller; found " diff --git a/services/core/java/com/android/server/pm/ResolveIntentHelper.java b/services/core/java/com/android/server/pm/ResolveIntentHelper.java index 309a4481e9de..a9fda1b3c021 100644 --- a/services/core/java/com/android/server/pm/ResolveIntentHelper.java +++ b/services/core/java/com/android/server/pm/ResolveIntentHelper.java @@ -91,6 +91,8 @@ final class ResolveIntentHelper { private final Supplier<ActivityInfo> mInstantAppInstallerActivitySupplier; @NonNull private final Handler mHandler; + @NonNull + private final ActivityManagerInternal mActivityManagerInternal; ResolveIntentHelper(@NonNull Context context, @NonNull PreferredActivityHelper preferredActivityHelper, @@ -99,7 +101,8 @@ final class ResolveIntentHelper { @NonNull UserNeedsBadgingCache userNeedsBadgingCache, @NonNull Supplier<ResolveInfo> resolveInfoSupplier, @NonNull Supplier<ActivityInfo> instantAppInstallerActivitySupplier, - @NonNull Handler handler) { + @NonNull Handler handler, + @NonNull ActivityManagerInternal activityManagerInternal) { mContext = context; mPreferredActivityHelper = preferredActivityHelper; mPlatformCompat = platformCompat; @@ -109,26 +112,25 @@ final class ResolveIntentHelper { mResolveInfoSupplier = resolveInfoSupplier; mInstantAppInstallerActivitySupplier = instantAppInstallerActivitySupplier; mHandler = handler; + mActivityManagerInternal = activityManagerInternal; } - private static void filterNonExportedComponents(Intent intent, int filterCallingUid, + private void filterNonExportedComponents(Intent intent, int filterCallingUid, int callingPid, List<ResolveInfo> query, PlatformCompat platformCompat, - String resolvedType, Computer computer, Handler handler) { + String resolvedType, Handler handler) { if (query == null || intent.getPackage() != null || intent.getComponent() != null || ActivityManager.canAccessUnexportedComponents(filterCallingUid)) { return; } - AndroidPackage caller = computer.getPackage(filterCallingUid); - String callerPackage = caller == null ? "Not specified" : caller.getPackageName(); ActivityManagerInternal activityManagerInternal = LocalServices .getService(ActivityManagerInternal.class); - final IUnsafeIntentStrictModeCallback callback = activityManagerInternal + final IUnsafeIntentStrictModeCallback callback = mActivityManagerInternal .getRegisteredStrictModeCallback(callingPid); for (int i = query.size() - 1; i >= 0; i--) { if (!query.get(i).getComponentInfo().exported) { - boolean hasToBeExportedToMatch = platformCompat.isChangeEnabledByUid( + boolean hasToBeExportedToMatch = platformCompat.isChangeEnabledByUidInternal( ActivityManagerService.IMPLICIT_INTENTS_ONLY_MATCH_EXPORTED_COMPONENTS, filterCallingUid); ActivityManagerUtils.logUnsafeIntentEvent( @@ -159,22 +161,7 @@ final class ResolveIntentHelper { public ResolveInfo resolveIntentInternal(Computer computer, Intent intent, String resolvedType, @PackageManager.ResolveInfoFlagsBits long flags, @PackageManagerInternal.PrivateResolveFlags long privateResolveFlags, int userId, - boolean resolveForStart, int filterCallingUid) { - return resolveIntentInternal(computer, intent, resolvedType, flags, - privateResolveFlags, userId, resolveForStart, filterCallingUid, false, 0); - } - - /** - * Normally instant apps can only be resolved when they're visible to the caller. - * However, if {@code resolveForStart} is {@code true}, all instant apps are visible - * since we need to allow the system to start any installed application. - * Allows picking exported components only. - */ - public ResolveInfo resolveIntentInternal(Computer computer, Intent intent, String resolvedType, - @PackageManager.ResolveInfoFlagsBits long flags, - @PackageManagerInternal.PrivateResolveFlags long privateResolveFlags, int userId, - boolean resolveForStart, int filterCallingUid, boolean exportedComponentsOnly, - int callingPid) { + boolean resolveForStart, int filterCallingUid, int callingPid) { try { Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "resolveIntent"); @@ -190,10 +177,8 @@ final class ResolveIntentHelper { final List<ResolveInfo> query = computer.queryIntentActivitiesInternal(intent, resolvedType, flags, privateResolveFlags, filterCallingUid, userId, resolveForStart, true /*allowDynamicSplits*/); - if (exportedComponentsOnly) { - filterNonExportedComponents(intent, filterCallingUid, callingPid, query, - mPlatformCompat, resolvedType, computer, mHandler); - } + filterNonExportedComponents(intent, filterCallingUid, callingPid, query, + mPlatformCompat, resolvedType, mHandler); Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); final boolean queryMayBeFiltered = @@ -705,7 +690,8 @@ final class ResolveIntentHelper { if (comp == null) { ri = resolveIntentInternal(computer, sintent, specificTypes != null ? specificTypes[i] : null, flags, - 0 /*privateResolveFlags*/, userId, false, Binder.getCallingUid()); + 0 /*privateResolveFlags*/, userId, false, + Binder.getCallingUid(), Binder.getCallingPid()); if (ri == null) { continue; } diff --git a/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java b/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java index a10f7e7b00d0..6c7471c1ea05 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java +++ b/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java @@ -769,7 +769,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks { // (e.g. AMS.startActivityAsUser). final long token = Binder.clearCallingIdentity(); try { - return mService.getPackageManagerInternalLocked().resolveIntentExported( + return mService.getPackageManagerInternalLocked().resolveIntent( intent, resolvedType, modifiedFlags, privateResolveFlags, userId, true, filterCallingUid, callingPid); } finally { diff --git a/services/tests/mockingservicestests/src/com/android/server/pm/MockSystem.kt b/services/tests/mockingservicestests/src/com/android/server/pm/MockSystem.kt index 396edae2f672..5743701adadd 100644 --- a/services/tests/mockingservicestests/src/com/android/server/pm/MockSystem.kt +++ b/services/tests/mockingservicestests/src/com/android/server/pm/MockSystem.kt @@ -187,7 +187,9 @@ class MockSystem(withSession: (StaticMockitoSessionBuilder) -> Unit = {}) { class Mocks { val lock = PackageManagerTracedLock() val installLock = PackageManagerTracedLock() - val injector: PackageManagerServiceInjector = mock() + val injector: PackageManagerServiceInjector = mock { + whenever(activityManagerInternal) { mock() } + } val systemWrapper: PackageManagerServiceInjector.SystemWrapper = mock() val context: Context = mock() val userManagerService: UserManagerService = mock() diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java index 89140a2c0b44..2030b301f9f7 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStarterTests.java @@ -416,9 +416,7 @@ public class ActivityStarterTests extends WindowTestsBase { doReturn("packageName").when(mMockPackageManager).getNameForUid(anyInt()); doReturn(false).when(mMockPackageManager).isInstantAppInstallerComponent(any()); doReturn(null).when(mMockPackageManager).resolveIntent(any(), any(), anyLong(), anyLong(), - anyInt(), anyBoolean(), anyInt()); - doReturn(null).when(mMockPackageManager).resolveIntentExported(any(), any(), - anyLong(), anyLong(), anyInt(), anyBoolean(), anyInt(), anyInt()); + anyInt(), anyBoolean(), anyInt(), anyInt()); doReturn(new ComponentName("", "")).when(mMockPackageManager).getSystemUiServiceComponent(); // Never review permissions |