summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2024-04-29 21:23:26 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-04-29 21:23:26 +0000
commita633dd253a62afee71675eddd04ea7580f3ef54c (patch)
treea06aa803f53e84433f065168c0997b8f3d9143d4 /core
parenta291637d6630508675a9dc9ec79f4c1cf826b5bb (diff)
parentd9519c346f7769ae0571b1fd48d8f11ab8469310 (diff)
downloadbase-a633dd253a62afee71675eddd04ea7580f3ef54c.tar.gz
Merge "SystemProperties.set(): more exception message detail." into main
Diffstat (limited to 'core')
-rw-r--r--core/jni/android_os_SystemProperties.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/core/jni/android_os_SystemProperties.cpp b/core/jni/android_os_SystemProperties.cpp
index 7f3b32e1abed..88e6fa3028ad 100644
--- a/core/jni/android_os_SystemProperties.cpp
+++ b/core/jni/android_os_SystemProperties.cpp
@@ -190,15 +190,31 @@ void SystemProperties_set(JNIEnv *env, jobject clazz, jstring keyJ,
return;
}
}
+ // Calling SystemProperties.set() with a null value is equivalent to an
+ // empty string, but this is not true for the underlying libc function.
+ const char* value_c_str = value ? value->c_str() : "";
+ // Explicitly clear errno so we can recognize __system_property_set()
+ // failures from failed system calls (as opposed to "init rejected your
+ // request" failures).
+ errno = 0;
bool success;
#if defined(__BIONIC__)
- success = !__system_property_set(key.c_str(), value ? value->c_str() : "");
+ success = !__system_property_set(key.c_str(), value_c_str);
#else
- success = android::base::SetProperty(key.c_str(), value ? value->c_str() : "");
+ success = android::base::SetProperty(key.c_str(), value_c_str);
#endif
if (!success) {
- jniThrowException(env, "java/lang/RuntimeException",
- "failed to set system property (check logcat for reason)");
+ if (errno != 0) {
+ jniThrowExceptionFmt(env, "java/lang/RuntimeException",
+ "failed to set system property \"%s\" to \"%s\": %m",
+ key.c_str(), value_c_str);
+ } else {
+ // Must have made init unhappy, which will have logged something,
+ // but there's no API to ask for more detail.
+ jniThrowExceptionFmt(env, "java/lang/RuntimeException",
+ "failed to set system property \"%s\" to \"%s\" (check logcat for reason)",
+ key.c_str(), value_c_str);
+ }
}
}