From 9aedadbedc955e854f052e69ba07a4e6a0ad688f Mon Sep 17 00:00:00 2001 From: Winson Chiu Date: Fri, 22 Apr 2022 20:47:58 +0000 Subject: [PATCH] Optimize ActiveServices targetSdkVersion fetch Rather than fetching the entire AppInfo object, call the method for specifically getting the targetSdkVersion. In this specific case, match flags and user ID can both be ignored as only 1 physical APK for each package name is allowed on the device, so as long as the caller has package visibility, the targetSdkVersion returned is guaranteed to be the right one. Bug: 219481486 Test: presubmit Change-Id: I1d8c155e9be9b80da0af241273ceb9cf3564d917 --- .../core/java/com/android/server/am/ActiveServices.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java index 730907c7d049e..83d074c7ead0e 100644 --- a/services/core/java/com/android/server/am/ActiveServices.java +++ b/services/core/java/com/android/server/am/ActiveServices.java @@ -6568,12 +6568,11 @@ public final class ActiveServices { } final int uidState = mAm.getUidStateLocked(callingUid); - int callerTargetSdkVersion = INVALID_UID; + int callerTargetSdkVersion = -1; try { - ApplicationInfo ai = mAm.mContext.getPackageManager().getApplicationInfoAsUser( - callingPackage, PackageManager.MATCH_KNOWN_PACKAGES, userId); - callerTargetSdkVersion = ai.targetSdkVersion; - } catch (PackageManager.NameNotFoundException e) { + callerTargetSdkVersion = mAm.mContext.getPackageManager() + .getTargetSdkVersion(callingPackage); + } catch (PackageManager.NameNotFoundException ignored) { } final String debugInfo = "[callingPackage: " + callingPackage