Search in sources :

Example 21 with AppInfo

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

the class UnrestrictAppTipTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    AppInfo appInfo = new AppInfo.Builder().setPackageName(PACKAGE_NAME).build();
    mBatteryTip = new UnrestrictAppTip(BatteryTip.StateType.NEW, appInfo);
}
Also used : AppInfo(com.android.settings.fuelgauge.batterytip.AppInfo) Before(org.junit.Before)

Example 22 with AppInfo

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

the class HighUsageTipTest method testParcelable.

@Test
public void testParcelable() {
    Parcel parcel = Parcel.obtain();
    mBatteryTip.writeToParcel(parcel, mBatteryTip.describeContents());
    parcel.setDataPosition(0);
    final HighUsageTip parcelTip = new HighUsageTip(parcel);
    assertThat(parcelTip.getTitle(mContext)).isEqualTo("Higher battery usage");
    assertThat(parcelTip.getType()).isEqualTo(BatteryTip.TipType.HIGH_DEVICE_USAGE);
    assertThat(parcelTip.getState()).isEqualTo(BatteryTip.StateType.NEW);
    assertThat(parcelTip.getLastFullChargeTimeMs()).isEqualTo(LAST_FULL_CHARGE_TIME);
    assertThat(parcelTip.mHighUsageAppList).isNotNull();
    assertThat(parcelTip.mHighUsageAppList.size()).isEqualTo(1);
    final AppInfo app = parcelTip.mHighUsageAppList.get(0);
    assertThat(app.packageName).isEqualTo(PACKAGE_NAME);
    assertThat(app.screenOnTimeMs).isEqualTo(SCREEN_TIME);
}
Also used : Parcel(android.os.Parcel) AppInfo(com.android.settings.fuelgauge.batterytip.AppInfo) Test(org.junit.Test)

Example 23 with AppInfo

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

the class RestrictAppTipTest method parcelable.

@Test
public void parcelable() {
    Parcel parcel = Parcel.obtain();
    mNewBatteryTip.writeToParcel(parcel, mNewBatteryTip.describeContents());
    parcel.setDataPosition(0);
    final RestrictAppTip parcelTip = new RestrictAppTip(parcel);
    assertThat(parcelTip.getType()).isEqualTo(BatteryTip.TipType.APP_RESTRICTION);
    assertThat(parcelTip.getState()).isEqualTo(BatteryTip.StateType.NEW);
    final AppInfo app = parcelTip.getRestrictAppList().get(0);
    assertThat(app.packageName).isEqualTo(PACKAGE_NAME);
}
Also used : Parcel(android.os.Parcel) AppInfo(com.android.settings.fuelgauge.batterytip.AppInfo) Test(org.junit.Test)

Example 24 with AppInfo

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

the class UnrestrictAppActionTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    final AppInfo appInfo = new AppInfo.Builder().setUid(UID_1).setPackageName(PACKAGE_NAME_1).build();
    mFeatureFactory = FakeFeatureFactory.setupForTest();
    mUnrestrictAppAction = new UnrestrictAppAction(RuntimeEnvironment.application, new UnrestrictAppTip(BatteryTip.StateType.NEW, appInfo));
    mUnrestrictAppAction.mBatteryUtils = mBatteryUtils;
}
Also used : AppInfo(com.android.settings.fuelgauge.batterytip.AppInfo) UnrestrictAppTip(com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip) Before(org.junit.Before)

Example 25 with AppInfo

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

the class RestrictAppAction method handlePositiveAction.

/**
 * Handle the action when user clicks positive button
 */
@Override
public void handlePositiveAction(int metricsKey) {
    final List<AppInfo> appInfos = mRestrictAppTip.getRestrictAppList();
    for (int i = 0, size = appInfos.size(); i < size; i++) {
        final AppInfo appInfo = appInfos.get(i);
        final String packageName = appInfo.packageName;
        // Force app standby, then app can't run in the background
        mBatteryUtils.setForceAppStandby(appInfo.uid, packageName, AppOpsManager.MODE_IGNORED);
        if (CollectionUtils.isEmpty(appInfo.anomalyTypes)) {
            // Only log context if there is no anomaly type
            mMetricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN, SettingsEnums.ACTION_TIP_RESTRICT_APP, metricsKey, packageName, 0);
        } else {
            for (int type : appInfo.anomalyTypes) {
                mMetricsFeatureProvider.action(SettingsEnums.PAGE_UNKNOWN, SettingsEnums.ACTION_TIP_RESTRICT_APP, metricsKey, packageName, type);
            }
        }
    }
    mBatteryDatabaseManager.updateAnomalies(appInfos, AnomalyDatabaseHelper.State.HANDLED);
}
Also used : AppInfo(com.android.settings.fuelgauge.batterytip.AppInfo)

Aggregations

AppInfo (com.android.settings.fuelgauge.batterytip.AppInfo)31 Test (org.junit.Test)11 Parcel (android.os.Parcel)4 VisibleForTesting (androidx.annotation.VisibleForTesting)4 CheckBoxPreference (androidx.preference.CheckBoxPreference)4 BatteryTipDialogFragment (com.android.settings.fuelgauge.batterytip.BatteryTipDialogFragment)4 RestrictAppTip (com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip)4 UnrestrictAppTip (com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip)4 AppCheckBoxPreference (com.android.settings.widget.AppCheckBoxPreference)4 Before (org.junit.Before)4 BatteryTip (com.android.settings.fuelgauge.batterytip.tips.BatteryTip)3 HighUsageTip (com.android.settings.fuelgauge.batterytip.tips.HighUsageTip)3 ArrayList (java.util.ArrayList)3 Context (android.content.Context)2 Intent (android.content.Intent)2 ApplicationInfo (android.content.pm.ApplicationInfo)2 PackageManager (android.content.pm.PackageManager)2 Bundle (android.os.Bundle)2 SparseLongArray (android.util.SparseLongArray)2 Slice (androidx.slice.Slice)1