use of com.android.settings.fuelgauge.batterytip.tips.BatteryTip in project android_packages_apps_Settings by omnirom.
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(TAG);
final Context context = getContext();
tips.add(new LowBatteryDetector(context, policy, batteryInfo).detect());
tips.add(new HighUsageDetector(context, policy, mBatteryUsageStats, batteryInfo).detect());
tips.add(new SmartBatteryDetector(context, policy, batteryInfo, context.getContentResolver()).detect());
tips.add(new EarlyWarningDetector(policy, context).detect());
tips.add(new BatteryDefenderDetector(batteryInfo).detect());
// Disable this feature now since it introduces false positive cases. We will try to improve
// it in the future.
// tips.add(new RestrictAppDetector(context, policy).detect());
Collections.sort(tips);
return tips;
}
use of com.android.settings.fuelgauge.batterytip.tips.BatteryTip in project android_packages_apps_Settings by omnirom.
the class BatteryTipPreferenceController method handlePreferenceTreeClick.
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
final BatteryTip batteryTip = mBatteryTipMap.get(preference.getKey());
if (batteryTip != null) {
if (batteryTip.shouldShowDialog()) {
BatteryTipDialogFragment dialogFragment = BatteryTipDialogFragment.newInstance(batteryTip, mFragment.getMetricsCategory());
dialogFragment.setTargetFragment(mFragment, REQUEST_ANOMALY_ACTION);
dialogFragment.show(mFragment.getFragmentManager(), TAG);
} else {
final BatteryTipAction action = BatteryTipUtils.getActionForBatteryTip(batteryTip, mSettingsActivity, mFragment);
if (action != null) {
action.handlePositiveAction(mFragment.getMetricsCategory());
}
if (mBatteryTipListener != null) {
mBatteryTipListener.onBatteryTipHandled(batteryTip);
}
}
return true;
}
return super.handlePreferenceTreeClick(preference);
}
use of com.android.settings.fuelgauge.batterytip.tips.BatteryTip in project android_packages_apps_Settings by omnirom.
the class BatteryFixSliceTest method getSlice_hasImportantTip_shouldTintIcon.
@Test
@Config(shadows = { BatteryFixSliceTest.ShadowEarlyWarningTip.class, BatteryFixSliceTest.ShadowSliceBackgroundWorker.class })
public void getSlice_hasImportantTip_shouldTintIcon() {
final List<BatteryTip> tips = new ArrayList<>();
tips.add(new EarlyWarningTip(BatteryTip.StateType.NEW, false));
// Create fake cache data
ShadowBatteryTipLoader.setBatteryTips(tips);
BatteryFixSlice.refreshBatteryTips(mContext);
// Create fake background worker data
BatteryFixSlice.BatteryTipWorker batteryTipWorker = mock(BatteryFixSlice.BatteryTipWorker.class);
when(batteryTipWorker.getResults()).thenReturn(tips);
ShadowSliceBackgroundWorker.setBatteryTipWorkerWorker(batteryTipWorker);
final Slice slice = mSlice.getSlice();
assertThat(ShadowEarlyWarningTip.isIconTintColorIdCalled()).isTrue();
}
use of com.android.settings.fuelgauge.batterytip.tips.BatteryTip in project android_packages_apps_Settings by omnirom.
the class BatteryFixSliceTest method refreshBatteryTips_hasImportantTip_shouldReturnTrue.
@Test
public void refreshBatteryTips_hasImportantTip_shouldReturnTrue() {
final List<BatteryTip> tips = new ArrayList<>();
tips.add(new LowBatteryTip(BatteryTip.StateType.INVISIBLE, false));
tips.add(new EarlyWarningTip(BatteryTip.StateType.NEW, false));
ShadowBatteryTipLoader.setBatteryTips(tips);
BatteryFixSlice.refreshBatteryTips(mContext);
assertThat(BatteryFixSlice.isBatteryTipAvailableFromCache(mContext)).isTrue();
}
use of com.android.settings.fuelgauge.batterytip.tips.BatteryTip in project android_packages_apps_Settings by omnirom.
the class BatteryHeaderPreferenceControllerTest method updateHeaderByBatteryTips_notLowBatteryTip_showRemainingLabel.
@Test
public void updateHeaderByBatteryTips_notLowBatteryTip_showRemainingLabel() {
setChargingState(/* isDischarging */
true, /* updatedByStatusFeature */
false);
BatteryTip lowBatteryTip = new SmartBatteryTip(BatteryTip.StateType.NEW);
mController.updateHeaderByBatteryTips(lowBatteryTip, mBatteryInfo);
verify(mBatteryUsageProgressBarPref).setBottomSummary(mBatteryInfo.remainingLabel);
}
Aggregations