diff --git a/xposed.cpp b/xposed.cpp index b6c9a9e25..377fb7fa2 100644 --- a/xposed.cpp +++ b/xposed.cpp @@ -104,6 +104,9 @@ bool initialize(bool zygote, bool startSystemServer, const char* className, int printRomInfo(); if (startSystemServer) { +#if PLATFORM_SDK_VERSION >= 21 + htcAdjustSystemServerClassPath(); +#endif if (!xposed::service::startAll()) return false; #if XPOSED_WITH_SELINUX @@ -290,6 +293,23 @@ bool shouldIgnoreCommand(int argc, const char* const argv[]) { return false; } +/** Adds a path to the beginning of an environment variable. */ +static bool addPathToEnv(const char* name, const char* path) { + char* oldPath = getenv(name); + if (oldPath == NULL) { + setenv(name, path, 1); + } else { + char newPath[4096]; + int neededLength = snprintf(newPath, sizeof(newPath), "%s:%s", path, oldPath); + if (neededLength >= (int)sizeof(newPath)) { + ALOGE("ERROR: %s would exceed %d characters", name, sizeof(newPath)); + return false; + } + setenv(name, newPath, 1); + } + return true; +} + /** Add XposedBridge.jar to the Java classpath. */ bool addJarToClasspath() { ALOGI("-----------------"); @@ -307,18 +327,9 @@ bool addJarToClasspath() { */ if (access(XPOSED_JAR, R_OK) == 0) { - char* oldClassPath = getenv("CLASSPATH"); - if (oldClassPath == NULL) { - setenv("CLASSPATH", XPOSED_JAR, 1); - } else { - char classPath[4096]; - int neededLength = snprintf(classPath, sizeof(classPath), "%s:%s", XPOSED_JAR, oldClassPath); - if (neededLength >= (int)sizeof(classPath)) { - ALOGE("ERROR: CLASSPATH would exceed %d characters", sizeof(classPath)); - return false; - } - setenv("CLASSPATH", classPath, 1); - } + if (!addPathToEnv("CLASSPATH", XPOSED_JAR)) + return false; + ALOGI("Added Xposed (%s) to CLASSPATH", XPOSED_JAR); return true; } else { @@ -327,6 +338,16 @@ bool addJarToClasspath() { } } +#if PLATFORM_SDK_VERSION >= 21 +/** On HTC ROMs, ensure that ub.jar is compiled before the system server is started. */ +void htcAdjustSystemServerClassPath() { + if (access("/system/framework/ub.jar", F_OK) != 0) + return; + + addPathToEnv("SYSTEMSERVERCLASSPATH", "/system/framework/ub.jar"); +} +#endif + /** Callback which checks the loaded shared libraries for libdvm/libart. */ static bool determineRuntime(const char** xposedLibPath) { FILE *fp = fopen("/proc/self/maps", "r"); diff --git a/xposed.h b/xposed.h index 47cbc3f8a..334416e62 100644 --- a/xposed.h +++ b/xposed.h @@ -45,6 +45,9 @@ namespace xposed { bool shouldSkipSafemodeDelay(); bool shouldIgnoreCommand(int argc, const char* const argv[]); bool addJarToClasspath(); +#if PLATFORM_SDK_VERSION >= 21 + void htcAdjustSystemServerClassPath(); +#endif void onVmCreated(JNIEnv* env); void setProcessName(const char* name); void dropCapabilities(int8_t keep[] = NULL);