I have been trying to make a Custom ROM in android. So, far I have been able to make changes and flash in Nexus 4 successfully. But my main aim is to provide Ota updates to my ROM. Right now I am able to update the device with update.zip using adb sideload and now I want it to be done automatically through a system app. For that I have made a system app which can download the update.zip from my server. I have gone through this link without any progress: Android development RecoverySystem.installPackage() cannot write to /cache/recovery/command permission denied
I have used the following code in Asynctask to install the update:
File update = new File("/data/update.zip");
try {
RecoverySystem.installPackage(mContext, update);
} catch (IOException e) {
e.printStackTrace();
}
But I am getting the following error:
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
The thing I am confused about is I am able to access data directory(which is not accessible to normal apps) when I am downloading, but I am not able to access /cache.
How should I proceed so that i don't get permission denied to system app when accessing /cache ?
My manifest file is:
<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" />
Btw, my build branch is android-5.1.1_r19
Update 1:
I built using full_mako-userdebug. So, I have su when needed in adb. In adb shell when I try creating cache/recovery/command
after su, it allows me to create file. But through app it is not allowing me to create file in cache/recovery/
, even though its system app. I don't want the user to root the phone just to install an ota update. Still having the same problem.