From 21a847380d2b337769a1667b9ad5e4c1c0731f98 Mon Sep 17 00:00:00 2001 From: Jackal Guo Date: Mon, 7 Jun 2021 16:40:31 +0800 Subject: [PATCH] Re-order early return when targetPkg is null It's possible that the target package is on removable stroage or uninstalled with keep data. The caller should be able to get the related info of the target with flag MATCH_UNINSTALLED_PACKAGES. However, the caller wouldn't be able to get the valid info if we directly filter out when targetPkg is null early. Bug: 193864540 Fix: 187650819 Test: atest AppEnumerationTests PackageVisibilityTest Change-Id: I7c6b2dcdb77c543e0826e5dff0ddc9f66e489033 Merged-In: I7c6b2dcdb77c543e0826e5dff0ddc9f66e489033 (cherry picked from commit a135e23fe97c5618ed04ff26d06e2a31a2d34004) --- .../com/android/server/pm/AppsFilter.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/services/core/java/com/android/server/pm/AppsFilter.java b/services/core/java/com/android/server/pm/AppsFilter.java index 06ff69176bb72..ed9b539c05df2 100644 --- a/services/core/java/com/android/server/pm/AppsFilter.java +++ b/services/core/java/com/android/server/pm/AppsFilter.java @@ -1287,20 +1287,6 @@ public class AppsFilter implements Watchable, Snappable { } } - // This package isn't technically installed and won't be written to settings, so we can - // treat it as filtered until it's available again. - final AndroidPackage targetPkg = targetPkgSetting.pkg; - if (targetPkg == null) { - if (DEBUG_LOGGING) { - Slog.wtf(TAG, "shouldFilterApplication: " + "targetPkg is null"); - } - return true; - } - if (targetPkg.isStaticSharedLibrary()) { - // not an app, this filtering takes place at a higher level - return false; - } - final String targetName = targetPkg.getPackageName(); if (DEBUG_TRACING) { Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "getAppId"); } @@ -1343,6 +1329,21 @@ public class AppsFilter implements Watchable, Snappable { Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER); } } + + // This package isn't technically installed and won't be written to settings, so we can + // treat it as filtered until it's available again. + final AndroidPackage targetPkg = targetPkgSetting.pkg; + if (targetPkg == null) { + if (DEBUG_LOGGING) { + Slog.wtf(TAG, "shouldFilterApplication: " + "targetPkg is null"); + } + return true; + } + if (targetPkg.isStaticSharedLibrary()) { + // not an app, this filtering takes place at a higher level + return false; + } + try { if (DEBUG_TRACING) { Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "mForceQueryable"); @@ -1415,6 +1416,7 @@ public class AppsFilter implements Watchable, Snappable { if (DEBUG_TRACING) { Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "mOverlayReferenceMapper"); } + final String targetName = targetPkg.getPackageName(); if (callingSharedPkgSettings != null) { int size = callingSharedPkgSettings.size(); for (int index = 0; index < size; index++) {