Android app can not access file when it's uploaded by Device File Explorer

44 views Asked by At

I'm debugging an app (Java) with Android Studio on an emulator device on API level 26 (Android 8)

My app is accessing some data in .xml files, which are saved in

/data/user/0/com.ibburkart.myapp/files/project.xml

This works fine, as long the app once has created the file itself. More over, I can edit a new project.xml on my Windows host, do an upload via the Device File Explorer and the app is getting its data from the modified project.xml. So far, so good.

But the problem is, when I delete project.xml completly and after that do an upload, the app refuses to create the new FileInputStream with an exception.

This is my code:

File projectFile = getProjectFile(context, projectFileName, true);
if (projectFile != null) {
    boolean exists = projectFile.exists();
    boolean canRead = projectFile.canRead();
    boolean canWrite = projectFile.canWrite();
    boolean isFile = projectFile.isFile();

    logger.info(LoggerUtils.getCurrentMethodName() + " from file " + projectFile.getAbsolutePath());
    try {
        final InputStream knxProjectStream = new BufferedInputStream(new FileInputStream(projectFile));
        loadProject(knxProjectStream, false);
        knxProjectStream.close();
    }
    catch (AccessDeniedException e) {
        logger.error(LoggerUtils.getCurrentMethodName() + " from file " + projectFile.getAbsolutePath() + " ", e);
        logger.error("{} {} {} {}", e.getReason(), e.getOtherFile(), e.getCause(), e.getMessage());
    }
    catch (Exception e) {
        logger.error(LoggerUtils.getCurrentMethodName() + " from file " + projectFile.getAbsolutePath() + " ", e);
    }
}

This is the logger output with exception:

initializeProject from file /data/user/0/com.ibburkart.knxcpu.debug/files/project.xml
Got a deoptimization request on un-deoptimizable method void java.io.FileInputStream.open0(java.lang.String)
initializeProject from file /data/user/0/com.ibburkart.knxcpu.debug/files/project.xml java.io.FileNotFoundException: /data/user/0/com.ibburkart.knxcpu.debug/files/project.xml (Permission denied)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:200)
at java.io.FileInputStream.<init>(FileInputStream.java:150)
at com.ibburkart.knxcpu.project.KnxCpuProject.initializeProject(KnxCpuProject.java:897)

I noticed (permission denied) in the exception, but the file shows -rwxrwxrwx permission. The four projectFile flags I get in the code are always set to "true"

Does anybody know what's going wrong and how to solve?

0

There are 0 answers