use of android.os.BatteryUsageStats in project android_packages_apps_Settings by omnirom.
the class BatteryFixSlice method refreshBatteryTips.
@WorkerThread
@VisibleForTesting
static List<BatteryTip> refreshBatteryTips(Context context) {
final BatteryUsageStatsLoader statsLoader = new BatteryUsageStatsLoader(context, /* includeBatteryHistory */
false);
final BatteryUsageStats batteryUsageStats = statsLoader.loadInBackground();
final BatteryTipLoader loader = new BatteryTipLoader(context, batteryUsageStats);
final List<BatteryTip> batteryTips = loader.loadInBackground();
for (BatteryTip batteryTip : batteryTips) {
if (batteryTip.getState() != BatteryTip.StateType.INVISIBLE) {
context.getSharedPreferences(PREFS, MODE_PRIVATE).edit().putInt(KEY_CURRENT_TIPS_TYPE, batteryTip.getType()).putInt(KEY_CURRENT_TIPS_STATE, batteryTip.getState()).apply();
break;
}
}
return batteryTips;
}
use of android.os.BatteryUsageStats in project android_packages_apps_Settings by omnirom.
the class BatteryUtils method getBatteryInfo.
@WorkerThread
public BatteryInfo getBatteryInfo(final String tag) {
final BatteryStatsManager systemService = mContext.getSystemService(BatteryStatsManager.class);
BatteryUsageStats batteryUsageStats;
try {
batteryUsageStats = systemService.getBatteryUsageStats(new BatteryUsageStatsQuery.Builder().includeBatteryHistory().build());
} catch (RuntimeException e) {
Log.e(TAG, "getBatteryInfo() error for getBatteryUsageStats()", e);
// Use default BatteryUsageStats.
batteryUsageStats = new BatteryUsageStats.Builder(new String[0], /* includePowerModels */
false).build();
}
final long startTime = System.currentTimeMillis();
// Stuff we always need to get BatteryInfo
final Intent batteryBroadcast = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
final long elapsedRealtimeUs = PowerUtil.convertMsToUs(SystemClock.elapsedRealtime());
BatteryInfo batteryInfo;
Estimate estimate = getEnhancedEstimate();
// couldn't get estimate from cache or provider, use fallback
if (estimate == null) {
estimate = new Estimate(batteryUsageStats.getBatteryTimeRemainingMs(), false, /* isBasedOnUsage */
EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN);
}
BatteryUtils.logRuntime(tag, "BatteryInfoLoader post query", startTime);
batteryInfo = BatteryInfo.getBatteryInfo(mContext, batteryBroadcast, batteryUsageStats, estimate, elapsedRealtimeUs, false);
BatteryUtils.logRuntime(tag, "BatteryInfoLoader.loadInBackground", startTime);
return batteryInfo;
}
use of android.os.BatteryUsageStats in project android_packages_apps_Settings by omnirom.
the class DebugEstimatesLoader method loadInBackground.
@Override
public List<BatteryInfo> loadInBackground() {
Context context = getContext();
PowerUsageFeatureProvider powerUsageFeatureProvider = FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);
// get stuff we'll need for both BatteryInfo
final long elapsedRealtimeUs = PowerUtil.convertMsToUs(SystemClock.elapsedRealtime());
Intent batteryBroadcast = getContext().registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
BatteryStats stats = mStatsHelper.getStats();
BatteryUsageStats batteryUsageStats = context.getSystemService(BatteryStatsManager.class).getBatteryUsageStats();
BatteryInfo oldinfo = BatteryInfo.getBatteryInfoOld(getContext(), batteryBroadcast, batteryUsageStats, elapsedRealtimeUs, false);
Estimate estimate = powerUsageFeatureProvider.getEnhancedBatteryPrediction(context);
if (estimate == null) {
estimate = new Estimate(0, false, EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN);
}
BatteryInfo newInfo = BatteryInfo.getBatteryInfo(getContext(), batteryBroadcast, batteryUsageStats, estimate, elapsedRealtimeUs, false);
List<BatteryInfo> infos = new ArrayList<>();
infos.add(oldinfo);
infos.add(newInfo);
return infos;
}
Aggregations