如何使能和关闭android设备上的console功能

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/rikeyone/article/details/84309535

system/core/rootdir/init.rc文件中定义:

以关机充电为例,使能console功能:

on charger
+      start console

关闭console功能:

on charger
-       start console

console除了直接在initrc中start和stop之外,还可以通过一个property来设置它是否启动:

on property:ro.debuggable=1
    # Give writes to anyone for the trace folder on debug builds.
    # The folder is used to store method traces.
    chmod 0773 /data/misc/trace
    start console


on property:ro.debuggable=0
# Give writes to anyone for the trace folder on debug builds.
# The folder is used to store method traces.
    chmod 0773 /data/misc/trace
    start console

这段init.rc的定义表示通过ro.debuggable的property的值用来确定是否启动console。那么console到底是什么呢?

console实际上在init.rc中被定义为一个service了:

service console /system/bin/sh
    class core
    console
    disabled
    user shell
    group shell log readproc
    seclabel u:r:shell:s0
    setenv HOSTNAME console

实际上该service就是启动一个shell程序,目标程序位置/system/bin/sh。通过shell我们就拥有了一个人机交互的接口了,类似于一个超级终端,通过串口就可以输入命令了。

这里我们还可以通过setenv来配置console进入时的hostname,比如

setenv HOSTNAME xiehaocheng

就可以把console的默认hostname修改为自己的名字了。

猜你喜欢

转载自blog.csdn.net/rikeyone/article/details/84309535