今日长缨在手,何时缚住苍龙。这篇文章主要讲述android user用户版本提高adb权限相关的知识,希望能为你提供帮助。
本文转载自:http://blog.csdn.net/liyongming1982/article/details/14108111
有的user用户版本的log 不全,且push/pull某些文件或者属性文件
常常会遇到权限不够的情况,给调试带来很多便:
对于user 版本adb shell 开启的还是shell 权限,而不是root 权限,
如果您需要root 权限,需要再改一下system/core/adb/adb.c 里面的should_drop_privileges()
这个函数,在#ifndef ALLOW_ADBD_ROOT 时return 0;
而不是return 1;
即可。
判断是否降低权限:
[cpp]
view plain
copy
- static int should_drop_privileges() {
- #ifndef ALLOW_ADBD_ROOT
- return 1;
- #else /* ALLOW_ADBD_ROOT */
- int secure = 0;
- char value[PROPERTY_VALUE_MAX];
- /* run adbd in secure mode if ro.secure is set and
- ** we are not in the emulator
- */
- property_get("ro.kernel.qemu", value, "");
- if (strcmp(value, "1") != 0) {
- property_get("ro.secure", value, "1");
- if (strcmp(value, "1") == 0) {
- // don‘t run as root if ro.secure is set...
- secure = 1;
- // ... except we allow running as root in userdebug builds if the
- // service.adb.root property has been set by the "adb root" command
- property_get("ro.debuggable", value, "");
- if (strcmp(value, "1") == 0) {
- property_get("service.adb.root", value, "");
- if (strcmp(value, "1") == 0) {
- secure = 0;
- }
- }
- }
- }
- return secure;
- #endif /* ALLOW_ADBD_ROOT */
- }
具体怎么降低权限:
[cpp] view plain copy
- if (should_drop_privileges()) {
- struct __user_cap_header_struct header;
- struct __user_cap_data_struct cap;
- if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) != 0) {
- exit(1);
- }
- /* add extra groups:
- ** AID_ADB to access the USB driver
- ** AID_LOG to read system logs (adb logcat)
- ** AID_INPUT to diagnose input issues (getevent)
- ** AID_INET to diagnose network issues (netcfg, ping)
- ** AID_GRAPHICS to access the frame buffer
- ** AID_NET_BT and AID_NET_BT_ADMIN to diagnose bluetooth (hcidump)
- ** AID_SDCARD_R to allow reading from the SD card
- ** AID_SDCARD_RW to allow writing to the SD card
- ** AID_MOUNT to allow unmounting the SD card before rebooting
- ** AID_NET_BW_STATS to read out qtaguid statistics
- */
- gid_t groups[] = { AID_ADB, AID_LOG, AID_INPUT, AID_INET, AID_GRAPHICS,
- AID_NET_BT, AID_NET_BT_ADMIN, AID_SDCARD_R, AID_SDCARD_RW,
- AID_MOUNT, AID_NET_BW_STATS };
- if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) {
- exit(1);
- }
- /* then switch user and group to "shell" */
- if (setgid(AID_SHELL) != 0) {
- exit(1);
- }
- if (setuid(AID_SHELL) != 0) {
- exit(1);
- }
- /* set CAP_SYS_BOOT capability, so "adb reboot" will succeed */
- header.version = _LINUX_CAPABILITY_VERSION;
- header.pid = 0;
- cap.effective = cap.permitted = (1 < < CAP_SYS_BOOT);
- cap.inheritable = 0;
- capset(& header, & cap);
- D("Local port disabled\n");
- }
推荐阅读
- 安卓开发——定位管理
- android user 版本如何默认adb调试为打开
- spring-boot application.properties设置最全指南
- Android系统设置Android adb 开关的方法
- 关于如何在Visual Studio上仿真调试安卓的U3D应用
- android SDK安装配置
- 张高兴的 Xamarin.Forms 开发笔记(Android 快捷方式 Shortcut 应用)
- 激活win8.1系统过程中需要访问验证微软服务器怎样办
- win8系统中如何刻录光盘?win8系统刻录光盘的3个步骤