Search in sources :

Example 6 with BatteryTip

use of com.android.settings.fuelgauge.batterytip.tips.BatteryTip in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BatteryTipLoader method loadInBackground.

@Override
public List<BatteryTip> loadInBackground() {
    if (USE_FAKE_DATA) {
        return getFakeData();
    }
    final List<BatteryTip> tips = new ArrayList<>();
    final BatteryTipPolicy policy = new BatteryTipPolicy(getContext());
    final BatteryInfo batteryInfo = mBatteryUtils.getBatteryInfo(mBatteryStatsHelper, TAG);
    final Context context = getContext();
    tips.add(new LowBatteryDetector(context, policy, batteryInfo).detect());
    tips.add(new HighUsageDetector(context, policy, mBatteryStatsHelper, batteryInfo.discharging).detect());
    tips.add(new SmartBatteryDetector(policy, context.getContentResolver()).detect());
    tips.add(new EarlyWarningDetector(policy, context).detect());
    tips.add(new SummaryDetector(policy, batteryInfo.averageTimeToDischarge).detect());
    tips.add(new RestrictAppDetector(context, policy).detect());
    Collections.sort(tips);
    return tips;
}
Also used : Context(android.content.Context) HighUsageDetector(com.android.settings.fuelgauge.batterytip.detectors.HighUsageDetector) RestrictAppDetector(com.android.settings.fuelgauge.batterytip.detectors.RestrictAppDetector) BatteryInfo(com.android.settings.fuelgauge.BatteryInfo) LowBatteryDetector(com.android.settings.fuelgauge.batterytip.detectors.LowBatteryDetector) SmartBatteryDetector(com.android.settings.fuelgauge.batterytip.detectors.SmartBatteryDetector) ArrayList(java.util.ArrayList) SummaryDetector(com.android.settings.fuelgauge.batterytip.detectors.SummaryDetector) EarlyWarningDetector(com.android.settings.fuelgauge.batterytip.detectors.EarlyWarningDetector) LowBatteryTip(com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip) BatteryTip(com.android.settings.fuelgauge.batterytip.tips.BatteryTip)

Example 7 with BatteryTip

use of com.android.settings.fuelgauge.batterytip.tips.BatteryTip in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BatteryTipLoader method getFakeData.

private List<BatteryTip> getFakeData() {
    final List<BatteryTip> tips = new ArrayList<>();
    tips.add(new SummaryTip(BatteryTip.StateType.NEW, EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN));
    tips.add(new LowBatteryTip(BatteryTip.StateType.NEW, false, /* powerSaveModeOn */
    "Fake data"));
    return tips;
}
Also used : SummaryTip(com.android.settings.fuelgauge.batterytip.tips.SummaryTip) ArrayList(java.util.ArrayList) LowBatteryTip(com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip) BatteryTip(com.android.settings.fuelgauge.batterytip.tips.BatteryTip) LowBatteryTip(com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip)

Example 8 with BatteryTip

use of com.android.settings.fuelgauge.batterytip.tips.BatteryTip in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BatteryTipPreferenceController method updateBatteryTips.

public void updateBatteryTips(List<BatteryTip> batteryTips) {
    if (batteryTips == null) {
        return;
    }
    if (mBatteryTips == null) {
        mBatteryTips = batteryTips;
    } else {
        // mBatteryTips and batteryTips always have the same length and same sequence.
        for (int i = 0, size = batteryTips.size(); i < size; i++) {
            mBatteryTips.get(i).updateState(batteryTips.get(i));
        }
    }
    for (int i = 0, size = batteryTips.size(); i < size; i++) {
        final BatteryTip batteryTip = mBatteryTips.get(i);
        batteryTip.sanityCheck(mContext);
        if (batteryTip.getState() != BatteryTip.StateType.INVISIBLE) {
            batteryTip.updatePreference(mCardPreference);
            mBatteryTipMap.put(mCardPreference.getKey(), batteryTip);
            batteryTip.log(mContext, mMetricsFeatureProvider);
            mNeedUpdate = batteryTip.needUpdate();
            break;
        }
    }
}
Also used : BatteryTip(com.android.settings.fuelgauge.batterytip.tips.BatteryTip)

Example 9 with BatteryTip

use of com.android.settings.fuelgauge.batterytip.tips.BatteryTip 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 10 with BatteryTip

use of com.android.settings.fuelgauge.batterytip.tips.BatteryTip in project android_packages_apps_Settings by omnirom.

the class BatteryTipLoader method getFakeData.

private List<BatteryTip> getFakeData() {
    final List<BatteryTip> tips = new ArrayList<>();
    tips.add(new SummaryTip(BatteryTip.StateType.NEW, EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN));
    tips.add(new LowBatteryTip(BatteryTip.StateType.NEW, false));
    return tips;
}
Also used : SummaryTip(com.android.settings.fuelgauge.batterytip.tips.SummaryTip) ArrayList(java.util.ArrayList) LowBatteryTip(com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip) BatteryTip(com.android.settings.fuelgauge.batterytip.tips.BatteryTip) LowBatteryTip(com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip)

Aggregations

BatteryTip (com.android.settings.fuelgauge.batterytip.tips.BatteryTip)23 LowBatteryTip (com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip)13 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)9 EarlyWarningTip (com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip)6 Slice (androidx.slice.Slice)4 VisibleForTesting (androidx.annotation.VisibleForTesting)3 AppInfo (com.android.settings.fuelgauge.batterytip.AppInfo)3 SmartBatteryTip (com.android.settings.fuelgauge.batterytip.tips.SmartBatteryTip)3 Context (android.content.Context)2 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)2 Drawable (android.graphics.drawable.Drawable)2 WorkerThread (androidx.annotation.WorkerThread)2 IconCompat (androidx.core.graphics.drawable.IconCompat)2 ListBuilder (androidx.slice.builders.ListBuilder)2 RowBuilder (androidx.slice.builders.ListBuilder.RowBuilder)2 SliceAction (androidx.slice.builders.SliceAction)2 BatteryInfo (com.android.settings.fuelgauge.BatteryInfo)2 BatteryTipDialogFragment (com.android.settings.fuelgauge.batterytip.BatteryTipDialogFragment)2 BatteryTipLoader (com.android.settings.fuelgauge.batterytip.BatteryTipLoader)2