Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 3a78ccb

Browse files
rovo89wanam
authored andcommitted
Adjust SYSTEMSERVERCLASSPATH for HTC devices
They make use of a HtcDeviceInfoManager class from /system/framework/ub.jar in the ActivityManagerService. This works fine on odex'ed ROMs because the class is precompiled. But with Xposed, the odex file can't be used as-is and has to be recompiled before. This would be done later by the PackageManagerService, but then it's too late. As a solution, add ub.jar to the SYSTEMSERVERCLASSPATH if it exists. In the end, it's exactly that: A class which is used by the system server.
1 parent 547aae0 commit 3a78ccb

2 files changed

Lines changed: 36 additions & 12 deletions

File tree

xposed.cpp

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ bool initialize(bool zygote, bool startSystemServer, const char* className, int
104104
printRomInfo();
105105

106106
if (startSystemServer) {
107+
#if PLATFORM_SDK_VERSION >= 21
108+
htcAdjustSystemServerClassPath();
109+
#endif
107110
if (!xposed::service::startAll())
108111
return false;
109112
#if XPOSED_WITH_SELINUX
@@ -290,6 +293,23 @@ bool shouldIgnoreCommand(int argc, const char* const argv[]) {
290293
return false;
291294
}
292295

296+
/** Adds a path to the beginning of an environment variable. */
297+
static bool addPathToEnv(const char* name, const char* path) {
298+
char* oldPath = getenv(name);
299+
if (oldPath == NULL) {
300+
setenv(name, path, 1);
301+
} else {
302+
char newPath[4096];
303+
int neededLength = snprintf(newPath, sizeof(newPath), "%s:%s", path, oldPath);
304+
if (neededLength >= (int)sizeof(newPath)) {
305+
ALOGE("ERROR: %s would exceed %d characters", name, sizeof(newPath));
306+
return false;
307+
}
308+
setenv(name, newPath, 1);
309+
}
310+
return true;
311+
}
312+
293313
/** Add XposedBridge.jar to the Java classpath. */
294314
bool addJarToClasspath() {
295315
ALOGI("-----------------");
@@ -307,18 +327,9 @@ bool addJarToClasspath() {
307327
*/
308328

309329
if (access(XPOSED_JAR, R_OK) == 0) {
310-
char* oldClassPath = getenv("CLASSPATH");
311-
if (oldClassPath == NULL) {
312-
setenv("CLASSPATH", XPOSED_JAR, 1);
313-
} else {
314-
char classPath[4096];
315-
int neededLength = snprintf(classPath, sizeof(classPath), "%s:%s", XPOSED_JAR, oldClassPath);
316-
if (neededLength >= (int)sizeof(classPath)) {
317-
ALOGE("ERROR: CLASSPATH would exceed %d characters", sizeof(classPath));
318-
return false;
319-
}
320-
setenv("CLASSPATH", classPath, 1);
321-
}
330+
if (!addPathToEnv("CLASSPATH", XPOSED_JAR))
331+
return false;
332+
322333
ALOGI("Added Xposed (%s) to CLASSPATH", XPOSED_JAR);
323334
return true;
324335
} else {
@@ -327,6 +338,16 @@ bool addJarToClasspath() {
327338
}
328339
}
329340

341+
#if PLATFORM_SDK_VERSION >= 21
342+
/** On HTC ROMs, ensure that ub.jar is compiled before the system server is started. */
343+
void htcAdjustSystemServerClassPath() {
344+
if (access("/system/framework/ub.jar", F_OK) != 0)
345+
return;
346+
347+
addPathToEnv("SYSTEMSERVERCLASSPATH", "/system/framework/ub.jar");
348+
}
349+
#endif
350+
330351
/** Callback which checks the loaded shared libraries for libdvm/libart. */
331352
static bool determineRuntime(const char** xposedLibPath) {
332353
FILE *fp = fopen("/proc/self/maps", "r");

xposed.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ namespace xposed {
4545
bool shouldSkipSafemodeDelay();
4646
bool shouldIgnoreCommand(int argc, const char* const argv[]);
4747
bool addJarToClasspath();
48+
#if PLATFORM_SDK_VERSION >= 21
49+
void htcAdjustSystemServerClassPath();
50+
#endif
4851
void onVmCreated(JNIEnv* env);
4952
void setProcessName(const char* name);
5053
void dropCapabilities(int8_t keep[] = NULL);

0 commit comments

Comments
 (0)