Loading res/xml/my_device_info.xml +2 −1 Original line number Diff line number Diff line Loading @@ -151,7 +151,8 @@ android:order="43" android:title="@string/battery_info" android:fragment="com.android.settings.deviceinfo.batteryinfo.BatteryInfoFragment" settings:keywords="@string/keywords_battery_info"/> settings:keywords="@string/keywords_battery_info" settings:controller="com.android.settings.deviceinfo.batteryinfo.BatteryInfoPreferenceController"/> </PreferenceCategory> <PreferenceCategory Loading src/com/android/settings/deviceinfo/batteryinfo/BatteryInfoPreferenceController.java 0 → 100644 +41 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.deviceinfo.batteryinfo; import android.content.Context; import com.android.settings.core.BasePreferenceController; import com.android.settings.fuelgauge.BatterySettingsFeatureProvider; import com.android.settings.overlay.FeatureFactory; /** Controller to enter battery information page. */ public class BatteryInfoPreferenceController extends BasePreferenceController { private final BatterySettingsFeatureProvider mBatterySettingsFeatureProvider; public BatteryInfoPreferenceController(Context context, String key) { super(context, key); mBatterySettingsFeatureProvider = FeatureFactory.getFeatureFactory() .getBatterySettingsFeatureProvider(); } @Override public int getAvailabilityStatus() { return mBatterySettingsFeatureProvider.isBatteryInfoEnabled(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } } src/com/android/settings/fuelgauge/BatterySettingsFeatureProvider.java +3 −0 Original line number Diff line number Diff line Loading @@ -26,4 +26,7 @@ public interface BatterySettingsFeatureProvider { /** Returns true if first use date should be shown */ boolean isFirstUseDateAvailable(Context context, long firstUseDateMs); /** Check whether the battery information page is enabled in the About phone page */ boolean isBatteryInfoEnabled(Context context); } src/com/android/settings/fuelgauge/BatterySettingsFeatureProviderImpl.java +5 −0 Original line number Diff line number Diff line Loading @@ -30,4 +30,9 @@ public class BatterySettingsFeatureProviderImpl implements BatterySettingsFeatur public boolean isFirstUseDateAvailable(Context context, long firstUseDateMs) { return false; } @Override public boolean isBatteryInfoEnabled(Context context) { return false; } } tests/robotests/src/com/android/settings/deviceinfo/batteryinfo/BatteryInfoPreferenceControllerTest.java 0 → 100644 +65 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.deviceinfo.batteryinfo; import static com.android.settings.core.BasePreferenceController.AVAILABLE; import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.when; import android.content.Context; import androidx.test.core.app.ApplicationProvider; import com.android.settings.fuelgauge.BatterySettingsFeatureProvider; import com.android.settings.testutils.FakeFeatureFactory; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; @RunWith(RobolectricTestRunner.class) public class BatteryInfoPreferenceControllerTest { private Context mContext; private BatteryInfoPreferenceController mController; private BatterySettingsFeatureProvider mBatterySettingsFeatureProvider; @Before public void setUp() { mContext = ApplicationProvider.getApplicationContext(); mBatterySettingsFeatureProvider = FakeFeatureFactory.setupForTest().batterySettingsFeatureProvider; mController = new BatteryInfoPreferenceController(mContext, /* key= */"battery_info"); } @Test public void getAvailabilityStatus_dateUnavailable_returnNotAvailable() { when(mBatterySettingsFeatureProvider.isBatteryInfoEnabled(mContext)).thenReturn(false); assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); } @Test public void getAvailabilityStatus_dateAvailable_returnAvailable() { when(mBatterySettingsFeatureProvider.isBatteryInfoEnabled(mContext)).thenReturn(true); assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); } } Loading
res/xml/my_device_info.xml +2 −1 Original line number Diff line number Diff line Loading @@ -151,7 +151,8 @@ android:order="43" android:title="@string/battery_info" android:fragment="com.android.settings.deviceinfo.batteryinfo.BatteryInfoFragment" settings:keywords="@string/keywords_battery_info"/> settings:keywords="@string/keywords_battery_info" settings:controller="com.android.settings.deviceinfo.batteryinfo.BatteryInfoPreferenceController"/> </PreferenceCategory> <PreferenceCategory Loading
src/com/android/settings/deviceinfo/batteryinfo/BatteryInfoPreferenceController.java 0 → 100644 +41 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.deviceinfo.batteryinfo; import android.content.Context; import com.android.settings.core.BasePreferenceController; import com.android.settings.fuelgauge.BatterySettingsFeatureProvider; import com.android.settings.overlay.FeatureFactory; /** Controller to enter battery information page. */ public class BatteryInfoPreferenceController extends BasePreferenceController { private final BatterySettingsFeatureProvider mBatterySettingsFeatureProvider; public BatteryInfoPreferenceController(Context context, String key) { super(context, key); mBatterySettingsFeatureProvider = FeatureFactory.getFeatureFactory() .getBatterySettingsFeatureProvider(); } @Override public int getAvailabilityStatus() { return mBatterySettingsFeatureProvider.isBatteryInfoEnabled(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } }
src/com/android/settings/fuelgauge/BatterySettingsFeatureProvider.java +3 −0 Original line number Diff line number Diff line Loading @@ -26,4 +26,7 @@ public interface BatterySettingsFeatureProvider { /** Returns true if first use date should be shown */ boolean isFirstUseDateAvailable(Context context, long firstUseDateMs); /** Check whether the battery information page is enabled in the About phone page */ boolean isBatteryInfoEnabled(Context context); }
src/com/android/settings/fuelgauge/BatterySettingsFeatureProviderImpl.java +5 −0 Original line number Diff line number Diff line Loading @@ -30,4 +30,9 @@ public class BatterySettingsFeatureProviderImpl implements BatterySettingsFeatur public boolean isFirstUseDateAvailable(Context context, long firstUseDateMs) { return false; } @Override public boolean isBatteryInfoEnabled(Context context) { return false; } }
tests/robotests/src/com/android/settings/deviceinfo/batteryinfo/BatteryInfoPreferenceControllerTest.java 0 → 100644 +65 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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.deviceinfo.batteryinfo; import static com.android.settings.core.BasePreferenceController.AVAILABLE; import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.when; import android.content.Context; import androidx.test.core.app.ApplicationProvider; import com.android.settings.fuelgauge.BatterySettingsFeatureProvider; import com.android.settings.testutils.FakeFeatureFactory; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; @RunWith(RobolectricTestRunner.class) public class BatteryInfoPreferenceControllerTest { private Context mContext; private BatteryInfoPreferenceController mController; private BatterySettingsFeatureProvider mBatterySettingsFeatureProvider; @Before public void setUp() { mContext = ApplicationProvider.getApplicationContext(); mBatterySettingsFeatureProvider = FakeFeatureFactory.setupForTest().batterySettingsFeatureProvider; mController = new BatteryInfoPreferenceController(mContext, /* key= */"battery_info"); } @Test public void getAvailabilityStatus_dateUnavailable_returnNotAvailable() { when(mBatterySettingsFeatureProvider.isBatteryInfoEnabled(mContext)).thenReturn(false); assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE); } @Test public void getAvailabilityStatus_dateAvailable_returnAvailable() { when(mBatterySettingsFeatureProvider.isBatteryInfoEnabled(mContext)).thenReturn(true); assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); } }