From 12a3f5cfdcc79f7a829bb2c96492c36f6d3ca42d Mon Sep 17 00:00:00 2001 From: Hall Liu Date: Mon, 13 Jul 2020 12:42:36 -0700 Subject: [PATCH] Skip carrier priv check for trusted UIDs Checking carrier privileges for UIDs with lots of shared apps can incur a significant performance hit. For UIDs that are fixed and trusted (system and phone), skip the permission check and always allow. Also, double the cache size for getPackageInfo in order to reduce the rate of cache misses. Bug: 160971853 Test: manual verification -- observed lower rate of cache misses for getPackageInfo from com.android.phone. Change-Id: I1399cab579308479d7cf191b8795441cbcd3ff65 --- core/java/android/content/pm/PackageManager.java | 2 +- .../com/android/internal/telephony/TelephonyPermissions.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java index 53e75d4548baa..ea4a2a0b8c35e 100644 --- a/core/java/android/content/pm/PackageManager.java +++ b/core/java/android/content/pm/PackageManager.java @@ -8171,7 +8171,7 @@ public abstract class PackageManager { private static final PropertyInvalidatedCache sPackageInfoCache = new PropertyInvalidatedCache( - 16, PermissionManager.CACHE_KEY_PACKAGE_INFO) { + 32, PermissionManager.CACHE_KEY_PACKAGE_INFO) { @Override protected PackageInfo recompute(PackageInfoQuery query) { return getPackageInfoAsUserUncached( diff --git a/telephony/common/com/android/internal/telephony/TelephonyPermissions.java b/telephony/common/com/android/internal/telephony/TelephonyPermissions.java index bc987a6282c7f..71a1964210b0f 100644 --- a/telephony/common/com/android/internal/telephony/TelephonyPermissions.java +++ b/telephony/common/com/android/internal/telephony/TelephonyPermissions.java @@ -623,6 +623,10 @@ public final class TelephonyPermissions { } private static int getCarrierPrivilegeStatus(Context context, int subId, int uid) { + if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { + // Skip the check if it's one of these special uids + return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; + } final long identity = Binder.clearCallingIdentity(); try { TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(