Get Intent from PendingIntent causes SecurityException

佐手、 提交于 2019-12-24 01:56:14

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/42401911/get-intent-from-pendingintent-causes-securityexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!