1 package com.google.android.setupcompat.logging.internal;
2 
3 import android.os.Bundle;
4 import com.google.android.setupcompat.logging.CustomEvent;
5 import com.google.android.setupcompat.logging.MetricKey;
6 import com.google.android.setupcompat.logging.internal.SetupMetricsLoggingConstants.MetricBundleKeys;
7 
8 /** Collection of helper methods for reading and writing {@link CustomEvent}, {@link MetricKey}. */
9 public final class MetricBundleConverter {
10 
createBundleForLogging(CustomEvent customEvent)11   public static Bundle createBundleForLogging(CustomEvent customEvent) {
12     Bundle bundle = new Bundle();
13     bundle.putParcelable(MetricBundleKeys.CUSTOM_EVENT_BUNDLE, CustomEvent.toBundle(customEvent));
14     return bundle;
15   }
16 
createBundleForLoggingCounter(MetricKey counterName, int times)17   public static Bundle createBundleForLoggingCounter(MetricKey counterName, int times) {
18     Bundle bundle = new Bundle();
19     bundle.putParcelable(MetricBundleKeys.METRIC_KEY_BUNDLE, MetricKey.fromMetricKey(counterName));
20     bundle.putInt(MetricBundleKeys.COUNTER_INT, times);
21     return bundle;
22   }
23 
createBundleForLoggingTimer(MetricKey timerName, long timeInMillis)24   public static Bundle createBundleForLoggingTimer(MetricKey timerName, long timeInMillis) {
25     Bundle bundle = new Bundle();
26     bundle.putParcelable(MetricBundleKeys.METRIC_KEY_BUNDLE, MetricKey.fromMetricKey(timerName));
27     bundle.putLong(MetricBundleKeys.TIME_MILLIS_LONG, timeInMillis);
28     return bundle;
29   }
30 
MetricBundleConverter()31   private MetricBundleConverter() {
32     throw new AssertionError("Cannot instantiate MetricBundleConverter");
33   }
34 }
35