简体   繁体   English

cp命令在Android 4.4上不起作用

[英]cp command does not work on Android 4.4

I am facing a weird behavior on Android 4.4. 我在Android 4.4上遇到奇怪的行为。 The command below works perfectly on android Jelly Bean rooted device: 下面的命令在android Jelly Bean植根设备上完美运行:

Process process = Runtime.getRuntime().exec("su");
DataOutputStream dos = new DataOutputStream(process.getOutputStream());

// path is a folder saved on sdcard
dos.writeBytes("cp -a " + path + " " + "/data/data" + " \n");
dos.flush();
process.waitFor() return 0 mean Ok

However on Android 4.4 rooted device, the above commands does not work. 但是,在装有Android 4.4的设备上,上述命令不起作用。 process.waitFor() return 1 mean there is error somewhere. process.waitFor()返回1表示某处存在错误。

I notice that when running on Android Jelly Bean rooted device, the permission for files are: rwxr-x. 我注意到,在以Android Jelly Bean为根的设备上运行时,文件的权限为:rwxr-x。 On Android 4.4 rooted, they are: rwxrwx-- 在根植于Android 4.4上,它们是:rwxrwx--

I googled this problem but did not find any result so far. 我用谷歌搜索了这个问题,但到目前为止没有找到任何结果。 Thanks. 谢谢。 :) :)

UPDATE: I can copy data from /data/data folder using cp command to sdcard folder. 更新:我可以使用cp命令将数据从/ data / data文件夹复制到sdcard文件夹。

Before running su on Android 4.4+ to copy/write files in a rooted device, make a backup of this file: 在Android 4.4+上运行su以在根设备上复制/写入文件之前,请对该文件进行备份:

/system/etc/permissions/platform.xml

Then see if the following permission and groups have been defined in platform.xml : 然后查看是否在platform.xml定义了以下权限和组:

<permission name="android.permission.WRITE_EXTERNAL_STORAGE" >
    <group gid="sdcard_r" />
    <group gid="sdcard_rw" />
    <group gid="media_rw" />
</permission>

If not, edit platform.xml and add them, save, then reboot your device and try your su command again. 如果不是,请编辑platform.xml并添加它们,保存,然后重新启动设备并再次尝试使用su命令。

If all else fail, try to install the BusyBox binary on the rooted device and run the su command through it. 如果所有其他方法均失败,请尝试在已根目录的设备上安装BusyBox二进制文件并通过它运行su命令。

I managed to make it work by changing the command. 我设法通过更改命令使其工作。

cp -a " + path + " " + "/data/data" + " \n"

to

cp -r " + path + " " + "/data/data" + " \n"

The difference between -a and -r is, -a will remain all the permission of the copying files that I dont know why it does not work on android 4.4. -a和-r之间的区别是-a将保留所有复制文件的权限,我不知道为什么它在android 4.4上不起作用。 -r will also copy all the files and folders but it changes the permission of file, the simple solution (I think) is to chmod the permission manually after copying. -r也将复制所有文件和文件夹,但是它会更改文件的权限,简单的解决方案(我认为)是在复制后手动更改权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM