Add auto restriction preference
1. Add method in feature provider to check whether smart battery
is supported
2. Hook up above method to controllers
3. Add auto restriction preference
4. Add tests
Bug: 73002171
Test: RunSettingsRoboTests
Change-Id: Ic314f61ad52e9bedb629b308731cb968bb4b1773
Merged-In: Ic314f61ad52e9bedb629b308731cb968bb4b1773
(cherry picked from commit ab0b0add0a
)
This commit is contained in:
@@ -18,10 +18,16 @@ package com.android.settings.fuelgauge;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -38,11 +44,15 @@ public class SmartBatteryPreferenceControllerTest {
|
||||
private SmartBatteryPreferenceController mController;
|
||||
private SwitchPreference mPreference;
|
||||
private ContentResolver mContentResolver;
|
||||
private Context mContext;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
mContentResolver = RuntimeEnvironment.application.getContentResolver();
|
||||
mController = new SmartBatteryPreferenceController(RuntimeEnvironment.application);
|
||||
mPreference = new SwitchPreference(RuntimeEnvironment.application);
|
||||
@@ -80,6 +90,22 @@ public class SmartBatteryPreferenceControllerTest {
|
||||
assertThat(getSmartBatteryValue()).isEqualTo(OFF);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAvailabilityStatus_smartBatterySupported_returnAvailable() {
|
||||
doReturn(true).when(mFeatureFactory.powerUsageFeatureProvider).isSmartBatterySupported();
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAvailabilityStatus_smartBatteryUnSupported_returnDisabled() {
|
||||
doReturn(false).when(mFeatureFactory.powerUsageFeatureProvider).isSmartBatterySupported();
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.DISABLED_UNSUPPORTED);
|
||||
}
|
||||
|
||||
private void putSmartBatteryValue(int value) {
|
||||
Settings.Global.putInt(mContentResolver, Settings.Global.APP_STANDBY_ENABLED, value);
|
||||
}
|
||||
|
Reference in New Issue
Block a user