首页 > 编程知识 正文

Android 自动阅读脚本应用(安卓脚本工具有哪些)

时间:2023-05-05 03:56:03 阅读:64970 作者:4558

最近在做项目的时候,遇到了这样的需求。 启动Android(4.2.2)时,必须执行以下命令: 不说明指令的具体含义。 mount-tusbfsnone/proc/bus/usb的第一个做法已添加到init.rc文件中,但发现此方法不成功。 理由

然后查看相关资料,发现将命令写入sh文件,然后在打开电源时运行sh文件也能取得效果。 因此,如下创建了新的sh文件usbfs.sh。

#!/system/cz dbl/sh mount-tusbfsnone/proc/bus/USB在使用此文件时,请注意尽量在Linux环境中,而不是在Windows上。 我开始这个步骤是在Win上编译内容,然后将文件复制到Android源代码的相应位置。 结果,在编译完成并镜像完成后,发现死活不会发生,或者报告错误,进行cat后发现内容中有多余的字符。

接下来的操作目的很明确。

首先,在编译过程中,Android必须将此文件复制到输出目录的适当位置,并最终添加到镜像中。

第二,Android启动时,必须运行此sh文件。

围绕以上两点,我们将展开下一步。

一、实现在编译时执行该文件的复制。

的新sh文件。 我的保存路径是device/hi silicon/big fish/etc/usbfs.sh。 根据平台的不同,文件路径可能会有些不同,但我的是海思平台的软件包。 具体怎么决定,取决于你自己的实际情况。

出于安全考虑,您打算将此文件复制到Android system分区下的etc目录中。 也就是说,目标地址为/system/etc/。

ok,做好以上两点,接下来是添加合适的复制动作。 这个动作需要自己添加吗? 当然,在大多数情况下,Android不会在编译时自动添加新添加的文件。 动作是在哪里添加的?

