2

In my app I must read data from a file in data folder. But I can not do that. I searched about that but many users say you can not read data from data folder. And we see that Rootbrowser can read data from android private folder files. My question is how can I read files from data/misc folder?

karimkhan
  • 321
  • 3
  • 18

2 Answers2

2

In my app I must read data from a file in data folder

If by "data folder", you mean /data or arbitrary directories under it, you do not have read access to most of that, except perhaps on a rooted device.

I searched about that but many users say you can not read data from data folder

Correct.

And we see that Rootbrowser can read data from android private folder files

If by "Rootbrowser" you mean Root Browser, that app can only do this on rooted devices. You can tell that by reading the product description, where it says:

Root Browser is the ultimate file manager for rooted users

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    Thank you for info. i have Root Browser installed in my phone and using that i can see /data folder and sub folders and any files in there and textfiles content. but i test my app in my phone and can not read files in /data folder and sub folders. Why i can not? and i use this code [this code](https://gist.github.com/starbug1/7fcefffd2dd18395b07b) – karimkhan Sep 14 '15 at 15:08
  • That is due to selinux enforcement, you need to oem-unlock the device. Anyways from P upgrade of android, it is enforced to use /sdcard partition for all application uses – be_good_do_good Feb 15 '18 at 08:35
0

There is no solution for reading any file from any folder (unless your device is rooted, and even then it may be device-dependent), but most likely you problem requires something more specific than that. For example, if one application wants to pass data to another one, it is possible. If you need to read a file created by your own application, it's no problem at all. Please ask a question about your particular problem rather than about the general case.

UPDATE: from the discussion in the comments it turns out that you use a rooted device and the permissions on the folder of interest do not allow everyone to read it, which is a normal decision about access policy. If it's ok for your app to be run only on rooted phones, you may borrow sudoForResult() from https://stackoverflow.com/a/26654728/755804 .

The difference between Runtime.getRuntime().exec("ls"); and sudoForResult("ls "+path) is that in the latter case ls is executed by su (invoked via Runtime.getRuntime().exec("su"); within sudoForResult()) and therefore has superuser permissions.

Alternatively, you may try to open access to these folders for everyone. This will require su, will have to be done from your program, and will be difficult to test because after the 1st run the directory permissions will be already changed. OTOH, if you manage to make the directory readable for your application via access permissions, you can unroot the device and still have your application working.

Community
  • 1
  • 1
18446744073709551615
  • 16,368
  • 4
  • 94
  • 127
  • no i have a app that i want to read some data that stored in /data/misc folder. but i can not read that. i can see that file through [Root Browser](https://play.google.com/store/apps/details?id=com.jrummy.root.browserfree) but i can not read it from my app. – karimkhan Sep 14 '15 at 15:21
  • `ls -l /data/misc` and `ls -l /data/misc/` from the console. What do you see? – 18446744073709551615 Sep 15 '15 at 08:44
  • I understand, but if you don't post the output, you will be on your own. (Well, you will need that output even if you are going to solve the problem by yourself.) – 18446744073709551615 Sep 15 '15 at 09:01
  • [This](https://gist.github.com/starbug1/50f0971835b566ba256b) is the code that i use for list files. – karimkhan Sep 15 '15 at 09:06
  • What output do the commands `ls -l /data/misc` and `ls -l /data/misc/` show when issued from the non-root console? It must be the owner, the permissions, and either a list of files or the error message. What is it? – 18446744073709551615 Sep 15 '15 at 09:17
  • [This](http://s6.picofile.com/file/8212237250/console.PNG) is the output that console gave to me. – karimkhan Sep 15 '15 at 09:46
  • Again, it's not /data/misc, but I see that you use a **rooted** device and that the owners of the files of interest are _system_ and _wifi_, that there are no read permissions for just everyone (you know what the `ls` output means, don't you?) If it's ok for your app to be run only on rooted phones, you may borrow _sudoForResult()_ from http://stackoverflow.com/a/26654728/755804 – 18446744073709551615 Sep 15 '15 at 10:42
  • The difference between `Runtime.getRuntime().exec("ls");` and `sudoForResult("ls "+path)` is that in the latter case `ls` is executed by `su` (invoked via `Runtime.getRuntime().exec("su");` within _sudoForResult()_) and has superuser permissions – 18446744073709551615 Sep 15 '15 at 10:48
  • I want to read wpa_supplicant.conf file, that it is a text file in data/misc/wifi. all of this question is about reading that file. i will thank you if you help me read that file. – karimkhan Sep 15 '15 at 19:07
  • `sudoForResult("cat /data/misc/wifi/wpa_supplicant.conf")` but that will work only on a rooted system. The access rights are `-rw-rw----`which means that only the owner and its group have r/w access. – 18446744073709551615 Sep 16 '15 at 07:14
  • Again, you can `sudo("chmod 666 /data/misc/wifi/wpa_supplicant.conf")` (set r/w access to anyone) and then read it with your program, but again you will need to root the system to perform that `chmod`. – 18446744073709551615 Sep 16 '15 at 07:19