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

Commit 4e78dec0 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add api to change charging state update delay"

parents 103a678a 0941120f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -5042,6 +5042,7 @@ package android.nfc {
package android.os {
  public class BatteryManager {
    method @RequiresPermission(android.Manifest.permission.POWER_SAVER) public boolean setChargingStateUpdateDelayMillis(int);
    field public static final String EXTRA_EVENTS = "android.os.extra.EVENTS";
    field public static final String EXTRA_EVENT_TIMESTAMP = "android.os.extra.EVENT_TIMESTAMP";
  }
+24 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.os;

import android.Manifest.permission;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.content.Context;
@@ -369,4 +371,26 @@ public class BatteryManager {
            throw e.rethrowFromSystemServer();
        }
    }

    /**
     * Sets the delay for reporting battery state as charging after device is plugged in.
     * This allows machine-learning or heuristics to delay the reporting and the corresponding
     * broadcast, based on battery level, charging rate, and/or other parameters.
     *
     * @param delayMillis the delay in milliseconds, negative value to reset.
     *
     * @return True if the delay was set successfully.
     *
     * @see ACTION_CHARGING
     * @hide
     */
    @RequiresPermission(permission.POWER_SAVER)
    @SystemApi
    public boolean setChargingStateUpdateDelayMillis(int delayMillis) {
        try {
            return mBatteryStats.setChargingStateUpdateDelayMillis(delayMillis);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }
}
+11 −0
Original line number Diff line number Diff line
@@ -14280,6 +14280,17 @@ public final class Settings {
         */
        public static final String APPOP_HISTORY_PARAMETERS =
                "appop_history_parameters";
        /**
         * Delay for sending ACTION_CHARGING after device is plugged in.
         * This is used as an override for constants defined in BatteryStatsImpl for
         * ease of experimentation.
         *
         * @see com.android.internal.os.BatteryStatsImpl.Constants.KEY_BATTERY_CHARGED_DELAY_MS
         * @hide
         */
        public static final String BATTERY_CHARGING_STATE_UPDATE_DELAY =
                "battery_charging_state_update_delay";
    }
    /**
+3 −0
Original line number Diff line number Diff line
@@ -154,4 +154,7 @@ interface IBatteryStats {
    oneway void noteBluetoothControllerActivity(in BluetoothActivityEnergyInfo info);
    oneway void noteModemControllerActivity(in ModemActivityInfo info);
    oneway void noteWifiControllerActivity(in WifiActivityEnergyInfo info);

    /** {@hide} */
    boolean setChargingStateUpdateDelayMillis(int delay);
}
+23 −3
Original line number Diff line number Diff line
@@ -13395,11 +13395,22 @@ public class BatteryStatsImpl extends BatteryStats {
            mResolver.registerContentObserver(
                    Settings.Global.getUriFor(Settings.Global.BATTERY_STATS_CONSTANTS),
                    false /* notifyForDescendants */, this);
            mResolver.registerContentObserver(
                    Settings.Global.getUriFor(Settings.Global.BATTERY_CHARGING_STATE_UPDATE_DELAY),
                    false /* notifyForDescendants */, this);
            updateConstants();
        }
        @Override
        public void onChange(boolean selfChange, Uri uri) {
            if (uri.equals(
                    Settings.Global.getUriFor(
                            Settings.Global.BATTERY_CHARGING_STATE_UPDATE_DELAY))) {
                synchronized (BatteryStatsImpl.this) {
                    updateBatteryChargedDelayMsLocked();
                }
                return;
            }
            updateConstants();
        }
@@ -13443,11 +13454,20 @@ public class BatteryStatsImpl extends BatteryStats {
                                DEFAULT_MAX_HISTORY_BUFFER_LOW_RAM_DEVICE_KB
                                : DEFAULT_MAX_HISTORY_BUFFER_KB)
                        * 1024;
                BATTERY_CHARGED_DELAY_MS = mParser.getInt(
                updateBatteryChargedDelayMsLocked();
            }
        }
        private void updateBatteryChargedDelayMsLocked() {
            // a negative value indicates that we should ignore this override
            final int delay = Settings.Global.getInt(mResolver,
                    Settings.Global.BATTERY_CHARGING_STATE_UPDATE_DELAY,
                    -1);
            BATTERY_CHARGED_DELAY_MS = delay >= 0 ? delay : mParser.getInt(
                    KEY_BATTERY_CHARGED_DELAY_MS,
                    DEFAULT_BATTERY_CHARGED_DELAY_MS);
        }
        }
        private void updateTrackCpuTimesByProcStateLocked(boolean wasEnabled, boolean isEnabled) {
            TRACK_CPU_TIMES_BY_PROC_STATE = isEnabled;
Loading