I am creating an Android system app whose sole purpose is to download and install an OTA update. I keep getting this error open failed: EACCES (Permission denied)
. I have these permissions set in my AndroidManifest:
<permission android:name="android.permission.ACCESS_CACHE_FILESYSTEM"
android:protectionLevel="signatureOrSystem"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<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" />
I am also requesting all the permissions listed in the manifest at runtime as follows:
int permissionReboot = checkSelfPermission( Manifest.permission.REBOOT );
if( permissionReboot != PackageManager.PERMISSION_GRANTED ){
if ( shouldShowRequestPermissionRationale( Manifest.permission.REBOOT ) ) {
Toast.makeText(DownloadUtil.this, "We need to reboot to Recovery mode to install your update", Toast.LENGTH_LONG).show();
} else {
requestPermissions(new String[]{Manifest.permission.REBOOT, Manifest.permission.ACCESS_CACHE_FILESYSTEM,
Manifest.permission.DELETE_CACHE_FILES, Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.ACCESS_NETWORK_STATE}, REQUEST_CODE_REBOOT);
Toast.makeText(DownloadUtil.this, "Requesting REBOOT permission", Toast.LENGTH_LONG).show();
}
}
I have logs that show the permissions requested, granted and not granted as follows:
D DownloadUtil: Permission: android.permission.REBOOT-------Permission Granted: -1 D DownloadUtil: Permission: android.permission.ACCESS_CACHE_FILESYSTEM-------Permission Granted: -1 D DownloadUtil: Permission: android.permission.DELETE_CACHE_FILES-------Permission Granted: -1 D DownloadUtil: Permission: android.permission.WRITE_EXTERNAL_STORAGE-------Permission Granted: 0 D DownloadUtil: Permission: android.permission.ACCESS_NETWORK_STATE-------Permission Granted: 0
This is the code that where the error is captured:
File packageFile = new File(Environment.getDownloadCacheDirectory() + "/signed-ota_update.zip");
if (packageFile.exists()) {
packageFile.delete();
}
FileChannel source = null; // downloaded file is stored here
FileChannel dest = null; // where we will place the downloaded ota file
try{
Log.d(TAG, "App local cache directory: " + context.getCacheDir().getAbsolutePath());
Log.d(TAG, "System cache directory: " + Environment.getDownloadCacheDirectory().toString());
source = (new FileInputStream(downLoadDirectory)).getChannel();
Log.d(TAG, "Size of the downloaded file(source file): " + source.size());
dest = (new FileOutputStream(packageFile)).getChannel();
Log.d(TAG, "Size of the destination file in /cache: " + dest.size());
long count = 0;
long size = source.size();
do{
count += dest.transferFrom(source, count, size-count);
}while (count < size);
} catch( IOException ioe){
Log.d(TAG, "I/O exception: " + ioe.getMessage() );
}
I'd like to know why these permissions aren't being granted to a system app. The permissions dialogue is displayed but does not reference the three denied permissions.
Additional info: The APK for the app has been signed with a unique release key which is verified each time with no exceptions.