Android recovery支持adb shell

近期开发过程注意到recovery不支持adb shell。为了便于调试方便,决定添加此功能。

刚開始我们採用的是user版本号系统,进入recovery后,输入adb shell命令。提示“error: no devices/emulators found”。我们先确认recovery.img是否包括有adb,看out\debug\target\product\xxx\recovery\root\sbin是否有adb文件(源码\system\core\adb),然后检查\bootable\recovery\etc\init.rc下关于adbd

service adbd /sbin/adbd--root_seclabel=u:r:su:s0 --device_banner=recovery
disabled
socket adbd stream 660 system system
seclabel u:r:adbd:s0 # Always start adbd on userdebug and engbuilds
on property:ro.debuggable=1
write /sys/class/android_usb/android0/enable 1
start adbd # Restart adbd so it can run as root
on property:service.adb.root=1
write /sys/class/android_usb/android0/enable 0
restart adbd
write/sys/class/android_usb/android0/enable 1

从上面可知init.rc 中adbd 是配置的,disabled 表示开机不启动,如  ro.debuggable 被置为1。那么adb 就会开启,或是service.adb.root设置为1,则重新启动adbd。

ro.debuggable 在\build\core\main.mk以下的内容赋值

ifeq (true,$(strip$(enable_target_debugging)))
#Target is more debuggable and adbd is on by default
ADDITIONAL_DEFAULT_PROPERTIES += ro.debuggable=1

enable_target_debugging 在\build\core\main.mk以下的内容赋值:

## user/userdebug ##

user_variant := $(filter useruserdebug,$(TARGET_BUILD_VARIANT))
enable_target_debugging := true
tags_to_install :=
ifneq (,$(user_variant))
#Target is secure in user builds.
ADDITIONAL_DEFAULT_PROPERTIES += ro.secure=1 ifeq ($(user_variant),userdebug)
#Pick up some extra useful tools
tags_to_install += debug #Enable Dalvik lock contention logging for userdebug builds.
ADDITIONAL_BUILD_PROPERTIES += dalvik.vm.lockprof.threshold=500
else
#Disable debugging in plain user builds.
enable_target_debugging := #Add for testUsbDebugging()
ADDITIONAL_DEFAULT_PROPERTIES += ro.adb.secure=1
Endif

Endif

可知默觉得enable_target_debugging := true,依据user_variant的值假设为user。则enable_target_debugging :=。这又和TARGET_BUILD_VARIANT有关,此变量相应于VARIANT_CHOICES=(user userdebug eng)中的一个值。由我们来选择,相关的实如今\build\envsetup.sh中。

依据上面可知。编译时假设选择userdebug或是eng。则ro.debuggable=1。以下我们选择eng版本号编译recovery.img。进入recovery后,输入adb shell命令。提示:

Exec ‘/system/bin/sh’ failed:No such fileor directory(2)

表示没有sh这个文件。无法进入shell,检查ramdisk 文件系统 system 文件夹为(out\debug\target\product\xxx\recovery\root\system)空。但我们知道boot.img下是能够的,看\system\core\rootdir\init.rc检查boot.img 启动的init.rc 关于sh的

service console /system/bin/sh
class core
console
disabled
user shell
group shell log
seclabel u:r:shell:s0 on property:ro.debuggable=1
start console

可知是启动了sh这控制台的。所以须要在bootable\recovery\etc\init.rc添加相应的内容:

图1

我们知道out\debug\target\product\xxx\recovery\root\system下没有bin文件夹(当然也没有sh),所以须要在编译的时候创建。须要\build\core\Makefile添加创建文件夹和把out文件夹下的/system/bin/sh复制到out/recovery/system/bin文件夹下

图2

但这样还是不行,后来知道recovery可运行文件是静态编译的。之所以这样是由于recovery模式中没有共享库还有缺动态链接库载入器(/system/bin/linker,Android动态连接器linker与静态连接器ld)。

所以\external\mksh\Android.mk

图3

參考链接:

Android recovery.img 支持adb shell

http://blog.csdn.net/chituhuan/article/details/52383655

[IMX6Q][Android5.1]移植笔记 --- Recovery mode的shell功能实现(sh+toolbox)

http://blog.csdn.net/kris_fei/article/details/50921384

Android Recovery 支持 Adb

http://www.jianshu.com/p/a0bdcce0a5e1

