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

Commit 0bb662a6 authored by Jerome Gaillard's avatar Jerome Gaillard Committed by Android (Google) Code Review
Browse files

Merge "Throw Java exceptions when failing to load ICU data" into main

parents 1c72035d 60ff9761
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -280,12 +280,18 @@ static string getJavaProperty(JNIEnv* env, const char* property_name,
    return string(chars.c_str());
}

static void loadIcuData(string icuPath) {
static void loadIcuData(JNIEnv* env, string icuPath) {
    void* addr = mmapFile(icuPath.c_str());
    if (addr == nullptr) {
        jniThrowRuntimeException(env, "Failed to map the ICU data file.");
    }
    UErrorCode err = U_ZERO_ERROR;
    udata_setCommonData(addr, &err);
    if (err != U_ZERO_ERROR) {
        ALOGE("Unable to load ICU data\n");
        jniThrowRuntimeException(env,
                                 format("udata_setCommonData failed with error code {}",
                                        u_errorName(err))
                                         .c_str());
    }
}

@@ -296,12 +302,12 @@ static void loadIcuData() {
    JNIEnv* env = AndroidRuntime::getJNIEnv();
    string icuPath = base::GetProperty("ro.icu.data.path", "");
    if (!icuPath.empty()) {
        loadIcuData(icuPath);
        loadIcuData(env, icuPath);
    } else {
        // fallback to read from java.lang.System.getProperty
        string icuPathFromJava = getJavaProperty(env, "icu.data.path");
        if (!icuPathFromJava.empty()) {
            loadIcuData(icuPathFromJava);
            loadIcuData(env, icuPathFromJava);
        }
    }