Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3d67a9ed authored by Felka Chang's avatar Felka Chang
Browse files

Remove PackageManager.getResourcesForApplicationAsUser API

To switch another user to do something should create the context of the
specified user by using Context.createContextAsUser rather than call
*AsUser API directly.

Test: make -j droid cts gts vts
Test: make -j docs
Test: atest SystemUITests \
    FrameworksServicesTests:com.android.server.pm
Fix: 170928809
Bug: 72863210
Change-Id: Ie1999ba9cf61a4e85b7172240cb198111389ab73
parent faf7e4a0
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -6195,9 +6195,30 @@ public abstract class PackageManager {
    public abstract Resources getResourcesForApplication(@NonNull String packageName)
            throws NameNotFoundException;

    /** @hide */
    /**
     * Please don't use this function because it is no longer supported.
     *
     * @deprecated Instead of using this function, please use
     *             {@link Context#createContextAsUser(UserHandle, int)} to create the specified user
     *             context, {@link Context#getPackageManager()} to get PackageManager instance for
     *             the specified user, and then
     *             {@link PackageManager#getResourcesForApplication(String)} to get the same
     *             Resources instance.
     * @see {@link Context#createContextAsUser(android.os.UserHandle, int)}
     * @see {@link Context#getPackageManager()}
     * @see {@link android.content.pm.PackageManager#getResourcesForApplication(java.lang.String)}
     * TODO(b/170852794): mark maxTargetSdk as {@code Build.VERSION_CODES.S}
     * @hide
     */
    @NonNull
    @UnsupportedAppUsage
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170928809,
            publicAlternatives = "Use {@code Context#createContextAsUser(UserHandle, int)}"
                    + " to create the relevant user context,"
                    + " {@link android.content.Context#getPackageManager()} and"
                    + " {@link android.content.pm.PackageManager#getResourcesForApplication("
                    + "java.lang.String)}"
                    + " instead.")
    @Deprecated
    public abstract Resources getResourcesForApplicationAsUser(@NonNull String packageName,
            @UserIdInt int userId) throws NameNotFoundException;

+3 −2
Original line number Diff line number Diff line
@@ -191,8 +191,9 @@ public class SuspendedAppActivity extends AlertActivity
        mOnUnsuspend = intent.getParcelableExtra(EXTRA_UNSUSPEND_INTENT);
        if (mSuppliedDialogInfo != null) {
            try {
                mSuspendingAppResources = mPm.getResourcesForApplicationAsUser(mSuspendingPackage,
                        mUserId);
                mSuspendingAppResources = createContextAsUser(
                        UserHandle.of(mUserId), /* flags */ 0).getPackageManager()
                        .getResourcesForApplication(mSuspendedPackage);
            } catch (PackageManager.NameNotFoundException ne) {
                Slog.e(TAG, "Could not find resources for " + mSuspendingPackage, ne);
            }