反思访问高级电话function

我正在尝试使用reflection访问电话API的一些未发布的function。 目前我遇到麻烦实例化一个serviceManager对象,需要获得“电话”服务作为活页夹,然后我可以用来实例化一个电话对象,这是需要打电话,结束通话等…

目前正在打电话

 serviceManagerObject = tempInterfaceMethod.invoke(null, new Object[] { new Binder() }); 

它返回一个nullPointerException。 我相信这与创build一个新的活页夹有关,而不是发送适当的活页夹(我不确定哪一个是合适的)

 public void placeReflectedCall() throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException, InstantiationException { String serviceManagerName = "android.os.IServiceManager"; String serviceManagerNativeName = "android.os.ServiceManagerNative"; String telephonyName = "com.android.internal.telephony.ITelephony"; Class telephonyClass; Class telephonyStubClass; Class serviceManagerClass; Class serviceManagerStubClass; Class serviceManagerNativeClass; Class serviceManagerNativeStubClass; Method telephonyCall; Method telephonyEndCall; Method telephonyAnswerCall; Method getDefault; Method[] temps; Constructor[] serviceManagerConstructor; // Method getService; Object telephonyObject; Object serviceManagerObject; String number = "1111111111"; telephonyClass = Class.forName(telephonyName); telephonyStubClass = telephonyClass.getClasses()[0]; serviceManagerClass = Class.forName(serviceManagerName); serviceManagerNativeClass = Class.forName(serviceManagerNativeName); Method getService = // getDefaults[29]; serviceManagerClass.getMethod("getService", String.class); Method tempInterfaceMethod = serviceManagerNativeClass.getMethod( "asInterface", IBinder.class); // this does not work serviceManagerObject = tempInterfaceMethod.invoke(null, new Object[] { new Binder() }); IBinder retbinder = (IBinder) getService.invoke(serviceManagerObject, "phone"); Method serviceMethod = telephonyStubClass.getMethod("asInterface", IBinder.class); telephonyObject = serviceMethod .invoke(null, new Object[] { retbinder }); telephonyCall = telephonyClass.getMethod("call", String.class); telephonyEndCall = telephonyClass.getMethod("endCall"); telephonyAnswerCall = telephonyClass.getMethod("answerRingingCall"); telephonyCall.invoke(telephonyObject, number); } 

Solutions Collecting From Web of "反思访问高级电话function"

通过以下操作

 Binder tmpBinder = new Binder(); tmpBinder.attachInterface(null, "fake"); serviceManagerObject = tempInterfaceMethod.invoke(null, new Object[] { tmpBinder }); 

你会得到一个ServiceManagerProxy实例,然后下一个问题发生在线上

 telephonyCall.invoke(telephonyObject, number); 

我有一个解决scheme。 更改:

 String serviceManagerName = "android.os.IServiceManager"; 

至:

 String serviceManagerName = "android.os.ServiceManager"; 

是的,这是可能的! 我花了24小时进行调查和发现,并find了“新鲜”的解决scheme!

 // "cheat" with Java reflection to gain access to // TelephonyManager's ITelephony getter Class c = Class.forName(tm.getClass().getName()); Method m = c.getDeclaredMethod("getITelephony"); m.setAccessible(true); telephonyService = (ITelephony) m.invoke(tm); 

任何想要开发呼叫控制软件的人都可以访问这个起点:
http://www.google.com/codesearch/p?hl=en#zvQ8rp58BUs/trunk/phone/src/i4nc4mp/myLock/phone/CallPrompt.java&q=itelephony%20package:http://mylockforandroid%5C.googlecode% 5C.com&d = 0

有一个项目。 并有重要的评论(和学分)。

简而言之:复制aidl文件,为清单添加权限,复制粘贴电话pipe理源。

一些更多信息给你:如果你是根植的,你只能发送AT命令。 然后,您可以终止系统进程并发送命令,但您需要重新启动以允许您的电话接收和发送呼叫。

我很开心! 现在我的Shake2MuteCall会得到一个更新!