Android recovery支持adb shell的更多相关文章

  1. win7 cmd终端连接android手机运行adb shell脚本命令

    win7 cmd终端连接android手机运行adb shell脚本命令 (2013-03-22 20:13:57) 转载▼ 标签: android it shell 连接 linux 分类: 嵌入式 ...

  2. android控制之 adb shell (已完成,不定期增加内容)

    第一步:首先,下载adb1.0.32.zip,里面有如下图的内容: 第二步:解压缩,复制Adb.exe,和fastboot.exe到System32,注意AdbWinUsbApi.dll,AdbWin ...

  3. Android之通过adb shell 模拟器 error: more than one device and emulator 改ip dns

    error: more than one device and emulator 如果出现上面那种情况 请关闭  ide 输入下面的  再次重新启动 模拟器 如果实际上只有一个设备或模拟器,并且查到有 ...

  4. android如何用adb shell启动应用程序

    昨天研究了很久,可能由于基础比较菜吧,所以,没有搜到一个可以直接解决问题的,需要综合几个之后,问题得以解决,记下方法,为了方便自己之后遇到同样问题,也为了方便搜索同样问题的朋友. 主要用到了aapt和 ...

  5. Android 8.0 adb shell dumpsys activity activities | findstr mFocusedActivity 获取当前的 activity 显示空的

    adb shell dumpsys activity activities | findstr mFocusedActivity Android 7.0 现象: Android 8.0 现象: 改用: ...

  6. Android开发——使用ADB Shell命令实现模拟点击(支付宝自动转账实现)

    首先声明,本人反对一切利用技术的违法行为 本文的实现代码已经销毁,本文以介绍流程为主 1.这里所说的模拟点击不是在自己的APP里点击,点自己APP上的控件没什么好说的 不仅是支付宝转账,其他的获取别人 ...

  7. Android 测试 之adb shell

    一.发送键盘事件: 命令格式1:adb shell input keyevent "value" 其中value以及对应的key code如下表所列: KeyEvent Value ...

  8. 我的Android进阶之旅------>Android中通过adb shell input来模拟滑动、按键、点击事件

    今天在维护公司的一个小项目的时候,发现按公司手机的某个物理按键,激活相应的Service后,会在屏幕上模拟的点击了屏幕的某个坐标点.好家伙,原来是之前该项目的版本是按这个物理按键后,会弹出一个对话框, ...

  9. [Android]Recovery调用外部Shell脚本,Shell脚本使用ui_print方法

    busybox_bin=/sbin/busybox # 获取PIPE get_outfd(){ | $busybox_bin grep -q 'pipe'; then else local all_p ...

随机推荐

  1. JVM之基本结构

    1. Java虚拟机的架构 1.1 Java的NIO库允许Java程序使用直接内存,访问直接内存的速度优于Java堆.出于性能的考虑,读写频繁的场合会考虑使用直接内存. 1.2 本地方法栈和Java栈 ...

  2. shell delete with line number

    If you want to delete lines 5 through 10 and 12: sed -e '5,10d;12d' file This will print the results ...

  3. XamarinAndroid组件教程RecylerView适配器设置动画

    XamarinAndroid组件教程RecylerView适配器设置动画 本小节将讲解动画相关设置,如动画的时长.插值器以及复合动画等. 1.设置动画时长 设置动画持续的时间可以使用Animation ...

  4. Hibernate中Restrictions查询用法(转)

    Restrictions查询用法 HQL运算符 QBC运算符 含义 = Restrictions.eq() 等于equal <> Restrictions.ne() 不等于not equa ...

  5. Ubantu17.10 上安装gitlab

    http://www.jianshu.com/p/92f97939e33a 亲测成功

  6. JavaScript—异步提交表单的6种方式

    FormData的详细介绍及使用请点击此处,那里对FormData的方法和事件已经表述的非常清楚,这里就不再浪费时间在介绍一遍了.本文主要针对FormData对象的使用以及异步文件上传进行详细的说明. ...

  7. Android 如何判断指定服务是否在运行中 “Service”

    如何判断一个服务是否正在运行中: /** * 判断某个服务是否正在运行的方法 * * @param mContext * @param serviceName 是包名+服务的类名 * @return ...

  8. BZOJ1290 : [Ctsc2009]序列变换

    设$f[i][j]$表示$a[i]$改成$j$时的最小总代价. 若$a[i]<A(i-1)+1$,则不妨将其强行改成$A(i-1)+1$,如此处理之后$\min(f[n][1..Q])$就是答案 ...

  9. [Vijos1130][NOIP2001]数的计数 (递推)

    自己的递推一塌糊涂 考前抱佛脚 #include<bits/stdc++.h> using namespace std; ]; int main() { int n;scanf(" ...

  10. redis:sentinel监控服务器

    1. Sentinel工具完成监控--操作步骤 (1)把redis解压包中的sentinel.conf拷贝到redis的安装目录下: [root@192 redis]# cp /opt/redis-4 ...