Search in sources :

Example 1 with EarlyWarningTip

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

the class BatteryFixSliceTest method getSlice_unimportantSlice_shouldSkip.

@Test
public void getSlice_unimportantSlice_shouldSkip() {
    final List<BatteryTip> tips = new ArrayList<>();
    tips.add(new LowBatteryTip(BatteryTip.StateType.INVISIBLE, false, ""));
    tips.add(new EarlyWarningTip(BatteryTip.StateType.HANDLED, false));
    ShadowBatteryTipLoader.setBatteryTips(tips);
    BatteryFixSlice.updateBatteryTipAvailabilityCache(mContext);
    final Slice slice = mSlice.getSlice();
    assertThat(SliceMetadata.from(mContext, slice).isErrorSlice()).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) LowBatteryTip(com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip) Test(org.junit.Test)

Example 2 with EarlyWarningTip

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

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.updateBatteryTipAvailabilityCache(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 3 with EarlyWarningTip

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

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

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

the class EarlyWarningDetector method detect.

@Override
public BatteryTip detect() {
    final Intent batteryBroadcast = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    final boolean discharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) == 0;
    final boolean powerSaveModeOn = mPowerManager.isPowerSaveMode();
    final boolean earlyWarning = mPowerUsageFeatureProvider.getEarlyWarningSignal(mContext, EarlyWarningDetector.class.getName()) || mPolicy.testBatterySaverTip;
    final int state = powerSaveModeOn ? BatteryTip.StateType.HANDLED : mPolicy.batterySaverTipEnabled && discharging && earlyWarning ? BatteryTip.StateType.NEW : BatteryTip.StateType.INVISIBLE;
    return new EarlyWarningTip(state, powerSaveModeOn);
}
Also used : EarlyWarningTip(com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent)

Aggregations

EarlyWarningTip (com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip)8 BatteryTip (com.android.settings.fuelgauge.batterytip.tips.BatteryTip)6 LowBatteryTip (com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip)6 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Slice (androidx.slice.Slice)4 Intent (android.content.Intent)2 IntentFilter (android.content.IntentFilter)2 Config (org.robolectric.annotation.Config)2 AppInfo (com.android.settings.fuelgauge.batterytip.AppInfo)1 HighUsageTip (com.android.settings.fuelgauge.batterytip.tips.HighUsageTip)1