Android - Why does endCall method work but answerRingingCall doesn't work?

匿名 (未验证) 提交于 2019-12-03 01:34:02

问题:

I use the following code to handle incoming calls from within a service. It works perfectly when i invode the endCall method (My phone's Android Version is ICS). But when I invoke the answerRingingCall method i get an exception for not having permission to modify phone state. I know that Google revoked this permission at one point but since i can invoke the end call method what is the explanation for not being able to invoke the answer call method as well? I mean..both methods modify the phone's state, so what's up? Is there a way to fix this?

   try {         TelephonyManager tm = (TelephonyManager)getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);         Class c = Class.forName(tm.getClass().getName());         Method m = c.getDeclaredMethod("getITelephony");         m.setAccessible(true);         Object telephonyService = m.invoke(tm); // Get the internal ITelephony object         c = Class.forName(telephonyService.getClass().getName()); // Get its class         m = c.getDeclaredMethod("endCall"); // Get the "endCall()" method         m.setAccessible(true); // Make it accessible         m.invoke(telephonyService); // invoke endCall()     }     catch (Exception e) {         Log.w("exception",e);     } 

回答1:

If I had to guess, I'd say in your OEM version of com.android.phone.PhoneInterfaceManager inside the Phone.apk the endCall function doesn't call enforceCallPermission(); before sending the request to end the call.

Where as in the answerRingingCall function calls enforceCallPermission();

You could try a hack where you get access the the private method, on the ITelephony object, sendRequestAsync set accessible to true, and then call it with 4 as the input param, aka CMD_ANSWER_RINGING_CALL.

This would avoid the permissions check.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!