From 9a94852937cb59a97f2d32c2f305d29d7bee5ba2 Mon Sep 17 00:00:00 2001 From: Sudheer Shanka Date: Tue, 31 Aug 2021 11:34:34 -0700 Subject: [PATCH] Cache device provisioning package in AppStandbyController. This is not going to change within a boot session, so no need to keep querying it multiple times. Fixes: 198303868 Test: treehugger verification Change-Id: I9d93452ddd1a928607cfe13c5a49f919271be0e9 --- .../android/server/usage/AppStandbyController.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java b/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java index 2fa10f08e9ae9..096211b433c7f 100644 --- a/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java +++ b/apex/jobscheduler/service/java/com/android/server/usage/AppStandbyController.java @@ -264,6 +264,11 @@ public class AppStandbyController // get the cached value private static final long NETWORK_SCORER_CACHE_DURATION_MILLIS = 5000L; + // Cache the device provisioning package queried from resource config_deviceProvisioningPackage. + // Note that there is no synchronization on this method which is okay since in the worst case + // scenario, they might be a few extra reads from resources. + private String mCachedDeviceProvisioningPackage = null; + // Messages for the handler static final int MSG_INFORM_LISTENERS = 3; static final int MSG_FORCE_IDLE_STATE = 4; @@ -1641,9 +1646,11 @@ public class AppStandbyController * returns {@code false}. */ private boolean isDeviceProvisioningPackage(String packageName) { - String deviceProvisioningPackage = mContext.getResources().getString( - com.android.internal.R.string.config_deviceProvisioningPackage); - return deviceProvisioningPackage != null && deviceProvisioningPackage.equals(packageName); + if (mCachedDeviceProvisioningPackage == null) { + mCachedDeviceProvisioningPackage = mContext.getResources().getString( + com.android.internal.R.string.config_deviceProvisioningPackage); + } + return mCachedDeviceProvisioningPackage.equals(packageName); } private boolean isCarrierApp(String packageName) {