Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e7d03a36 authored by Elliott Hughes's avatar Elliott Hughes Committed by Automerger Merge Worker
Browse files

Merge "SystemProperties.set(): more exception message detail." into main am:...

Merge "SystemProperties.set(): more exception message detail." into main am: a633dd25 am: 55e8903b

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/3056523



Change-Id: I0bee854be11db4d52bbba2a2092eea069eeb0977
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 8ddf1c51 55e8903b
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -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);
        }
    }
}