我正在尝试使用反射来访问电话API的一些未发布的功能.目前我无法实例化serviceManager将"电话"服务作为活页夹所需的对象,然后我可以使用该对象来实例化拨打电话,结束通话等所需的电话对象......
目前我打电话的时候
serviceManagerObject = tempInterfaceMethod.invoke(null, new Object[] { new Binder() });
Run Code Online (Sandbox Code Playgroud)
它返回nullPointerException.我相信这与创建一个新的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);
}
Run Code Online (Sandbox Code Playgroud)
通过执行以下操作
Binder tmpBinder = new Binder();
tmpBinder.attachInterface(null, "fake");
serviceManagerObject = tempInterfaceMethod.invoke(null, new Object[] { tmpBinder });
Run Code Online (Sandbox Code Playgroud)
您将获得一个ServiceManagerProxy实例,然后下一个问题就行了
telephonyCall.invoke(telephonyObject, number);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16147 次 |
| 最近记录: |