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

Commit c1d844a5 authored by Kweku Adams's avatar Kweku Adams
Browse files

Making Battery Saver policy setting more defensive.

1. Making a full copy of the config Builder's map so that changing
the map in the builder doesn't change the config's map.

2. Ensuring that location mode and brightness adjustment factors are
within valid ranges.

Bug: 129474588
Test: manual
Change-Id: I6117b7857afa10d71c1fc3de818c51d8719a281b
parent 319e7cb6
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -58,7 +58,8 @@ public final class BatterySaverPolicyConfig implements Parcelable {
        mAdvertiseIsEnabled = in.mAdvertiseIsEnabled;
        mDeferFullBackup = in.mDeferFullBackup;
        mDeferKeyValueBackup = in.mDeferKeyValueBackup;
        mDeviceSpecificSettings = Collections.unmodifiableMap(in.mDeviceSpecificSettings);
        mDeviceSpecificSettings = Collections.unmodifiableMap(
                new ArrayMap<>(in.mDeviceSpecificSettings));
        mDisableAnimation = in.mDisableAnimation;
        mDisableAod = in.mDisableAod;
        mDisableLaunchBoost = in.mDisableLaunchBoost;
+4 −2
Original line number Diff line number Diff line
@@ -773,8 +773,10 @@ public final class PowerManager {
     */
    public static final int LOCATION_MODE_THROTTLE_REQUESTS_WHEN_SCREEN_OFF = 4;

    static final int MIN_LOCATION_MODE = LOCATION_MODE_NO_CHANGE;
    static final int MAX_LOCATION_MODE = LOCATION_MODE_THROTTLE_REQUESTS_WHEN_SCREEN_OFF;
    /** @hide */
    public static final int MIN_LOCATION_MODE = LOCATION_MODE_NO_CHANGE;
    /** @hide */
    public static final int MAX_LOCATION_MODE = LOCATION_MODE_THROTTLE_REQUESTS_WHEN_SCREEN_OFF;

    /**
     * @hide
+9 −2
Original line number Diff line number Diff line
@@ -594,7 +594,7 @@ public class BatterySaverPolicy extends ContentObserver {
                boolean forceBackgroundCheck,
                int locationMode) {

            this.adjustBrightnessFactor = adjustBrightnessFactor;
            this.adjustBrightnessFactor = Math.min(1, Math.max(0, adjustBrightnessFactor));
            this.advertiseIsEnabled = advertiseIsEnabled;
            this.deferFullBackup = deferFullBackup;
            this.deferKeyValueBackup = deferKeyValueBackup;
@@ -613,7 +613,14 @@ public class BatterySaverPolicy extends ContentObserver {
            this.filesForNoninteractive = filesForNoninteractive;
            this.forceAllAppsStandby = forceAllAppsStandby;
            this.forceBackgroundCheck = forceBackgroundCheck;

            if (locationMode < PowerManager.MIN_LOCATION_MODE
                    || PowerManager.MAX_LOCATION_MODE < locationMode) {
                Slog.e(TAG, "Invalid location mode: " + locationMode);
                this.locationMode = PowerManager.LOCATION_MODE_NO_CHANGE;
            } else {
                this.locationMode = locationMode;
            }

            mHashCode = Objects.hash(
                    adjustBrightnessFactor,