java 反射访问高级电话功能
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2001146/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Reflection to access advanced telephony features
提问by tsmith
I am trying to use reflection to access some unpublished features of the telephony API. Currently I am having trouble instantiating a serviceManagerobject that is needed to get the "phone" service as a binder which I can then use to instantiate a telephony object which is needed to make a call, end call, etc...
我正在尝试使用反射来访问电话 API 的一些未发布的功能。目前,我在实例化serviceManager获取“电话”服务所需的对象作为绑定器时遇到问题,然后我可以使用它来实例化拨打电话、结束通话等所需的电话对象...
currently when I make the call
目前当我打电话时
serviceManagerObject = tempInterfaceMethod.invoke(null, new Object[] { new Binder() });
it returns a nullPointerException. I believe this has to do with creating a new Binder instead of sending the appropriate binder (which I am unsure of which one is appropriate)
它返回一个 nullPointerException。我相信这与创建一个新的 Binder 而不是发送适当的 Binder(我不确定哪个是合适的)有关
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);
}
回答by david
By doing the following
通过执行以下操作
Binder tmpBinder = new Binder();
tmpBinder.attachInterface(null, "fake");
serviceManagerObject = tempInterfaceMethod.invoke(null, new Object[] { tmpBinder });
you will get a ServiceManagerProxy instance, then the next issue happens on the line
你会得到一个ServiceManagerProxy实例,然后下一个问题就行了
telephonyCall.invoke(telephonyObject, number);
回答by brad
I have a solution. Change:
我有一个解决方案。改变:
String serviceManagerName = "android.os.IServiceManager";
to:
到:
String serviceManagerName = "android.os.ServiceManager";
回答by foryou
Yes, it's possible! I spent 24 hours of investigating and discovering, and I've found "fresh" solution!
是的,这是可能的!我花了24小时的调查和发现,我找到了“新鲜”的解决方案!
// "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);
Anyone who wants to develop their call-control software visit this start point:
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
任何想要开发他们的呼叫控制软件的人请访问这个起点: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
There is a project. and there are important comments (and credits).
有一个项目。并且有重要的评论(和学分)。
In short: copy aidl file, add permissions to manifest, copy-paste source for telephony management.
简而言之:复制aidl文件,添加清单权限,复制粘贴电话管理源。
Some more info for you: You can only send AT commands if you are rooted. Then you can kill system process and send commands but you will need a reboot to allow your phone to receive and send calls.
给你的更多信息:如果你是 root,你只能发送 AT 命令。然后您可以终止系统进程并发送命令,但您需要重新启动才能让您的手机接收和发送呼叫。
I'm very happy! Now my Shake2MuteCall will get an update!
我很开心!现在我的 Shake2MuteCall 将获得更新!

