Merge "Add api to change charging state update delay"
This commit is contained in:
committed by
Android (Google) Code Review
commit
4e78dec0d8
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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,12 +13454,21 @@ 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(
|
||||
KEY_BATTERY_CHARGED_DELAY_MS,
|
||||
DEFAULT_BATTERY_CHARGED_DELAY_MS);
|
||||
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;
|
||||
if (isEnabled && !wasEnabled) {
|
||||
|
||||
Reference in New Issue
Block a user