在此----device/hi silicon/hi 3716 cv 200/device.MK文件中,这当然也因平台而异。 打开此文件后,您将看到(

#版权(c ) 2011 theandroidopen-source project ) #许可证授权,版本2.0 ) the '许可证); # youmaynotusethisfileexceptincompliancewiththelicense.# youmayobtainacopyofthelicenseat # # http://www.Apache.org/lice neng unlessrequiredbyapplicablelaworagreedtoinwriting,软件# distributedunderthelicenseisdistributedonan ' asis ' basis # withoutwarrantiesorconditionsofanykind, etherexpressorimplied.# sethelicenseforthespecificlanguagegoverningpermissionsand # limitationsunderthelicense.# product _ aapt _ pref _ config :=xhdpiproduct _ character istics 3360=table t product _ copy _ files 3360=_ } frames 安卓. hardware.wifi.XML 3360系统/etc/permissions /安卓. hardware.wifi frameworks/native/data/etc/Anand permissions/Android.hardwarr d框架/native/data/etc/Android.hardware.USB.accessory.XML :系统/eted hi silicon/big fish/etc/init.RC : root/init.RCdevice/hi silicon/big fish/etc

/init.hidolphin.rc:root/init.hidolphin.rc      device/hisilicon/bigfish/etc/ueventd.bigfish.rc:root/ueventd.bigfish.rc      device/hisilicon/bigfish/etc/media_codecs.xml:/system/etc/media_codecs.xml      device/hisilicon/bigfish/etc/media_profiles.xml:/system/etc/media_profiles.xml      device/hisilicon/bigfish/etc/tablet_core_hardware.xml:system/etc/permissions/tablet_core_hardware.xml      device/hisilicon/Hi3716CV200/etc/init.Hi3716CV200.rc:root/init.bigfish.rc      device/hisilicon/Hi3716CV200/etc/init.Hi3716CV200.sh:system/etc/init.bigfish.sh

我们需要做的,就是将以下内容添加到上述文件合适的位置:

PRODUCT_COPY_FILES +=          device/hisilicon/bigfish/etc/usbfs.sh:system/etc/usbfs.sh

“:”前面是文件源路径,后面的是目的路径。

这样,Android在执行编译的时候就会把新增文件拷贝至相应的目标路径去了,拷贝动作已经实现。

 

二、添加启动动作,使Android在启动时候执行。

 

如何添加启动动作?大部分人或许都知道,那就是在init.rc文件中添加上就是了,网上也有一些此类的介绍,我是这么做的:

init.rc文件末尾处加入以下内容(不再详述,不懂的自己翻书或者爬网查)

service mount-usbfs /system/etc/usbfs.sh     class main     user root     group root     oneshot

之后编译系统,烧写,启动,观察启动log,发现确实执行了该sh文件,但是却报了一个“权限不足”的提示,ll了一下usbfs.sh文件,发现权限是644,没有执行权限。

OK,没有执行权限,给他添加上执行权限就是了,同样是在init.rc文件中,添加以下内容:

chown root shell /system/etc/usbfs.sh chmod 0550 /system/etc/usbfs.sh

添加了执行的权限,这次应该没有问题了吧,网上很多介绍也是这么干的。

之后又是编译、烧写、启动...漫长的过程(┬_┬),Android系统级开发,要有耐心啊。

观察启动的log,居然还是“权限不足”!!!怎么回事,难道没有生效?ll了一下usbfs.sh文件,发现权限居然还是644,说明刚才的赋权限是没有效果的。

为什么?接着查,在查看init.rc的过程中,发现了以下内容:

mount ext4 ext4@system /system ro

原来system分区是以只读的形式进行挂载的,忽略这点了。以只读形式挂载,再怎么赋权限,也是徒劳啊。

突然又发现,与usbfs.sh在同一个目录的init.bigfish.sh,权限是正常的,并且该文件的源文件与sh文件同样都在一个目录里。那么,这说明Android在编译过程中,除了拷贝以外,应该还有一个赋权限的动作。

基于以上思路,继续进行查找。功夫不负有心人,还真被我找到了,确实存在这么一个动作,它在哪里呢?

在这里:system/core/include/private/android_filesystem_config.h,其中有个结构体做如下定义:

/* Rules for files. ** These rules are applied based on "first match", so they ** should start with the most specific path and work their ** way up to the root. Prefixes ending in * denotes wildcard ** and will allow partial matches. */ static struct fs_path_config android_files[] = {     { 00440, AID_ROOT,      AID_SHELL,     "system/etc/init.goldfish.rc" },     { 00550, AID_ROOT,      AID_SHELL,     "system/etc/init.goldfish.sh" },     { 00550, AID_ROOT,      AID_SHELL,     "system/etc/init.bigfish.sh" },     { 00440, AID_ROOT,      AID_SHELL,     "system/etc/init.trout.rc" },     { 00550, AID_ROOT,      AID_SHELL,     "system/etc/init.ril" },     { 00550, AID_ROOT,      AID_SHELL,     "system/etc/init.testmenu" },     { 00550, AID_DHCP,      AID_SHELL,     "system/etc/dhcpcd/dhcpcd-run-hooks" },     { 00550, AID_DHCP,      AID_SHELL,     "system/etc/dhclient*" },     { 00440, AID_BLUETOOTH, AID_BLUETOOTH, "system/etc/dbus.conf" },     { 00444, AID_RADIO,     AID_AUDIO,     "system/etc/AudioPara4.csv" },     { 00555, AID_ROOT,      AID_ROOT,      "system/etc/ppp/*" },     { 00555, AID_ROOT,      AID_ROOT,      "system/etc/rc.*" },     { 00644, AID_SYSTEM,    AID_SYSTEM,    "data/app/*" },     { 00644, AID_MEDIA_RW,  AID_MEDIA_RW,  "data/media/*" },     { 00644, AID_SYSTEM,    AID_SYSTEM,    "data/app-private/*" },     { 00644, AID_APP,       AID_APP,       "data/data/*" },         /* the following two files are INTENTIONALLY set-gid and not set-uid.          * Do not change. */     { 02755, AID_ROOT,      AID_NET_RAW,   "system/czdbl/ping" },     { 04750, AID_ROOT,      AID_INET,      "system/czdbl/netcfg" }, //modified by lwf 20141008,for resolve a bug when DHCP enable.                                                                   //called by BrowserEthernetClientX::submitParameters().         /* the following five files are INTENTIONALLY set-uid, but they      * are NOT included on user builds. */     { 06755, AID_ROOT,      AID_ROOT,      "system/xczdbl/su" },     { 06755, AID_ROOT,      AID_ROOT,      "system/xczdbl/librank" },     { 06755, AID_ROOT,      AID_ROOT,      "system/xczdbl/procrank" },     { 06755, AID_ROOT,      AID_ROOT,      "system/xczdbl/procmem" },     { 06755, AID_ROOT,      AID_ROOT,      "system/xczdbl/tcpdump" },     { 04770, AID_ROOT,      AID_RADIO,     "system/czdbl/pppd-ril" },         /* the following file is INTENTIONALLY set-uid, and IS included          * in user builds. */     { 06750, AID_ROOT,      AID_SHELL,     "system/czdbl/run-as" },     { 00755, AID_ROOT,      AID_SHELL,     "system/czdbl/*" },     { 00755, AID_ROOT,      AID_ROOT,      "system/lib/valgrind/*" },     { 00755, AID_ROOT,      AID_SHELL,     "system/xczdbl/*" },     { 00755, AID_ROOT,      AID_SHELL,     "system/vendor/czdbl/*" },     { 00750, AID_ROOT,      AID_SHELL,     "sczdbl/*" },     { 00755, AID_ROOT,      AID_ROOT,      "czdbl/*" },     { 00750, AID_ROOT,      AID_SHELL,     "init*" },     { 00750, AID_ROOT,      AID_SHELL,     "charger*" },     { 00750, AID_ROOT,      AID_SHELL,     "sczdbl/fs_mgr" },     { 00640, AID_ROOT,      AID_SHELL,     "fstab.*" },     { 00644, AID_ROOT,      AID_ROOT,       0 }, };

从行9可以看到,此处重新定义了init.bigfish.sh的权限,OK,我们应该只需要加入以下内容,就可以了:

{ 00550, AID_ROOT,      AID_SHELL,     "system/etc/usbfs.sh" },

保存,编译,启动。。。果然可以了!

 

后话

 

个人感觉,我这种做法是比较遵循Android规则的一种方法。可能存在一些更加简单、直接的方法,我在爬网文过程中也看到过,比如更改system分区的挂载方式,由只读变为读写等等,但是这样的方法,你自己感觉合适吗?

当然,如果你有更好的方法,希望能够留言分享,不胜感激o(∩_∩)o 。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。