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:
@@ -460,6 +460,12 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
@Override
|
@Override
|
||||||
public SharedPreferences getSharedPreferences(String name, int mode) {
|
public SharedPreferences getSharedPreferences(String name, int mode) {
|
||||||
if (name.equals(getPackageName() + "_preferences")) {
|
if (name.equals(getPackageName() + "_preferences")) {
|
||||||
|
return new SharedPreferencesLogger(this, getMetricsTag());
|
||||||
|
}
|
||||||
|
return super.getSharedPreferences(name, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getMetricsTag() {
|
||||||
String tag = getClass().getName();
|
String tag = getClass().getName();
|
||||||
if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
|
if (getIntent() != null && getIntent().hasExtra(EXTRA_SHOW_FRAGMENT)) {
|
||||||
tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
|
tag = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
|
||||||
@@ -467,9 +473,7 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
if (tag.startsWith("com.android.settings.")) {
|
if (tag.startsWith("com.android.settings.")) {
|
||||||
tag = tag.replace("com.android.settings.", "");
|
tag = tag.replace("com.android.settings.", "");
|
||||||
}
|
}
|
||||||
return new SharedPreferencesLogger(this, tag);
|
return tag;
|
||||||
}
|
|
||||||
return super.getSharedPreferences(name, mode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isShortCutIntent(final Intent intent) {
|
private static boolean isShortCutIntent(final Intent intent) {
|
||||||
@@ -610,6 +614,9 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
|
mActionBar.setHomeButtonEnabled(mDisplayHomeAsUpEnabled);
|
||||||
}
|
}
|
||||||
mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
|
mSwitchBar = (SwitchBar) findViewById(R.id.switch_bar);
|
||||||
|
if (mSwitchBar != null) {
|
||||||
|
mSwitchBar.setMetricsTag(getMetricsTag());
|
||||||
|
}
|
||||||
|
|
||||||
// see if we should show Back/Next buttons
|
// see if we should show Back/Next buttons
|
||||||
if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
|
if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
|
||||||
|
@@ -34,6 +34,7 @@ import android.widget.LinearLayout;
|
|||||||
import android.widget.Switch;
|
import android.widget.Switch;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.android.internal.logging.MetricsLogger;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
|
|
||||||
@@ -64,6 +65,8 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
|||||||
private boolean mDisabledByAdmin = false;
|
private boolean mDisabledByAdmin = false;
|
||||||
private EnforcedAdmin mEnforcedAdmin = null;
|
private EnforcedAdmin mEnforcedAdmin = null;
|
||||||
|
|
||||||
|
private String mMetricsTag;
|
||||||
|
|
||||||
private ArrayList<OnSwitchChangeListener> mSwitchChangeListeners =
|
private ArrayList<OnSwitchChangeListener> mSwitchChangeListeners =
|
||||||
new ArrayList<OnSwitchChangeListener>();
|
new ArrayList<OnSwitchChangeListener>();
|
||||||
|
|
||||||
@@ -125,6 +128,10 @@ public class SwitchBar extends LinearLayout implements CompoundButton.OnCheckedC
|
|||||||
setVisibility(View.GONE);
|
setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMetricsTag(String tag) {
|
||||||
|
mMetricsTag = tag;
|
||||||
|
}
|
||||||
|
|
||||||
public void setTextViewLabel(boolean isChecked) {
|
public void setTextViewLabel(boolean isChecked) {
|
||||||
mLabel = getResources()
|
mLabel = getResources()
|
||||||
.getString(isChecked ? R.string.switch_on_text : R.string.switch_off_text);
|
.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
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (mDisabledByAdmin) {
|
if (mDisabledByAdmin) {
|
||||||
|
MetricsLogger.histogram(mContext, mMetricsTag + "/switch_bar|restricted", 1);
|
||||||
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(mContext, mEnforcedAdmin);
|
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(mContext, mEnforcedAdmin);
|
||||||
} else {
|
} else {
|
||||||
final boolean isChecked = !mSwitch.isChecked();
|
final boolean isChecked = !mSwitch.isChecked();
|
||||||
|
MetricsLogger.histogram(mContext, mMetricsTag + "/switch_bar|" + isChecked, 1);
|
||||||
setChecked(isChecked);
|
setChecked(isChecked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user