android user用户版本提高adb权限

Posted 请给我倒杯茶

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
 
  1. static int should_drop_privileges() {  
  2. #ifndef ALLOW_ADBD_ROOT  
  3.     return 1;  
  4. #else /* ALLOW_ADBD_ROOT */  
  5.     int secure = 0;  
  6.     char value[PROPERTY_VALUE_MAX];  
  7.   
  8.    /* run adbd in secure mode if ro.secure is set and 
  9.     ** we are not in the emulator 
  10.     */  
  11.     property_get("ro.kernel.qemu", value, "");  
  12.     if (strcmp(value, "1") != 0) {  
  13.         property_get("ro.secure", value, "1");  
  14.         if (strcmp(value, "1") == 0) {  
  15.             // don‘t run as root if ro.secure is set...  
  16.             secure = 1;  
  17.   
  18.             // ... except we allow running as root in userdebug builds if the  
  19.             // service.adb.root property has been set by the "adb root" command  
  20.             property_get("ro.debuggable", value, "");  
  21.             if (strcmp(value, "1") == 0) {  
  22.                 property_get("service.adb.root", value, "");  
  23.                 if (strcmp(value, "1") == 0) {  
  24.                     secure = 0;  
  25.                 }  
  26.             }  
  27.         }  
  28.     }  
  29.     return secure;  
  30. #endif /* ALLOW_ADBD_ROOT */  
  31. }  


具体怎么降低权限:

[cpp] view plain copy
 
    1. if (should_drop_privileges()) {  
    2.     struct __user_cap_header_struct header;  
    3.     struct __user_cap_data_struct cap;  
    4.   
    5.     if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) != 0) {  
    6.         exit(1);  
    7.     }  
    8.   
    9.     /* add extra groups: 
    10.     ** AID_ADB to access the USB driver 
    11.     ** AID_LOG to read system logs (adb logcat) 
    12.     ** AID_INPUT to diagnose input issues (getevent) 
    13.     ** AID_INET to diagnose network issues (netcfg, ping) 
    14.     ** AID_GRAPHICS to access the frame buffer 
    15.     ** AID_NET_BT and AID_NET_BT_ADMIN to diagnose bluetooth (hcidump) 
    16.     ** AID_SDCARD_R to allow reading from the SD card 
    17.     ** AID_SDCARD_RW to allow writing to the SD card 
    18.     ** AID_MOUNT to allow unmounting the SD card before rebooting 
    19.     ** AID_NET_BW_STATS to read out qtaguid statistics 
    20.     */  
    21.     gid_t groups[] = { AID_ADB, AID_LOG, AID_INPUT, AID_INET, AID_GRAPHICS,  
    22.                        AID_NET_BT, AID_NET_BT_ADMIN, AID_SDCARD_R, AID_SDCARD_RW,  
    23.                        AID_MOUNT, AID_NET_BW_STATS };  
    24.     if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) {  
    25.         exit(1);  
    26.     }  
    27.   
    28.     /* then switch user and group to "shell" */  
    29.     if (setgid(AID_SHELL) != 0) {  
    30.         exit(1);  
    31.     }  
    32.     if (setuid(AID_SHELL) != 0) {  
    33.         exit(1);  
    34.     }  
    35.   
    36.     /* set CAP_SYS_BOOT capability, so "adb reboot" will succeed */  
    37.     header.version = _LINUX_CAPABILITY_VERSION;  
    38.     header.pid = 0;  
    39.     cap.effective = cap.permitted = (1 << CAP_SYS_BOOT);  
    40.     cap.inheritable = 0;  
    41.     capset(&header, &cap);  
    42.   
    43.     D("Local port disabled\n");  
    44. }  

以上是关于android user用户版本提高adb权限的主要内容,如果未能解决你的问题,请参考以下文章

android MTK平台 user/eng 版本的差别

Android adb调试

android user 版本如何默认adb调试为打开

shell脚本

android系统如何通过$ adb 来获得/data/data目录的访问权限

adb remount 权限被拒绝,但能够在 shell 中访问超级用户 -- android