Update related UI if battery is not present

This change is to update the related UI in the battery page if the
battery is not present. This includes the following updates:
1. Update the summary of battery tile in the Settings homepage
2. Replace the battery level with "Unknown"
3. Replace the summary with help message in the battery page
4. Remove the battery meter icon

Bug: 171368508
Test: verify on an issue device
Change-Id: I892e0d137143160a0bce0c11ce9265120ebb8fd4
This commit is contained in:
Mill Chen
2020-10-21 16:32:56 +08:00
parent d682b2cc57
commit ad99e2ef38
15 changed files with 182 additions and 15 deletions

View File

@@ -18,18 +18,25 @@ package com.android.settings.display;
import static android.provider.Settings.System.SHOW_BATTERY_PERCENT;
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.provider.Settings;
import com.android.settings.testutils.shadow.ShadowUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowUtils.class)
public class BatteryPercentagePreferenceControllerTest {
private static final String PREF_KEY = "battery_percentage";
@@ -43,6 +50,11 @@ public class BatteryPercentagePreferenceControllerTest {
mController = new BatteryPercentagePreferenceController(mContext, PREF_KEY);
}
@After
public void tearDown() {
ShadowUtils.reset();
}
private int getPercentageSetting() {
return Settings.System.getInt(mContext.getContentResolver(), SHOW_BATTERY_PERCENT, 0);
}
@@ -60,4 +72,11 @@ public class BatteryPercentagePreferenceControllerTest {
final int isOn = getPercentageSetting();
assertThat(isOn).isEqualTo(0);
}
@Test
public void getAvailabilityStatus_batteryNotPresent_shouldReturnConditionallyUnavailable() {
ShadowUtils.setIsBatteryPresent(false);
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
}
}