Read file from /data folder (with chmod 744) in android

70 views Asked by At

I have a rooted device and I added a file named test.txt to the root /data directory. And then I changed its permission to 744 with following adb command:

adb shell su -c 'chmod 744 /data/test.txt'

After the command the permission changed to -rwxr--r--
Now I want to read that file with this code:

                    val file = File("/data/test.txt")
                    val text = StringBuilder()
                    try {
                        val reader = BufferedReader(FileReader(file))
                        var line: String?
                        while (reader.readLine().also { line = it } != null) {
                            text.append(line)
                            text.append('\n')
                        }
                        reader.close()
                        showText(text.toString())
                    } catch (e: Exception) {
                        logE(e)
                    }

But it gives me this exception:

java.io.FileNotFoundException: /data/test.txt: open failed: EACCES (Permission denied)

Now I know that some libraries can read files with 744 permission like AppsFlyer: AppsFlyer factory preinstall As you see in documentation it mentions that:

The manufacturer places the pre_install.appsflyer in a file path of its choosing. The pre_install.appsflyer file permissions should be set to 744.

So how can I read this data like AppsFlyer library?

0

There are 0 answers