Android development RecoverySystem.installPackage() cannot write to /cache/recovery/command permission denied

前端 未结 5 1639
陌清茗
陌清茗 2020-12-10 03:42

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

相关标签:
5条回答
  • 2020-12-10 04:08

    System apps (apps with shared user ID set to android.uid.system) cannot install system updates on Android 5 and newer - it's forbidden by a SELinux policy. To be specific writing to /cache is forbidden for system apps. In other words:

    • /cache is owned by system user so your app running under system UID can write to it. But only if SELinux is disabled/permissive.
    • If you have android.permission.ACCESS_CACHE_FILESYSTEM platform signature permission, you can write to /cache.

    You'll need to remove the shared user ID. You still have to sign the app with platform signature and ensure you have the following permissions:

    • android.permission.REBOOT
    • android.permission.ACCESS_CACHE_FILESYSTEM - to write to /cache
    • android.permission.RECOVERY - required on API 21 to reboot to recovery

    This will work on Kitkat and Lollipop+ alike.

    0 讨论(0)
  • 2020-12-10 04:12

    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.

    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.

    0 讨论(0)
  • 2020-12-10 04:13

    I have problem the same with you when create custom OtaUpdate app in android 5.0.2 and i have resolved it. I will share with you with 2 steps below:

    1. Add android:sharedUserId="com.google.uid.shared" in AndroidManifest.xml
    2. Push your apk to system/app or system/priv-app

    For android 4.1.2 :

    1. Add android:sharedUserId="android.uid.system" in AndroidManifest.xml
    2. Push your apk to system/app
    0 讨论(0)
  • 2020-12-10 04:17

    I met the same problem in android 8.
    If you add android:sharedUserId="android.uid.system" in AndroidManifest.xml, it should work.

    0 讨论(0)
  • 2020-12-10 04:32

    For Android 5.1.0

    1. Add android:sharedUserId="android.uid.system" in AndroidManifest.xml
    2. Push your apk to system/priv-app
    3. and then

      adb root
      adb shell setenforce 0
      
    0 讨论(0)
提交回复
热议问题