DO NOT MERGE Chk QUERY_ALL_PACKAGES when resolving am: 6628f4e7b8

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13564389

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ie471324b1bec6fea195e35f61158a877a82e0bb0
This commit is contained in:
Danny Epstein
2021-02-23 02:49:03 +00:00
committed by Automerger Merge Worker

View File

@@ -20,6 +20,7 @@ import static android.Manifest.permission.DELETE_PACKAGES;
import static android.Manifest.permission.INSTALL_PACKAGES; import static android.Manifest.permission.INSTALL_PACKAGES;
import static android.Manifest.permission.MANAGE_DEVICE_ADMINS; import static android.Manifest.permission.MANAGE_DEVICE_ADMINS;
import static android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS; import static android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS;
import static android.Manifest.permission.QUERY_ALL_PACKAGES;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE; import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.REQUEST_DELETE_PACKAGES; import static android.Manifest.permission.REQUEST_DELETE_PACKAGES;
import static android.Manifest.permission.SET_HARMFUL_APP_WARNINGS; import static android.Manifest.permission.SET_HARMFUL_APP_WARNINGS;
@@ -28,6 +29,7 @@ import static android.app.AppOpsManager.MODE_ALLOWED;
import static android.app.AppOpsManager.MODE_DEFAULT; import static android.app.AppOpsManager.MODE_DEFAULT;
import static android.app.AppOpsManager.MODE_IGNORED; import static android.app.AppOpsManager.MODE_IGNORED;
import static android.content.Intent.ACTION_MAIN; import static android.content.Intent.ACTION_MAIN;
import static android.content.Intent.CATEGORY_BROWSABLE;
import static android.content.Intent.CATEGORY_DEFAULT; import static android.content.Intent.CATEGORY_DEFAULT;
import static android.content.Intent.CATEGORY_HOME; import static android.content.Intent.CATEGORY_HOME;
import static android.content.Intent.EXTRA_LONG_VERSION_CODE; import static android.content.Intent.EXTRA_LONG_VERSION_CODE;
@@ -35,8 +37,6 @@ import static android.content.Intent.EXTRA_PACKAGE_NAME;
import static android.content.Intent.EXTRA_VERSION_CODE; import static android.content.Intent.EXTRA_VERSION_CODE;
import static android.content.pm.PackageManager.CERT_INPUT_RAW_X509; import static android.content.pm.PackageManager.CERT_INPUT_RAW_X509;
import static android.content.pm.PackageManager.CERT_INPUT_SHA256; import static android.content.pm.PackageManager.CERT_INPUT_SHA256;
import static android.content.Intent.CATEGORY_BROWSABLE;
import static android.content.Intent.CATEGORY_DEFAULT;
import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED; import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED; import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED;
@@ -6467,14 +6467,10 @@ public class PackageManagerService extends IPackageManager.Stub
true /*allowDynamicSplits*/); true /*allowDynamicSplits*/);
Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
final boolean queryMayBeFiltered =
UserHandle.getAppId(filterCallingUid) >= Process.FIRST_APPLICATION_UID
&& !resolveForStart;
final ResolveInfo bestChoice = final ResolveInfo bestChoice =
chooseBestActivity( chooseBestActivity(
intent, resolvedType, flags, privateResolveFlags, query, userId, intent, resolvedType, flags, privateResolveFlags, query, userId,
queryMayBeFiltered); queryMayBeFiltered(filterCallingUid, resolveForStart));
final boolean nonBrowserOnly = final boolean nonBrowserOnly =
(privateResolveFlags & PackageManagerInternal.RESOLVE_NON_BROWSER_ONLY) != 0; (privateResolveFlags & PackageManagerInternal.RESOLVE_NON_BROWSER_ONLY) != 0;
if (nonBrowserOnly && bestChoice != null && bestChoice.handleAllWebDataURI) { if (nonBrowserOnly && bestChoice != null && bestChoice.handleAllWebDataURI) {
@@ -6486,6 +6482,25 @@ public class PackageManagerService extends IPackageManager.Stub
} }
} }
/**
* Returns whether the query may be filtered to packages which are visible to the caller.
* Filtering occurs except in the following cases:
* <ul>
* <li>system processes
* <li>applications granted {@link android.Manifest.permission#QUERY_ALL_PACKAGES}
* <li>when querying to start an app
* </ul>
*
* @param filterCallingUid the UID of the calling application
* @param queryForStart whether query is to start an app
* @return whether filtering may occur
*/
private boolean queryMayBeFiltered(int filterCallingUid, boolean queryForStart) {
return UserHandle.getAppId(filterCallingUid) >= Process.FIRST_APPLICATION_UID
&& checkUidPermission(QUERY_ALL_PACKAGES, filterCallingUid) != PERMISSION_GRANTED
&& !queryForStart;
}
@Override @Override
public ResolveInfo findPersistentPreferredActivity(Intent intent, int userId) { public ResolveInfo findPersistentPreferredActivity(Intent intent, int userId) {
if (!UserHandle.isSameApp(Binder.getCallingUid(), Process.SYSTEM_UID)) { if (!UserHandle.isSameApp(Binder.getCallingUid(), Process.SYSTEM_UID)) {
@@ -6851,7 +6866,7 @@ public class PackageManagerService extends IPackageManager.Stub
boolean removeMatches, boolean debug, int userId) { boolean removeMatches, boolean debug, int userId) {
return findPreferredActivityNotLocked( return findPreferredActivityNotLocked(
intent, resolvedType, flags, query, priority, always, removeMatches, debug, userId, intent, resolvedType, flags, query, priority, always, removeMatches, debug, userId,
UserHandle.getAppId(Binder.getCallingUid()) >= Process.FIRST_APPLICATION_UID); queryMayBeFiltered(Binder.getCallingUid(), /* queryForStart= */ false));
} }
// TODO: handle preferred activities missing while user has amnesia // TODO: handle preferred activities missing while user has amnesia