Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Intent from PendingIntent causes SecurityException

We have some old code that worked for a long time:

public static Intent getIntent(PendingIntent pendingIntent) {
    Intent intent = null;
    try {
        Method getIntent = PendingIntent.class.getDeclaredMethod("getIntent");
        intent = (Intent) getIntent.invoke(pendingIntent);
    } catch (Exception e) {
        // Log line
    }
    return intent;
}

We are now getting a security exception:

java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at com.company.util.IntentUtils.getIntent(IntentUtils.java:160)
Caused by: java.lang.SecurityException: Permission Denial: getIntentForIntentSender() from pid=28128, uid=10127 requires android.permission.GET_INTENT_SENDER_INTENT
    at android.os.Parcel.readException(Parcel.java:1683)
    at android.os.Parcel.readException(Parcel.java:1636)
    at android.app.ActivityManagerProxy.getIntentForIntentSender(ActivityManagerNative.java:5924)
    at android.app.PendingIntent.getIntent(PendingIntent.java:987)
    ... 17 more

Looks like it might be related to AOSP change: https://android.googlesource.com/platform/frameworks/base/+/e5ad41b%5E!/

Any help getting the intend would be appreciated.

like image 673
Andrew Avatar asked Feb 22 '17 20:02

Andrew


People also ask

How does Pending Intent work?

A PendingIntent itself is simply a reference to a token maintained by the system describing the original data used to retrieve it. This means that, even if its owning application's process is killed, the PendingIntent itself will remain usable from other processes that have been given it.

What is pending intent in notification?

Android PendingIntent In other words, PendingIntent lets us pass a future Intent to another application and allow that application to execute that Intent as if it had the same permissions as our application, whether or not our application is still around when the Intent is eventually invoked.

What is pending intent request code?

1- requestCode is used to get the same pending intent later on (for cancelling etc) 2- Yes, they will get override as long as your specify the same Receiver to your Intent that you specify on your PendingIntent.


1 Answers

There's no workaround: as per the error message and commit, that hidden method that was never part of the public API now requires a signature permission that only apps that are signed with the system signature can hold.

like image 186
ianhanniballake Avatar answered Oct 03 '22 14:10

ianhanniballake