Update the logic for logging anomaly information to WW.

Bug: 316075226
Test: manual
Change-Id: I22198ee1ae3cedee6ee9d2e8191423000ba32af2
diff --git a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownController.java b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownController.java
index 0ffd090..47c171e 100644
--- a/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownController.java
+++ b/src/com/android/settings/fuelgauge/batteryusage/BatteryUsageBreakdownController.java
@@ -65,6 +65,8 @@
     private static final String SPINNER_PREFERENCE_KEY = "battery_usage_spinner";
     private static final String APP_LIST_PREFERENCE_KEY = "app_list";
     private static final String PACKAGE_NAME_NONE = "none";
+    private static final String SLOT_TIMESTAMP = "slot_timestamp";
+    private static final String ANOMALY_KEY = "anomaly_key";
     private static final List<BatteryDiffEntry> EMPTY_ENTRY_LIST = new ArrayList<>();
 
     private static int sUiMode = Configuration.UI_MODE_NIGHT_UNDEFINED;
@@ -77,7 +79,7 @@
     @VisibleForTesting final Map<String, Preference> mPreferenceCache = new ArrayMap<>();
 
     private int mSpinnerPosition;
-    private String mSlotTimestamp;
+    private String mSlotInformation;
 
     @VisibleForTesting Context mPrefContext;
     @VisibleForTesting PreferenceCategory mRootPreference;
@@ -87,7 +89,7 @@
     @VisibleForTesting BatteryDiffData mBatteryDiffData;
     @VisibleForTesting String mPercentLessThanThresholdText;
     @VisibleForTesting boolean mIsHighlightSlot;
-    @VisibleForTesting String mAnomalyEventId;
+    @VisibleForTesting int mAnomalyKeyNumber;
     @VisibleForTesting String mAnomalyEntryKey;
     @VisibleForTesting String mAnomalyHintString;
     @VisibleForTesting String mAnomalyHintPrefKey;
@@ -142,12 +144,25 @@
                 && mAnomalyEntryKey.equals(entry.getKey());
     }
 
-    private String getActionKey(BatteryDiffEntry entry) {
-        final String actionKey =
+    private void logPreferenceClickedMetrics(BatteryDiffEntry entry) {
+        final int attribution = SettingsEnums.OPEN_BATTERY_USAGE;
+        final int action = entry.isSystemEntry()
+                ? SettingsEnums.ACTION_BATTERY_USAGE_SYSTEM_ITEM
+                : SettingsEnums.ACTION_BATTERY_USAGE_APP_ITEM;
+        final int pageId = SettingsEnums.OPEN_BATTERY_USAGE;
+        final String packageName =
                 TextUtils.isEmpty(entry.getPackageName())
                         ? PACKAGE_NAME_NONE
                         : entry.getPackageName();
-        return !isAnomalyBatteryDiffEntry(entry) ? actionKey : actionKey + "|" + mAnomalyEventId;
+        final int percentage = (int) Math.round(entry.getPercentage());
+        final int slotTimestamp = (int) (mBatteryDiffData.getStartTimestamp() / 1000);
+        mMetricsFeatureProvider.action(attribution, action, pageId, packageName, percentage);
+        mMetricsFeatureProvider.action(attribution, action, pageId, SLOT_TIMESTAMP, slotTimestamp);
+
+        if (isAnomalyBatteryDiffEntry(entry)) {
+            mMetricsFeatureProvider.action(
+                    attribution, action, pageId, ANOMALY_KEY, mAnomalyKeyNumber);
+        }
     }
 
     @Override
@@ -157,14 +172,7 @@
         }
         final PowerGaugePreference powerPref = (PowerGaugePreference) preference;
         final BatteryDiffEntry diffEntry = powerPref.getBatteryDiffEntry();
-        mMetricsFeatureProvider.action(
-                /* attribution */ SettingsEnums.OPEN_BATTERY_USAGE,
-                /* action */ diffEntry.isSystemEntry()
-                        ? SettingsEnums.ACTION_BATTERY_USAGE_SYSTEM_ITEM
-                        : SettingsEnums.ACTION_BATTERY_USAGE_APP_ITEM,
-                /* pageId */ SettingsEnums.OPEN_BATTERY_USAGE,
-                getActionKey(diffEntry),
-                (int) Math.round(diffEntry.getPercentage()));
+        logPreferenceClickedMetrics(diffEntry);
         Log.d(
                 TAG,
                 String.format(
@@ -179,7 +187,7 @@
                 mFragment.getMetricsCategory(),
                 diffEntry,
                 powerPref.getPercentage(),
-                mSlotTimestamp,
+                mSlotInformation,
                 /* showTimeInformation= */ true,
                 anomalyHintPrefKey,
                 anomalyHintText);
@@ -245,13 +253,14 @@
             boolean isHighlightSlot,
             Optional<AnomalyEventWrapper> optionalAnomalyEventWrapper) {
         mBatteryDiffData = slotUsageData;
-        mSlotTimestamp = slotTimestamp;
+        mSlotInformation = slotTimestamp;
         mIsHighlightSlot = isHighlightSlot;
 
         if (optionalAnomalyEventWrapper != null) {
             final AnomalyEventWrapper anomalyEventWrapper =
                     optionalAnomalyEventWrapper.orElse(null);
-            mAnomalyEventId = anomalyEventWrapper != null ? anomalyEventWrapper.getEventId() : null;
+            mAnomalyKeyNumber =
+                    anomalyEventWrapper != null ? anomalyEventWrapper.getAnomalyKeyNumber() : -1;
             mAnomalyEntryKey =
                     anomalyEventWrapper != null ? anomalyEventWrapper.getAnomalyEntryKey() : null;
             mAnomalyHintString =