Impl dismiss action in battery tips cards.

- Use SharedPreferences to record and filter the already dimissed anomaly.

Bug: 291689623
Test: manual
Change-Id: I4fd4a39066591a4a201857f9586b6595b7d5c43b
This commit is contained in:
mxyyiyi
2023-08-17 15:30:22 +08:00
parent 5cbf3b0f74
commit 737b9ab5b7
8 changed files with 133 additions and 7 deletions

View File

@@ -50,6 +50,7 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
private final MetricsFeatureProvider mMetricsFeatureProvider;
private String mAnomalyEventId;
private PowerAnomalyKey mPowerAnomalyKey;
@VisibleForTesting
CharSequence mMainButtonLabel;
@@ -69,6 +70,7 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
final FeatureFactory featureFactory = FeatureFactory.getFactory(context);
mPowerUsageFeatureProvider = featureFactory.getPowerUsageFeatureProvider(context);
mMetricsFeatureProvider = featureFactory.getMetricsFeatureProvider();
mPowerAnomalyKey = null;
}
/**
@@ -98,6 +100,13 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
}
}
/**
* Sets the power anomaly key of battery tips card.
*/
public void setPowerAnomalyKey(final PowerAnomalyKey powerAnomalyKey) {
mPowerAnomalyKey = powerAnomalyKey;
}
/**
* Sets the info of target fragment launched by main button.
*/
@@ -133,6 +142,9 @@ public class BatteryTipsCardPreference extends Preference implements View.OnClic
setVisible(false);
mMetricsFeatureProvider.action(
getContext(), SettingsEnums.ACTION_BATTERY_TIPS_CARD_DISMISS, mAnomalyEventId);
if (mPowerAnomalyKey != null) {
DatabaseUtils.setDismissedPowerAnomalyKeys(getContext(), mPowerAnomalyKey.name());
}
}
}