Merge "Add log for battery tip action." into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
09ed2f2596
@@ -59,6 +59,7 @@ public class BatteryTipDialogFragmentTest {
|
||||
private static final String DISPLAY_NAME = "app";
|
||||
private static final long SCREEN_TIME_MS = DateUtils.HOUR_IN_MILLIS;
|
||||
private static final long AVERAGE_TIME_MS = DateUtils.HOUR_IN_MILLIS;
|
||||
private static final int METRICS_KEY = 1;
|
||||
|
||||
private BatteryTipDialogFragment mDialogFragment;
|
||||
private Context mContext;
|
||||
@@ -102,7 +103,7 @@ public class BatteryTipDialogFragmentTest {
|
||||
public void testOnCreateDialog_highUsageTip_fireHighUsageDialog() {
|
||||
Robolectric.getForegroundThreadScheduler().pause();
|
||||
|
||||
mDialogFragment = BatteryTipDialogFragment.newInstance(mHighUsageTip);
|
||||
mDialogFragment = BatteryTipDialogFragment.newInstance(mHighUsageTip, METRICS_KEY);
|
||||
|
||||
FragmentTestUtil.startFragment(mDialogFragment);
|
||||
|
||||
@@ -117,7 +118,7 @@ public class BatteryTipDialogFragmentTest {
|
||||
|
||||
@Test
|
||||
public void testOnCreateDialog_restrictOneAppTip_fireRestrictOneAppDialog() {
|
||||
mDialogFragment = BatteryTipDialogFragment.newInstance(mRestrictedOneAppTip);
|
||||
mDialogFragment = BatteryTipDialogFragment.newInstance(mRestrictedOneAppTip, METRICS_KEY);
|
||||
|
||||
FragmentTestUtil.startFragment(mDialogFragment);
|
||||
|
||||
@@ -134,7 +135,8 @@ public class BatteryTipDialogFragmentTest {
|
||||
public void testOnCreateDialog_restrictTwoAppsTip_fireRestrictTwoAppsDialog() {
|
||||
Robolectric.getForegroundThreadScheduler().pause();
|
||||
|
||||
mDialogFragment = BatteryTipDialogFragment.newInstance(mRestrictTwoAppsTip);
|
||||
mDialogFragment = BatteryTipDialogFragment.newInstance(mRestrictTwoAppsTip, METRICS_KEY);
|
||||
|
||||
|
||||
FragmentTestUtil.startFragment(mDialogFragment);
|
||||
|
||||
@@ -161,7 +163,7 @@ public class BatteryTipDialogFragmentTest {
|
||||
final RestrictAppTip restrictSixAppsTip = new RestrictAppTip(BatteryTip.StateType.NEW,
|
||||
appInfos);
|
||||
|
||||
mDialogFragment = BatteryTipDialogFragment.newInstance(restrictSixAppsTip);
|
||||
mDialogFragment = BatteryTipDialogFragment.newInstance(restrictSixAppsTip, METRICS_KEY);
|
||||
|
||||
FragmentTestUtil.startFragment(mDialogFragment);
|
||||
|
||||
@@ -178,7 +180,8 @@ public class BatteryTipDialogFragmentTest {
|
||||
|
||||
@Test
|
||||
public void testOnCreateDialog_unRestrictAppTip_fireUnRestrictDialog() {
|
||||
mDialogFragment = BatteryTipDialogFragment.newInstance(mUnrestrictAppTip);
|
||||
mDialogFragment = BatteryTipDialogFragment.newInstance(mUnrestrictAppTip, METRICS_KEY);
|
||||
ShadowUtils.setApplicationLabel(PACKAGE_NAME, DISPLAY_NAME);
|
||||
|
||||
FragmentTestUtil.startFragment(mDialogFragment);
|
||||
|
||||
@@ -193,7 +196,7 @@ public class BatteryTipDialogFragmentTest {
|
||||
@Test
|
||||
public void testOnCreateDialog_summaryTipWithEstimation_fireDialogWithEstimation() {
|
||||
doReturn(AVERAGE_TIME_MS).when(mSummaryTip).getAverageTimeMs();
|
||||
mDialogFragment = BatteryTipDialogFragment.newInstance(mSummaryTip);
|
||||
mDialogFragment = BatteryTipDialogFragment.newInstance(mSummaryTip, METRICS_KEY);
|
||||
|
||||
FragmentTestUtil.startFragment(mDialogFragment);
|
||||
|
||||
@@ -207,7 +210,7 @@ public class BatteryTipDialogFragmentTest {
|
||||
|
||||
@Test
|
||||
public void testOnCreateDialog_summaryTipWithoutEstimation_fireDialogWithoutEstimation() {
|
||||
mDialogFragment = BatteryTipDialogFragment.newInstance(mSummaryTip);
|
||||
mDialogFragment = BatteryTipDialogFragment.newInstance(mSummaryTip, METRICS_KEY);
|
||||
|
||||
FragmentTestUtil.startFragment(mDialogFragment);
|
||||
|
||||
|
@@ -37,6 +37,7 @@ import android.text.format.DateUtils;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
@@ -70,6 +71,8 @@ public class BatteryTipPreferenceControllerTest {
|
||||
private SettingsActivity mSettingsActivity;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private PreferenceManager mPreferenceManager;
|
||||
@Mock
|
||||
private InstrumentedPreferenceFragment mFragment;
|
||||
|
||||
private Context mContext;
|
||||
private PreferenceGroup mPreferenceGroup;
|
||||
@@ -98,7 +101,7 @@ public class BatteryTipPreferenceControllerTest {
|
||||
mNewBatteryTips.add(new SummaryTip(BatteryTip.StateType.INVISIBLE, AVERAGE_TIME_MS));
|
||||
|
||||
mBatteryTipPreferenceController = new BatteryTipPreferenceController(mContext, KEY_PREF,
|
||||
mSettingsActivity, null, mBatteryTipListener);
|
||||
mSettingsActivity, mFragment, mBatteryTipListener);
|
||||
mBatteryTipPreferenceController.mPreferenceGroup = mPreferenceGroup;
|
||||
mBatteryTipPreferenceController.mPrefContext = mContext;
|
||||
}
|
||||
|
@@ -20,12 +20,16 @@ import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.AppOpsManager;
|
||||
import android.content.Context;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.fuelgauge.batterytip.AppInfo;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip;
|
||||
import com.android.settings.testutils.DatabaseTestUtils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.After;
|
||||
@@ -44,21 +48,32 @@ public class RestrictAppActionTest {
|
||||
|
||||
private static final String PACKAGE_NAME_1 = "com.android.app1";
|
||||
private static final String PACKAGE_NAME_2 = "com.android.app2";
|
||||
private static final int ANOMALY_WAKEUP = 0;
|
||||
private static final int ANOMALY_BT = 1;
|
||||
private static final int METRICS_KEY = 1;
|
||||
|
||||
@Mock
|
||||
private BatteryUtils mBatteryUtils;
|
||||
private RestrictAppAction mRestrictAppAction;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
final List<AppInfo> mAppInfos = new ArrayList<>();
|
||||
mAppInfos.add(new AppInfo.Builder().setPackageName(PACKAGE_NAME_1).build());
|
||||
mAppInfos.add(new AppInfo.Builder().setPackageName(PACKAGE_NAME_2).build());
|
||||
mAppInfos.add(new AppInfo.Builder()
|
||||
.setPackageName(PACKAGE_NAME_1)
|
||||
.build());
|
||||
mAppInfos.add(new AppInfo.Builder()
|
||||
.setPackageName(PACKAGE_NAME_2)
|
||||
.addAnomalyType(ANOMALY_BT)
|
||||
.addAnomalyType(ANOMALY_WAKEUP)
|
||||
.build());
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
|
||||
mRestrictAppAction = new RestrictAppAction(RuntimeEnvironment.application,
|
||||
new RestrictAppTip(BatteryTip.StateType.NEW, mAppInfos));
|
||||
new RestrictAppTip(BatteryTip.StateType.NEW, mAppInfos));
|
||||
mRestrictAppAction.mBatteryUtils = mBatteryUtils;
|
||||
}
|
||||
|
||||
@@ -69,11 +84,22 @@ public class RestrictAppActionTest {
|
||||
|
||||
@Test
|
||||
public void testHandlePositiveAction() {
|
||||
mRestrictAppAction.handlePositiveAction();
|
||||
mRestrictAppAction.handlePositiveAction(METRICS_KEY);
|
||||
|
||||
verify(mBatteryUtils)
|
||||
.setForceAppStandby(anyInt(), eq(PACKAGE_NAME_1), eq(AppOpsManager.MODE_IGNORED));
|
||||
.setForceAppStandby(anyInt(), eq(PACKAGE_NAME_1), eq(AppOpsManager.MODE_IGNORED));
|
||||
verify(mBatteryUtils)
|
||||
.setForceAppStandby(anyInt(), eq(PACKAGE_NAME_2), eq(AppOpsManager.MODE_IGNORED));
|
||||
.setForceAppStandby(anyInt(), eq(PACKAGE_NAME_2), eq(AppOpsManager.MODE_IGNORED));
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(RuntimeEnvironment.application,
|
||||
MetricsProto.MetricsEvent.ACTION_TIP_RESTRICT_APP, PACKAGE_NAME_1, Pair.create(
|
||||
MetricsProto.MetricsEvent.FIELD_CONTEXT, METRICS_KEY));
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(RuntimeEnvironment.application,
|
||||
MetricsProto.MetricsEvent.ACTION_TIP_RESTRICT_APP, PACKAGE_NAME_2,
|
||||
Pair.create(MetricsProto.MetricsEvent.FIELD_CONTEXT, METRICS_KEY),
|
||||
Pair.create(MetricsProto.MetricsEvent.FIELD_ANOMALY_TYPE, ANOMALY_WAKEUP));
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(RuntimeEnvironment.application,
|
||||
MetricsProto.MetricsEvent.ACTION_TIP_RESTRICT_APP, PACKAGE_NAME_2,
|
||||
Pair.create(MetricsProto.MetricsEvent.FIELD_CONTEXT, METRICS_KEY),
|
||||
Pair.create(MetricsProto.MetricsEvent.FIELD_ANOMALY_TYPE, ANOMALY_BT));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.fuelgauge.batterytip.actions;
|
||||
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.app.AppOpsManager;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.fuelgauge.batterytip.AppInfo;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip;
|
||||
import com.android.settings.testutils.DatabaseTestUtils;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class UnrestrictAppActionTest {
|
||||
|
||||
private static final String PACKAGE_NAME_1 = "com.android.app1";
|
||||
private static final int METRICS_KEY = 1;
|
||||
|
||||
@Mock
|
||||
private BatteryUtils mBatteryUtils;
|
||||
private UnrestrictAppAction mUnrestrictAppAction;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
final AppInfo appInfo = new AppInfo.Builder().setPackageName(PACKAGE_NAME_1).build();
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
|
||||
mUnrestrictAppAction = new UnrestrictAppAction(RuntimeEnvironment.application,
|
||||
new UnrestrictAppTip(BatteryTip.StateType.NEW, appInfo));
|
||||
mUnrestrictAppAction.mBatteryUtils = mBatteryUtils;
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
DatabaseTestUtils.clearDb(RuntimeEnvironment.application);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePositiveAction() {
|
||||
mUnrestrictAppAction.handlePositiveAction(METRICS_KEY);
|
||||
|
||||
verify(mBatteryUtils)
|
||||
.setForceAppStandby(anyInt(), eq(PACKAGE_NAME_1), eq(AppOpsManager.MODE_ALLOWED));
|
||||
verify(mFeatureFactory.metricsFeatureProvider).action(RuntimeEnvironment.application,
|
||||
MetricsProto.MetricsEvent.ACTION_TIP_UNRESTRICT_APP, PACKAGE_NAME_1, Pair.create(
|
||||
MetricsProto.MetricsEvent.FIELD_CONTEXT, METRICS_KEY));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user