Add generic logging to Settings switch bar

Same usage/format as the shared preference logging.

Bug: 27043208
Change-Id: I7a7a5c0a9c92ec6cef50df58313016218cf2f2f7
This commit is contained in:
Jason Monk
2016-02-21 09:37:41 -05:00
parent 18d9865388
commit e4ebcd12be
2 changed files with 24 additions and 8 deletions

View File

@@ -460,18 +460,22 @@ public class SettingsActivity extends SettingsDrawerActivity
@Override
public SharedPreferences getSharedPreferences(String name, int mode) {
if (name.equals(getPackageName() + "_preferences")) {
String tag = getClass().getName();
if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
}
if (tag.startsWith("com.android.settings.")) {
tag = tag.replace("com.android.settings.", "");
}
return new SharedPreferencesLogger(this, tag);
return new SharedPreferencesLogger(this, getMetricsTag());
}
return super.getSharedPreferences(name, mode);
}
private String getMetricsTag() {
String tag = getClass().getName();
if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
}
if (tag.startsWith("com.android.settings.")) {
tag = tag.replace("com.android.settings.", "");
}
return tag;
}
private static boolean isShortCutIntent(final Intent intent) {
Set<String> categories = intent.getCategories();
return (categories != null) && categories.contains("com.android.settings.SHORTCUT");
@@ -610,6 +614,9 @@ public class SettingsActivity extends SettingsDrawerActivity
mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
}
mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
if (mSwitchBar != null) {
mSwitchBar.setMetricsTag(getMetricsTag());
}
// see if we should show Back/Next buttons
if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {

View File

@@ -34,6 +34,7 @@ import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextView;
import com.android.internal.logging.MetricsLogger;
import com.android.settings.R;
import com.android.settingslib.RestrictedLockUtils;
@@ -64,6 +65,8 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
private boolean mDisabledByAdmin = false;
private EnforcedAdmin mEnforcedAdmin = null;
private String mMetricsTag;
private ArrayList<OnSwitchChangeListener> mSwitchChangeListeners =
new ArrayList<OnSwitchChangeListener>();
@@ -125,6 +128,10 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
setVisibility(View.GONE);
}
public void setMetricsTag(String tag) {
mMetricsTag = tag;
}
public void setTextViewLabel(boolean isChecked) {
mLabel = getResources()
.getString(isChecked ? R.string.switch_on_text : R.string.switch_off_text);
@@ -217,9 +224,11 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
@Override
public void onClick(View v) {
if (mDisabledByAdmin) {
MetricsLogger.histogram(mContext, mMetricsTag + "/switch_bar|restricted", 1);
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(mContext, mEnforcedAdmin);
} else {
final boolean isChecked = !mSwitch.isChecked();
MetricsLogger.histogram(mContext, mMetricsTag + "/switch_bar|" + isChecked, 1);
setChecked(isChecked);
}
}