Android7.1update.zip升级在system/bin下新增可执行文件没有可执行权限问题
外出的设备,只能通过update.zip方式升级,比如要在设备/system/bin目录下增加login,在需要时执行login,升级后发现login文件没有可执行权限
msm8937_64:/ # ls -l system/bin/login
-rw-r--r-- 1 root root 1256440 2008-08-0120:00 system/bin/login
第1个root是指UID(文件的owner),第2个root是指GID(Group ID)
但我们需要有可执行文件,怎么解决呢,下面给出解决过程的尝试及解决方法
1. device\qcom\common\rootdir\etc\init.qcom.rc增加chmod来修改---无效
on boot
…
chmod 0755/system/bin/login
2. updater-script调用set_perm()设置权限---无效
更新失败,/cache/recovery/last_log提示
提示line 15 col 48: unknown function"set_perm",原因未知
这是因为bootable\recovery\updater\updater.cpp的没有实现set_perm(),下面给出android4.4版本下相关代码:
// Maybe, at some future point, we candelete these functions? They have been
// replaced by perm_set and perm_set_recursive.
RegisterFunction("set_perm", SetPermFn);
RegisterFunction("set_perm_recursive",SetPermFn);
我们代码是android7.1的,取而代之的是set_metadata_recursive和set_metadata命令,主要是修改文件或目录权限和属组等信息
比如:set_metadata("/system/bin/login","uid", 0, "gid", 0, "mode", 0755,"capabilities", 0x0, "selabel", "u:object_r:system_file:s0");-----------此方法可以解决此问题(推荐)
第1个0表示ROOT,上帝用户: ROOT, 他的UID= 0; 上帝用户永远属于任何UID
Uid和gid的值system\core\include\private\android_filesystem_config.h定义,比如:
/* This is the master Users and Groupsconfig for the platform. * DONOT EVER RENUMBER */ #define AID_ROOT 0 /* traditional unix root user */ #define AID_SYSTEM 1000 /* system server */ #define AID_RADIO 1001 /* telephony subsystem, RIL */#define AID_BLUETOOTH 1002 /* bluetooth subsystem */#define AID_GRAPHICS 1003 /* graphics devices */#define AID_INPUT 1004 /* input devices */#define AID_AUDIO 1005 /* audio devices */…
set_metadata(filename, key1, value1[, key2 , value2,...])
Sets the keys ofthe given filename to values. For example: set_metadata("/system/bin/netcfg","uid", 0, "gid", 3003, "mode", 02750,"selabel", "u:object_r:system_file:s0","capabilities", 0x0).
set_metadata_recursive(dirname, key1, value1[, key2, value2,...])
Recursively setsthe keys of the given dirname and all its children to values.For example:set_metadata_recursive("/system","uid", 0, "gid", 0, "fmode", 0644,"dmode", 0755, "selabel","u:object_r:system_file:s0", "capabilities", 0x0).
3. 另一种解决方法(但不推荐)
package_extract_dir()对应的PackageExtractDirFn()调用mzExtractRecursive(),此函数bootable\recovery\minzip\Zip.c在中实现
把UNZIP_FILEMODE的值由0644改为0755即可,但是如果之前用0644方式的升级包升级过,在此基础上再升级,login权限还是0644其他,为了解决此问题,还需要在updater-script文件增加了delete("/system/bin/login");配合才能解决,但这种解决方法不是很合理,不推荐。
参考链接:
Android 5.x OTA Update官方文档(四、OTA更新包解读)
http://blog.csdn.net/huangyabin001/article/details/44873753
Flashing CM 11, I get`set_metadata_recursive: some changes failed`:
https://android.stackexchange.com/questions/62982/flashing-cm-11-i-get-set-metadata-recursive-some-changes-failed