简体   繁体   中英

Access /data folders from a system app

I'm working on an application that requires the data from some files in the /data folder ( /data/system_ce/0 mainly, but some other folders as well).

The app is supposed to be a system application. I signed the .apk file with platform keys and moved it into the /system/priv-app (tried it with /system/app as well) folder.

However, when I try reading a file with the permissions rw------- (that is, 600), I get a FileNotFoundException saying "Permission denied" . The owner of the file is "system". Why am I unable to read the file? What can be done, other than changing the file permissions from my app?

My current Android version is Oreo (8.1) . I'm not concerned about backwards compatibility.

Permission of 600 means that only the file owner can read/write to the file. The app probably is not the owner of the file. In such case, you can do one of the following:

1) Have your app get root privileges, for example as follows:

public void onCreate ()
{
    // ...
    try
    {
        Runtime.getRuntime ().exec ("su");

    } catch (Exception e)
    {
        // Failed to obtain root privileges...
    }

And when your app executes that code, you grant root privileges in whatever app you use for root management (for example, in Magisk Manager).

OR

2) Change the file permission to world-readable/writable.

OR

3) Change the ownership of the file to the owner of your application.

Also, make sure your app is really running as system app (look at its Android settings: if it shows the UNINSTALL button, it's not running as system app).

One of those should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM