OSDN Git Service

Update preference logger to log pref change as ACTION
authorFan Zhang <zhfan@google.com>
Mon, 6 Mar 2017 23:32:30 +0000 (15:32 -0800)
committerFan Zhang <zhfan@google.com>
Mon, 6 Mar 2017 23:39:22 +0000 (15:39 -0800)
Change-Id: I600cf6ec79cbc876347c3fdb20ea70fffbc04524
Fix: 34775467
Test: make RunSettingsRoboTests

src/com/android/settings/core/instrumentation/SharedPreferencesLogger.java
tests/robotests/src/com/android/settings/core/instrumentation/SharedPreferenceLoggerTest.java

index a5efcc1..6c23b39 100644 (file)
@@ -21,6 +21,7 @@ import android.content.SharedPreferences;
 import android.content.pm.PackageManager;
 import android.os.AsyncTask;
 import android.text.TextUtils;
+import android.util.Pair;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.overlay.FeatureFactory;
@@ -111,13 +112,17 @@ public class SharedPreferencesLogger implements SharedPreferences {
             return;
         }
         // Pref key exists in set, log it's change in metrics.
-        mMetricsFeature.count(mContext, prefKey + "|" + value, 1);
+        mMetricsFeature.action(mContext, MetricsEvent.ACTION_SETTINGS_PREFERENCE_CHANGE,
+                Pair.create(MetricsEvent.FIELD_SETTINGS_PREFERENCE_CHANGE_NAME, prefKey),
+                Pair.create(MetricsEvent.FIELD_SETTINGS_PREFERENCE_CHANGE_VALUE, value));
     }
 
     private void logPackageName(String key, String value) {
-        mMetricsFeature.count(mContext, mTag + "/" + key, 1);
+        final String prefKey = mTag + "/" + key;
+        mMetricsFeature.action(mContext, MetricsEvent.ACTION_SETTINGS_PREFERENCE_CHANGE,
+                Pair.create(MetricsEvent.FIELD_SETTINGS_PREFERENCE_CHANGE_NAME, prefKey));
         mMetricsFeature.action(mContext, MetricsEvent.ACTION_GENERIC_PACKAGE,
-                mTag + "/" + key + "|" + value);
+                prefKey + "|" + value);
     }
 
     private void safeLogValue(String key, String value) {
index eeaa175..763d6e3 100644 (file)
@@ -17,6 +17,7 @@ package com.android.settings.core.instrumentation;
 
 import android.content.Context;
 import android.content.SharedPreferences;
+import android.util.Pair;
 
 import com.android.settings.SettingsRobolectricTestRunner;
 import com.android.settings.TestConfig;
@@ -32,7 +33,6 @@ import org.robolectric.annotation.Config;
 
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
@@ -71,7 +71,8 @@ public class SharedPreferenceLoggerTest {
         editor.putInt(TEST_KEY, 2);
         editor.putInt(TEST_KEY, 2);
 
-        verify(mMetricsFeature, times(6)).count(any(Context.class), anyString(), anyInt());
+        verify(mMetricsFeature, times(6)).action(any(Context.class), anyInt(),
+                any(Pair.class), any(Pair.class));
     }
 
     @Test
@@ -83,7 +84,8 @@ public class SharedPreferenceLoggerTest {
         editor.putBoolean(TEST_KEY, false);
         editor.putBoolean(TEST_KEY, false);
 
-        verify(mMetricsFeature, times(4)).count(any(Context.class), anyString(), anyInt());
+        verify(mMetricsFeature, times(4)).action(any(Context.class), anyInt(),
+                any(Pair.class), any(Pair.class));
     }
 
     @Test
@@ -95,7 +97,8 @@ public class SharedPreferenceLoggerTest {
         editor.putLong(TEST_KEY, 1);
         editor.putLong(TEST_KEY, 2);
 
-        verify(mMetricsFeature, times(4)).count(any(Context.class), anyString(), anyInt());
+        verify(mMetricsFeature, times(4)).action(any(Context.class), anyInt(),
+                any(Pair.class), any(Pair.class));
     }
 
     @Test
@@ -107,7 +110,8 @@ public class SharedPreferenceLoggerTest {
         editor.putFloat(TEST_KEY, 1);
         editor.putFloat(TEST_KEY, 2);
 
-        verify(mMetricsFeature, times(4)).count(any(Context.class), anyString(), anyInt());
+        verify(mMetricsFeature, times(4)).action(any(Context.class), anyInt(),
+                any(Pair.class), any(Pair.class));
     }
 
 }