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

Commit 0c5ec80d authored by Kweku Adams's avatar Kweku Adams
Browse files

Make target battery life configurable.

Make the background battery life target configurable. Also lower the
initial targets since they appear to be too aggressive on current
devices.

Bug: 240726265
Bug: 250007395
Test: Configure target via adb shell and confirm in dump
Change-Id: Iae35d34409334893a4699d28374e485d53c1c358
parent c6346aa1
Loading
Loading
Loading
Loading
+23 −5
Original line number Diff line number Diff line
@@ -209,8 +209,10 @@ public class InternalResourceService extends SystemService {
    @GuardedBy("mLock")
    private int mCurrentBatteryLevel;

    // TODO(250007395): make configurable per device
    private final int mTargetBackgroundBatteryLifeHours;
    // TODO(250007395): make configurable per device (via config.xml)
    private final int mDefaultTargetBackgroundBatteryLifeHours;
    @GuardedBy("mLock")
    private int mTargetBackgroundBatteryLifeHours;

    private final IAppOpsCallback mApbListener = new IAppOpsCallback.Stub() {
        @Override
@@ -353,10 +355,11 @@ public class InternalResourceService extends SystemService {

        mConfigObserver = new ConfigObserver(mHandler, context);

        mTargetBackgroundBatteryLifeHours =
        mDefaultTargetBackgroundBatteryLifeHours =
                mPackageManager.hasSystemFeature(PackageManager.FEATURE_WATCH)
                        ? 200 // ~ 0.5%/hr
                        : 100; // ~ 1%/hr
                        ? 100 // ~ 1.0%/hr
                        : 40; // ~ 2.5%/hr
        mTargetBackgroundBatteryLifeHours = mDefaultTargetBackgroundBatteryLifeHours;

        publishLocalService(EconomyManagerInternal.class, new LocalService());
    }
@@ -1483,6 +1486,8 @@ public class InternalResourceService extends SystemService {
    private class ConfigObserver extends ContentObserver
            implements DeviceConfig.OnPropertiesChangedListener {
        private static final String KEY_ENABLE_TIP3 = "enable_tip3";
        private static final String KEY_TARGET_BACKGROUND_BATTERY_LIFE_HOURS =
                "target_bg_battery_life_hrs";

        private static final boolean DEFAULT_ENABLE_TIP3 = true;

@@ -1541,6 +1546,13 @@ public class InternalResourceService extends SystemService {
                        case KEY_ENABLE_TIP3:
                            ENABLE_TIP3 = properties.getBoolean(name, DEFAULT_ENABLE_TIP3);
                            break;
                        case KEY_TARGET_BACKGROUND_BATTERY_LIFE_HOURS:
                            synchronized (mLock) {
                                mTargetBackgroundBatteryLifeHours = properties.getInt(name,
                                        mDefaultTargetBackgroundBatteryLifeHours);
                                maybeAdjustDesiredStockLevelLocked();
                            }
                            break;
                        default:
                            if (!economicPolicyUpdated
                                    && (name.startsWith("am") || name.startsWith("js")
@@ -1670,6 +1682,12 @@ public class InternalResourceService extends SystemService {
            pw.print("/");
            pw.println(cakeToString(mScribe.getSatiatedConsumptionLimitLocked()));

            pw.print("Target bg battery life (hours): ");
            pw.print(mTargetBackgroundBatteryLifeHours);
            pw.print(" (");
            pw.print(String.format("%.2f", 100f / mTargetBackgroundBatteryLifeHours));
            pw.println("%/hr)");

            final long remainingConsumable = mScribe.getRemainingConsumableCakesLocked();
            pw.print("Goods remaining: ");
            pw.print(cakeToString(remainingConsumable));