【问题标题】:Ota Update in AOSPAOSP 中的 Ota 更新
【发布时间】:2016-06-09 12:48:11
【问题描述】:

我一直在尝试在 android 中制作自定义 ROM。所以,到目前为止,我已经能够成功地在 Nexus 4 中进行更改和闪烁。但我的主要目标是为我的 ROM 提供 Ota 更新。现在我可以使用 adb sideload 使用 update.zip 更新设备,现在我希望它通过系统应用程序自动完成。为此,我制作了一个系统应用程序,可以从我的服务器下载 update.zip。 我已经通过这个链接没有任何进展: Android development RecoverySystem.installPackage() cannot write to /cache/recovery/command permission denied

我在 Asynctask 中使用了以下代码来安装更新:

    File update = new File("/data/update.zip");
    try {
        RecoverySystem.installPackage(mContext, update);
    } catch (IOException e) {
        e.printStackTrace();
    }

但我收到以下错误:

    W/RecoverySystem( 3900): !!! REBOOTING TO INSTALL /data/update.zip !!!
    W/System.err( 3900): java.io.FileNotFoundException: /cache/recovery/command: open failed: ENOENT (No such file or directory)
    W/System.err( 3900):    at libcore.io.IoBridge.open(IoBridge.java:456)
    W/System.err( 3900):    at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
    W/System.err( 3900):    at java.io.FileOutputStream.<init>(FileOutputStream.java:72)
    W/System.err( 3900):    at java.io.FileWriter.<init>(FileWriter.java:42)
    W/System.err( 3900):    at android.os.RecoverySystem.bootCommand(RecoverySystem.java:454)
    W/com.test.ota( 3966): type=1400 audit(0.0:8): avc: denied { write } for comm=4173796E635461736B202331 name="/" dev="mmcblk0p22" ino=2 scontext=u:r:system_app:s0 tcontext=u:object_r:cache_file:s0 tclass=dir

我很困惑的是我在下载时能够访问数据目录(普通应用程序无法访问),但我无法访问 /cache。

我应该如何进行,以便在访问 /cache 时不会获得系统应用程序的权限被拒绝?

我的清单文件是:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:sharedUserId="android.uid.system"
xmlns:tools="http://schemas.android.com/tools"
package="com.test.ota">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission
    android:name="android.permission.ACCESS_CACHE_FILESYSTEM"
    tools:ignore="ProtectedPermissions"/>
<uses-permission
    android:name="android.permission.DELETE_CACHE_FILES"
    tools:ignore="ProtectedPermissions"/>
<uses-permission
    android:name="android.permission.REBOOT"
    tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.RECOVERY" />

顺便说一句,我的构建分支是 android-5.1.1_r19

更新 1: 我使用 full_mako-userdebug 构建。所以,我在 adb 中需要时有 su。在 adb shell 中,当我尝试在 su 之后创建 cache/recovery/command 时,它允许我创建文件。但是通过应用程序它不允许我在cache/recovery/ 中创建文件,即使它的系统应用程序。我不希望用户只是为了安装 ota 更新而 root 手机。还是一样的问题。

【问题讨论】:

    标签: android updates android-source ota


    【解决方案1】:

    虽然您作为系统用户具有对缓存文件系统的读取权限,但您需要更改 Linux SEPolicy 以授予系统用户对 /cache 分区的写入权限。

    将以下内容添加到文件external/sepolicy/system_app.te

    allow system_app cache_file:dir create_dir_perms;
    allow system_app cache_file:file create_file_perms;
    

    然后重建,你不应该再有这个错误:)

    【讨论】:

      【解决方案2】:

      请注意new File("/data/update.zip"); 默认不创建新文件,它只保留文件名字符串。检查methods to create a file

      如果您确定/data/update.zip 文件存在,请尝试在运行RecoverySystem.installPackage 之前手动创建/cache/recovery/command

      【讨论】:

      • 是的,我检查了 update.zip 是否存在。在我尝试通过 app 手动制作 /cache/recovery/command 之前。但是创建文件会出现相同的权限被拒绝错误。
      【解决方案3】:

      在 logcat 上执行 grep 'denied' 以检查 selinux 在执行 RecoverySystem.installPackage 时是否阻止您的应用访问缓存。或者,由于您具有 su 访问权限,请在执行 RecoverySystem.installPackage 之前通过 adb setenforce 0 暂时关闭 selinux。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-25
        • 2015-12-25
        相关资源
        最近更新 更多