1

Sometimes I have a trouble matching application's package name in /data/data/ or /data/app/*.apk with the user-friendly activity label I see in GUI.

How do I list application packages together with their activities?

Expecting something like this:

$ adb shell list_apps
de.shandschuh.sparserss "Sparse rss"
org.vudroid "VuDroid"
jcpezzullo.statical "StatiCal"
tone.control "Tone Control"
...
Vi0
  • 1,665
  • 7
  • 23
  • 43

1 Answers1

0

Based on my answer on the question Andrew linked to, this is what should be in your list_apps script:

for app in $(ls /data/app/*.apk); do
    appname=$(aapt d badging $app | grep 'application: label' | sed -n \"s/.*label\='\([^']*\)'.*/\1/p\")
    pkgname=$(basename $app)
    echo ${pkgname} "${appname}"
done

Run this on your Android device.

  • Requirements: Either a CM based ROM with Kitkat or higher (which seems to ship with the aapt binary) – or a rooted device where you can install aapt onto yourself (find it here; tested with Android 4.1).
  • Known issues: app name most likely gets truncated when it contains a single quote (see sed expression). Not having such one installed here I could not test that.
  • Only lists user apps. Easy to fix by repeating the block for /system/app ;)
Izzy
  • 91,166
  • 73
  • 343
  • 943
  • On Samsung Galaxy S 5, ls /data yields opendir failed, Permission denied. – Stéphane Gourichon Aug 25 '17 at 11:41
  • 1
    @StéphaneGourichon requirements not met, see first bullet-point: you need to be root for that. – Izzy Aug 27 '17 at 15:44
  • fully valid point yet unexpected. Firelord's comment mentions non-root but mentions entering /data also. Yet I remember having used an app that did this without root access. My guess is, there is probably a way to fulfill OP's question on a non-rooted device, perhaps just aapt in another temp location. – Stéphane Gourichon Aug 28 '17 at 03:29
  • @StéphaneGourichon you've missed one thing possibly: ls /data requires root, ls /data/app might not. I'm not sure about the permissions on that folder, but I wouldn't wonder if it's readable and executable to each app. Have you checked that? While without root you cannot list the contents of /data, you can cd into it, and also into /data/app. You just cannot list the contents of /data itself. But without access to tha .apk file it doesn't help to place aapt in another location either; the information required is stored in the .apk files. – Izzy Aug 28 '17 at 05:37
  • thanks. Yes and no. You're right in that I can cd into /data and /data/app. But ls still fails in both locations, making the whole operation impractical. I expect the app did it via some API which has necessary access. – Stéphane Gourichon Aug 28 '17 at 11:37
  • There might be a way to query those details via the package manager (pm) - which is what I e.g. use for many details in my little tool Adebar. But I never checked "activity labels" that way, so I cannot tell for sure (and I'm currently not at my desk so I cannot really verify). What I do with Adebar is, via adb, parsing the packages.xml which pm uses/maintains. you can check what can be found there, @StéphaneGourichon – Izzy Aug 28 '17 at 12:28