Add smart battery tip.
Also move the action method from BatteryTip to TipAction. Since it need extra data that we don't want to store it in parcel. Bug: 71502850 Test: RunSettingsRoboTests Change-Id: Ib658426725158d26fcdd437fa8bf6bf24e9a8c14
This commit is contained in:
@@ -4773,6 +4773,10 @@
|
||||
<string name="battery_tip_low_battery_title">Low battery capacity</string>
|
||||
<!-- Summary for the low battery tip [CHAR LIMIT=NONE] -->
|
||||
<string name="battery_tip_low_battery_summary">Battery can\'t provide good battery life</string>
|
||||
<!-- Title for the smart battery tip [CHAR LIMIT=NONE] -->
|
||||
<string name="battery_tip_smart_battery_title">Turn on smart battery manager</string>
|
||||
<!-- Summary for the smart battery tip [CHAR LIMIT=NONE] -->
|
||||
<string name="battery_tip_smart_battery_summary">Turn on to optimize battery usage</string>
|
||||
<!-- Title for the battery high usage tip [CHAR LIMIT=NONE] -->
|
||||
<string name="battery_tip_high_usage_title" product="default">Phone used heavily</string>
|
||||
<!-- Title for the battery high usage tip [CHAR LIMIT=NONE] -->
|
||||
|
@@ -266,7 +266,7 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
||||
KEY_APP_LIST, lifecycle, activity, this);
|
||||
controllers.add(mBatteryAppListPreferenceController);
|
||||
mBatteryTipPreferenceController = new BatteryTipPreferenceController(context,
|
||||
KEY_BATTERY_TIP, this, this);
|
||||
KEY_BATTERY_TIP, (SettingsActivity) getActivity(), this, this);
|
||||
controllers.add(mBatteryTipPreferenceController);
|
||||
controllers.add(new BatterySaverController(context, getLifecycle()));
|
||||
controllers.add(new BatteryPercentagePreferenceController(context));
|
||||
|
@@ -27,8 +27,10 @@ import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController.BatteryTipListener;
|
||||
import com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
|
||||
|
||||
@@ -97,7 +99,11 @@ public class BatteryTipDialogFragment extends InstrumentedDialogFragment impleme
|
||||
if (lsn == null) {
|
||||
return;
|
||||
}
|
||||
mBatteryTip.action();
|
||||
final BatteryTipAction action = BatteryTipUtils.getActionForBatteryTip(mBatteryTip,
|
||||
(SettingsActivity) getActivity(), this);
|
||||
if (action != null) {
|
||||
action.handlePositiveAction();
|
||||
}
|
||||
lsn.onBatteryTipHandled(mBatteryTip);
|
||||
}
|
||||
|
||||
|
@@ -25,6 +25,7 @@ import com.android.settings.fuelgauge.BatteryUtils;
|
||||
import com.android.settings.fuelgauge.batterytip.detectors.BatteryTipDetector;
|
||||
import com.android.settings.fuelgauge.batterytip.detectors.HighUsageDetector;
|
||||
import com.android.settings.fuelgauge.batterytip.detectors.LowBatteryDetector;
|
||||
import com.android.settings.fuelgauge.batterytip.detectors.SmartBatteryDetector;
|
||||
import com.android.settings.fuelgauge.batterytip.detectors.SummaryDetector;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip;
|
||||
@@ -68,6 +69,8 @@ public class BatteryTipLoader extends AsyncLoader<List<BatteryTip>> {
|
||||
addBatteryTipFromDetector(tips, new LowBatteryDetector(policy, batteryInfo));
|
||||
addBatteryTipFromDetector(tips,
|
||||
new HighUsageDetector(getContext(), policy, mBatteryStatsHelper));
|
||||
addBatteryTipFromDetector(tips,
|
||||
new SmartBatteryDetector(policy, getContext().getContentResolver()));
|
||||
// Add summary detector at last since it need other detectors to update the mVisibleTips
|
||||
addBatteryTipFromDetector(tips, new SummaryDetector(policy, mVisibleTips));
|
||||
|
||||
|
@@ -23,7 +23,9 @@ import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
|
||||
|
||||
@@ -41,6 +43,7 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
|
||||
private BatteryTipListener mBatteryTipListener;
|
||||
private List<BatteryTip> mBatteryTips;
|
||||
private Map<String, BatteryTip> mBatteryTipMap;
|
||||
private SettingsActivity mSettingsActivity;
|
||||
@VisibleForTesting
|
||||
PreferenceGroup mPreferenceGroup;
|
||||
@VisibleForTesting
|
||||
@@ -48,15 +51,17 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
|
||||
PreferenceFragment mFragment;
|
||||
|
||||
public BatteryTipPreferenceController(Context context, String preferenceKey) {
|
||||
this(context, preferenceKey, null, null);
|
||||
this(context, preferenceKey, null, null, null);
|
||||
}
|
||||
|
||||
public BatteryTipPreferenceController(Context context, String preferenceKey,
|
||||
PreferenceFragment fragment, BatteryTipListener batteryTipListener) {
|
||||
SettingsActivity settingsActivity, PreferenceFragment fragment,
|
||||
BatteryTipListener batteryTipListener) {
|
||||
super(context, preferenceKey);
|
||||
mBatteryTipListener = batteryTipListener;
|
||||
mBatteryTipMap = new HashMap<>();
|
||||
mFragment = fragment;
|
||||
mSettingsActivity = settingsActivity;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -107,7 +112,11 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
|
||||
dialogFragment.setTargetFragment(mFragment, REQUEST_ANOMALY_ACTION);
|
||||
dialogFragment.show(mFragment.getFragmentManager(), TAG);
|
||||
} else {
|
||||
batteryTip.action();
|
||||
final BatteryTipAction action = BatteryTipUtils.getActionForBatteryTip(batteryTip,
|
||||
mSettingsActivity, mFragment);
|
||||
if (action != null) {
|
||||
action.handlePositiveAction();
|
||||
}
|
||||
if (mBatteryTipListener != null) {
|
||||
mBatteryTipListener.onBatteryTipHandled(batteryTip);
|
||||
}
|
||||
|
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import android.app.Fragment;
|
||||
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.fuelgauge.batterytip.actions.BatteryTipAction;
|
||||
import com.android.settings.fuelgauge.batterytip.actions.SmartBatteryAction;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
|
||||
/**
|
||||
* Utility class for {@link BatteryTip}
|
||||
*/
|
||||
public class BatteryTipUtils {
|
||||
|
||||
/**
|
||||
* Get a corresponding action based on {@code batteryTip}
|
||||
* @param batteryTip used to detect which action to choose
|
||||
* @param settingsActivity used to populate {@link BatteryTipAction}
|
||||
* @param fragment used to populate {@link BatteryTipAction}
|
||||
* @return an action for {@code batteryTip}
|
||||
*/
|
||||
public static BatteryTipAction getActionForBatteryTip(BatteryTip batteryTip,
|
||||
SettingsActivity settingsActivity, Fragment fragment) {
|
||||
switch (batteryTip.getType()) {
|
||||
case BatteryTip.TipType.SMART_BATTERY_MANAGER:
|
||||
return new SmartBatteryAction(settingsActivity, fragment);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 android.content.Context;
|
||||
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
/**
|
||||
* Abstract class for battery tip action, which is triggered if we need to handle the battery tip
|
||||
*/
|
||||
public abstract class BatteryTipAction {
|
||||
protected Context mContext;
|
||||
|
||||
public BatteryTipAction(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the action when user clicks positive button
|
||||
*/
|
||||
public abstract void handlePositiveAction();
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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 android.app.Fragment;
|
||||
import android.os.UserHandle;
|
||||
import android.support.v14.preference.PreferenceFragment;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settings.fuelgauge.SmartBatterySettings;
|
||||
|
||||
public class SmartBatteryAction extends BatteryTipAction {
|
||||
private SettingsActivity mSettingsActivity;
|
||||
private Fragment mFragment;
|
||||
|
||||
public SmartBatteryAction(SettingsActivity settingsActivity, Fragment fragment) {
|
||||
super(settingsActivity.getApplicationContext());
|
||||
mSettingsActivity = settingsActivity;
|
||||
mFragment = fragment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the action when user clicks positive button
|
||||
*/
|
||||
@Override
|
||||
public void handlePositiveAction() {
|
||||
mSettingsActivity.startPreferencePanelAsUser(mFragment,
|
||||
SmartBatterySettings.class.getName(), null /* args */,
|
||||
R.string.smart_battery_manager_title, null /* titleText */,
|
||||
new UserHandle(UserHandle.myUserId()));
|
||||
}
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.detectors;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.SmartBatteryTip;
|
||||
|
||||
/**
|
||||
* Detect whether to show smart battery tip.
|
||||
*/
|
||||
public class SmartBatteryDetector implements BatteryTipDetector {
|
||||
private BatteryTipPolicy mPolicy;
|
||||
private ContentResolver mContentResolver;
|
||||
|
||||
public SmartBatteryDetector(BatteryTipPolicy policy, ContentResolver contentResolver) {
|
||||
mPolicy = policy;
|
||||
mContentResolver = contentResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BatteryTip detect() {
|
||||
// Show it if there is no other tips shown
|
||||
final boolean smartBatteryOn = Settings.Global.getInt(mContentResolver,
|
||||
Settings.Global.APP_STANDBY_ENABLED, 1) != 0;
|
||||
final int state =
|
||||
smartBatteryOn ? BatteryTip.StateType.INVISIBLE : BatteryTip.StateType.NEW;
|
||||
return new SmartBatteryTip(state);
|
||||
}
|
||||
}
|
@@ -105,11 +105,6 @@ public abstract class BatteryTip implements Comparable<BatteryTip>, Parcelable {
|
||||
*/
|
||||
public abstract void updateState(BatteryTip tip);
|
||||
|
||||
/**
|
||||
* Execute the action for this {@link BatteryTip}
|
||||
*/
|
||||
public abstract void action();
|
||||
|
||||
public Preference buildPreference(Context context) {
|
||||
Preference preference = new Preference(context);
|
||||
|
||||
|
@@ -78,11 +78,6 @@ public class HighUsageTip extends BatteryTip {
|
||||
mState = tip.mState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
public long getScreenTimeMs() {
|
||||
return mScreenTimeMs;
|
||||
}
|
||||
|
@@ -55,11 +55,6 @@ public class LowBatteryTip extends BatteryTip {
|
||||
mState = tip.mState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
|
||||
public BatteryTip createFromParcel(Parcel in) {
|
||||
return new LowBatteryTip(in);
|
||||
|
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.tips;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
/**
|
||||
* Tip to suggest turn on smart battery if it is not on
|
||||
*/
|
||||
public class SmartBatteryTip extends BatteryTip {
|
||||
|
||||
public SmartBatteryTip(@StateType int state) {
|
||||
super(TipType.SMART_BATTERY_MANAGER, state, false /* showDialog */);
|
||||
}
|
||||
|
||||
private SmartBatteryTip(Parcel in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle(Context context) {
|
||||
return context.getString(R.string.battery_tip_smart_battery_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary(Context context) {
|
||||
return context.getString(R.string.battery_tip_smart_battery_summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconId() {
|
||||
return R.drawable.ic_perm_device_information_red_24dp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(BatteryTip tip) {
|
||||
mState = tip.mState;
|
||||
}
|
||||
|
||||
public static final Creator CREATOR = new Creator() {
|
||||
public BatteryTip createFromParcel(Parcel in) {
|
||||
return new SmartBatteryTip(in);
|
||||
}
|
||||
|
||||
public BatteryTip[] newArray(int size) {
|
||||
return new SmartBatteryTip[size];
|
||||
}
|
||||
};
|
||||
|
||||
}
|
@@ -55,11 +55,6 @@ public class SummaryTip extends BatteryTip {
|
||||
mState = tip.mState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
|
||||
public BatteryTip createFromParcel(Parcel in) {
|
||||
return new SummaryTip(in);
|
||||
|
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package com.android.settings.fuelgauge.batterytip;
|
||||
|
||||
import static com.android.settings.fuelgauge.batterytip.tips.BatteryTip.TipType
|
||||
.SMART_BATTERY_MANAGER;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
@@ -29,6 +32,7 @@ import android.support.v7.preference.PreferenceGroup;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
|
||||
import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
|
||||
@@ -57,6 +61,8 @@ public class BatteryTipPreferenceControllerTest {
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
@Mock
|
||||
private BatteryTip mBatteryTip;
|
||||
@Mock
|
||||
private SettingsActivity mSettingsActivity;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private PreferenceManager mPreferenceManager;
|
||||
|
||||
@@ -85,7 +91,7 @@ public class BatteryTipPreferenceControllerTest {
|
||||
mNewBatteryTips.add(new SummaryTip(BatteryTip.StateType.INVISIBLE));
|
||||
|
||||
mBatteryTipPreferenceController = new BatteryTipPreferenceController(mContext, KEY_PREF,
|
||||
null, mBatteryTipListener);
|
||||
mSettingsActivity, null, mBatteryTipListener);
|
||||
mBatteryTipPreferenceController.mPreferenceGroup = mPreferenceGroup;
|
||||
mBatteryTipPreferenceController.mPrefContext = mContext;
|
||||
}
|
||||
@@ -109,7 +115,8 @@ public class BatteryTipPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePreferenceTreeClick_noDialog_invokeAction() {
|
||||
public void testHandlePreferenceTreeClick_noDialog_invokeCallback() {
|
||||
doReturn(SMART_BATTERY_MANAGER).when(mBatteryTip).getType();
|
||||
List<BatteryTip> batteryTips = new ArrayList<>();
|
||||
batteryTips.add(mBatteryTip);
|
||||
doReturn(mPreference).when(mBatteryTip).buildPreference(any());
|
||||
@@ -119,7 +126,7 @@ public class BatteryTipPreferenceControllerTest {
|
||||
|
||||
mBatteryTipPreferenceController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
verify(mBatteryTip).action();
|
||||
verify(mBatteryTipListener).onBatteryTipHandled(mBatteryTip);
|
||||
}
|
||||
|
||||
private void assertOnlyContainsSummaryTip(final PreferenceGroup preferenceGroup) {
|
||||
|
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.detectors;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class SmartBatteryDetectorTest {
|
||||
private Context mContext;
|
||||
private BatteryTipPolicy mPolicy;
|
||||
private SmartBatteryDetector mSmartBatteryDetector;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mPolicy = spy(new BatteryTipPolicy(mContext));
|
||||
mSmartBatteryDetector = new SmartBatteryDetector(mPolicy, mContext.getContentResolver());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetect_smartBatteryOff_tipVisible() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.APP_STANDBY_ENABLED, 0);
|
||||
|
||||
assertThat(mSmartBatteryDetector.detect().isVisible()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetect_smartBatteryOn_tipInvisible() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.APP_STANDBY_ENABLED, 1);
|
||||
|
||||
assertThat(mSmartBatteryDetector.detect().isVisible()).isFalse();
|
||||
}
|
||||
}
|
@@ -107,11 +107,6 @@ public class BatteryTipTest {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void action() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
public final Parcelable.Creator CREATOR = new Parcelable.Creator() {
|
||||
public BatteryTip createFromParcel(Parcel in) {
|
||||
return new TestBatteryTip(in);
|
||||
|
Reference in New Issue
Block a user