Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5914d143 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Update preference logger to log pref change as ACTION"

parents 0d988208 c6f4c9c9
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -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) {
+9 −5
Original line number Diff line number Diff line
@@ -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));
    }

}