rovo89 / XposedBridge

The Java part of the Xposed framework.
3.91k stars 1.1k forks source link

help, anyway to make custom service get by servicemanager ? #66

Closed gnastnosaj closed 9 years ago

gnastnosaj commented 9 years ago
    XposedHelpers.findAndHookMethod("android.os.ServiceManager", (ClassLoader) null, "getService", new Object[]{String.class, new XC_MethodHook() {
        protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
            String EmmMangerServiceName = "EmmMangerService";
            String serviceName = (String) param.args[0];
            if (serviceName.equals(EmmMangerServiceName)) {
                if(binder == null) {
                    AndroidAppHelper.currentApplication().bindService(new Intent("EmmMangerService"),
                        new ServiceConnection() {
                            public void onServiceDisconnected(ComponentName name) {
                            }

                            public void onServiceConnected(ComponentName name, IBinder service) {
                                binder = service;
                                param.setResult(binder);
                            }
                        }, 1);
                }
            }
        }
    }});