gpt4 book ai didi

android - 为什么 NotificationManagerCompat::cancelAll() 得到 SecurityException?

转载 作者:IT老高 更新时间:2023-10-28 22:10:23 26 4
gpt4 key购买 nike

使用 NotificationManagerCompat 取消所有通知。

NotificationManagerCompat manager =  
NotificationManagerCompat.from(ctx.getApplicationContext());
manager.cancelAll();

它有时会出现异常(大部分时间都有效)。

在安卓 6 上:

java.lang.SecurityException: Permission Denial: getCurrentUser() from pid=22994, uid=10184 requires android.permission.INTERACT_ACROSS_USERS

Fatal Exception: java.lang.SecurityException: Permission Denial: getCurrentUser() from pid=22994, uid=10184 requires android.permission.INTERACT_ACROSS_USERS
at android.os.Parcel.readException(Parcel.java:1602)
at android.os.Parcel.readException(Parcel.java:1555)
at android.app.INotificationManager$Stub$Proxy.cancelAllNotifications(INotificationManager.java:649)
at android.app.NotificationManager.cancelAll(NotificationManager.java:323)
at android.support.v4.app.NotificationManagerCompat.cancelAll(NotificationManagerCompat.java:197)

在 Android 5.0、4.4.2 上:

ava.lang.SecurityException: Permission Denial: getIntentSender() from pid=5460, uid=10135, (need uid=1000) is not allowed to send as package android at android.os.Parcel.readException(Parcel.java:1465)

Fatal Exception: java.lang.SecurityException: Permission Denial: getIntentSender() from pid=3109, uid=10153, (need uid=1000) is not allowed to send as package android
at android.os.Parcel.readException(Parcel.java:1472)
at android.os.Parcel.readException(Parcel.java:1426)
at android.app.INotificationManager$Stub$Proxy.cancelAllNotifications(INotificationManager.java:271)
at android.app.NotificationManager.cancelAll(NotificationManager.java:220)
at android.support.v4.app.NotificationManagerCompat.cancelAll(NotificationManagerCompat.java:197)

问题:

  1. 可能是什么原因?
  2. 这里的 id 是什么?是 ctx.getApplicationContext().getApplicationInfo().uid 还是 android.os.Process.myUid()

最佳答案

答案并没有为问题提供可靠的解决方案,而是试图解释 OP 和 @66CLSjY 的原因。 ,谁提供了赏金,similar issue .


检查堆栈跟踪

根据堆栈跟踪 SecurityException 在远程进程中抛出:您的应用进程的 Binder 对象(例如 INotificationManager.StubActivityManagerProxy 等)makes a Binder transaction (mRemote.transact()) * 在远程 Binder 对象上并从对象中读取发生的异常 (_reply.readException())远程调用。如果有的话,exception message is analyzed and a corresponding exception is thrown在你的过程中。

分析异常消息

两个异常消息(一个带有 getIntentSender() 和另一个带有 getCurrentUser() 的消息)都非常简单 - 您的应用没有通过权限检查,或者换句话说,ActivityManagerService 的代码 fragment under the system_server process' identity 的 (UID=1000) **,但实际上被称为 under your app process' identity .

可能的原因和解决方法

It got exception some time (most time works).

不做任何假设,你得到的“一段时间”是不正确的Android行为。 Wrapping the problem call with try/catch在有人提出可靠的解决方案(如果存在)之前,这似乎是一种解决方法。


* ActivityManagerProxy.setRequestedOrientation()IAccessibilityManager$Stub$Proxy.sendAccessibilityEvent()
** android.permission.INTERACT_ACROSS_USERSsignature | system protection level

关于android - 为什么 NotificationManagerCompat::cancelAll() 得到 SecurityException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36634008/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com