Search in sources :

Example 11 with RestrictAppTip

use of com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip in project android_packages_apps_Settings by omnirom.

the class RestrictAppDetectorTest method testDetect_typeNewHasUninstalledAnomaly_removeIt.

@Test
public void testDetect_typeNewHasUninstalledAnomaly_removeIt() {
    mAppInfoList.add(new AppInfo.Builder().setPackageName(UNINSTALLED_PACKAGE_NAME).build());
    doReturn(mAppInfoList).when(mBatteryDatabaseManager).queryAllAnomalies(anyLong(), eq(AnomalyDatabaseHelper.State.NEW));
    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) AppInfo(com.android.settings.fuelgauge.batterytip.AppInfo) Test(org.junit.Test)

Example 12 with RestrictAppTip

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

the class BatteryTipDialogFragmentTest method testOnCreateDialog_restrictSixAppsTip_fireRestrictSixAppsDialog.

@Test
public void testOnCreateDialog_restrictSixAppsTip_fireRestrictSixAppsDialog() {
    Robolectric.getForegroundThreadScheduler().pause();
    final List<AppInfo> appInfos = new ArrayList<>();
    for (int i = 0; i < 6; i++) {
        appInfos.add(mAppInfo);
    }
    final RestrictAppTip restrictSixAppsTip = new RestrictAppTip(BatteryTip.StateType.NEW, appInfos);
    mDialogFragment = BatteryTipDialogFragment.newInstance(restrictSixAppsTip, METRICS_KEY);
    FragmentController.setupFragment(mDialogFragment, FragmentActivity.class, 0, /* containerViewId */
    null);
    Robolectric.getForegroundThreadScheduler().advanceToLastPostedRunnable();
    final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
    ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
    assertThat(shadowDialog.getTitle()).isEqualTo("Restrict 6 apps?");
    assertThat(shadowDialog.getMessage()).isEqualTo("To save battery, stop these apps from using battery in the background. " + "Restricted apps may not work properly and notifications may be" + " delayed.\n\nApps:\napp, app, app, app, app, and app.");
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) RestrictAppTip(com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip) ArrayList(java.util.ArrayList) ShadowAlertDialogCompat(com.android.settings.testutils.shadow.ShadowAlertDialogCompat) Test(org.junit.Test)

Example 13 with RestrictAppTip

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

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)

Example 14 with RestrictAppTip

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

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 15 with RestrictAppTip

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

the class RestrictAppDetectorTest method testDetect_typeNewHasUninstalledAnomaly_removeIt.

@Test
public void testDetect_typeNewHasUninstalledAnomaly_removeIt() {
    mAppInfoList.add(new AppInfo.Builder().setPackageName(UNINSTALLED_PACKAGE_NAME).build());
    doReturn(mAppInfoList).when(mBatteryDatabaseManager).queryAllAnomalies(anyLong(), eq(AnomalyDatabaseHelper.State.NEW));
    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) AppInfo(com.android.settings.fuelgauge.batterytip.AppInfo) 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