use of com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip in project android_packages_apps_Settings by omnirom.
the class RestrictedAppDetails method onBatteryTipHandled.
@Override
public void onBatteryTipHandled(BatteryTip batteryTip) {
final AppInfo appInfo;
final boolean isRestricted = batteryTip instanceof RestrictAppTip;
if (isRestricted) {
appInfo = ((RestrictAppTip) batteryTip).getRestrictAppList().get(0);
} else {
appInfo = ((UnrestrictAppTip) batteryTip).getUnrestrictAppInfo();
}
CheckBoxPreference preference = (CheckBoxPreference) mRestrictedAppListGroup.findPreference(getKeyFromAppInfo(appInfo));
if (preference != null) {
preference.setChecked(isRestricted);
}
}
use of com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip in project android_packages_apps_Settings by omnirom.
the class RestrictedAppDetailsTest method onBatteryTipHandled_restrict_setChecked.
@Test
public void onBatteryTipHandled_restrict_setChecked() {
final RestrictAppTip restrictAppTip = new RestrictAppTip(BatteryTip.StateType.NEW, mAppInfo);
mRestrictedAppDetails.mRestrictedAppListGroup.addPreference(mCheckBoxPreference);
mRestrictedAppDetails.onBatteryTipHandled(restrictAppTip);
assertThat(mCheckBoxPreference.isChecked()).isTrue();
}
use of com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip in project android_packages_apps_Settings by omnirom.
the class BatteryTipDialogFragmentTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
FakeFeatureFactory.setupForTest();
ShadowUtils.setApplicationLabel(PACKAGE_NAME, DISPLAY_NAME);
mPackageManager = Shadows.shadowOf(mContext.getPackageManager());
final ApplicationInfo applicationInfo = new ApplicationInfo();
applicationInfo.name = DISPLAY_NAME;
applicationInfo.packageName = PACKAGE_NAME;
final PackageInfo packageInfo = new PackageInfo();
packageInfo.packageName = PACKAGE_NAME;
packageInfo.applicationInfo = applicationInfo;
mPackageManager.addPackage(packageInfo);
mPackageManager.setApplicationIcon(PACKAGE_NAME, new ColorDrawable());
List<AppInfo> highUsageTips = new ArrayList<>();
mAppInfo = new AppInfo.Builder().setScreenOnTimeMs(SCREEN_TIME_MS).setPackageName(PACKAGE_NAME).build();
highUsageTips.add(mAppInfo);
mHighUsageTip = new HighUsageTip(SCREEN_TIME_MS, highUsageTips);
final List<AppInfo> restrictApps = new ArrayList<>();
restrictApps.add(mAppInfo);
mRestrictedOneAppTip = new RestrictAppTip(BatteryTip.StateType.NEW, new ArrayList<>(restrictApps));
restrictApps.add(mAppInfo);
mRestrictTwoAppsTip = new RestrictAppTip(BatteryTip.StateType.NEW, new ArrayList<>(restrictApps));
mUnrestrictAppTip = new UnrestrictAppTip(BatteryTip.StateType.NEW, mAppInfo);
mSummaryTip = spy(new SummaryTip(BatteryTip.StateType.NEW, EstimateKt.AVERAGE_TIME_TO_DISCHARGE_UNKNOWN));
mDefenderTip = new BatteryDefenderTip(BatteryTip.StateType.NEW);
}
use of com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip in project android_packages_apps_Settings by omnirom.
the class RestrictAppDetectorTest method testDetect_typeHandledHasUnRestrictedAnomaly_removeIt.
@Test
public void testDetect_typeHandledHasUnRestrictedAnomaly_removeIt() throws PackageManager.NameNotFoundException {
mAppInfoList.clear();
mAppInfoList.add(new AppInfo.Builder().setUid(UNRESTRICTED_UID).setPackageName(UNRESTRICTED_PACKAGE_NAME).build());
doReturn(new ArrayList<>()).when(mBatteryDatabaseManager).queryAllAnomalies(anyLong(), eq(AnomalyDatabaseHelper.State.NEW));
doReturn(mAppInfoList).when(mBatteryDatabaseManager).queryAllAnomalies(anyLong(), eq(AnomalyDatabaseHelper.State.AUTO_HANDLED));
doReturn(mApplicationInfo).when(mPackageManager).getApplicationInfo(eq(UNRESTRICTED_PACKAGE_NAME), anyInt());
final RestrictAppTip restrictAppTip = (RestrictAppTip) mRestrictAppDetector.detect();
assertThat(restrictAppTip.getState()).isEqualTo(BatteryTip.StateType.INVISIBLE);
}
use of com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip in project android_packages_apps_Settings by omnirom.
the class RestrictAppDetectorTest method testDetect_typeNewHasRestrictedAnomaly_removeIt.
@Test
public void testDetect_typeNewHasRestrictedAnomaly_removeIt() throws PackageManager.NameNotFoundException {
mAppInfoList.add(new AppInfo.Builder().setUid(RESTRICTED_UID).setPackageName(RESTRICTED_PACKAGE_NAME).build());
doReturn(mAppInfoList).when(mBatteryDatabaseManager).queryAllAnomalies(anyLong(), eq(AnomalyDatabaseHelper.State.NEW));
doReturn(mApplicationInfo).when(mPackageManager).getApplicationInfo(eq(RESTRICTED_PACKAGE_NAME), anyInt());
final RestrictAppTip restrictAppTip = (RestrictAppTip) mRestrictAppDetector.detect();
assertThat(restrictAppTip.getState()).isEqualTo(BatteryTip.StateType.NEW);
assertThat(restrictAppTip.getRestrictAppList()).containsExactly(mAppInfo);
}
Aggregations