This is my code where i'm trying to access a file from /data directory on my rooted device. My app is successfully getting root privileges and also, it can access data from other folders like / or /sdcard or /system etc. The problem arises only in the case of /data directory. And, i'm sure such file exists on the file system and getting the correct path. If the file doesn't exist, then it shows a different error. Now, how can i read the file inside /data directory?
try {
File wifiConfFile = new File(Environment.getDataDirectory()+ File.separator + "system" + File.separator + "appops.xml");
if(!wifiConfFile.exists()){
Log.d("FILE", Environment.getDataDirectory()+"/system/appops.xml couldn't be loaded!");
}
fis = new FileInputStream(wifiConfFile);
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader bufferedReader = new BufferedReader(isr);
StringBuilder sb = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
sb.append(line);
}
wifiDesc.append(sb.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
This is the permission block in my android-menifest file.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
And, this is from android monitor...
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: java.io.FileNotFoundException: /data/system/appops.xml: open failed: EACCES (Permission denied)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at libcore.io.IoBridge.open(IoBridge.java:456)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at java.io.FileInputStream.<init>(FileInputStream.java:76)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at rizanamic.wifipass.MainActivity.onCreate(MainActivity.java:71)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at android.app.Activity.performCreate(Activity.java:5933)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at android.app.ActivityThread.access$800(ActivityThread.java:144)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at android.os.Looper.loop(Looper.java:135)
12-08 19:47:28.326 26634-26634/rizanamic.wifipass W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5229)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err: at java.lang.reflect.Method.invoke(Native Method)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err: at java.lang.reflect.Method.invoke(Method.java:372)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err: Caused by: android.system.ErrnoException: open failed: EACCES (Permission denied)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err: at libcore.io.Posix.open(Native Method)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err: at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err: at libcore.io.IoBridge.open(IoBridge.java:442)
12-08 19:47:28.327 26634-26634/rizanamic.wifipass W/System.err: ... 15 more