当前位置: 首页 > news >正文

Android framework 编程之 - Binder调用方UID

注:不要弄混 uid 和 userID 的区别。

1. 获取Binder 调用方UID

	Binder.getCallingUid/*** Return the Linux UID assigned to the process that sent you the* current transaction that is being processed. This UID can be used with* higher-level system services to determine its identity and check* permissions. If the current thread is not currently executing an* incoming transaction, then its own UID is returned.*/@CriticalNative@android.ravenwood.annotation.RavenwoodReplacepublic static final native int getCallingUid();

2. 判断UID 是否是特殊UID

例如判断是否是System UID

uid == Process.SYSTEM_UID

特殊 UID 的列表
这里仅仅列出一部分
frameworks/base/core/java/android/os/Process.java

    /*** An invalid UID value.*/public static final int INVALID_UID = -1;/*** Defines the root UID.*/public static final int ROOT_UID = 0;/*** Defines the UID/GID under which system code runs.*/public static final int SYSTEM_UID = 1000;/*** Defines the UID/GID under which the telephony code runs.*/public static final int PHONE_UID = 1001;/*** Defines the UID/GID for the user shell.*/public static final int SHELL_UID = 2000;

将 Binder 调用方 UID 变为本地 UID ,豁免部分权限检查

	// 将调用标识变为本地进程,相对于System Server 就是 system server 进程final long token = Binder.clearCallingIdentity();try {// 权限检查的是本地进程。} finally {// 将调用标识变为非本地标识Binder.restoreCallingIdentity(token);}

http://www.mrgr.cn/news/19477.html

相关文章:

  • 5月,我面试60多号人,才发现很多人没有这项能力
  • 国产统信UOS桌面操作系统安装网络打印机
  • 代码随想录算法训练营第七天|LeetCode 334.反转字符串、541反转字符串II、151反转字符串中的单词
  • Unknown command: “create-react-app“
  • 【大模型相关】
  • python 生成随机密码
  • 24.9.3学习心得
  • GEE APP——Bellingcat 雷达影像监测平台分析
  • 工具方法 - 如何对他人表示尊重
  • 集团企业主数据管理项目实施步骤及要点
  • Jetpack之Room操作数据库
  • 中锂天源:驻车电源,让出行更安心
  • 更懂消费者 火山引擎数据飞轮助力乳企数智升级
  • 浅谈人工智能之VSCode:使用插件与ollama本地大模型交互
  • 【LabVIEW学习篇(补充) - 15】:常用快捷键和Quick Drop
  • ArkUI-状态管理最佳实践
  • 龙兴物联5G物联网主机:开启电力智能化新篇章
  • Java MVC
  • 基于人工智能的垃圾分类系统
  • Elasticsearch在高并发下如何保证读写一致性