Search in sources :

Example 11 with BatteryTip

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;
}
Also used : Context(android.content.Context) HighUsageDetector(com.android.settings.fuelgauge.batterytip.detectors.HighUsageDetector) BatteryDefenderDetector(com.android.settings.fuelgauge.batterytip.detectors.BatteryDefenderDetector) 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) 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 12 with BatteryTip

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);
}
Also used : BatteryTipAction(com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction) BatteryTip(com.android.settings.fuelgauge.batterytip.tips.BatteryTip)

Example 13 with BatteryTip

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();
}
Also used : EarlyWarningTip(com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip) Slice(androidx.slice.Slice) ArrayList(java.util.ArrayList) LowBatteryTip(com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip) BatteryTip(com.android.settings.fuelgauge.batterytip.tips.BatteryTip) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 14 with BatteryTip

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();
}
Also used : EarlyWarningTip(com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip) 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) Test(org.junit.Test)

Example 15 with BatteryTip

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);
}
Also used : SmartBatteryTip(com.android.settings.fuelgauge.batterytip.tips.SmartBatteryTip) LowBatteryTip(com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip) SmartBatteryTip(com.android.settings.fuelgauge.batterytip.tips.SmartBatteryTip) BatteryTip(com.android.settings.fuelgauge.batterytip.tips.BatteryTip) Test(org.junit.Test)

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