Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Settings: add logpersist selection (actions)
Browse files Browse the repository at this point in the history
- Only add logpersist menu if debuggable.
- Only enable logpersist menu if Logging is On.
- Add selection for Off, All and All minus radio.
- Pop up warning box that persistent storage is to be cleared when
  selecting Off (but not if turned off by Logging Size Off or
  Disabling Debugger Options).

Bug: 28936216
Change-Id: Ic0a58abdcd6ca41069efb818d1dcef4e3927d2de
  • Loading branch information
Mark Salyzyn committed Jun 10, 2016
1 parent 99afd4a commit 03af228
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 0 deletions.
7 changes: 7 additions & 0 deletions res/xml/development_prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@
android:entries="@array/select_logd_size_titles"
android:entryValues="@array/select_logd_size_values" />

<ListPreference
android:key="select_logpersist"
android:title="@string/select_logpersist_title"
android:dialogTitle="@string/select_logpersist_dialog_title"
android:entries="@array/select_logpersist_titles"
android:entryValues="@array/select_logpersist_values" />

</PreferenceCategory>

<PreferenceCategory android:key="debug_networking_category"
Expand Down
144 changes: 144 additions & 0 deletions src/com/android/settings/DevelopmentSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
// 32768 is merely a menu marker, 64K is our lowest log buffer size we replace it with.
private static final String SELECT_LOGD_MINIMUM_SIZE_VALUE = "65536";
private static final String SELECT_LOGD_OFF_SIZE_MARKER_VALUE = "32768";
private static final String SELECT_LOGPERSIST_KEY = "select_logpersist";
private static final String SELECT_LOGPERSIST_PROPERTY = "persist.logd.logpersistd";
private static final String SELECT_LOGPERSIST_PROPERTY_SERVICE = "logcatd";
private static final String SELECT_LOGPERSIST_PROPERTY_CLEAR = "clear";
private static final String SELECT_LOGPERSIST_PROPERTY_STOP = "stop";
private static final String SELECT_LOGPERSIST_PROPERTY_BUFFER = "persist.logd.logpersistd.buffer";

private static final String WIFI_DISPLAY_CERTIFICATION_KEY = "wifi_display_certification";
private static final String WIFI_VERBOSE_LOGGING_KEY = "wifi_verbose_logging";
Expand Down Expand Up @@ -252,6 +258,7 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
private SwitchPreference mForceRtlLayout;
private ListPreference mDebugHwOverdraw;
private ListPreference mLogdSize;
private ListPreference mLogpersist;
private ListPreference mUsbConfiguration;
private ListPreference mTrackFrameTime;
private ListPreference mShowNonRectClip;
Expand Down Expand Up @@ -288,6 +295,9 @@ public class DevelopmentSettings extends SettingsPreferenceFragment
private Dialog mAdbKeysDialog;
private boolean mUnavailable;

private boolean mLogpersistCleared;
private Dialog mLogpersistClearDialog;

