Add isBatteryManagerSupported() to control adaptive preferences page

Add isBatteryManagerSupported() in the PowerUsageFeatureProvider to
support controlling the adaptive preferences page dynamically

Bug: 229558366
Test: presubmit
Change-Id: Iffb552feb9e08ca72f2970eb778cd3fcd18f0b7e
This commit is contained in:
ykhung
2022-12-27 14:34:12 +08:00
parent fec083b2cd
commit b875752307
5 changed files with 34 additions and 46 deletions

View File

@@ -105,16 +105,6 @@ public class PowerUsageFeatureProviderImplTest {
assertThat(mPowerFeatureProvider.isTypeSystem(UID_OTHER, null)).isFalse();
}
@Test
public void testIsAdvancedUiEnabled_returnTrue() {
assertThat(mPowerFeatureProvider.isAdvancedUiEnabled()).isTrue();
}
@Test
public void testIsPowerAccountingToggleEnabled_returnTrue() {
assertThat(mPowerFeatureProvider.isPowerAccountingToggleEnabled()).isTrue();
}
@Test
public void testIsSmartBatterySupported_smartBatterySupported_returnTrue() {
when(mContext.getResources().getBoolean(

View File

@@ -26,6 +26,7 @@ import android.provider.Settings;
import androidx.preference.Preference;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.testutils.FakeFeatureFactory;
import org.junit.Before;
@@ -48,6 +49,7 @@ public class BatteryManagerPreferenceControllerTest {
private Context mContext;
private Preference mPreference;
private FakeFeatureFactory mFeatureFactory;
private PowerUsageFeatureProvider mPowerUsageFeatureProvider;
private BatteryManagerPreferenceController mController;
@@ -60,6 +62,7 @@ public class BatteryManagerPreferenceControllerTest {
mFeatureFactory = FakeFeatureFactory.setupForTest();
mPreference = new Preference(mContext);
mController = new BatteryManagerPreferenceController(mContext);
mPowerUsageFeatureProvider = mFeatureFactory.powerUsageFeatureProvider;
}
@Test
@@ -71,7 +74,7 @@ public class BatteryManagerPreferenceControllerTest {
@Test
public void updateState_smartBatteryWithoutRestriction_showSummary() {
when(mFeatureFactory.powerUsageFeatureProvider.isSmartBatterySupported()).thenReturn(true);
when(mPowerUsageFeatureProvider.isSmartBatterySupported()).thenReturn(true);
Settings.Global.putInt(mContext.getContentResolver(),
Settings.Global.ADAPTIVE_BATTERY_MANAGEMENT_ENABLED, ON);
@@ -79,4 +82,20 @@ public class BatteryManagerPreferenceControllerTest {
assertThat(mPreference.getSummary()).isEqualTo("Detecting when apps drain battery");
}
@Test
public void getAvailabilityStatus_supportBatteryManager_showPrefPage() {
when(mPowerUsageFeatureProvider.isBatteryManagerSupported()).thenReturn(true);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BatteryManagerPreferenceController.AVAILABLE_UNSEARCHABLE);
}
@Test
public void getAvailabilityStatus_notSupportBatteryManager_notShowPrefPage() {
when(mPowerUsageFeatureProvider.isBatteryManagerSupported()).thenReturn(false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(
BatteryManagerPreferenceController.UNSUPPORTED_ON_DEVICE);
}
}