Search in sources :

Example 6 with RestrictAppTip

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);
    }
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) AppCheckBoxPreference(com.android.settings.widget.AppCheckBoxPreference) RestrictAppTip(com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip) AppInfo(com.android.settings.fuelgauge.batterytip.AppInfo)

Example 7 with RestrictAppTip

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

Example 8 with RestrictAppTip

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);
}
Also used : HighUsageTip(com.android.settings.fuelgauge.batterytip.tips.HighUsageTip) BatteryDefenderTip(com.android.settings.fuelgauge.batterytip.tips.BatteryDefenderTip) ColorDrawable(android.graphics.drawable.ColorDrawable) PackageInfo(android.content.pm.PackageInfo) RestrictAppTip(com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip) SummaryTip(com.android.settings.fuelgauge.batterytip.tips.SummaryTip) ApplicationInfo(android.content.pm.ApplicationInfo) ArrayList(java.util.ArrayList) UnrestrictAppTip(com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip) Before(org.junit.Before)

Example 9 with RestrictAppTip

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

Example 10 with RestrictAppTip

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

Aggregations

RestrictAppTip (com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip)18 Test (org.junit.Test)10 AppInfo (com.android.settings.fuelgauge.batterytip.AppInfo)6 UnrestrictAppTip (com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip)6 AlertDialog (androidx.appcompat.app.AlertDialog)4 HighUsageTip (com.android.settings.fuelgauge.batterytip.tips.HighUsageTip)4 ArrayList (java.util.ArrayList)4 Context (android.content.Context)2 Bundle (android.os.Bundle)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2 CheckBoxPreference (androidx.preference.CheckBoxPreference)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 BatteryTipDialogFragment (com.android.settings.fuelgauge.batterytip.BatteryTipDialogFragment)2 BatteryTip (com.android.settings.fuelgauge.batterytip.tips.BatteryTip)2 SummaryTip (com.android.settings.fuelgauge.batterytip.tips.SummaryTip)2 ShadowAlertDialogCompat (com.android.settings.testutils.shadow.ShadowAlertDialogCompat)2 AppCheckBoxPreference (com.android.settings.widget.AppCheckBoxPreference)2 Before (org.junit.Before)2 ApplicationInfo (android.content.pm.ApplicationInfo)1