系统应用程序无法访问/缓存目录 - “打开失败:EACCES(权限被拒绝)”

时间:2016-11-08 16:49:53

标签: android android-source

我正在创建一个Android系统应用,其唯一目的是下载并安装OTA更新。我一直收到此错误open failed: EACCES (Permission denied)。我在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" />

我还在运行时请求清单中列出的所有权限,如下所示:

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();
    }
}

我的日志显示了请求,授予和未授予的权限,如下所示:

  

D DownloadUtil:权限:android.permission.REBOOT -------权限   授予:-1 D DownloadUtil:权限:   android.permission.ACCESS_CACHE_FILESYSTEM -------授予权限:   -1 D DownloadUtil:权限:android.permission.DELETE_CACHE_FILES -------授予权限:-1 D   DownloadUtil:权限:   android.permission.WRITE_EXTERNAL_STORAGE -------授权许可:0   D DownloadUtil:权限:   android.permission.ACCESS_NETWORK_STATE -------授权许可:0

这是捕获错误的代码:

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() );
}

我想知道为什么没有将这些权限授予系统应用程序。将显示权限对话框,但不会引用三个被拒绝的权限。

其他信息:该应用的APK已使用唯一的发布密钥进行签名,每次都会进行验证,没有例外。

0 个答案:

没有答案