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

Commit 9746ef1a authored by Rohit Goyal's avatar Rohit Goyal
Browse files

Fix uninstallation flow for archived apps on server side.

* These changes fix the adb uninstall command to work correctly while uninstalling the archived app.
* ACTION_PACKAGE_REMOVED broadcast is also emitted with these changes.

Test: Manually tested the uninstallation flow.
Bug: 305926659
Change-Id: I588a21a2f5980d515a3644a6dc2b6f99214b61b8
parent 77d95dbc
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
@@ -2454,7 +2454,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
@@ -2468,6 +2469,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.
@@ -2475,7 +2478,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));
@@ -2523,7 +2530,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,
@@ -2533,7 +2553,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) {
@@ -2542,7 +2563,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) {
@@ -2557,7 +2579,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) {
@@ -2566,7 +2589,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) {
@@ -5014,7 +5049,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;
            }
@@ -5032,7 +5067,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
@@ -439,7 +439,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
@@ -772,6 +772,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();
    }