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
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.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 recoveryThis will work on Kitkat and Lollipop+ alike.
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.
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:
For android 4.1.2 :
I met the same problem in android 8.
If you add android:sharedUserId="android.uid.system"
in AndroidManifest.xml
,
it should work.
For Android 5.1.0
android:sharedUserId="android.uid.system"
in AndroidManifest.xml system/priv-app
and then
adb root
adb shell setenforce 0