Android开发RecoverySystem.installPackage()无法写入否认/缓存/恢复/命令的权限 [英] Android development RecoverySystem.installPackage() cannot write to /cache/recovery/command permission denied
问题描述
我被要求写一个基于Android的产品小型简单的应用程序。该设备自带两款Android系统映像各具特色。我正在写的应用程序只是当你点击一个按钮,其概念证明,它采用了回收系统的图像之一,以取代目前的操作系统。
I have been asked to write a small simple app for an Android-based product. The device comes with two Android system images with different features. The app I'm writing is just a proof of concept where when you click on a button, it uses the Recovery System to replace the current OS with one of the images.
该设备是植根和应用程序运行作为一个系统的应用程序。
The device is rooted and the application runs as a system app.
我用
RecoverySystem.installPackage(context, packageFile);
(<一个href=\"http://developer.android.com/reference/android/os/RecoverySystem.html#installPackage%28android.content.Context,%20java.io.File%29\">see在这里,以供参考)与图片更换操作系统。这应该重新启动系统和初始化恢复系统到安装映像。
(see here for reference) to replace the OS with one of the images. This should reboot the system and initialize the recovery system to install the image.
这是我已经是这个电话,因为 RecoverySystem.installPackage
方法似乎无法访问/缓存/恢复/命令文件失败的问题。我想它会尝试写一些命令来恢复系统要在重新启动时执行,但失败。下面是我得到异常:
The problem that I have is that this call fails because the RecoverySystem.installPackage
method can't seem to access the /cache/recovery/command file. I guess it tries to write some commands for the recovery system to be executed on reboot, but fails. Here is the exception I am getting:
02-27 16:44:39.463: E/BroadSign Resolution Switcher(4439): java.io.FileNotFoundException: /cache/recovery/command: open failed: EACCES (Permission denied)
02-27 16:44:39.463: E/BroadSign Resolution Switcher(4439): at libcore.io.IoBridge.open(IoBridge.java:416)
02-27 16:44:39.463: E/BroadSign Resolution Switcher(4439): at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
02-27 16:44:39.463: E/BroadSign Resolution Switcher(4439): at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
02-27 16:44:39.463: E/BroadSign Resolution Switcher(4439): at java.io.FileWriter.<init>(FileWriter.java:42)
02-27 16:44:39.463: E/BroadSign Resolution Switcher(4439): at android.os.RecoverySystem.bootCommand(RecoverySystem.java:381)
02-27 16:44:39.463: E/BroadSign Resolution Switcher(4439): at android.os.RecoverySystem.installPackage(RecoverySystem.java:330)
所以,我假设我没有访问此文件适当的权限。虽然这里是我在我的清单中设置的权限:
So, I am assuming that I don't have the proper permission to access this file. Though here are the permission that I have set in my manifest:
<uses-permission android:name="android.permission.REBOOT" />
<uses-permission android:name="android.permission.ACCESS_CACHE_FILESYSTEM" />
<uses-permission android:name="android.permission.DELETE_CACHE_FILES" />
我知道我需要为 RecoverySystem
重启许可。但是,我不知道其他两个是相关的。我甚至不知道我是否需要一些其他权限创建/写在/缓存分区的文件。
I know I need the REBOOT permission for the RecoverySystem
. However, I don't know if the other two are relevant. I don't even know if I need some other permission to create/write to files in the /cache partition.
有谁知道我可能会错过?
Does anybody know what I could be missing?
更新:
好了,它看起来像我想通了。权限是正确的毕竟。一切是正确的。
Well, it looks like I figured it out. The permissions were right after all. Everything was right.
当我被apk文件移动到/系统/应用程序,我没有把所有的权限,但设置应用程序作为一个系统的应用程序。当我跑我的设备上最新的code,它在/数据/应用安装了它,认可它作为更新到系统中的应用。正因为如此,只有原来的系统应用程序的权限得到了承认。
When I was setting up the app as a system app by moving the apk file to /system/app I hadn't put all the permissions in yet. When I ran the latest code on my device, it installed it in /data/app and recognized it as an update to the system app. Because of that, only the permissions of the original system app were recognized.
我后,重新建立了我的最新的code从/ system / app中直接运行,它的工作。
After I re-set up my latest code to run from /system/app directly, it worked.
现在我唯一的问题是,当它重新启动它不会安装的形象和我结束了同一个感叹号死绿色的机器人。我会继续调查。
Now the only issue I have is that when it reboots it doesn't install the image and I end up with a dead green robot with an exclamation mark. I'll keep investigating.
我希望这篇文章可以帮助同一问题的人。我很乐意回答任何问题为好。
I hope this post helps anyone with the same issue. I'll be happy to answer any questions as well.
推荐答案
当安装在/系统/应用程序我正在下面的错误我的应用程序之前:
Before when my app was installed in /system/app I was getting below error:
07-20 10:52:46.512 933-951/? W/RecoverySystem﹕ !!! REBOOTING TO INSTALL /storage/emulated/legacy/Download/Update.zip !!!
07-20 10:52:46.512 933-951/? W/System.err﹕ java.io.FileNotFoundException: /cache/recovery/command: open failed: EACCES (Permission denied)
07-20 10:52:46.512 933-951/? W/System.err﹕ at libcore.io.IoBridge.open(IoBridge.java:409)
07-20 10:52:46.512 933-951/? W/System.err﹕ at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
07-20 10:52:46.512 933-951/? W/System.err﹕ at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
07-20 10:52:46.512 933-951/? W/System.err﹕ at java.io.FileWriter.<init>(FileWriter.java:42)
07-20 10:52:46.512 933-951/? W/System.err﹕ at android.os.RecoverySystem.bootCommand(RecoverySystem.java:389)
07-20 10:52:46.522 933-951/? W/System.err﹕ at android.os.RecoverySystem.installPackage(RecoverySystem.java:337)
我试过被要求的所有权限,但我无法继续。
I had tried all permissions that were required but I couldn't proceed.
于是,因为我是用上面4.2我试图API的把我的应用程序到 /系统/私法应用
和它的工作对我来说
So then since I was using API above 4.2 I tried to put my app into /system/priv-app
and it worked for me.
这篇关于Android开发RecoverySystem.installPackage()无法写入否认/缓存/恢复/命令的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!