Tuesday, August 27, 2019

system info - Obtain package name AND common name of apps via ADB



I'm looking for a possibility to retrieve both, the package names and the common names of apps installed on an Android device via ADB – or at least to retrieve the common name if the package name is known. A quick search on our site brought up two related questions, but they don't solve my issue:



I'm looking for a way to retrieve the information directly from the device, if possible – not "any" way (including "web lookups" or "via an app") as those two questions have it.


I know there are multiple tools available to obtain package details:



  • adb dumpsys package: While this lists all packages with a bunch of details, the "common name" is not shown

  • adb shell pm list: only gives the package names

  • aapt would be able to obtain the common name, but would require to first pull the .apk file from the device, which is not really convenient (and obviously will be pretty slow with many and/or large apps installed)


Did I miss something? I know the information must be on the device (how else could it show the app names in the GUI? I doubt Android parses the .apk file each time the GUI need the "common name"). So is there a way to get hold of it, using ADB directly?





TL;DR


Background (if somebody's curious): I want to be able to quickly obtain a list of user-apps from any of my devices, without having to revert to acrobatics. A list of their package names I can retrieve using adb shell pm list -3, but as those are package names only, recognizing apps is a guess-work. So if there were some ADB command to retrieve the common name for a given package name, I could simply use a loop like for pkg in $(adb shell pm list -3); do echo "- $(adb $pkg) ($pkg)"; done – and get a listing of all the installed user-apps in a "human readable format" together with their package names.


Use-cases:



  • See what "superflous" apps are installed (which I could remove)

  • Cross-check lists from multiple devices

  • Documentation ;)

  • and probably more (but the above 3 are what I need it for)




Answer



This is not a final answer, as it is not generic (only works on some devices) – but it's a start at least:


As we've figured out, at least CM based ROMs with Kitkat (Android 4.4) and above ship with the aapt binary available in /system/bin1. If your ROM doesn't have it, and installing the binary on the device is an option, you can find it here.


Using aapt, retrieving the app name is possible with


aapt d badging  | grep "application: label" |awk '{print $2}'

The output will be something like label='Funny App', which you then easily can parse for the app name, e.g.


aapt d badging  | grep 'application: label' | sed -n \"s/.*label\='\([^']*\)'.*/\1/p\"

(not good if the app name contains single quotes, but that might count as cosmetics – or you figure how to improve the sed part to deal with that).





1: we didn't find this in the Kitkat-and-above stock ROMs we've checked, so it might be CM based ROMs only


No comments:

Post a Comment

samsung galaxy s 2 - Cannot restore Kies backup after firmware upgrade

I backed up my Samsung Galaxy S2 on Kies before updating to Ice Cream Sandwich. After the upgrade I tried to restore, but the restore fails ...