Merge "Config battery info page(1/2)" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
4cc92858f4
@@ -151,7 +151,8 @@
|
|||||||
android:order="43"
|
android:order="43"
|
||||||
android:title="@string/battery_info"
|
android:title="@string/battery_info"
|
||||||
android:fragment="com.android.settings.deviceinfo.batteryinfo.BatteryInfoFragment"
|
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>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
|
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
@@ -26,4 +26,7 @@ public interface BatterySettingsFeatureProvider {
|
|||||||
|
|
||||||
/** Returns true if first use date should be shown */
|
/** Returns true if first use date should be shown */
|
||||||
boolean isFirstUseDateAvailable(Context context, long firstUseDateMs);
|
boolean isFirstUseDateAvailable(Context context, long firstUseDateMs);
|
||||||
|
|
||||||
|
/** Check whether the battery information page is enabled in the About phone page */
|
||||||
|
boolean isBatteryInfoEnabled(Context context);
|
||||||
}
|
}
|
||||||
|
@@ -30,4 +30,9 @@ public class BatterySettingsFeatureProviderImpl implements BatterySettingsFeatur
|
|||||||
public boolean isFirstUseDateAvailable(Context context, long firstUseDateMs) {
|
public boolean isFirstUseDateAvailable(Context context, long firstUseDateMs) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isBatteryInfoEnabled(Context context) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
}
|
@@ -47,4 +47,9 @@ public class BatterySettingsFeatureProviderImplTest {
|
|||||||
public void isFirstUseDateAvailable_returnFalse() {
|
public void isFirstUseDateAvailable_returnFalse() {
|
||||||
assertThat(mImpl.isFirstUseDateAvailable(mContext, 1000L)).isFalse();
|
assertThat(mImpl.isFirstUseDateAvailable(mContext, 1000L)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isBatteryInfoEnabled_returnFalse() {
|
||||||
|
assertThat(mImpl.isBatteryInfoEnabled(mContext)).isFalse();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user