summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Patrick Baumann <patb@google.com> 2019-11-18 13:43:11 -0800
committer Patrick Baumann <patb@google.com> 2019-11-22 11:55:10 -0800
commit182ea1cd99ac429630a48fa0b0618fda46c40b13 (patch)
treefd87d812f1b901bcc738150e724551ab5a60e204
parent081777becde7d5dee0341461844a5561d0eb0a31 (diff)
Avoids deadlock when applying preferred activities
Prior to this change, we were resolving the mime type of a given intent while holding the package lock. With this change, we instead rely on the preferred-activity declaration to define the mime type if it's important, removing need for an activity manager service call and the potential for deadlock. Bug: 143105100 Test: Manual; sideload to /system/etc/preferred-apps/ and reset app preferences Change-Id: Ie0b124216b49a1147bd5c2e82cf8c7cadb3f08ac
-rw-r--r--services/core/java/android/content/pm/PackageManagerInternal.java9
-rw-r--r--services/core/java/com/android/server/pm/CrossProfileAppsServiceImpl.java1
-rw-r--r--services/core/java/com/android/server/pm/LauncherAppsService.java4
-rw-r--r--services/core/java/com/android/server/pm/PackageManagerService.java3
-rw-r--r--services/core/java/com/android/server/pm/Settings.java3
-rw-r--r--services/tests/servicestests/src/com/android/server/pm/CrossProfileAppsServiceImplTest.java2
6 files changed, 16 insertions, 6 deletions
diff --git a/services/core/java/android/content/pm/PackageManagerInternal.java b/services/core/java/android/content/pm/PackageManagerInternal.java
index dc24cffa54a4..e67d736796b9 100644
--- a/services/core/java/android/content/pm/PackageManagerInternal.java
+++ b/services/core/java/android/content/pm/PackageManagerInternal.java
@@ -22,6 +22,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.content.ComponentName;
+import android.content.ContentResolver;
import android.content.Intent;
import android.content.IntentSender;
import android.content.pm.PackageManager.ApplicationInfoFlags;
@@ -244,12 +245,16 @@ public abstract class PackageManagerInternal {
/**
* Retrieve all activities that can be performed for the given intent.
+ * @param resolvedType the resolved type of the intent, which should be resolved via
+ * {@link Intent#resolveTypeIfNeeded(ContentResolver)} before passing to {@link PackageManager}
* @param filterCallingUid The results will be filtered in the context of this UID instead
* of the calling UID.
* @see PackageManager#queryIntentActivities(Intent, int)
*/
- public abstract List<ResolveInfo> queryIntentActivities(Intent intent,
- @ResolveInfoFlags int flags, int filterCallingUid, int userId);
+ public abstract List<ResolveInfo> queryIntentActivities(
+ Intent intent, @Nullable String resolvedType, @ResolveInfoFlags int flags,
+ int filterCallingUid, int userId);
+
/**
* Retrieve all services that can be performed for the given intent.
diff --git a/services/core/java/com/android/server/pm/CrossProfileAppsServiceImpl.java b/services/core/java/com/android/server/pm/CrossProfileAppsServiceImpl.java
index d6108b7cc390..d2a6b42f3140 100644
--- a/services/core/java/com/android/server/pm/CrossProfileAppsServiceImpl.java
+++ b/services/core/java/com/android/server/pm/CrossProfileAppsServiceImpl.java
@@ -202,6 +202,7 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub {
final List<ResolveInfo> apps =
mInjector.getPackageManagerInternal().queryIntentActivities(
launchIntent,
+ launchIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
MATCH_DIRECT_BOOT_AWARE | MATCH_DIRECT_BOOT_UNAWARE,
callingUid,
userId);
diff --git a/services/core/java/com/android/server/pm/LauncherAppsService.java b/services/core/java/com/android/server/pm/LauncherAppsService.java
index bd9566728b1b..f7fd1b2ddb37 100644
--- a/services/core/java/com/android/server/pm/LauncherAppsService.java
+++ b/services/core/java/com/android/server/pm/LauncherAppsService.java
@@ -344,6 +344,7 @@ public class LauncherAppsService extends SystemService {
final PackageManagerInternal pmInt =
LocalServices.getService(PackageManagerInternal.class);
List<ResolveInfo> apps = pmInt.queryIntentActivities(intent,
+ intent.resolveTypeIfNeeded(mContext.getContentResolver()),
PackageManager.MATCH_DIRECT_BOOT_AWARE
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
callingUid, user.getIdentifier());
@@ -468,6 +469,7 @@ public class LauncherAppsService extends SystemService {
matchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
matchIntent.setPackage(packageName);
final List<ResolveInfo> infoList = pmInt.queryIntentActivities(matchIntent,
+ matchIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
PackageManager.MATCH_DISABLED_COMPONENTS, Binder.getCallingUid(),
getCallingUserId());
final int size = infoList.size();
@@ -539,6 +541,7 @@ public class LauncherAppsService extends SystemService {
final PackageManagerInternal pmInt =
LocalServices.getService(PackageManagerInternal.class);
List<ResolveInfo> apps = pmInt.queryIntentActivities(intent,
+ intent.resolveTypeIfNeeded(mContext.getContentResolver()),
PackageManager.MATCH_DIRECT_BOOT_AWARE
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
callingUid, user.getIdentifier());
@@ -842,6 +845,7 @@ public class LauncherAppsService extends SystemService {
// as calling startActivityAsUser ignores the category and just
// resolves based on the component if present.
List<ResolveInfo> apps = pmInt.queryIntentActivities(launchIntent,
+ launchIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
PackageManager.MATCH_DIRECT_BOOT_AWARE
| PackageManager.MATCH_DIRECT_BOOT_UNAWARE,
callingUid, user.getIdentifier());
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index fa98c962afbf..6046a8a2008a 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -23061,8 +23061,7 @@ public class PackageManagerService extends IPackageManager.Stub
@Override
public List<ResolveInfo> queryIntentActivities(
- Intent intent, int flags, int filterCallingUid, int userId) {
- final String resolvedType = intent.resolveTypeIfNeeded(mContext.getContentResolver());
+ Intent intent, String resolvedType, int flags, int filterCallingUid, int userId) {
return PackageManagerService.this
.queryIntentActivitiesInternal(intent, resolvedType, flags, filterCallingUid,
userId, false /*resolveForStart*/, true /*allowDynamicSplits*/);
diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java
index 5f3650c21b8e..69c7cf2fc0f2 100644
--- a/services/core/java/com/android/server/pm/Settings.java
+++ b/services/core/java/com/android/server/pm/Settings.java
@@ -3348,7 +3348,8 @@ public final class Settings {
int flags, ComponentName cn, String scheme, PatternMatcher ssp,
IntentFilter.AuthorityEntry auth, PatternMatcher path, int userId) {
final List<ResolveInfo> ri =
- pmInternal.queryIntentActivities(intent, flags, Binder.getCallingUid(), 0);
+ pmInternal.queryIntentActivities(
+ intent, intent.getType(), flags, Binder.getCallingUid(), 0);
if (PackageManagerService.DEBUG_PREFERRED) {
Log.d(TAG, "Queried " + intent + " results: " + ri);
}
diff --git a/services/tests/servicestests/src/com/android/server/pm/CrossProfileAppsServiceImplTest.java b/services/tests/servicestests/src/com/android/server/pm/CrossProfileAppsServiceImplTest.java
index 839b25f8491d..e18ff61e32dc 100644
--- a/services/tests/servicestests/src/com/android/server/pm/CrossProfileAppsServiceImplTest.java
+++ b/services/tests/servicestests/src/com/android/server/pm/CrossProfileAppsServiceImplTest.java
@@ -509,7 +509,7 @@ public class CrossProfileAppsServiceImplTest {
mActivityInfo = activityInfo;
when(mPackageManagerInternal.queryIntentActivities(
- any(Intent.class), anyInt(), anyInt(), anyInt()))
+ any(Intent.class), nullable(String.class), anyInt(), anyInt(), anyInt()))
.thenReturn(Collections.singletonList(resolveInfo));
}