Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e784c520 authored by YK Hung's avatar YK Hung Committed by Automerger Merge Worker
Browse files

Merge "Add a new config for checking BatteryManager show/hide rule" into udc-dev am: edb03e55

parents ad26c287 edb03e55
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -553,7 +553,7 @@
    <!-- Cell broacast receiver package name -->
    <string name="config_cell_broadcast_receiver_package" translatable="false">com.android.cellbroadcastreceiver.module</string>

    <!-- TODO(b/174964885): These media Uri are not defined in framework yet. Replace with framework defined variables once it's available. -->
    <!-- These media Uri are not defined in framework yet. Replace with framework defined variables once it's available. -->
    <!-- Media Uri to view images storage category. -->
    <string name="config_images_storage_category_uri" translatable="false">content://com.android.providers.media.documents/root/images_root</string>

@@ -695,4 +695,7 @@

    <!-- Whether auto data switching on secondary SIM enables cross-SIM calling on both SIMs. -->
    <bool name="config_auto_data_switch_enables_cross_sim_calling">false</bool>

    <!-- Whether checking adaptive charging to define battery manager visibility. -->
    <bool name="config_battery_manager_consider_ac">false</bool>
</resources>
+7 −2
Original line number Diff line number Diff line
@@ -50,8 +50,13 @@ public class BatteryManagerPreferenceController extends BasePreferenceController

    @Override
    public int getAvailabilityStatus() {
        return mPowerUsageFeatureProvider.isBatteryManagerSupported()
                    && mPowerUsageFeatureProvider.isAdaptiveChargingSupported()
        if (!mPowerUsageFeatureProvider.isBatteryManagerSupported()) {
            return UNSUPPORTED_ON_DEVICE;
        }
        if (!mContext.getResources().getBoolean(R.bool.config_battery_manager_consider_ac)) {
            return AVAILABLE_UNSEARCHABLE;
        }
        return mPowerUsageFeatureProvider.isAdaptiveChargingSupported()
                ? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
    }

+0 −9
Original line number Diff line number Diff line
@@ -85,15 +85,6 @@ public class BatterySaverButtonPreferenceControllerTest {
        assertThat(mPreference.isChecked()).isFalse();
    }

    @Test
    public void onSwitchChanged_isCheckedAndAcked_setPowerSaveMode() {
        setLowPowerWarningAcked(/* acked= */ 1);

        mController.onSwitchChanged(/* switchView= */ null, /* isChecked= */ true);

        verify(mPowerManager).setPowerSaveModeEnabled(true);
    }

    @Test
    public void updateState_lowPowerOn_preferenceIsChecked() {
        when(mPowerManager.isPowerSaveMode()).thenReturn(true);
+19 −0
Original line number Diff line number Diff line
@@ -26,8 +26,10 @@ import android.provider.Settings;

import androidx.preference.Preference;

import com.android.settings.R;
import com.android.settings.fuelgauge.PowerUsageFeatureProvider;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.SettingsShadowResources;

import org.junit.Before;
import org.junit.Test;
@@ -36,8 +38,10 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

@RunWith(RobolectricTestRunner.class)
@Config(shadows = SettingsShadowResources.class)
public class BatteryManagerPreferenceControllerTest {
    private static final int ON = 1;
    private static final int OFF = 0;
@@ -85,6 +89,8 @@ public class BatteryManagerPreferenceControllerTest {

    @Test
    public void getAvailabilityStatus_supportBatteryManager_showPrefPage() {
        SettingsShadowResources.overrideResource(
                R.bool.config_battery_manager_consider_ac, true);
        when(mPowerUsageFeatureProvider.isBatteryManagerSupported()).thenReturn(true);
        when(mPowerUsageFeatureProvider.isAdaptiveChargingSupported()).thenReturn(true);

@@ -102,10 +108,23 @@ public class BatteryManagerPreferenceControllerTest {

    @Test
    public void getAvailabilityStatus_supportBatteryManagerWithoutAC_notShowPrefPage() {
        SettingsShadowResources.overrideResource(
                R.bool.config_battery_manager_consider_ac, true);
        when(mPowerUsageFeatureProvider.isBatteryManagerSupported()).thenReturn(true);
        when(mPowerUsageFeatureProvider.isAdaptiveChargingSupported()).thenReturn(false);

        assertThat(mController.getAvailabilityStatus()).isEqualTo(
                BatteryManagerPreferenceController.UNSUPPORTED_ON_DEVICE);
    }

    @Test
    public void getAvailabilityStatus_ignoreBatteryManagerWithoutAC_showPrefPage() {
        SettingsShadowResources.overrideResource(
                R.bool.config_battery_manager_consider_ac, false);
        when(mPowerUsageFeatureProvider.isBatteryManagerSupported()).thenReturn(true);
        when(mPowerUsageFeatureProvider.isAdaptiveChargingSupported()).thenReturn(false);

        assertThat(mController.getAvailabilityStatus()).isEqualTo(
                BatteryManagerPreferenceController.AVAILABLE_UNSEARCHABLE);
    }
}