Android Multi-User behaviour: how to install application package for all users
I'm exploring the Android Multi-User behavior regarding the PackageManager.
I’m trying to understand how the Packages are installed in each User and how the installation in all users can be achieved.
Could not find a way to install a package for all users, only for the current user. Testing in Android 11 emulator (AOSP) with my sample application that installs packages using PackageInstaller.
What I'm able to test:
- Put my sample app as system app, so it will have the restricted permissions to install and remove packages and also it will be shown in every User
- Create new Users and switch between them
- List all application packages that are installed for the current user
- Using the my sample app, install package for the current user. I'm using the PackageInstaller.Session to achieve this successfully.
- Install package X with User A, switch to User B and I couldn't see the package X in the applications, however I was able to install the same package X on User B
- Unable to install lower versions of the same package (same packagename). (Install package X, verCode=2 on User A, switch to User B and try to install package X, verCode=1). However I can install packages with vercode >=
- User B does not see what User A have installed
- With help of Android Studio (AS) Device Explorer, I'm able to find the installed packages metadata (apk) located here: /data/app/[some strange hash]/[packagename of the app]
- With help of AS device explorer I'm able to find the data folder for each package that is dedicated for each user: /data/user/[user id]/[packagename of the app]
As per my knowledge, and I'm only referring to what I've found in the official Android documentation, I couldn't find a way to programmatically install packages in all the Users. Also, I couldn't find a method to list all the packages installed in the device (not in current user, but in the device).
Now that you know my status of investigation, maybe there is someone who can help me some official statement or a workaround.
1. Is there a way to (programmatically) list all the installed packages in the device, not dependent on current user?
2. Is there a way to (programmatically) install packages for all the users and not only the current user?