App anomaly tips on PowerUsage App list
Screenshots: [in bg - banner] https://screenshot.googleplex.com/MzLC6LfX93TkkYf [in bg - hints] https://screenshot.googleplex.com/9JLXNsRiVG8arAU [in fg - banner] https://screenshot.googleplex.com/9oYbwUkeeLbQX2t [in fg - hints] https://screenshot.googleplex.com/53DTTUCUnf8rsoE [apps anomaly highlight hint + settings anomaly banner] https://screenshot.googleplex.com/8NdS2VMrSzwv2DM Bug: 291689643 Bug: 291689623 Test: manual (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:bfd0f5859b6e5ffef4727ee562009f2050de7a58) Change-Id: Ic02db49cb3794ef134759d9dcec5f5ef32454a95
This commit is contained in:
@@ -53,6 +53,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/** Controller for battery usage breakdown preference group. */
|
||||
@@ -93,6 +94,14 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
||||
BatteryDiffData mBatteryDiffData;
|
||||
@VisibleForTesting
|
||||
String mPercentLessThanThresholdText;
|
||||
@VisibleForTesting
|
||||
boolean mIsHighlightSlot;
|
||||
@VisibleForTesting
|
||||
String mAnomalyEventId;
|
||||
@VisibleForTesting
|
||||
String mAnomalyEntryKey;
|
||||
@VisibleForTesting
|
||||
String mAnomalyHintString;
|
||||
|
||||
public BatteryUsageBreakdownController(
|
||||
Context context, Lifecycle lifecycle, SettingsActivity activity,
|
||||
@@ -137,6 +146,12 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getActionKey(String packageName) {
|
||||
final String actionKey = TextUtils.isEmpty(packageName)
|
||||
? PACKAGE_NAME_NONE : packageName;
|
||||
return mAnomalyEventId == null ? actionKey : actionKey + "|" + mAnomalyEventId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (!(preference instanceof PowerGaugePreference)) {
|
||||
@@ -151,7 +166,7 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
||||
? SettingsEnums.ACTION_BATTERY_USAGE_SYSTEM_ITEM
|
||||
: SettingsEnums.ACTION_BATTERY_USAGE_APP_ITEM,
|
||||
/* pageId */ SettingsEnums.OPEN_BATTERY_USAGE,
|
||||
TextUtils.isEmpty(packageName) ? PACKAGE_NAME_NONE : packageName,
|
||||
getActionKey(packageName),
|
||||
(int) Math.round(diffEntry.getPercentage()));
|
||||
Log.d(TAG, String.format("handleClick() label=%s key=%s package=%s",
|
||||
diffEntry.getAppLabel(), diffEntry.getKey(), packageName));
|
||||
@@ -211,9 +226,23 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
||||
* used when showing the footer.
|
||||
*/
|
||||
void handleBatteryUsageUpdated(
|
||||
BatteryDiffData slotUsageData, String slotTimestamp, boolean isAllUsageDataEmpty) {
|
||||
BatteryDiffData slotUsageData, String slotTimestamp,
|
||||
boolean isAllUsageDataEmpty, boolean isHighlightSlot,
|
||||
Optional<AnomalyEventWrapper> optionalAnomalyEventWrapper) {
|
||||
mBatteryDiffData = slotUsageData;
|
||||
mSlotTimestamp = slotTimestamp;
|
||||
mIsHighlightSlot = isHighlightSlot;
|
||||
|
||||
if (optionalAnomalyEventWrapper != null) {
|
||||
final AnomalyEventWrapper anomalyEventWrapper =
|
||||
optionalAnomalyEventWrapper.orElse(null);
|
||||
mAnomalyEventId = anomalyEventWrapper != null
|
||||
? anomalyEventWrapper.getEventId() : null;
|
||||
mAnomalyEntryKey = anomalyEventWrapper != null
|
||||
? anomalyEventWrapper.getAnomalyEntryKey() : null;
|
||||
mAnomalyHintString = anomalyEventWrapper != null
|
||||
? anomalyEventWrapper.getAnomalyHintString() : null;
|
||||
}
|
||||
|
||||
showCategoryTitle(slotTimestamp);
|
||||
showSpinnerAndAppList();
|
||||
@@ -278,15 +307,15 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
||||
continue;
|
||||
}
|
||||
final String prefKey = entry.getKey();
|
||||
PowerGaugePreference pref = mAppListPreferenceGroup.findPreference(prefKey);
|
||||
AnomalyAppItemPreference pref = mAppListPreferenceGroup.findPreference(prefKey);
|
||||
if (pref != null) {
|
||||
isAdded = true;
|
||||
} else {
|
||||
pref = (PowerGaugePreference) mPreferenceCache.get(prefKey);
|
||||
pref = (AnomalyAppItemPreference) mPreferenceCache.get(prefKey);
|
||||
}
|
||||
// Creates new innstance if cached preference is not found.
|
||||
// Creates new instance if cached preference is not found.
|
||||
if (pref == null) {
|
||||
pref = new PowerGaugePreference(mPrefContext);
|
||||
pref = new AnomalyAppItemPreference(mPrefContext);
|
||||
pref.setKey(prefKey);
|
||||
mPreferenceCache.put(prefKey, pref);
|
||||
}
|
||||
@@ -294,6 +323,10 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
||||
pref.setTitle(appLabel);
|
||||
pref.setOrder(prefIndex);
|
||||
pref.setSingleLineTitle(true);
|
||||
// Updates App item preference style
|
||||
pref.setAnomalyHint(mIsHighlightSlot && mAnomalyEntryKey != null
|
||||
&& mAnomalyEntryKey.equals(entry.getKey())
|
||||
? mAnomalyHintString : null);
|
||||
// Sets the BatteryDiffEntry to preference for launching detailed page.
|
||||
pref.setBatteryDiffEntry(entry);
|
||||
pref.setSelectable(entry.validForRestriction());
|
||||
|
Reference in New Issue
Block a user