UiAutomator automated test scripts hang up the phone

 
 
In the context of the instance constructor
	this.targetContext=InstrumentationRegistry.getTargetContext();
    public void hangUpCommand() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        TelephonyManager telephonyManager = (TelephonyManager)targetContext.getSystemService(Context.TELEPHONY_SERVICE);
        Class<TelephonyManager> c = TelephonyManager.class;
        Method mthEndCall = c.getDeclaredMethod("getITelephony",(Class[])null);
        mthEndCall.setAccessible(true);
        final Object obj = mthEndCall.invoke(telephonyManager,(Object[])null);
        Method mt = obj.getClass().getMethod("endCall");
        mt.setAccessible(true);
        mt.invoke(obj);
    }

Guess you like

Origin blog.csdn.net/xyd_113/article/details/76716106
Recommended