Change preference value changed metrics log format

- Pass metric category into SharedPreferenceLogger
- Update MainSwitchBar metric log format

Bug: 246483846
Test: Robotest

Change-Id: I91c7b89ee35ae4922aea0d8c998f7d0e33365da2
This commit is contained in:
Edgar Wang
2022-09-13 03:37:03 +00:00
parent 1b9f06c002
commit 81aaba00e7
5 changed files with 63 additions and 24 deletions

View File

@@ -24,6 +24,7 @@ import static com.android.settings.applications.appinfo.AppButtonsPreferenceCont
import android.app.ActionBar; import android.app.ActionBar;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.settings.SettingsEnums;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName; import android.content.ComponentName;
@@ -230,11 +231,32 @@ public class SettingsActivity extends SettingsBaseActivity
@Override @Override
public SharedPreferences getSharedPreferences(String name, int mode) { public SharedPreferences getSharedPreferences(String name, int mode) {
if (name.equals(getPackageName() + "_preferences")) { if (!TextUtils.equals(name, getPackageName() + "_preferences")) {
return new SharedPreferencesLogger(this, getMetricsTag(), return super.getSharedPreferences(name, mode);
FeatureFactory.getFactory(this).getMetricsFeatureProvider());
} }
return super.getSharedPreferences(name, mode);
String tag = getMetricsTag();
return new SharedPreferencesLogger(this, tag,
FeatureFactory.getFactory(this).getMetricsFeatureProvider(),
lookupMetricsCategory());
}
private int lookupMetricsCategory() {
int category = SettingsEnums.PAGE_UNKNOWN;
Bundle args = null;
if (getIntent() != null) {
args = getIntent().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
}
Fragment fragment = Utils.getTargetFragment(this, getMetricsTag(), args);
if (fragment instanceof Instrumentable) {
category = ((Instrumentable) fragment).getMetricsCategory();
}
Log.d(LOG_TAG, "MetricsCategory is " + category);
return category;
} }
private String getMetricsTag() { private String getMetricsTag() {
@@ -242,13 +264,11 @@ public class SettingsActivity extends SettingsBaseActivity
if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) { if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
tag = getInitialFragmentName(getIntent()); tag = getInitialFragmentName(getIntent());
} }
if (TextUtils.isEmpty(tag)) { if (TextUtils.isEmpty(tag)) {
Log.w(LOG_TAG, "MetricsTag is invalid " + tag); Log.w(LOG_TAG, "MetricsTag is invalid " + tag);
tag = getClass().getName(); tag = getClass().getName();
} }
if (tag.startsWith("com.android.settings.")) {
tag = tag.replace("com.android.settings.", "");
}
return tag; return tag;
} }
@@ -320,7 +340,7 @@ public class SettingsActivity extends SettingsBaseActivity
} }
mMainSwitch = findViewById(R.id.switch_bar); mMainSwitch = findViewById(R.id.switch_bar);
if (mMainSwitch != null) { if (mMainSwitch != null) {
mMainSwitch.setMetricsTag(getMetricsTag()); mMainSwitch.setMetricsCategory(lookupMetricsCategory());
mMainSwitch.setTranslationZ(findViewById(R.id.main_content).getTranslationZ() + 1); mMainSwitch.setTranslationZ(findViewById(R.id.main_content).getTranslationZ() + 1);
} }

View File

