6

Many of you will know (or at least have heard of) commands like adb shell pm list packages or adb shell dumpsys package to retrieve a list of apps available on your device. What I am looking for and cannot find is a command to list default apps – like what is set as default launcher, default camera, default browser etc. Not even parsing the full details of all apps via e.g. for app in $(pm list packages); do [[ -n "$(dumpsys package ${app#package:} | grep APP_BROWSER)" ]] && echo ${app#package:}; done reveals that (the command would simply list all web browsers on the device).

So how can I query for those default apps via ADB? It's fine if I have to pass the "type" (like APP_BROWSER in my example) as long as there's a reference of types available.

6
  • As of Android 10 roles are saved in /data/system/users/<user_id>/roles.xml which can be dumped using dumpsys role. Jul 28, 2020 at 20:53
  • Thanks, @IrfanLatif – that's what I was looking for in dumpsys. Looks like role was added only with Q (and up), as it's not available on the Oreo or lower devices I've got here for testing (did not yet check with the Pie one as it's currently "occupied"). Any clue for what would work at least with Oreo, and ideally also below? I mean, the concept of "default apps" goes back at least to 2.x IIRC – so the system must remember them somewhere there as well. I've combed dumpsys up and down, didn't find a hint.
    – Izzy
    Jul 28, 2020 at 21:24
  • I don't have access to any Android release other than Q ATM. But IIRC these settings were split across multiple locations, at least /data/system/users/0/package-restrictions.xml and /data/system/users/0/settings_secure.xml. So the respective CLI tools (pm and settings) might dump the required info. Or may see the files directly if root access is available. Jul 29, 2020 at 5:00
  • Thanks again! settings doesn't show them, and for pm I didn't see a corresponding parameter. What sounded close was cmd package resolve-activity -c android.intent.category.LAUNCHER – but that returns nada ("No activity found") for all I tried. I was able to identify the dialer using cmd package resolve-activity tel://123456; similarly the browser with a http URL (yields the OS (package android) if no default set, interesting) and the mail app with a mailto:[email protected]. But what actions to attempt for homescreen, assistant etc?
    – Izzy
    Jul 29, 2020 at 6:52
  • By "default apps", did you mean apps that the user can set from the Settings (e.g. default dialer, default camera), the default "open with" apps, or both? Other than those that are explicitly set from the Settings, most apps are set as default from calling implicit intents -- usually for specific filetype/mime or some URL schemes -- that match the intent filters registered on the apps' manifest file. Haven't researched where these values are stored in the system though.
    – Andrew T.
    Jul 29, 2020 at 12:05

1 Answer 1

4

I meanwhile found a partly resolve working with Android 7/8 and up (when the cmd package command was added):

  • Default dialer: cmd package resolve-activity tel://123456
  • Default mail: cmd package resolve-activity mailto:[email protected]
  • Default browser: cmd package resolve-activity http://www.example.com/
  • Default messenging: cmd package resolve-activity sms://123456
  • Default homescreen launcher: cmd package resolve-activity -c android.intent.category.HOME -a android.intent.action.MAIN

In the output, then grep for packageName= (e.g. packageName=com.android.messaging for the default SMS app). If a given action has no default set (e.g. multiple browsers are installed but none was declared to be "always used"), the action will resolve to the OS (packageName=android) to prompt the user. Side-note: if you want to check for available alternatives, just replace resolve-activity with query-activities (note it might also return a one-liner like "No activities found", especially on Android < 8).

I call this a "partly resolve" as it lacks several default apps I've no idea what activity to ask for – like the default homescreen launcher (note: just figured) or the assistant app (hints welcome!).

Thanks to Irfan Latif for pointing out a solution for Android 10 and up. Here, the role manager was added which I had already found but didn't figure how to call it via ADB. Turns out that was because all my devices are running Android < 10 (and as just said, role manager was added with Android 10), and the command would be dumpsys role (but not availabe before Android 10).

1
  • PS: Still missing something that resolves to the Contacts app, the Emergency app and the Assistant app…
    – Izzy
    Jul 29, 2020 at 21:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .