Listen ACTION_BATTERY_LEVEL_CHANGED in Settings and fetch usage data

when battery is full charged.

Bug: 253395332
Test: make RunSettingsRoboTests + manually
Change-Id: Ie83e5f319074ff404a600c4eb375fbecad651b6d
This commit is contained in:
Kuan Wang
2022-10-20 17:07:01 +08:00
parent 7ef1fb7ef5
commit 45be6bae05
4 changed files with 87 additions and 21 deletions

View File

@@ -141,6 +141,12 @@ public final class DatabaseUtils {
});
}
/** Gets the latest sticky battery intent from framework. */
static Intent getBatteryIntent(Context context) {
return context.registerReceiver(
/*receiver=*/ null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}
static List<ContentValues> sendBatteryEntryData(
Context context,
List<BatteryEntry> batteryEntryList,
@@ -300,12 +306,6 @@ public final class DatabaseUtils {
return resultMap;
}
/** Gets the latest sticky battery intent from framework. */
private static Intent getBatteryIntent(Context context) {
return context.registerReceiver(
/*receiver=*/ null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}
private static int getBatteryLevel(Intent intent) {
final int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
final int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0);