Reputation: 41
I intend to write tests related to the Phone and Direct SIM write.
What are the alternatives in case the required APIs aren't exposed in TelephonyManager but exist as private APIs in PhoneBase.java
, PhoneFactory.java
or CommandInterface.java
?
Specifically, my questions are:
PhoneFactory.getDefaultPhone()
?CommandsInterface
(e.g.: CommandsInterface mCmdIf = ((PhoneBase)mPhone).mCM
)?Thanks in advance,
Micha
Upvotes: 4
Views: 3638
Reputation: 12548
You can use java reflection
.
Here is how I accessed methods of com.android.internal.telephony.ITelephony
class to block an incoming call ...
private void endCall() throws Exception {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Class<?> c = Class.forName(tm.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
ITelephony telephonyService = (ITelephony) m.invoke(tm);
telephonyService.silenceRinger();
telephonyService.endCall();
Toast.makeText(context, "Call Ended !", Toast.LENGTH_SHORT).show();
}
Upvotes: 6