Commit 1133424c authored by Bartosz Fabianowski's avatar Bartosz Fabianowski

Wire up PM.getInstalledApplicationsAsUser(flags, userId) as hidden API

Settings needs to access a variant of getInstalledApplications() which
takes a |userId| argument. Since this is not currently exposed by
PackageManager, Settings calls into PackageManagerService directly. This
is ugly and breaks the regular abstraction layer hierarchy.

The CL fixes the problem by exposing the required variant of
getInstalledApplications() as a hidden API, analogously to what was done
before with getInstalledPackages().

Bug: 32692748
Test: Will be CTS-verifier-tested together with Settings
Change-Id: Id9c4e8e18524d312159821f1a4d5527263c7e950
parent 0d11dc0c
......@@ -698,7 +698,13 @@ public class ApplicationPackageManager extends PackageManager {
@SuppressWarnings("unchecked")
@Override
public List<ApplicationInfo> getInstalledApplications(int flags) {
final int userId = mContext.getUserId();
return getInstalledApplicationsAsUser(flags, mContext.getUserId());
}
/** @hide */
@SuppressWarnings("unchecked")
@Override
public List<ApplicationInfo> getInstalledApplicationsAsUser(int flags, int userId) {
try {
ParceledListSlice<ApplicationInfo> parceledList =
mPM.getInstalledApplications(flags, userId);
......
......@@ -3513,6 +3513,36 @@ public abstract class PackageManager {
*/
public abstract List<ApplicationInfo> getInstalledApplications(@ApplicationInfoFlags int flags);
/**
* Return a List of all application packages that are installed on the device, for a specific
* user. If flag GET_UNINSTALLED_PACKAGES has been set, a list of all applications including
* those deleted with {@code DONT_DELETE_DATA} (partially installed apps with data directory)
* will be returned.
*
* @param flags Additional option flags. Use any combination of
* {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
* {@link #MATCH_SYSTEM_ONLY}, {@link #MATCH_UNINSTALLED_PACKAGES}
* to modify the data returned.
* @param userId The user for whom the installed applications are to be listed
*
* @return A List of ApplicationInfo objects, one for each installed application.
* In the unlikely case there are no installed packages, an empty list
* is returned. If flag {@code MATCH_UNINSTALLED_PACKAGES} is set, the
* application information is retrieved from the list of uninstalled
* applications (which includes installed applications as well as
* applications with data directory i.e. applications which had been
* deleted with {@code DONT_DELETE_DATA} flag set).
* @hide
*
* @see #GET_META_DATA
* @see #GET_SHARED_LIBRARY_FILES
* @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
* @see #MATCH_SYSTEM_ONLY
* @see #MATCH_UNINSTALLED_PACKAGES
*/
public abstract List<ApplicationInfo> getInstalledApplicationsAsUser(
@ApplicationInfoFlags int flags, @UserIdInt int userId);
/**
* Gets the ephemeral applications the user recently used. Requires
* holding "android.permission.ACCESS_EPHEMERAL_APPS".
......
......@@ -314,6 +314,12 @@ public class MockPackageManager extends PackageManager {
throw new UnsupportedOperationException();
}
/** @hide */
@Override
public List<ApplicationInfo> getInstalledApplicationsAsUser(int flags, int userId) {
throw new UnsupportedOperationException();
}
/** @hide */
@Override
public List<EphemeralApplicationInfo> getEphemeralApplications() {
......
......@@ -271,6 +271,11 @@ public class BridgePackageManager extends PackageManager {
return null;
}
@Override
public List<ApplicationInfo> getInstalledApplicationsAsUser(int flags, int userId) {
return null;
}
@Override
public List<EphemeralApplicationInfo> getEphemeralApplications() {
return null;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment