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

Commit 3f6598bb authored by Rohit Goyal's avatar Rohit Goyal Committed by Android (Google) Code Review
Browse files

Merge "Fix uninstallation flow for archived apps on server side." into main

parents ee51e62c 9746ef1a
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -259,6 +259,19 @@ public interface Computer extends PackageDataSnapshot {
     */
    boolean shouldFilterApplicationIncludingUninstalled(@Nullable PackageStateInternal ps,
            int callingUid, int userId);

    /**
     * Different from
     * {@link #shouldFilterApplicationIncludingUninstalled(PackageStateInternal, int, int)}, the
     * function returns {@code true} if:
     * <ul>
     * <li>The target package is not archived.
     * <li>The package cannot be found in the device or has been uninstalled in the current user.
     * </ul>
     */
    boolean shouldFilterApplicationIncludingUninstalledNotArchived(
            @Nullable PackageStateInternal ps,
            int callingUid, int userId);
    /**
     * Different from {@link #shouldFilterApplication(SharedUserSetting, int, int)}, the function
     * returns {@code true} if packages with the same shared user are all uninstalled in the current
+47 −11
Original line number Diff line number Diff line
@@ -2455,7 +2455,8 @@ public class ComputerEngine implements Computer {
     */
    public final boolean shouldFilterApplication(@Nullable PackageStateInternal ps,
            int callingUid, @Nullable ComponentName component,
            @PackageManager.ComponentType int componentType, int userId, boolean filterUninstall) {
            @PackageManager.ComponentType int componentType, int userId, boolean filterUninstall,
            boolean filterArchived) {
        if (Process.isSdkSandboxUid(callingUid)) {
            int clientAppUid = Process.getAppUidForSdkSandboxUid(callingUid);
            // SDK sandbox should be able to see it's client app
@@ -2469,6 +2470,8 @@ public class ComputerEngine implements Computer {
        }
        final String instantAppPkgName = getInstantAppPackageName(callingUid);
        final boolean callerIsInstantApp = instantAppPkgName != null;
        final boolean packageArchivedForUser = ps != null && PackageArchiver.isArchived(
                ps.getUserStateOrDefault(userId));
        // Don't treat hiddenUntilInstalled as an uninstalled state, phone app needs to access
        // these hidden application details to customize carrier apps. Also, allowing the system
        // caller accessing to application across users.
@@ -2476,7 +2479,11 @@ public class ComputerEngine implements Computer {
                || (filterUninstall
                && !isSystemOrRootOrShell(callingUid)
                && !ps.isHiddenUntilInstalled()
                        && !ps.getUserStateOrDefault(userId).isInstalled())) {
                && !ps.getUserStateOrDefault(userId).isInstalled()
                // Archived packages behave like uninstalled packages. So if filterUninstall is
                // set to true, we dismiss filtering some uninstalled package only if it is
                // archived and filterArchived is set as false.
                && (!packageArchivedForUser || filterArchived))) {
            // If caller is instant app or sdk sandbox and ps is null, pretend the application
            // exists, but, needs to be filtered
            return (callerIsInstantApp || filterUninstall || Process.isSdkSandboxUid(callingUid));
@@ -2524,7 +2531,20 @@ public class ComputerEngine implements Computer {
    }

    /**
     * @see #shouldFilterApplication(PackageStateInternal, int, ComponentName, int, int, boolean)
     * @see #shouldFilterApplication(PackageStateInternal, int, ComponentName, int, int, boolean,
     * boolean)
     */
    public final boolean shouldFilterApplication(@Nullable PackageStateInternal ps,
            int callingUid, @Nullable ComponentName component,
            @PackageManager.ComponentType int componentType, int userId, boolean filterUninstall) {
        return shouldFilterApplication(
                ps, callingUid, component, componentType, userId, filterUninstall,
                true /* filterArchived */);
    }

    /**
     * @see #shouldFilterApplication(PackageStateInternal, int, ComponentName, int, int, boolean,
     * boolean)
     */
    public final boolean shouldFilterApplication(@Nullable PackageStateInternal ps,
            int callingUid, @Nullable ComponentName component,
@@ -2534,7 +2554,8 @@ public class ComputerEngine implements Computer {
    }

    /**
     * @see #shouldFilterApplication(PackageStateInternal, int, ComponentName, int, int, boolean)
     * @see #shouldFilterApplication(PackageStateInternal, int, ComponentName, int, int, boolean,
     * boolean)
     */
    public final boolean shouldFilterApplication(
            @Nullable PackageStateInternal ps, int callingUid, int userId) {
@@ -2543,7 +2564,8 @@ public class ComputerEngine implements Computer {
    }

    /**
     * @see #shouldFilterApplication(PackageStateInternal, int, ComponentName, int, int, boolean)
     * @see #shouldFilterApplication(PackageStateInternal, int, ComponentName, int, int, boolean,
     * boolean)
     */
    public final boolean shouldFilterApplication(@NonNull SharedUserSetting sus,
            int callingUid, int userId) {
@@ -2558,7 +2580,8 @@ public class ComputerEngine implements Computer {
    }

    /**
     * @see #shouldFilterApplication(PackageStateInternal, int, ComponentName, int, int, boolean)
     * @see #shouldFilterApplication(PackageStateInternal, int, ComponentName, int, int, boolean,
     * boolean)
     */
    public final boolean shouldFilterApplicationIncludingUninstalled(
            @Nullable PackageStateInternal ps, int callingUid, int userId) {
@@ -2567,7 +2590,19 @@ public class ComputerEngine implements Computer {
    }

    /**
     * @see #shouldFilterApplication(PackageStateInternal, int, ComponentName, int, int, boolean)
     * @see #shouldFilterApplication(PackageStateInternal, int, ComponentName, int, int, boolean,
     * boolean)
     */
    public final boolean shouldFilterApplicationIncludingUninstalledNotArchived(
            @Nullable PackageStateInternal ps, int callingUid, int userId) {
        return shouldFilterApplication(
                ps, callingUid, null, TYPE_UNKNOWN, userId, true /* filterUninstall */,
                false /* filterArchived */);
    }

    /**
     * @see #shouldFilterApplication(PackageStateInternal, int, ComponentName, int, int, boolean,
     * boolean)
     */
    public final boolean shouldFilterApplicationIncludingUninstalled(
            @NonNull SharedUserSetting sus, int callingUid, int userId) {
@@ -5015,7 +5050,7 @@ public class ComputerEngine implements Computer {
        String installerPackageName = installSource.mInstallerPackageName;
        if (installerPackageName != null) {
            final PackageStateInternal ps = mSettings.getPackage(installerPackageName);
            if (ps == null || shouldFilterApplicationIncludingUninstalled(ps, callingUid,
            if (ps == null || shouldFilterApplicationIncludingUninstalledNotArchived(ps, callingUid,
                    UserHandle.getUserId(callingUid))) {
                installerPackageName = null;
            }
@@ -5033,7 +5068,8 @@ public class ComputerEngine implements Computer {
            return InstallSource.EMPTY;
        }

        if (ps == null || shouldFilterApplicationIncludingUninstalled(ps, callingUid, userId)) {
        if (ps == null || shouldFilterApplicationIncludingUninstalledNotArchived(ps, callingUid,
                userId)) {
            return null;
        }

+1 −1
Original line number Diff line number Diff line
@@ -440,7 +440,7 @@ final class DeletePackageHelper {
        if (outInfo != null) {
            // Remember which users are affected, before the installed states are modified
            outInfo.mRemovedUsers = (systemApp || userId == UserHandle.USER_ALL)
                    ? ps.queryInstalledUsers(allUserHandles, /* installed= */true)
                    ? ps.queryUsersInstalledOrHasData(allUserHandles)
                    : new int[]{userId};
        }

+4 −0
Original line number Diff line number Diff line
@@ -779,6 +779,10 @@ public class PackageSetting extends SettingBase implements PackageStateInternal
        return readUserState(userId).isInstalled();
    }

    boolean isArchived(int userId) {
        return PackageArchiver.isArchived(readUserState(userId));
    }

    int getInstallReason(int userId) {
        return readUserState(userId).getInstallReason();
    }