Change the order of battery tips
Bug: 72492206 Test: RunSettingsRoboTests Change-Id: I27b2d5c27fbac2259d9ee483b755ac799dd0de68
This commit is contained in:
@@ -21,7 +21,9 @@ import android.os.Parcel;
|
|||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.support.annotation.IdRes;
|
import android.support.annotation.IdRes;
|
||||||
import android.support.annotation.IntDef;
|
import android.support.annotation.IntDef;
|
||||||
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.util.SparseIntArray;
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
@@ -63,6 +65,20 @@ public abstract class BatteryTip implements Comparable<BatteryTip>, Parcelable {
|
|||||||
int REMOVE_APP_RESTRICTION = 7;
|
int REMOVE_APP_RESTRICTION = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
static final SparseIntArray TIP_ORDER;
|
||||||
|
static {
|
||||||
|
TIP_ORDER = new SparseIntArray();
|
||||||
|
TIP_ORDER.append(TipType.APP_RESTRICTION, 0);
|
||||||
|
TIP_ORDER.append(TipType.BATTERY_SAVER, 1);
|
||||||
|
TIP_ORDER.append(TipType.HIGH_DEVICE_USAGE, 2);
|
||||||
|
TIP_ORDER.append(TipType.SUMMARY, 3);
|
||||||
|
TIP_ORDER.append(TipType.SMART_BATTERY_MANAGER, 4);
|
||||||
|
TIP_ORDER.append(TipType.REDUCED_BATTERY, 5);
|
||||||
|
TIP_ORDER.append(TipType.LOW_BATTERY, 6);
|
||||||
|
TIP_ORDER.append(TipType.REMOVE_APP_RESTRICTION, 7);
|
||||||
|
}
|
||||||
|
|
||||||
private static final String KEY_PREFIX = "key_battery_tip";
|
private static final String KEY_PREFIX = "key_battery_tip";
|
||||||
|
|
||||||
protected int mType;
|
protected int mType;
|
||||||
@@ -140,6 +156,6 @@ public abstract class BatteryTip implements Comparable<BatteryTip>, Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(BatteryTip o) {
|
public int compareTo(BatteryTip o) {
|
||||||
return mType - o.mType;
|
return TIP_ORDER.get(mType) - TIP_ORDER.get(o.mType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -50,12 +50,12 @@ import java.util.List;
|
|||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public class BatteryTipLoaderTest {
|
public class BatteryTipLoaderTest {
|
||||||
private static final int[] TIP_ORDER = {
|
private static final int[] TIP_ORDER = {
|
||||||
BatteryTip.TipType.SMART_BATTERY_MANAGER,
|
|
||||||
BatteryTip.TipType.APP_RESTRICTION,
|
BatteryTip.TipType.APP_RESTRICTION,
|
||||||
BatteryTip.TipType.HIGH_DEVICE_USAGE,
|
|
||||||
BatteryTip.TipType.BATTERY_SAVER,
|
BatteryTip.TipType.BATTERY_SAVER,
|
||||||
BatteryTip.TipType.LOW_BATTERY,
|
BatteryTip.TipType.HIGH_DEVICE_USAGE,
|
||||||
BatteryTip.TipType.SUMMARY};
|
BatteryTip.TipType.SUMMARY,
|
||||||
|
BatteryTip.TipType.SMART_BATTERY_MANAGER,
|
||||||
|
BatteryTip.TipType.LOW_BATTERY};
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
private BatteryStatsHelper mBatteryStatsHelper;
|
private BatteryStatsHelper mBatteryStatsHelper;
|
||||||
@Mock
|
@Mock
|
||||||
|
@@ -34,6 +34,9 @@ import org.junit.runner.RunWith;
|
|||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public class BatteryTipTest {
|
public class BatteryTipTest {
|
||||||
@@ -75,6 +78,16 @@ public class BatteryTipTest {
|
|||||||
assertThat(parcelTip.getIconId()).isEqualTo(ICON_ID);
|
assertThat(parcelTip.getIconId()).isEqualTo(ICON_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTipOrder_orderUnique() {
|
||||||
|
final List<Integer> orders = new ArrayList<>();
|
||||||
|
for (int i = 0, size = BatteryTip.TIP_ORDER.size(); i < size; i++) {
|
||||||
|
orders.add(BatteryTip.TIP_ORDER.valueAt(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
assertThat(orders).containsNoDuplicates();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to test the non abstract methods in {@link TestBatteryTip}
|
* Used to test the non abstract methods in {@link TestBatteryTip}
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user