2

i am developing a tracker application for which i need to know which application is starting the hardware (by using pid) e.g camera or gps. This information is logged into dumpsys file in android. I want to access this file in my application ,do some analysis on it and extract the required information. i can access this file through adb but when the same commands i run form my java coding permission denied error occurs. i have also added android.permission.dump in my manifest file still error.

Naveen
  • 31
  • 8

1 Answers1

0

Unfortunately "android.permission.DUMP" is only granted to system apps.

Unless you sign your application with system signature and use system shared user id (android:sharedUserId="android.uid.system") in your manifest, you won't be able to get the permission.

What you could do is to redirect dumpsys output manually to an external storage and examine the file with FileInputStream and BufferedReader

ex: dumpsys > /sdcard/my_dump.txt

in your .java class:

FileInputStream fis     = new FileInputStream("/sdcard/my_dump.txt");
BufferedReader  bfr     = new BufferedReader (new InputStreamReader(fis));
StringBuilder   builder = new StringBuilder  ();
String          line    = "";

while ((line = br.readLine()) != null) {
    builder.append(line);
    Log.i("TEST", line);
}

You can check the builder with

String whateverYouAreLookingFor = "camera";
if (builder.toString().contains(whateverYouAreLookingFor)) {
    //do something
}

I know it's not the best solution but you can still get something out of it.

Hope you find your solution, cheers.

Burak Day
  • 907
  • 14
  • 28
  • i am not an expert in android so i don't know how to sign my application as system application and how to use system shared user id. Can you please explain. i have also rooted my phone and add superuser permission in my application still its not working. – Naveen May 26 '16 at 04:56
  • i have searched for how to sign my application as system application i got this (http://stackoverflow.com/a/12013730/5750621). According to him i am unable to distribute the app if i do...is there a way to do it by root access or super user access?? – Naveen May 26 '16 at 05:57
  • Yes you can't sign your app with system signature unless you have your own rom. Even if you somehow sign it by finding the signature from somewhere, the manifacturer won't let you publish your app since system signatured apps can do pretty much anything. I need time to answer your question i hope you get your solution in the meantime. – Burak Day May 26 '16 at 14:12
  • Before 5.0, you could move your app to /system/app folder and your app could automatically become a system app after rebooting. I'm not sure for 5.0+. All you need a rooted phone and mount system folder as "mount -o remount,rw /system" so you can write on system folder. And then move your app by "mv /path/to/your/app /system/app" – Burak Day May 26 '16 at 14:14
  • i have tried to install my app as system as by moving it to /system/app path and i got access to the dumpsys file.thank you so much for your help – Naveen May 29 '16 at 09:51
  • Great! Good luck :) – Burak Day May 30 '16 at 05:20