3

I was using the code below to end a call. But now on Oreo, I'm getting an error which states that the MODIFY_PHONE_STATE permission is required and hence this code is no longer working.

  TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

                // Toast.makeText(context, "here", Toast.LENGTH_LONG).show();
                assert telephonyManager != null;
                Class clazz = Class.forName(telephonyManager.getClass().getName());
                Method method = clazz.getDeclaredMethod("getITelephony");
                method.setAccessible(true);
                ITelephony telephonyService;
                telephonyService = (ITelephony) method.invoke(telephonyManager);
                telephonyService.silenceRinger();
                telephonyService.endCall();

Furthermore, as per docs and many blogs, MODIFY_PHONE_STATE permission is valid for system apps only.
So now how we will end calls in future?
Is there any other way.

Error:

java.lang.SecurityException: MODIFY_PHONE_STATE permission required.
        at android.os.Parcel.readException(Parcel.java:2004)
        at android.os.Parcel.readException(Parcel.java:1950)
W/System.err:     at com.android.internal.telephony.ITelephony$Stub$Proxy.endCall(ITelephony.java:2025)
Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
Panache
  • 1,701
  • 3
  • 19
  • 33
  • I think downvoters should put comment for the same. just came silently and run away. – Panache Jun 02 '18 at 05:55
  • https://stackoverflow.com/questions/4715250/how-to-grant-modify-phone-state-permission-for-apps-ran-on-gingerbread?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Daisy Day Jun 02 '18 at 05:57

1 Answers1

1

Google is imposing lots of restrictions on what a App can do and cannot. Even if you managed to find some internal implementation and call through reflection, it won't help from Anddoid P which has enhanced mechanism to block these attempts.

Only way out is to build your own call app which will give you entire control over the call management. You can follow this official document which describes the process for building the app

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Sagar
  • 23,903
  • 4
  • 62
  • 62