[Xposed General] toni.xda:
Hello folks,

the audio jack connector of my phone sporadically wrongly detects a plugged in headphone. I guess it's a hardware issue but for me, the detection feature isn't worth the pain replacing the jack.

Until now I was able to fix this problem with pressured air or a small needle. But this is a rather ugly and only temporary fix.

A more favorable idea is to make this thing software controllable. I searched for some apps but nothing seemed to do the job right.

So I'm going to try to create something for that, and I took a dive into the Android development ecosystem.

So I found in services/core/java/com/android/server/WiredAccessoryManager.java the method

public void notifyWiredAccessoryChanged(long whenNanos, int switchValues, int switchMask) which seems to do the detection job in a fine abstraction level.

Now I'm trying to hook this method with Xposed and manipulate the parameters before the call.

But my first try didn't detect the package and was not installing the hooks:

public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
if (!lpparam.packageName.equals("com.android.server"))
return;

XposedBridge.log("add hooks in com.android.server...");

findAndHookMethod("com.android.server.WiredAccessoryManager", lpparam.classLoader, "notifyWiredAccessoryChanged", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("<beforeHookedMethod> com.android.server.WiredAccessoryManager.notifyWiredAccessoryChanged(...)");
}
});
}

After some logging and grepping I found the class in the system_server process on my phone:

06-26 12:54:10.964 2709 2963 V WiredAccessoryManager: notifyWiredAccessoryChanged: when=352445121000 bits= mask=c0
06-26 12:54:10.965 2709 2963 V WiredAccessoryManager: newName=h2w newState=32 headsetState=32 prev headsetState=0
06-26 12:54:10.965 2709 2963 I WiredAccessoryManager: MSG_NEW_DEVICE_STATE
06-26 12:54:10.966 2709 2709 V WiredAccessoryManager: headsetName: connected

06-26 12:54:44.811 2709 2963 V WiredAccessoryManager: notifyWiredAccessoryChanged: when=386292110000 bits= mask=c0
06-26 12:54:44.812 2709 2963 V WiredAccessoryManager: newName=h2w newState=0 headsetState=0 prev headsetState=32
06-26 12:54:44.812 2709 2963 I WiredAccessoryManager: MSG_NEW_DEVICE_STATE
06-26 12:54:44.813 2709 2709 V WiredAccessoryManager: headsetName: disconnected

system 2709 2019 5421616 288988 SyS_epoll+ 0 S system_server

My guess is that this process is started before the handleLoadPackage hook is available, so I changed code to the earlier entry point:

public void initZygote (IXposedHookZygoteInit.StartupParam startupParam) {
XposedBridge.log("we are in initZygote...");

findAndHookMethod("com.android.server.WiredAccessoryManager", null, "notifyWiredAccessoryChanged", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log("<beforeHookedMethod> com.android.server.WiredAccessoryManager.notifyWiredAccessoryChanged(...)");
}
});
}

But with this method I only getting a ClassNotFoundException: com.android.server.WiredAccessoryManager

Before I continue to search countless more hours, I'd like to ask if somebody here knows if hooking the system_server class is possible with Xposed.

Thanks in advance!

Btw: Sorry for posting here but I cannot start a thread in Xposed Framework Development or pm the moderator about this.