0

so im having problem with accessing root app data directory my example dir: /data/app/com.android.chrome-jAB96abq4RXcFrKebL0BUQ==

i want to get into /data/app/com.android.chrome without extension name to get list folder tried /data/app/* com.android.chrome */ but got null

and here's my code

String path = "/data/app/*com.android.chrome*";
File file = new File(path);
String[] dir = file.list();
for(int i=0;i<dir.length;i++) {
Toast.makeText(this, "File: "+dir[i], Toast.LENGTH_LONG).show();}

and before that i've done changing the permission to 777 and using * com.android.chrome * goes well but my code above return null when try to listing directory

try {
Runtime.getRuntime().exec("su -c chmod 777 /data");
Runtime.getRuntime().exec("su -c chmod 777 /data/app");
Runtime.getRuntime().exec("su -c chmod 777 /data/app/*com.android.chrome*")
} catch (IOException e) { e.printStackTrace(); }

tried without * package * and still got null sry the stars doesnt have whitespace...got to whitespace because the texteditor recognize as text format

thanks before

Robert
  • 39,162
  • 17
  • 99
  • 152
  • So i must include com.android.chrome-jAB96abq4RXcFrKebL0BUQ== into path? – Vulture Nov 10 '20 at 14:48
  • or is there another way to get a list of folders in com.android.chrome? because im sure each device has different -extension :( – Vulture Nov 10 '20 at 14:50

1 Answers1

0

Your code does not work, because java.io.File can not handle wildcards. You have to specify the exact path.

As /data is not readable for regular users Java code will never be able to list a directory in this directory (a wildcard requires directory listing).

Get the app info via PackageManager and the dataDir from the ApplicationInfo for the app you are interested in:

context.getPackageManager().getPackageInfo("com.android.chrome", 0).applicationInfo.dataDir;

source

Alternatively you can run a shell ls command with su/root that lists the /data/data directory and parse the result for the chrome app data directory.

Robert
  • 39,162
  • 17
  • 99
  • 152