Update power_anomaly_event proto fields
- add enum PowerAnomalyType/PowerAnomalyKey - update the func to get anomaly index Test: manual Bug: 291689623 Change-Id: If4e6684c8169dfa3edd4e18a11d518737a3b2840 Merged-In: If4e6684c8169dfa3edd4e18a11d518737a3b2840
This commit is contained in:
@@ -36,8 +36,6 @@ public class BatteryTipsController extends BasePreferenceController {
|
||||
private static final String ROOT_PREFERENCE_KEY = "battery_tips_category";
|
||||
private static final String CARD_PREFERENCE_KEY = "battery_tips_card";
|
||||
|
||||
private final String[] mPowerAnomalyKeys;
|
||||
|
||||
@VisibleForTesting
|
||||
BatteryTipsCardPreference mCardPreference;
|
||||
@VisibleForTesting
|
||||
@@ -47,7 +45,6 @@ public class BatteryTipsController extends BasePreferenceController {
|
||||
super(context, ROOT_PREFERENCE_KEY);
|
||||
mPowerUsageFeatureProvider = FeatureFactory.getFactory(context)
|
||||
.getPowerUsageFeatureProvider(context);
|
||||
mPowerAnomalyKeys = context.getResources().getStringArray(R.array.power_anomaly_keys);
|
||||
}
|
||||
|
||||
private boolean isTipsCardVisible() {
|
||||
@@ -66,16 +63,6 @@ public class BatteryTipsController extends BasePreferenceController {
|
||||
mCardPreference = screen.findPreference(CARD_PREFERENCE_KEY);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
int getPowerAnomalyEventIndex(String powerAnomalyKey) {
|
||||
for (int index = 0; index < mPowerAnomalyKeys.length; index++) {
|
||||
if (mPowerAnomalyKeys[index].equals(powerAnomalyKey)) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private <T> T getInfo(PowerAnomalyEvent powerAnomalyEvent,
|
||||
Function<WarningBannerInfo, T> warningBannerInfoSupplier,
|
||||
Function<WarningItemInfo, T> warningItemInfoSupplier) {
|
||||
@@ -98,8 +85,9 @@ public class BatteryTipsController extends BasePreferenceController {
|
||||
return string;
|
||||
}
|
||||
|
||||
if (resourceIndex >= 0) {
|
||||
string = mContext.getResources().getStringArray(resourceId)[resourceIndex];
|
||||
String[] stringArray = mContext.getResources().getStringArray(resourceId);
|
||||
if (resourceIndex >= 0 && resourceIndex < stringArray.length) {
|
||||
string = stringArray[resourceIndex];
|
||||
}
|
||||
|
||||
return string;
|
||||
@@ -117,10 +105,11 @@ public class BatteryTipsController extends BasePreferenceController {
|
||||
}
|
||||
|
||||
// Get card preference strings and navigate fragment info
|
||||
final int index = getPowerAnomalyEventIndex(powerAnomalyEvent.getKey());
|
||||
final int resourceIndex = powerAnomalyEvent.hasKey()
|
||||
? powerAnomalyEvent.getKey().getNumber() : -1;
|
||||
|
||||
String titleString = getString(powerAnomalyEvent, WarningBannerInfo::getTitleString,
|
||||
WarningItemInfo::getTitleString, R.array.power_anomaly_titles, index);
|
||||
WarningItemInfo::getTitleString, R.array.power_anomaly_titles, resourceIndex);
|
||||
if (titleString.isEmpty()) {
|
||||
mCardPreference.setVisible(false);
|
||||
return;
|
||||
@@ -128,10 +117,10 @@ public class BatteryTipsController extends BasePreferenceController {
|
||||
|
||||
String mainBtnString = getString(powerAnomalyEvent,
|
||||
WarningBannerInfo::getMainButtonString, WarningItemInfo::getMainButtonString,
|
||||
R.array.power_anomaly_main_btn_strings, index);
|
||||
R.array.power_anomaly_main_btn_strings, resourceIndex);
|
||||
String dismissBtnString = getString(powerAnomalyEvent,
|
||||
WarningBannerInfo::getCancelButtonString, WarningItemInfo::getCancelButtonString,
|
||||
R.array.power_anomaly_dismiss_btn_strings, index);
|
||||
R.array.power_anomaly_dismiss_btn_strings, resourceIndex);
|
||||
|
||||
String destinationClassName = getString(powerAnomalyEvent,
|
||||
WarningBannerInfo::getMainButtonDestination,
|
||||
|
@@ -11,8 +11,8 @@ message PowerAnomalyEventList {
|
||||
message PowerAnomalyEvent {
|
||||
optional string event_id = 1;
|
||||
optional int64 timestamp = 2;
|
||||
optional string type = 3; // e.g. settings, apps
|
||||
optional string key = 4; // e.g. brightness, significant_increase
|
||||
optional PowerAnomalyType type = 3;
|
||||
optional PowerAnomalyKey key = 4;
|
||||
optional float score = 5;
|
||||
oneof info {
|
||||
WarningBannerInfo warning_banner_info = 6;
|
||||
@@ -20,6 +20,25 @@ message PowerAnomalyEvent {
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: Please DO NOT delete enum items or change enum values. Use [deprecated = true] instead.
|
||||
// The enum value will be used to decide the tips card style like icons and colors.
|
||||
//
|
||||
// Next id: 2
|
||||
enum PowerAnomalyType{
|
||||
TYPE_SETTINGS_BANNER = 0;
|
||||
TYPE_APPS_ITEM = 1;
|
||||
}
|
||||
|
||||
// NOTE: Please DO NOT delete enum items or change enum values. Use [deprecated = true] instead.
|
||||
// The enum value will be used to decide pre-defined title and button labels.
|
||||
//
|
||||
// Next id: 3
|
||||
enum PowerAnomalyKey{
|
||||
KEY_BRIGHTNESS = 0;
|
||||
KEY_SCREEN_TIMEOUT = 1;
|
||||
KEY_APP = 2;
|
||||
}
|
||||
|
||||
message WarningBannerInfo {
|
||||
optional string title_string = 1;
|
||||
optional string description_string = 2;
|
||||
|
Reference in New Issue
Block a user