问题描述
我想使用反射来访问电话API的一些未公开的功能。目前,我有麻烦实例化是需要获得手机服务为粘合剂,然后我就可以用它来实例化哪一个是需要做出一个电话对象的ServiceManager
对象一个电话,结束通话,等...
目前,当我打这个电话
serviceManagerObject = tempInterfaceMethod.invoke(空,新的对象[] {新活页夹()});
它返回一个NullPointerException异常。我相信这是同创建一个新的活页夹,而不是发送相应的粘合剂(我不能确定哪一个是合适的)
公共无效placeReflectedCall()抛出ClassNotFoundException异常,
SecurityException异常,NoSuchMethodException,抛出:IllegalArgumentException,
IllegalAccessException,的InvocationTargetException,
InstantiationException {
字符串serviceManagerName =android.os.IServiceManager;
字符串serviceManagerNativeName =android.os.ServiceManagerNative;
字符串telephonyName =com.android.internal.telephony.ITelephony;
类telephonyClass;
类telephonyStubClass;
类serviceManagerClass;
类serviceManagerStubClass;
类serviceManagerNativeClass;
类serviceManagerNativeStubClass;
方法telephonyCall;
方法telephonyEndCall;
方法telephonyAnswerCall;
方法getDefault;
方法[]临时工;
构造函数[] serviceManagerConstructor;
//方法GetService;
对象telephonyObject;
对象serviceManagerObject;
串号=1111111111;
telephonyClass =的Class.forName(telephonyName);
telephonyStubClass = telephonyClass.getClasses()[0];
serviceManagerClass =的Class.forName(serviceManagerName);
serviceManagerNativeClass =的Class.forName(serviceManagerNativeName);
方法GetService = // getDefaults所[29];
serviceManagerClass.getMethod(的getService,为String.class);
方法tempInterfaceMethod = serviceManagerNativeClass.getMethod(
asInterface,IBinder.class);
//这不起作用
serviceManagerObject = tempInterfaceMethod.invoke(空,
新对象[] {新活页夹()});
的IBinder retbinder =(的IBinder)getService.invoke(serviceManagerObject,
电话);
方法serviceMethod = telephonyStubClass.getMethod(asInterface
IBinder.class);
telephonyObject = serviceMethod
.invoke(空,新的对象[] {retbinder});
telephonyCall = telephonyClass.getMethod(呼,为String.class);
telephonyEndCall = telephonyClass.getMethod(结束呼叫);
telephonyAnswerCall = telephonyClass.getMethod(answerRingingCall);
telephonyCall.invoke(telephonyObject,数量);
}
执行以下操作
粘合剂tmpBinder =新活页夹();
tmpBinder.attachInterface(NULL,假货);
serviceManagerObject = tempInterfaceMethod.invoke(空,新的对象[] {tmpBinder});
您将得到一个ServiceManagerProxy实例,那么下一个问题就行发生
telephonyCall.invoke(telephonyObject,数量);
I am trying to use reflection to access some unpublished features of the telephony API. Currently I am having trouble instantiating a serviceManager
object 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...
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)
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 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
telephonyCall.invoke(telephonyObject, number);
这篇关于反射来访问先进的电话功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!