Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6531a739 authored by Suprabh Shukla's avatar Suprabh Shukla
Browse files

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
parent 813b664c
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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;
            }
        }