gpt4 book ai didi

android - getCallingUid/getCallingPid 在 Handler.handleMessage 中返回当前的 uid 和 pid

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:28:29 29 4
gpt4 key购买 nike

我有一个扩展 android.os.Handler 的类。此处理程序的一个实例被传递给 Messenger 的构造函数。来自 getBinderMessengerIBinder 作为我服务中的 onBind 事件的结果传递。从远程应用程序通过 Binder 发送的消息确实会转到处理程序的 handleMessage 方法,但是在 中调用 Binder.getCallingUidBinder.getCallingPid >handleMessage 始终返回服务进程的 uid 和 pid(这绝对不是远程应用程序的进程)。 handleMessage 绝对是 IPC 事务的一部分,不是吗?那么我哪里出错了?我需要它来对连接的应用程序进行身份验证。

提前致谢。

编辑

好的。我有一种可怕的感觉,即 handleMessage 不是 IPC 事务的一部分,因为这发生在 AIDL 的单独线程中,AIDL 将消息放入 Messenger 的队列中。有没有其他方法可以获取调用方的用户 ID 和进程 ID?

最佳答案

创建一个自定义的Handler类并覆盖sendMessageAtTime(这是Handler类中唯一可覆盖的发布方法),然后使用它创建从 onBind 返回的 Messenger

sendMessageAtTime方法中,可以通过getCallingPidgetCallingUid获取调用远程应用程序的pid/uid。

但是,在使用 Messenger 的 IPC 中,与使用 AIDL 相反,getCallingPid 将始终返回 0,因为远程应用程序发送的消息是异步的;与 IBinder.FLAG_ONEWAY 的交易。因此,uid 是唯一可用的信息。

关于android - getCallingUid/getCallingPid 在 Handler.handleMessage 中返回当前的 uid 和 pid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7309952/

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