From 6531a739abe5971f81cb5a6c7a34dca81005ff2c Mon Sep 17 00:00:00 2001 From: Suprabh Shukla Date: Fri, 5 May 2023 16:20:41 -0700 Subject: [PATCH] Count modifications to user's power allowlist Log a counter everytime an app is put into or taken out of the power allowlist. In normal conditions, this is only expected to happen when the user toggles this in Settings, so should be relatively rare. Test: N/A Bug: 263411625 Change-Id: Ie0d79d66cf2b480e8d94c7d6b1567d7785cde7be --- .../java/com/android/server/DeviceIdleController.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apex/jobscheduler/service/java/com/android/server/DeviceIdleController.java b/apex/jobscheduler/service/java/com/android/server/DeviceIdleController.java index b0b3b1f3cb5ea..8316a2625ccd5 100644 --- a/apex/jobscheduler/service/java/com/android/server/DeviceIdleController.java +++ b/apex/jobscheduler/service/java/com/android/server/DeviceIdleController.java @@ -100,6 +100,7 @@ import com.android.internal.util.ArrayUtils; import com.android.internal.util.DumpUtils; import com.android.internal.util.FastXmlSerializer; import com.android.internal.util.XmlUtils; +import com.android.modules.expresslog.Counter; import com.android.server.am.BatteryStatsService; import com.android.server.deviceidle.ConstraintController; import com.android.server.deviceidle.DeviceIdleConstraintTracker; @@ -300,6 +301,12 @@ public class DeviceIdleController extends SystemService implements AnyMotionDetector.DeviceIdleCallback { private static final String TAG = "DeviceIdleController"; + private static final String USER_ALLOWLIST_ADDITION_METRIC_ID = + "battery.value_app_added_to_power_allowlist"; + + private static final String USER_ALLOWLIST_REMOVAL_METRIC_ID = + "battery.value_app_removed_from_power_allowlist"; + private static final boolean DEBUG = false; private static final boolean COMPRESS_TIME = false; @@ -2805,6 +2812,7 @@ public class DeviceIdleController extends SystemService if (mPowerSaveWhitelistUserApps.put(name, UserHandle.getAppId(ai.uid)) == null) { numAdded++; + Counter.logIncrement(USER_ALLOWLIST_ADDITION_METRIC_ID); } } catch (PackageManager.NameNotFoundException e) { Slog.e(TAG, "Tried to add unknown package to power save whitelist: " + name); @@ -2826,6 +2834,7 @@ public class DeviceIdleController extends SystemService reportPowerSaveWhitelistChangedLocked(); updateWhitelistAppIdsLocked(); writeConfigFileLocked(); + Counter.logIncrement(USER_ALLOWLIST_REMOVAL_METRIC_ID); return true; } }