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

Commit 194b7e31 authored by Song Chun Fan's avatar Song Chun Fan Committed by Android (Google) Code Review
Browse files

Merge "[pm] Reland: make dataDir null if the app is uninstalled with data deleted" into main

parents 4ee22bf1 c43bb7a0
Loading
Loading
Loading
Loading
+30 −5
Original line number Diff line number Diff line
@@ -444,7 +444,7 @@ public class PackageInfoUtils {

        updateApplicationInfo(info, flags, state);

        initForUser(info, pkg, userId);
        initForUser(info, pkg, userId, state);

        // TODO(b/135203078): Remove PackageParser1/toAppInfoWithoutState and clean all this up
        PackageStateUnserialized pkgState = pkgSetting.getTransientState();
@@ -690,7 +690,7 @@ public class PackageInfoUtils {
        info.splitDependencies = pkg.getSplitDependencies().size() == 0
                ? null : pkg.getSplitDependencies();

        initForUser(info, pkg, userId);
        initForUser(info, pkg, userId, state);

        info.primaryCpuAbi = pkgSetting.getPrimaryCpuAbi();
        info.secondaryCpuAbi = pkgSetting.getSecondaryCpuAbi();
@@ -1006,7 +1006,7 @@ public class PackageInfoUtils {
    }

    private static void initForUser(ApplicationInfo output, AndroidPackage input,
            @UserIdInt int userId) {
            @UserIdInt int userId, PackageUserStateInternal state) {
        PackageImpl pkg = ((PackageImpl) input);
        String packageName = input.getPackageName();
        output.uid = UserHandle.getUid(userId, UserHandle.getAppId(input.getUid()));
@@ -1016,6 +1016,13 @@ public class PackageInfoUtils {
            return;
        }

        if (android.content.pm.Flags.nullableDataDir()
                && !state.isInstalled() && !state.dataExists()) {
            // The data dir has been deleted
            output.dataDir = null;
            return;
        }

        // For performance reasons, all these paths are built as strings
        if (userId == UserHandle.USER_SYSTEM) {
            output.credentialProtectedDataDir =
@@ -1050,7 +1057,7 @@ public class PackageInfoUtils {
    // This duplicates the ApplicationInfo variant because it uses field assignment and the classes
    // don't inherit from each other, unfortunately. Consolidating logic would introduce overhead.
    private static void initForUser(InstrumentationInfo output, AndroidPackage input,
            @UserIdInt int userId) {
            @UserIdInt int userId, PackageUserStateInternal state) {
        PackageImpl pkg = ((PackageImpl) input);
        String packageName = input.getPackageName();
        if ("android".equals(packageName)) {
@@ -1058,6 +1065,13 @@ public class PackageInfoUtils {
            return;
        }

        if (android.content.pm.Flags.nullableDataDir()
                && !state.isInstalled() && !state.dataExists()) {
            // The data dir has been deleted
            output.dataDir = null;
            return;
        }

        // For performance reasons, all these paths are built as strings
        if (userId == UserHandle.USER_SYSTEM) {
            output.credentialProtectedDataDir =
@@ -1089,12 +1103,23 @@ public class PackageInfoUtils {
        }
    }

    @NonNull
    /**
     * Returns the data dir of the app for the target user. Return null if the app isn't installed
     * on the target user and doesn't have a data dir on the target user.
     */
    @Nullable
    public static File getDataDir(PackageStateInternal ps, int userId) {
        if ("android".equals(ps.getPackageName())) {
            return Environment.getDataSystemDirectory();
        }

        if (android.content.pm.Flags.nullableDataDir()
                && !ps.getUserStateOrDefault(userId).isInstalled()
                && !ps.getUserStateOrDefault(userId).dataExists()) {
            // The app has been uninstalled for the user and the data dir has been deleted
            return null;
        }

        if (ps.isDefaultToDeviceProtectedStorage()
                && PackageManager.APPLY_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) {
            return Environment.getDataUserDePackageDirectory(ps.getVolumeUuid(), userId,