本文转载自: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; 即可。

判断是否降低权限:

  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. /* run adbd in secure mode if ro.secure is set and
  8. ** we are not in the emulator
  9. */
  10. property_get("ro.kernel.qemu", value, "");
  11. if (strcmp(value, "1") != 0) {
  12. property_get("ro.secure", value, "1");
  13. if (strcmp(value, "1") == 0) {
  14. // don't run as root if ro.secure is set...
  15. secure = 1;
  16. // ... except we allow running as root in userdebug builds if the
  17. // service.adb.root property has been set by the "adb root" command
  18. property_get("ro.debuggable", value, "");
  19. if (strcmp(value, "1") == 0) {
  20. property_get("service.adb.root", value, "");
  21. if (strcmp(value, "1") == 0) {
  22. secure = 0;
  23. }
  24. }
  25. }
  26. }
  27. return secure;
  28. #endif /* ALLOW_ADBD_ROOT */
  29. }

具体怎么降低权限:

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

android user用户版本提高adb权限【转】的更多相关文章

  1. android 开发 实现多个动态权限的方法(并且兼容6.0以下的版本权限授权)

    android开发权限授权因为版本的不同有不同的授权方式,6.0以下的版本使用的是在注册表中添加权限的静态授权(这种授权权限提示只会出现在app安装的时候),而6.0以上(包含6.0)就需要动态授权的 ...

  2. android apk 的root 权限和USB adb 权限的差别

    USB adb 权限是指,当adb 连接手机时,手机中的守护进程adbd 的权限为root 权限,从而它的子进程也具有root 权限.通常假设adb shell 看到是: Android 4.0 以后 ...

  3. Vista之前的版本,默认本地登陆用户都以管理员权限启动程序

    Vista之前的版本,默认本地登陆用户都以管理员权限启动程序,之后的OS版本默认都没有管理员权限,需要用户提权才能做某些操作,否则需要管理员权限的操作都会失败MSSQL是用户名账号连接,Socket方 ...

  4. Android P(9.0) userdebug版本执行adb remount失败

    [DESCRIPTION]      在android P版本上如果按照“FAQ18076 android 6.0 M userdebug版本执行adb remount失败”的做法在userdebug ...

  5. Android 6.0 如何默认打开user版本的root权限【转】

    本文转载自:http://blog.csdn.net/wangjicong_215/article/details/77601638 1.system/core/adb/Android.mkdiff ...

  6. 在ubuntu下真机调试android程序出现设备没有访问权限

    今天把android的开发环境从windows平台切换到了ubuntu上. java jdk android-adt android-ndk都下好,环境变量都配好之后, 在调试程序的时候,出现设备没有 ...

  7. 【Android】一种提高Android应用进程存活率新方法

    [Android]一种提高Android应用进程存活率新方法 SkySeraph Jun. 19st 2016 Email:skyseraph00@163.com 更多精彩请直接访问SkySeraph ...

  8. 【转】Android Studio-1.2版本设置教程

    如果重新安装Android Studio的话要重新配置风格选项啥的,这篇是个很好的教程,原文链接:http://blog.csdn.net/skykingf/article/details/45485 ...

  9. Android M新的运行时权限开发者需要知道的一切

    android M 的名字官方刚发布不久,最终正式版即将来临!android在不断发展,最近的更新 M 非常不同,一些主要的变化例如运行时权限将有颠覆性影响.惊讶的是android社区鲜有谈论这事儿, ...

随机推荐

  1. 【区间更新区间求和】HDU 1698 Just a Hook

    acm.hdu.edu.cn/showproblem.php?pid=1698 [AC] #include<cstdio> ; #define lson (i<<1) #def ...

  2. mongo 操作符

    1 $unset The $unset operator deletes a particular field. https://docs.mongodb.com/manual/reference/o ...

  3. poj 1486 Sorting Slides

    Sorting Slides Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4469   Accepted: 1766 De ...

  4. 无记录时显示gridview表头,并增加一行显示“没有记录”【绑定SqlDataSource控件时】

    原文发布时间为:2008-08-04 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...

  5. hdu 4091 Zombie’s Treasure Chest 贪心+枚举

    转自:http://blog.csdn.net/a601025382s/article/details/12308193 题意: 输入背包体积n,绿宝石体积s1,价值v1,蓝宝石体积s2,价值v2,宝 ...

  6. Codeforces Round #268 (Div. 2) D. Two Sets [stl - set + 暴力]

    8161957                 2014-10-10 06:12:37     njczy2010     D - Two Sets             GNU C++     A ...

  7. 【转】UITableViewCell自适应高度 UILabel自适应高度和自动换行

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {     ...

  8. 将数字转换成Excel表头格式的字母序号

    /**     * 从0开始算起,0-25转A-Z     * @param num     * @return  Character.valueOf((char)((num-1)+65))+&quo ...

  9. 关于错误Access Violation和too many consecutive exceptions 解决方法

    关于错误Access Violation和too many consecutive exceptions 解决方法 “如果DLL中用到了DELPHI的string类型,则DLL和主程序中都需要加上Sh ...

  10. codevs——1570 去看电影

    1570 去看电影  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 农夫约翰带着他的一些奶牛去看电影.而他的 ...