2

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.

Jared Rummler
  • 37,824
  • 19
  • 133
  • 148
csd
  • 21
  • 6
  • When you say "has been signed with a unique release key" is this the same key as the key used to sign the custom ROM? – Emmanuel Nov 08 '16 at 17:19
  • @Emmanuel Yes. It's the same key that has been used to sign the custom ROM. – csd Nov 08 '16 at 17:50
  • Do you also install the app while building the framework or after using adb install? – Nir Duan Nov 09 '16 at 09:11
  • @NirDuan I usually use adb sideload, not sideload, as a quick way to verify the certificates match before including the app in the full release. I've created an Android.mk file for the app for including it as part of the system release. – csd Nov 09 '16 at 10:51
  • @NirDuan correction...I usually use adb sideload, not adb install. – csd Nov 09 '16 at 12:43
  • That can be caused by SELinux. Take a look at this https://stackoverflow.com/a/55748901/10086742 – mahdi Nov 01 '20 at 14:11

0 Answers0