1

I would like to make use of android.permission.MODIFY_PHONE_STATE on Android Lollipop by auto-answering a call, much like some of the hands-free "driver assist" apps that are available on the Play Store.

I found some code from the AutoAnswer project, but when I run it, I get a InvocationTargetException stating that "neither the user #### nor the application has MODIFY_PHONE_STATE permissions."

However, in my Manifest I have: <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" /> and I have installed my apk into /system/app/AutoAnswer.apk and set it's permissions to 644.

The requirement is that I don't need a phone to be rooted in order for it to work, but I do have the ability to add my application to the custom ROM (so it is a system app).

The calling code looks like this:

        TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
        Class c = Class.forName(tm.getClass().getName());
        Method m = c.getDeclaredMethod("getITelephony");
        m.setAccessible(true);
        Object telephonyService = m.invoke(tm);

        Method m1 = telephonyService.getClass().getMethod("silenceRinger");
        Method m2 = telephonyService.getClass().getMethod("answerRingingCall");

        //m1.invoke(telephonyService); // not supported for OnePlus2
        m2.invoke(telephonyService); // <- This is the line that throws the error

Why is it not allowing me to use MODIFY_PHONE_STATE from my system app..? Is there a workaround?

tommed
  • 1,521
  • 2
  • 19
  • 33
  • 1
    Does it signed by same signature, which was used to sign your ROM? Both should be signed by same. Pushing apk into /system/ is not enaugh to make application as system app. – Pankaj Kumar Sep 30 '15 at 14:30
  • No it wasn't signed using the same signature. MODIFY_PHONE_STATE is marked as "signatureOrSystem" so I read this as either signed by the same signature OR is run from a system app..? https://android.googlesource.com/platform/frameworks/base/+/f4ece2086f3b7060edc4b93a12f04c9af648867a%5E!/ – tommed Sep 30 '15 at 14:32

1 Answers1

1

For a work around you may wish to check out How can incoming calls be answered programmatically in Android 5.0 (Lollipop)?

If getting explicit grant of Notification access from the user is ok then you can check out my answer there which worked for me under Android 5.0 and 5.1.

Community
  • 1
  • 1
headuck
  • 2,763
  • 16
  • 19