Search in sources :

Example 1 with BatteryUsageStats

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;
}
Also used : BatteryTipLoader(com.android.settings.fuelgauge.batterytip.BatteryTipLoader) BatteryUsageStats(android.os.BatteryUsageStats) BatteryUsageStatsLoader(com.android.settings.fuelgauge.BatteryUsageStatsLoader) BatteryTip(com.android.settings.fuelgauge.batterytip.tips.BatteryTip) VisibleForTesting(androidx.annotation.VisibleForTesting) WorkerThread(androidx.annotation.WorkerThread)

Example 2 with BatteryUsageStats

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;
}
Also used : IntentFilter(android.content.IntentFilter) Estimate(com.android.settingslib.fuelgauge.Estimate) Intent(android.content.Intent) BatteryStatsManager(android.os.BatteryStatsManager) BatteryUsageStats(android.os.BatteryUsageStats) WorkerThread(androidx.annotation.WorkerThread)

Example 3 with BatteryUsageStats

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;
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) Estimate(com.android.settingslib.fuelgauge.Estimate) ArrayList(java.util.ArrayList) Intent(android.content.Intent) BatteryStatsManager(android.os.BatteryStatsManager) BatteryUsageStats(android.os.BatteryUsageStats) BatteryStats(android.os.BatteryStats)

Aggregations

BatteryUsageStats (android.os.BatteryUsageStats)3 Intent (android.content.Intent)2 IntentFilter (android.content.IntentFilter)2 BatteryStatsManager (android.os.BatteryStatsManager)2 WorkerThread (androidx.annotation.WorkerThread)2 Estimate (com.android.settingslib.fuelgauge.Estimate)2 Context (android.content.Context)1 BatteryStats (android.os.BatteryStats)1 VisibleForTesting (androidx.annotation.VisibleForTesting)1 BatteryUsageStatsLoader (com.android.settings.fuelgauge.BatteryUsageStatsLoader)1 BatteryTipLoader (com.android.settings.fuelgauge.batterytip.BatteryTipLoader)1 BatteryTip (com.android.settings.fuelgauge.batterytip.tips.BatteryTip)1 ArrayList (java.util.ArrayList)1