@Override
protected int getMetricsCategory() {
return MetricsLogger.DEVELOPMENT;
Expand Down Expand Up @@ -393,6 +403,18 @@ public void onCreate(Bundle icicle) {
mLegacyDhcpClient = findAndInitSwitchPref(WIFI_LEGACY_DHCP_CLIENT_KEY);
mMobileDataAlwaysOn = findAndInitSwitchPref(MOBILE_DATA_ALWAYS_ON);
mLogdSize = addListPreference(SELECT_LOGD_SIZE_KEY);
if ("1".equals(SystemProperties.get("ro.debuggable", "0"))) {
mLogpersist = addListPreference(SELECT_LOGPERSIST_KEY);
} else {
mLogpersist = (ListPreference) findPreference(SELECT_LOGPERSIST_KEY);
if (mLogpersist != null) {
mLogpersist.setEnabled(false);
if (debugDebuggingCategory != null) {
debugDebuggingCategory.removePreference(mLogpersist);
}
}
mLogpersist = null;
}
mUsbConfiguration = addListPreference(USB_CONFIGURATION_KEY);
mBluetoothDisableAbsVolume = findAndInitSwitchPref(BLUETOOTH_DISABLE_ABSOLUTE_VOLUME_KEY);

Expand Down Expand Up @@ -648,6 +670,7 @@ private void updateAllOptions() {
updateBugreportOptions();
updateForceRtlOptions();
updateLogdSizeValues();
updateLogpersistValues();
updateWifiDisplayCertificationOptions();
updateWifiVerboseLoggingOptions();
updateWifiAggressiveHandoverOptions();
Expand All @@ -672,6 +695,7 @@ private void resetDangerousOptions() {
}
}
resetDebuggerOptions();
writeLogpersistOption(null, true);
writeLogdSizeOption(null);
writeAnimationScaleOption(0, mWindowAnimationScale, null);
writeAnimationScaleOption(1, mTransitionAnimationScale, null);
Expand Down Expand Up @@ -1331,6 +1355,14 @@ private void updateLogdSizeValues() {
String currentValue = SystemProperties.get(SELECT_LOGD_SIZE_PROPERTY);
if ((currentTag != null) && currentTag.startsWith(SELECT_LOGD_TAG_SILENCE)) {
currentValue = SELECT_LOGD_OFF_SIZE_MARKER_VALUE;
if (mLogpersist != null) {
writeLogpersistOption(null, true);
mLogpersist.setEnabled(false);
}
} else {
if ((mLogpersist != null) && mLastEnabledState) {
mLogpersist.setEnabled(true);
}
}
if ((currentValue == null) || (currentValue.length() == 0)) {
currentValue = defaultLogdSizeValue();
Expand Down Expand Up @@ -1399,6 +1431,103 @@ private void writeLogdSizeOption(Object newValue) {
updateLogdSizeValues();
}

private void updateLogpersistValues() {
if (mLogpersist == null) {
return;
}
String currentValue = SystemProperties.get(SELECT_LOGPERSIST_PROPERTY);
if (currentValue == null) {
currentValue = "";
}
String currentBuffers = SystemProperties.get(SELECT_LOGPERSIST_PROPERTY_BUFFER);
if ((currentBuffers == null) || (currentBuffers.length() == 0)) {
currentBuffers = "all";
}
int index = 0;
if (currentValue.equals(SELECT_LOGPERSIST_PROPERTY_SERVICE)) {
index = 1;
if (!currentBuffers.equals("all") &&
!currentBuffers.contains("radio") &&
currentBuffers.contains("security") &&
currentBuffers.contains("kernel")) {
index = 2;
if (!currentBuffers.contains("default")) {
String[] contains = { "main", "events", "system", "crash" };
for (int i = 0; i < contains.length; i++) {
if (!currentBuffers.contains(contains[i])) {
index = 1;
break;
}
}
}
}
}
mLogpersist.setValue(getResources().getStringArray(R.array.select_logpersist_values)[index]);
mLogpersist.setSummary(getResources().getStringArray(R.array.select_logpersist_summaries)[index]);
mLogpersist.setOnPreferenceChangeListener(this);
if (index != 0) {
mLogpersistCleared = false;
} else if (!mLogpersistCleared) {
// would File.delete() directly but need to switch uid/gid to access
SystemProperties.set(SELECT_LOGPERSIST_PROPERTY, SELECT_LOGPERSIST_PROPERTY_CLEAR);
pokeSystemProperties();
mLogpersistCleared = true;
}
}

private void setLogpersistOff(boolean update) {
SystemProperties.set(SELECT_LOGPERSIST_PROPERTY_BUFFER, "");
SystemProperties.set(SELECT_LOGPERSIST_PROPERTY,
update ? "" : SELECT_LOGPERSIST_PROPERTY_STOP);
pokeSystemProperties();
if (update) {
updateLogpersistValues();
}
}

private void writeLogpersistOption(Object newValue, boolean skipWarning) {
if (mLogpersist == null) {
return;
}
String currentTag = SystemProperties.get(SELECT_LOGD_TAG_PROPERTY);
if ((currentTag != null) && currentTag.startsWith(SELECT_LOGD_TAG_SILENCE)) {
newValue = null;
skipWarning = true;
}

if ((newValue == null) || newValue.toString().equals("")) {
if (skipWarning) {
mLogpersistCleared = false;
} else if (!mLogpersistCleared) {
// if transitioning from on to off, pop up an are you sure?
String currentValue = SystemProperties.get(SELECT_LOGPERSIST_PROPERTY);
if ((currentValue != null) && (currentValue.length() != 0)) {
if (mLogpersistClearDialog != null) dismissDialogs();
mLogpersistClearDialog = new AlertDialog.Builder(getActivity()).setMessage(
getActivity().getResources().getString(
R.string.dev_logpersist_clear_warning_message))
.setTitle(R.string.dev_logpersist_clear_warning_title)
.setPositiveButton(android.R.string.yes, this)
.setNegativeButton(android.R.string.no, this)
.show();
mLogpersistClearDialog.setOnDismissListener(this);
return;
}
}
setLogpersistOff(true);
return;
}

String currentBuffer = SystemProperties.get(SELECT_LOGPERSIST_PROPERTY_BUFFER);
if ((currentBuffer != null) && !currentBuffer.equals(newValue.toString())) {
setLogpersistOff(false);
}
SystemProperties.set(SELECT_LOGPERSIST_PROPERTY_BUFFER, newValue.toString());
SystemProperties.set(SELECT_LOGPERSIST_PROPERTY, SELECT_LOGPERSIST_PROPERTY_SERVICE);
pokeSystemProperties();
updateLogpersistValues();
}

private void updateUsbConfigurationValues() {
if (mUsbConfiguration != null) {
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
Expand Down Expand Up @@ -1831,6 +1960,9 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
} else if (preference == mLogdSize) {
writeLogdSizeOption(newValue);
return true;
} else if (preference == mLogpersist) {
writeLogpersistOption(newValue, false);
return true;
} else if (preference == mUsbConfiguration) {
writeUsbConfigurationOption(newValue);
return true;
Expand Down Expand Up @@ -1881,6 +2013,10 @@ private void dismissDialogs() {
mEnableDialog.dismiss();
mEnableDialog = null;
}
if (mLogpersistClearDialog != null) {
mLogpersistClearDialog.dismiss();
mLogpersistClearDialog = null;
}
}

public void onClick(DialogInterface dialog, int which) {
Expand Down Expand Up @@ -1917,6 +2053,12 @@ public void onClick(DialogInterface dialog, int which) {
// Reset the toggle
mSwitchBar.setChecked(false);
}
} else if (dialog == mLogpersistClearDialog) {
if (which == DialogInterface.BUTTON_POSITIVE) {
setLogpersistOff(true);
} else {
updateLogpersistValues();
}
}
}

Expand All @@ -1932,6 +2074,8 @@ public void onDismiss(DialogInterface dialog) {
mSwitchBar.setChecked(false);
}
mEnableDialog = null;
} else if (dialog == mLogpersistClearDialog) {
mLogpersistClearDialog = null;
}
}

Expand Down

0 comments on commit 03af228

Please sign in to comment.