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

Commit 15a0bb3e authored by Jeongsik Mun's avatar Jeongsik Mun Committed by Song Chun Fan
Browse files

Clear enabled/disabled components when uninstalled

Persisting component enabled/disabled state even if a single user
is uninstalled is counter intuitive to developers.

This CL clears it for a user when an app is uninstalled on a user with
app data cleared.

Bug: 269407126
Test: Manually install a non-system app and enable/disable components
      for all users.
      $ adb uninstall --user 0 com.example.app
Test: Manually install a non-system app and enable/disable components
      for all users.
      $ adb uninstall -k --user 0 com.example.app
Test: Manually install a system app and enable/disable components for
      all users.
      $ adb uninstall --user 0 com.example.app
Test: Manually install an updated system app and enable/disable
      components for all users.
      $ adb uninstall --user all com.example.app
(cherry picked from https://partner-android-review.googlesource.com/q/commit:c0f18445d05d7afc0338bd0a4ae36fbd51e8e96a)
Merged-In: I5265ffabf44d44e81e791e6b4c1433afe3b1a145
Change-Id: I5265ffabf44d44e81e791e6b4c1433afe3b1a145

NOTE FOR REVIEWERS - errors occurred while applying the patch.
PLEASE REVIEW CAREFULLY.
Errors:
Error applying patch in services/core/java/com/android/server/pm/DeletePackageHelper.java, hunk HunkHeader[437,7->438,7]: Hunk cannot be applied

Original patch:
 From c0f18445d05d7afc0338bd0a4ae36fbd51e8e96a Mon Sep 17 00:00:00 2001
From: Jeongsik Mun <jeongsik.mun@samsung.corp-partner.google.com>
Date: Tue, 05 Sep 2023 10:37:52 +0900
Subject: [PATCH] Clear enabled/disabled components when uninstalled

Persisting component enabled/disabled state even if a single user
is uninstalled is counter intuitive to developers.

This CL clears it for a user when an app is uninstalled on a user with
app data cleared.

Bug: 269407126
Test: Manually install a non-system app and enable/disable components
      for all users.
      $ adb uninstall --user 0 com.example.app
Test: Manually install a non-system app and enable/disable components
      for all users.
      $ adb uninstall -k --user 0 com.example.app
Test: Manually install a system app and enable/disable components for
      all users.
      $ adb uninstall --user 0 com.example.app
Test: Manually install an updated system app and enable/disable
      components for all users.
      $ adb uninstall --user all com.example.app

Change-Id: I3f79436fcdb60b8e44d157c5d65756d000bbffa8
parent 7bee98d7
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
import android.text.TextUtils;
import android.util.ArraySet;
import android.util.EventLog;
import android.util.Log;
import android.util.Slog;
@@ -561,6 +562,17 @@ final class DeletePackageHelper {
                Slog.d(TAG, "Marking package:" + ps.getPackageName()
                        + " uninstalled for user:" + nextUserId);
            }

            // Keep enabled and disabled components in case of DELETE_KEEP_DATA
            ArraySet<String> enabledComponents = null;
            ArraySet<String> disabledComponents = null;
            if ((flags & PackageManager.DELETE_KEEP_DATA) != 0) {
                enabledComponents = new ArraySet<String>(
                        ps.readUserState(nextUserId).getEnabledComponents());
                disabledComponents = new ArraySet<String>(
                        ps.readUserState(nextUserId).getDisabledComponents());
            }

            // Preserve ArchiveState if this is not a full uninstall
            ArchiveState archiveState =
                    (flags & DELETE_KEEP_DATA) == 0
@@ -580,8 +592,8 @@ final class DeletePackageHelper {
                    false /*instantApp*/,
                    false /*virtualPreload*/,
                    null /*lastDisableAppCaller*/,
                    null /*enabledComponents*/,
                    null /*disabledComponents*/,
                    enabledComponents,
                    disabledComponents,
                    PackageManager.INSTALL_REASON_UNKNOWN,
                    PackageManager.UNINSTALL_REASON_UNKNOWN,
                    null /*harmfulAppWarning*/,
+6 −8
Original line number Diff line number Diff line
@@ -393,29 +393,27 @@ public class PackageUserStateImpl extends WatchableImpl implements PackageUserSt
    }

    public @NonNull PackageUserStateImpl setDisabledComponents(@Nullable ArraySet<String> value) {
        if (value == null) {
            return this;
        }
        if (mDisabledComponentsWatched == null) {
            mDisabledComponentsWatched = new WatchedArraySet<>();
            mDisabledComponentsWatched.registerObserver(mSnapshot);
        }
        mDisabledComponentsWatched.clear();
        if (value != null) {
            mDisabledComponentsWatched.addAll(value);
        }
        onChanged();
        return this;
    }

    public @NonNull PackageUserStateImpl setEnabledComponents(@Nullable ArraySet<String> value) {
        if (value == null) {
            return this;
        }
        if (mEnabledComponentsWatched == null) {
            mEnabledComponentsWatched = new WatchedArraySet<>();
            mEnabledComponentsWatched.registerObserver(mSnapshot);
        }
        mEnabledComponentsWatched.clear();
        if (value != null) {
            mEnabledComponentsWatched.addAll(value);
        }
        onChanged();
        return this;
    }