title: ITelephony.endCall() doesn't work anymore for blocking calls in Android 8/Android O/API 26
body: <p>I have an app that uses the following code to block calls:</p>
  
  <pre><code>TelephonyManager telephonyManager = 
      (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
  
  try {
      Class&lt;?&gt; telephonyManagerClass = 
          Class.forName(telephonyManager.getClass().getName());
      Method getITelephonyMethod = 
          telephonyManagerClass.getDeclaredMethod("getITelephony");
      getITelephonyMethod.setAccessible(true);
      Object iTelephony = getITelephonyMethod.invoke(telephonyManager);
      Class&lt;?&gt; iTelephonyClass = Class.forName(iTelephony.getClass().getName());
      Method endCallMethod = iTelephonyClass.getDeclaredMethod("endCall");
      endCallMethod.setAccessible(true);
      endCallMethod.invoke(iTelephony);
  } catch (ClassNotFoundException e) {
      // ClassNotFoundException
  } catch (NoSuchMethodException e) {
      // NoSuchMethodException
  } catch (IllegalAccessException e) {
      // IllegalAccessException
  } catch (InvocationTargetException e) {
      // InvocationTargetException
  } catch (Exception e) {
      // Some other exception
  }
  </code></pre>
  
  <p>To work, this required android.permission.MODIFY_PHONE_STATE in AndroidManifest.xml. In Android M and N, I also had to ask the user for permission Manifest.permission.CALL_PHONE.</p>
  
  <p>But now in Android 8/Android O, the above code fails with InvocationTargetException: MODIFY_PHONE_STATE permission required</p>
  
  <p>I found this related StackOverflow post: <a href="https://stackoverflow.com/questions/21584372/android-why-does-endcall-method-work-but-answerringingcall-doesnt-work">Android - Why does endCall method work but answerRingingCall doesn&#39;t work?</a></p>
  
  <p>Here it is suggested that I might be able to use reflection on PhoneInterfaceManager (instead of ITelephony, like I have done above) and use the private method sendRequestAsync(int command) with the end call command, and by doing this getting around the security measure inside the endCall() method.</p>
  
  <p>Has anyone tried something like this? Is it possible? How would I even get the PhoneInterfaceManager object/class instead of ITelephony?</p>
  
  <p>I think this is the source code in question: <a href="https://android.googlesource.com/platform/packages/services/Telephony/+/oreo-release/src/com/android/phone/PhoneInterfaceManager.java" rel="noreferrer">https://android.googlesource.com/platform/packages/services/Telephony/+/oreo-release/src/com/android/phone/PhoneInterfaceManager.java</a></p>
  
  <p>I can't see any difference between this and the code for Android N when it comes to ending calls, so I might be mistaken:
  <a href="https://android.googlesource.com/platform/packages/services/Telephony/+/nougat-release/src/com/android/phone/PhoneInterfaceManager.java" rel="noreferrer">https://android.googlesource.com/platform/packages/services/Telephony/+/nougat-release/src/com/android/phone/PhoneInterfaceManager.java</a></p>