Merge "Update related UI if battery is not present" into rvc-qpr-dev am: 03f15baeef
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/12999576 Change-Id: I974e064265986265d0984e8c6e4b4db4314bbdf4
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -90,6 +90,19 @@ public class BatteryBroadcastReceiverTest {
|
||||
verify(mBatteryListener).onBatteryChanged(BatteryUpdateType.BATTERY_LEVEL);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {
|
||||
BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,
|
||||
BatteryFixSliceTest.ShadowBatteryTipLoader.class
|
||||
})
|
||||
public void onReceive_batteryNotPresent_shouldShowHelpMessage() {
|
||||
mChargingIntent.putExtra(BatteryManager.EXTRA_PRESENT, false);
|
||||
|
||||
mBatteryBroadcastReceiver.onReceive(mContext, mChargingIntent);
|
||||
|
||||
verify(mBatteryListener).onBatteryChanged(BatteryUpdateType.BATTERY_NOT_PRESENT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {
|
||||
BatteryFixSliceTest.ShadowBatteryStatsHelperLoader.class,
|
||||
|
@@ -44,6 +44,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;
|
||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||
import com.android.settings.widget.EntityHeaderController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
@@ -61,7 +62,7 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowPowerManager;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowEntityHeaderController.class)
|
||||
@Config(shadows = {ShadowEntityHeaderController.class, ShadowUtils.class})
|
||||
public class BatteryHeaderPreferenceControllerTest {
|
||||
|
||||
private static final String PREF_KEY = "battery_header";
|
||||
@@ -116,7 +117,7 @@ public class BatteryHeaderPreferenceControllerTest {
|
||||
|
||||
mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
|
||||
|
||||
mController = new BatteryHeaderPreferenceController(mContext, PREF_KEY);
|
||||
mController = spy(new BatteryHeaderPreferenceController(mContext, PREF_KEY));
|
||||
mLifecycle.addObserver(mController);
|
||||
mController.setActivity(mActivity);
|
||||
mController.setFragment(mPreferenceFragment);
|
||||
@@ -129,6 +130,7 @@ public class BatteryHeaderPreferenceControllerTest {
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowEntityHeaderController.reset();
|
||||
ShadowUtils.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -214,4 +216,13 @@ public class BatteryHeaderPreferenceControllerTest {
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE_UNSEARCHABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_batteryNotPresent_shouldShowHelpMessage() {
|
||||
ShadowUtils.setIsBatteryPresent(false);
|
||||
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
|
||||
verify(mController).showHelpMessage();
|
||||
}
|
||||
}
|
||||
|
@@ -45,7 +45,6 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.loader.app.LoaderManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
@@ -56,6 +55,7 @@ import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.XmlTestUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowUtils;
|
||||
import com.android.settingslib.core.instrumentation.VisibilityLoggerMixin;
|
||||
import com.android.settingslib.widget.LayoutPreference;
|
||||
|
||||
@@ -72,6 +72,7 @@ import org.mockito.stubbing.Answer;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -224,6 +225,7 @@ public class PowerUsageSummaryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowUtils.class)
|
||||
public void nonIndexableKeys_MatchPreferenceKeys() {
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
final List<String> niks =
|
||||
|
@@ -24,6 +24,8 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -66,4 +68,12 @@ public class TopLevelBatteryPreferenceControllerTest {
|
||||
info.chargeLabel = "5% - charging";
|
||||
assertThat(getDashboardLabel(mContext, info)).isEqualTo("5% - charging");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_batteryNotPresent_shouldShowWarningMessage() {
|
||||
mController.mIsBatteryPresent = false;
|
||||
|
||||
assertThat(mController.getSummary())
|
||||
.isEqualTo(mContext.getString(R.string.battery_missing_message));
|
||||
}
|
||||
}
|
||||
|
@@ -46,6 +46,7 @@ public class ShadowUtils {
|
||||
private static boolean sIsSystemAlertWindowEnabled;
|
||||
private static boolean sIsVoiceCapable;
|
||||
private static ArraySet<String> sResultLinks = new ArraySet<>();
|
||||
private static boolean sIsBatteryPresent;
|
||||
|
||||
@Implementation
|
||||
protected static int enforceSameOwner(Context context, int userId) {
|
||||
@@ -67,6 +68,7 @@ public class ShadowUtils {
|
||||
sIsDemoUser = false;
|
||||
sIsVoiceCapable = false;
|
||||
sResultLinks = new ArraySet<>();
|
||||
sIsBatteryPresent = true;
|
||||
}
|
||||
|
||||
public static void setIsDemoUser(boolean isDemoUser) {
|
||||
@@ -155,4 +157,13 @@ public class ShadowUtils {
|
||||
public static void setHandledDomains(ArraySet<String> links) {
|
||||
sResultLinks = links;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
protected static boolean isBatteryPresent(Context context) {
|
||||
return sIsBatteryPresent;
|
||||
}
|
||||
|
||||
public static void setIsBatteryPresent(boolean isBatteryPresent) {
|
||||
sIsBatteryPresent = isBatteryPresent;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user