@@ -40,6 +40,22 @@ public class SettingsEventLogWriter extends EventLogWriter {
super.hidden(context, category, visibleTime); super.hidden(context, category, visibleTime);
} }
@Override
public void clicked(int sourceCategory, String key) {
if (shouldDisableGenericEventLogging()) {
return;
}
super.clicked(sourceCategory, key);
}
@Override
public void changed(int category, String key, int value) {
if (shouldDisableGenericEventLogging()) {
return;
}
super.changed(category, key, value);
}
@Override @Override
public void action(Context context, int category, String pkg) { public void action(Context context, int category, String pkg) {
if (shouldDisableGenericEventLogging()) { if (shouldDisableGenericEventLogging()) {

View File

@@ -84,6 +84,10 @@ public class SettingsIntelligenceLogWriter implements LogWriter {
public void clicked(int sourceCategory, String key) { public void clicked(int sourceCategory, String key) {
} }
@Override
public void changed(int category, String key, int value) {
}
@Override @Override
public void action(Context context, int action, Pair<Integer, Object>... taggedData) { public void action(Context context, int action, Pair<Integer, Object>... taggedData) {
action(SettingsEnums.PAGE_UNKNOWN /* attribution */, action(SettingsEnums.PAGE_UNKNOWN /* attribution */,

View File

@@ -54,6 +54,16 @@ public class StatsLogWriter implements LogWriter {
0 /* changedPreferenceIntValue */); 0 /* changedPreferenceIntValue */);
} }
@Override
public void changed(int sourceCategory, String key, int value) {
SettingsStatsLog.write(SettingsStatsLog.SETTINGS_UI_CHANGED /* Atom name */,
sourceCategory /* attribution */,
SettingsEnums.ACTION_SETTINGS_PREFERENCE_CHANGE /* action */,
SettingsEnums.PAGE_UNKNOWN /* pageId */,
key /* changedPreferenceKey */,
value /* changedPreferenceIntValue */);
}
@Override @Override
public void action(Context context, int action, Pair<Integer, Object>... taggedData) { public void action(Context context, int action, Pair<Integer, Object>... taggedData) {
action(SettingsEnums.PAGE_UNKNOWN /* attribution */, action(SettingsEnums.PAGE_UNKNOWN /* attribution */,

View File

@@ -18,7 +18,6 @@ package com.android.settings.widget;
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
import android.app.settings.SettingsEnums;
import android.content.Context; import android.content.Context;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
@@ -55,7 +54,7 @@ public class SettingsMainSwitchBar extends MainSwitchBar {
private final MetricsFeatureProvider mMetricsFeatureProvider; private final MetricsFeatureProvider mMetricsFeatureProvider;
private OnBeforeCheckedChangeListener mOnBeforeListener; private OnBeforeCheckedChangeListener mOnBeforeListener;
private String mMetricsTag; private int mMetricsCategory;
public SettingsMainSwitchBar(Context context) { public SettingsMainSwitchBar(Context context) {
this(context, null); this(context, null);
@@ -125,12 +124,7 @@ public class SettingsMainSwitchBar extends MainSwitchBar {
} }
protected void onRestrictedIconClick() { protected void onRestrictedIconClick() {
mMetricsFeatureProvider.action( mMetricsFeatureProvider.clicked(mMetricsCategory, "switch_bar|restricted");
SettingsEnums.PAGE_UNKNOWN,
SettingsEnums.ACTION_SETTINGS_PREFERENCE_CHANGE,
SettingsEnums.PAGE_UNKNOWN,
mMetricsTag + "/switch_bar|restricted",
1);
} }
@Override @Override
@@ -159,8 +153,8 @@ public class SettingsMainSwitchBar extends MainSwitchBar {
/** /**
* Set the metrics tag. * Set the metrics tag.
*/ */
public void setMetricsTag(String tag) { public void setMetricsCategory(int category) {
mMetricsTag = tag; mMetricsCategory = category;
} }
private View getDelegatingView() { private View getDelegatingView() {
@@ -168,11 +162,6 @@ public class SettingsMainSwitchBar extends MainSwitchBar {
} }
private void logMetrics(boolean isChecked) { private void logMetrics(boolean isChecked) {
mMetricsFeatureProvider.action( mMetricsFeatureProvider.changed(mMetricsCategory, "switch_bar", isChecked ? 1 : 0);
SettingsEnums.PAGE_UNKNOWN,
SettingsEnums.ACTION_SETTINGS_PREFERENCE_CHANGE,
SettingsEnums.PAGE_UNKNOWN,
mMetricsTag + "/switch_bar",
isChecked ? 1 : 0);
} }
} }