一.先看上层
1.1. 布局 KEY
private static final String SELECT_LOGD_SIZE_KEY = "select_logd_size";
private static final String SELECT_LOGD_SIZE_PROPERTY = "persist.logd.size";
1.2. writeLogdSizeOption()
updateLogpersistValues()
private void writeLogdSizeOption(Object newValue) {
boolean disable = (newValue != null) &&
(newValue.toString().equals(SELECT_LOGD_OFF_SIZE_MARKER_VALUE));
String currentTag = SystemProperties.get(SELECT_LOGD_TAG_PROPERTY);
if (currentTag == null) {
currentTag = "";
}
// filter clean and unstack all references to our setting
String newTag = currentTag.replaceAll(
",+" + SELECT_LOGD_TAG_SILENCE, "").replaceFirst(
"^" + SELECT_LOGD_TAG_SILENCE + ",*", "").replaceAll(
",+", ",").replaceFirst(
",+$", "");
if (disable) {
newValue = SELECT_LOGD_MINIMUM_SIZE_VALUE;
// Make sure snet_event_log get through first, but do not override
String snetValue = SystemProperties.get(SELECT_LOGD_SNET_TAG_PROPERTY);
if ((snetValue == null) || (snetValue.length() == 0)) {
snetValue = SystemProperties.get(SELECT_LOGD_RUNTIME_SNET_TAG_PROPERTY);
if ((snetValue == null) || (snetValue.length() == 0)) {
SystemProperties.set(SELECT_LOGD_SNET_TAG_PROPERTY, "I");
}
}
// Silence all log sources, security logs notwithstanding
if (newTag.length() != 0) {
newTag = "," + newTag;
}
// Stack settings, stack to help preserve original value
newTag = SELECT_LOGD_TAG_SILENCE + newTag;
}
if (!newTag.equals(currentTag)) {
SystemProperties.set(SELECT_LOGD_TAG_PROPERTY, newTag);
}
String defaultValue = defaultLogdSizeValue();
final String size = ((newValue != null) && (newValue.toString().length() != 0)) ?
newValue.toString() : defaultValue;
SystemProperties.set(SELECT_LOGD_SIZE_PROPERTY, defaultValue.equals(size) ? "" : size);
SystemProperties.set("ctl.start", "logd-reinit");
pokeSystemProperties();
updateLogdSizeValues();
}
private void updateLogdSizeValues() {
if (mLogdSize != null) {
String currentTag = SystemProperties.get(SELECT_LOGD_TAG_PROPERTY);
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) {
String currentLogpersistEnable
= SystemProperties.get(ACTUAL_LOGPERSIST_PROPERTY_ENABLE);
if ((currentLogpersistEnable == null)
|| !currentLogpersistEnable.equals("true")
|| currentValue.equals(SELECT_LOGD_OFF_SIZE_MARKER_VALUE)) {
writeLogpersistOption(null, true);
mLogpersist.setEnabled(false);
} else if (mLastEnabledState) {
mLogpersist.setEnabled(true);
}
}
if ((currentValue == null) || (currentValue.length() == 0)) {
currentValue = defaultLogdSizeValue();
}
//gatsby 加载res 资源
String[] values = getResources().getStringArray(R.array.select_logd_size_values);
String[] titles = getResources().getStringArray(R.array.select_logd_size_titles);
int index = 2; // punt to second entry if not found
if (SystemProperties.get("ro.config.low_ram").equals("true")) {
mLogdSize.setEntries(R.array.select_logd_size_lowram_titles);
titles = getResources().getStringArray(R.array.select_logd_size_lowram_titles);
index = 1;
}
String[] summaries = getResources().getStringArray(R.array.select_logd_size_summaries);
for (int i = 0; i < titles.length; i++) {
if (currentValue.equals(values[i])
|| currentValue.equals(titles[i])) {
index = i;
break;
}
}
mLogdSize.setValue(values[index]);
mLogdSize.setSummary(summaries[index]);
mLogdSize.setOnPreferenceChangeListener(this);
}
}
二.LogBuffer.cpp
persist.logd.size
persist.logd.size
ro.logd.size
LOG_BUFFER_SIZE, 即256k
LOG_BUFFER_MIN_SIZE, 即64k
三.默认512K
--- a/frameworks/base/packages/SettingsLib/res/values-zh-rCN/arrays.xml
+++ b/frameworks/base/packages/SettingsLib/res/values-zh-rCN/arrays.xml
@@ -62,6 +62,7 @@
"关闭"
"64K"
"256K"
+ "512K"
"1M"
"4M"
"16M"
@@ -76,6 +77,7 @@
"关闭"
"每个日志缓冲区 64K"
"每个日志缓冲区 256K"
+ "每个日志缓冲区 512K"
"每个日志缓冲区 1M"
"每个日志缓冲区 4M"
"每个日志缓冲区 16M"
diff --git a/frameworks/base/packages/SettingsLib/res/values/arrays.xml b/frameworks/base/packages/SettingsLib/res/values/arrays.xml
old mode 100644
new mode 100755
index 920e061..b57115b
--- a/frameworks/base/packages/SettingsLib/res/values/arrays.xml
+++ b/frameworks/base/packages/SettingsLib/res/values/arrays.xml
@@ -122,6 +122,7 @@
32768
65536
+524288
262144
1048576
4194304
diff --git a/system/core/logd/LogBuffer.cpp b/system/core/logd/LogBuffer.cpp
old mode 100644
new mode 100755
index 0497a89..5a2a597
--- a/system/core/logd/LogBuffer.cpp
+++ b/system/core/logd/LogBuffer.cpp
@@ -97,14 +97,20 @@ void LogBuffer::init() {
static const char global_tuneable[] = "persist.logd.size"; // Settings App
static const char global_default[] = "ro.logd.size"; // BoardConfig.mk
+SLOGE("gatsby LogBuffer init");
+
unsigned long default_size = property_get_size(global_tuneable);
+SLOGE("000 gatsby default_size -> %lu .",default_size);
if (!default_size) {
+SLOGE("000 gatsby !!!default_size aaa -> %lu .",default_size);
default_size = property_get_size(global_default);
+SLOGE("000 gatsby !!!default_size bbb -> %lu .",default_size);
if (!default_size) {
default_size = property_get_bool("ro.config.low_ram",
BOOL_DEFAULT_FALSE)
? LOG_BUFFER_MIN_SIZE // 64K
: LOG_BUFFER_SIZE; // 256K
+SLOGE("000 gatsby !!!!!default_size ccc -> %lu .",default_size);
}
}
@@ -116,24 +122,32 @@ void LogBuffer::init() {
snprintf(key, sizeof(key), "%s.%s",
global_tuneable, android_log_id_to_name(i));
+//getprop persist.logd.size
unsigned long property_size = property_get_size(key);
if (!property_size) {
snprintf(key, sizeof(key), "%s.%s",
global_default, android_log_id_to_name(i));
property_size = property_get_size(key);
+SLOGE("111 gatsby global_tuneable -> %s . android_log_id_to_name(i) -> %s .",global_tuneable,android_log_id_to_name(i));
+SLOGE("111 gatsby property_size -> %lu .",property_size);
}
if (!property_size) {
property_size = default_size;
+SLOGE("2222 gatsby property_size -> %lu .",property_size);
}
if (!property_size) {
+//256k
property_size = LOG_BUFFER_SIZE;
+SLOGE("333 gatsby property_size -> %lu .",property_size);
}
if (setSize(i, property_size)) {
+//64k
setSize(i, LOG_BUFFER_MIN_SIZE);
+SLOGE("444 gatsby property_size -> %lu .",property_size);
}
}
bool lastMonotonic = monotonic;