0

The title doesn't grasp the body much. Edits are requested.


I've a string android.permission.CAMERA to match in the output of adb shell dumpsys package. My goal is to list the package name of the apps which are using the permission android.permission.CAMERA.

Consider this example: If I do adb shell dumpsys com.google.android.GoogleCamera I would get:

Package [com.google.android.GoogleCamera] (cbd5725):
  ...
  applicationInfo=ApplicationInfo{235b16ab com.google.android.GoogleCamera}
  ...
  dataDir=/data/data/com.google.android.GoogleCamera
  ...
  grantedPermissions:
  ...
  ...
  android.permission.CAMERA
  ...

That was a specific example which was given because I knew the package name. In the original command i.e. adb shell dumpsys package you would get to see the permissions et al, of all the apps installed.

What I want to do is find out which apps have declared the permission android.permission.CAMERA.

If you consider all the varied apps installed in the system then there is no fixed distance between:

  • Package [PKG_NAME] (ID): and android.permission.CAMERA
  • applicationInfo=ApplicationInfo{235b16ab PKG_NAME} and android.permission.CAMERA
  • dataDir=/data/data/PKG_NAME and android.permission.CAMERA

which means I at least cannot use grep -Bn on the output.

It is definitely doable but I don't know where to begin with.

Complete dump of adb shell dumpsys package: http://pasted.co/e0cd2d4d or https://paste.ee/p/ylpax


It it matters, I'm using Slackware 14.1 on Laptop and COS12 on my rooted Android device.

1

awk might work. Something like:

awk -v RS='^Package ' '/android\.permission\.CAMERA/ {print $1}'

This assumes that line starting with Package mark the beginning of the description of a new app.

Looking at the actual contents, lines don't start with Package, but with Package - indented two spaces. So the following should work:

awk -v RS='\n +Package' '/android\.permission\.CAMERA/{print $1}'

This marks a newline followed by any amount of spaces and Package as the record separator, and filters out those records containing android.permission.CAMERA. The first field is the package name. And Verifiers: will be printed because the permission is listed before the package descriptions begin.

1
perl -nE '/Package \[([^\]]+)/ and $p=$1; /android.permission.CAMERA/ and say $p' datfile

So what this does is to match Package [...] lines (saving the package name to $p as the backref variable $1 will be clobbered, a lot); if a CAMERA line shows up, emit the contents of $p. (This will fail with an uninitialized warning message if a CAMERA line shows up before the first package line, which a BEGIN { $p = "dunno" } leading sub definition would correct.) This should also be fairly easy to do in awk, but I don't think in awk.

(If the input data had be delimited by a blank line, then the perl -00 (perldoc perlrun) ivocation would likely have been involved in my answer.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.