Search in sources :

Example 41 with BatteryStatsHelper

use of com.android.internal.os.BatteryStatsHelper in project android_packages_apps_Settings by SudaMod.

the class BatteryInfo method getBatteryInfo.

public static BatteryInfo getBatteryInfo(final Context context, final BatteryStatsHelper statsHelper, boolean shortString) {
    final BatteryStats stats;
    final long batteryStatsTime = System.currentTimeMillis();
    if (statsHelper == null) {
        final BatteryStatsHelper localStatsHelper = new BatteryStatsHelper(context, true);
        localStatsHelper.create((Bundle) null);
        stats = localStatsHelper.getStats();
    } else {
        stats = statsHelper.getStats();
    }
    BatteryUtils.logRuntime(LOG_TAG, "time for getStats", batteryStatsTime);
    final long startTime = System.currentTimeMillis();
    PowerUsageFeatureProvider provider = FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);
    final long elapsedRealtimeUs = PowerUtil.convertMsToUs(SystemClock.elapsedRealtime());
    final Intent batteryBroadcast = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    // 0 means we are discharging, anything else means charging
    final boolean discharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) == 0;
    if (discharging && provider != null && provider.isEnhancedBatteryPredictionEnabled(context)) {
        Estimate estimate = provider.getEnhancedBatteryPrediction(context);
        if (estimate != null) {
            Estimate.storeCachedEstimate(context, estimate);
            BatteryUtils.logRuntime(LOG_TAG, "time for enhanced BatteryInfo", startTime);
            return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats, estimate, elapsedRealtimeUs, shortString);
        }
    }
    final long prediction = discharging ? stats.computeBatteryTimeRemaining(elapsedRealtimeUs) : 0;
    final Estimate estimate = new Estimate(PowerUtil.convertUsToMs(prediction), false, /* isBasedOnUsage */
    EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN);
    BatteryUtils.logRuntime(LOG_TAG, "time for regular BatteryInfo", startTime);
    return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats, estimate, elapsedRealtimeUs, shortString);
}
Also used : IntentFilter(android.content.IntentFilter) Estimate(com.android.settingslib.fuelgauge.Estimate) Intent(android.content.Intent) BatteryStatsHelper(com.android.internal.os.BatteryStatsHelper) BatteryStats(android.os.BatteryStats)

Example 42 with BatteryStatsHelper

use of com.android.internal.os.BatteryStatsHelper in project android_packages_apps_Settings by SudaMod.

the class PowerUsageBase method onAttach.

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    mUm = (UserManager) activity.getSystemService(Context.USER_SERVICE);
    mStatsHelper = new BatteryStatsHelper(activity, true);
}
Also used : BatteryStatsHelper(com.android.internal.os.BatteryStatsHelper)

Example 43 with BatteryStatsHelper

use of com.android.internal.os.BatteryStatsHelper in project android_packages_apps_Settings by DirtyUnicorns.

the class BatteryInfo method getBatteryInfo.

public static BatteryInfo getBatteryInfo(final Context context, final BatteryStatsHelper statsHelper, boolean shortString) {
    final BatteryStats stats;
    final long batteryStatsTime = System.currentTimeMillis();
    if (statsHelper == null) {
        final BatteryStatsHelper localStatsHelper = new BatteryStatsHelper(context, true);
        localStatsHelper.create((Bundle) null);
        stats = localStatsHelper.getStats();
    } else {
        stats = statsHelper.getStats();
    }
    BatteryUtils.logRuntime(LOG_TAG, "time for getStats", batteryStatsTime);
    final long startTime = System.currentTimeMillis();
    PowerUsageFeatureProvider provider = FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);
    final long elapsedRealtimeUs = PowerUtil.convertMsToUs(SystemClock.elapsedRealtime());
    final Intent batteryBroadcast = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    // 0 means we are discharging, anything else means charging
    final boolean discharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) == 0;
    if (discharging && provider != null && provider.isEnhancedBatteryPredictionEnabled(context)) {
        Estimate estimate = provider.getEnhancedBatteryPrediction(context);
        if (estimate != null) {
            Estimate.storeCachedEstimate(context, estimate);
            BatteryUtils.logRuntime(LOG_TAG, "time for enhanced BatteryInfo", startTime);
            return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats, estimate, elapsedRealtimeUs, shortString);
        }
    }
    final long prediction = discharging ? stats.computeBatteryTimeRemaining(elapsedRealtimeUs) : 0;
    final Estimate estimate = new Estimate(PowerUtil.convertUsToMs(prediction), false, /* isBasedOnUsage */
    EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN);
    BatteryUtils.logRuntime(LOG_TAG, "time for regular BatteryInfo", startTime);
    return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats, estimate, elapsedRealtimeUs, shortString);
}
Also used : IntentFilter(android.content.IntentFilter) Estimate(com.android.settingslib.fuelgauge.Estimate) Intent(android.content.Intent) BatteryStatsHelper(com.android.internal.os.BatteryStatsHelper) BatteryStats(android.os.BatteryStats)

Example 44 with BatteryStatsHelper

use of com.android.internal.os.BatteryStatsHelper in project android_packages_apps_Settings by DirtyUnicorns.

the class BatteryFixSlice method refreshBatteryTips.

@WorkerThread
@VisibleForTesting
static List<BatteryTip> refreshBatteryTips(Context context) {
    final BatteryStatsHelperLoader statsLoader = new BatteryStatsHelperLoader(context);
    final BatteryStatsHelper statsHelper = statsLoader.loadInBackground();
    final BatteryTipLoader loader = new BatteryTipLoader(context, statsHelper);
    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) BatteryStatsHelperLoader(com.android.settings.fuelgauge.BatteryStatsHelperLoader) BatteryStatsHelper(com.android.internal.os.BatteryStatsHelper) BatteryTip(com.android.settings.fuelgauge.batterytip.tips.BatteryTip) VisibleForTesting(androidx.annotation.VisibleForTesting) WorkerThread(androidx.annotation.WorkerThread)

Example 45 with BatteryStatsHelper

use of com.android.internal.os.BatteryStatsHelper in project platform_packages_apps_Settings by BlissRoms.

the class PowerUsageBase method onAttach.

@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    mUm = (UserManager) activity.getSystemService(Context.USER_SERVICE);
    mStatsHelper = new BatteryStatsHelper(activity, true);
}
Also used : BatteryStatsHelper(com.android.internal.os.BatteryStatsHelper)

Aggregations

BatteryStatsHelper (com.android.internal.os.BatteryStatsHelper)45 ArrayMap (android.util.ArrayMap)10 BatterySipper (com.android.internal.os.BatterySipper)10 HashMap (java.util.HashMap)10 Map (java.util.Map)10 Context (android.content.Context)7 ArrayList (java.util.ArrayList)5 Comparator (java.util.Comparator)5 Intent (android.content.Intent)3 IntentFilter (android.content.IntentFilter)3 BatteryStats (android.os.BatteryStats)3 WorkerThread (androidx.annotation.WorkerThread)3 BatteryStatsHelperLoader (com.android.settings.fuelgauge.BatteryStatsHelperLoader)3 BatteryTipLoader (com.android.settings.fuelgauge.batterytip.BatteryTipLoader)3 BatteryTip (com.android.settings.fuelgauge.batterytip.tips.BatteryTip)3 Estimate (com.android.settingslib.fuelgauge.Estimate)3 INetworkStatsService (android.net.INetworkStatsService)2 RemoteException (android.os.RemoteException)2 VisibleForTesting (androidx.annotation.VisibleForTesting)1 SettingsActivity (com.android.settings.SettingsActivity)1