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

Commit b9f1867d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[pm] better annotation for storage flags"

parents 0ee1df68 e801d3e4
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -273,6 +273,15 @@ public class StorageManager {
    /** {@hide} */
    public static final int FLAG_STORAGE_EXTERNAL = IInstalld.FLAG_STORAGE_EXTERNAL;

    /** {@hide} */
    @IntDef(prefix = "FLAG_STORAGE_",  value = {
            FLAG_STORAGE_DE,
            FLAG_STORAGE_CE,
            FLAG_STORAGE_EXTERNAL
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface StorageFlags {}

    /** {@hide} */
    public static final int FLAG_FOR_WRITE = 1 << 8;
    /** {@hide} */
+5 −3
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.os.IBinder;
import android.os.Looper;
import android.os.PersistableBundle;
import android.os.Process;
import android.os.storage.StorageManager;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.SparseArray;
@@ -872,8 +873,8 @@ public abstract class PackageManagerInternal implements PackageSettingsSnapshotP
     *
     * @throws IOException if the request was unable to be fulfilled.
     */
    public abstract void freeStorage(String volumeUuid, long bytes, int storageFlags)
            throws IOException;
    public abstract void freeStorage(String volumeUuid, long bytes,
            @StorageManager.AllocateFlags int flags) throws IOException;

    /** Returns {@code true} if the specified component is enabled and matches the given flags. */
    public abstract boolean isEnabledAndMatches(@NonNull ParsedMainComponent component,
@@ -1261,5 +1262,6 @@ public abstract class PackageManagerInternal implements PackageSettingsSnapshotP
    /**
     * Reconcile all app data for the given user.
     */
    public abstract void reconcileAppsData(int userId, int storageFlags, boolean migrateAppsData);
    public abstract void reconcileAppsData(int userId, @StorageManager.StorageFlags int flags,
            boolean migrateAppsData);
}
+10 −7
Original line number Diff line number Diff line
@@ -162,7 +162,8 @@ final class AppDataHelper {
     * </ul>
     */
    private @NonNull CompletableFuture<?> prepareAppData(@NonNull Installer.Batch batch,
            @Nullable AndroidPackage pkg, int previousAppId, int userId, int flags) {
            @Nullable AndroidPackage pkg, int previousAppId, int userId,
            @StorageManager.StorageFlags int flags) {
        if (pkg == null) {
            Slog.wtf(TAG, "Package was null!", new Throwable());
            return CompletableFuture.completedFuture(null);
@@ -171,7 +172,8 @@ final class AppDataHelper {
    }

    private void prepareAppDataAndMigrate(@NonNull Installer.Batch batch,
            @NonNull AndroidPackage pkg, int userId, int flags, boolean maybeMigrateAppData) {
            @NonNull AndroidPackage pkg, int userId, @StorageManager.StorageFlags int flags,
            boolean maybeMigrateAppData) {
        prepareAppData(batch, pkg, Process.INVALID_UID, userId, flags).thenRun(() -> {
            // Note: this code block is executed with the Installer lock
            // already held, since it's invoked as a side-effect of
@@ -331,7 +333,8 @@ final class AppDataHelper {
     * correct for all installed apps on all mounted volumes.
     */
    @NonNull
    public void reconcileAppsData(int userId, int flags, boolean migrateAppsData) {
    public void reconcileAppsData(int userId, @StorageManager.StorageFlags int flags,
            boolean migrateAppsData) {
        final StorageManager storage = mInjector.getSystemService(StorageManager.class);
        for (VolumeInfo vol : storage.getWritablePrivateVolumes()) {
            final String volumeUuid = vol.getFsUuid();
@@ -342,7 +345,7 @@ final class AppDataHelper {
    }

    @GuardedBy("mPm.mInstallLock")
    void reconcileAppsDataLI(String volumeUuid, int userId, int flags,
    void reconcileAppsDataLI(String volumeUuid, int userId, @StorageManager.StorageFlags int flags,
            boolean migrateAppData) {
        reconcileAppsDataLI(volumeUuid, userId, flags, migrateAppData, false /* onlyCoreApps */);
    }
@@ -359,8 +362,8 @@ final class AppDataHelper {
     * @return list of skipped non-core packages (if {@code onlyCoreApps} is true)
     */
    @GuardedBy("mPm.mInstallLock")
    private List<String> reconcileAppsDataLI(String volumeUuid, int userId, int flags,
            boolean migrateAppData, boolean onlyCoreApps) {
    private List<String> reconcileAppsDataLI(String volumeUuid, int userId,
            @StorageManager.StorageFlags int flags, boolean migrateAppData, boolean onlyCoreApps) {
        Slog.v(TAG, "reconcileAppsData for " + volumeUuid + " u" + userId + " 0x"
                + Integer.toHexString(flags) + " migrateAppData=" + migrateAppData);
        List<String> result = onlyCoreApps ? new ArrayList<>() : null;
@@ -479,7 +482,7 @@ final class AppDataHelper {
     * can't wait for user to start
     */
    public Future<?> fixAppsDataOnBoot() {
        final int storageFlags;
        final @StorageManager.StorageFlags int storageFlags;
        if (StorageManager.isFileEncryptedNativeOrEmulated()) {
            storageFlags = StorageManager.FLAG_STORAGE_DE;
        } else {
+12 −11
Original line number Diff line number Diff line
@@ -2741,13 +2741,13 @@ public class PackageManagerService extends IPackageManager.Stub

    @Override
    public void freeStorageAndNotify(final String volumeUuid, final long freeStorageSize,
            final int storageFlags, final IPackageDataObserver observer) {
            final @StorageManager.AllocateFlags int flags, final IPackageDataObserver observer) {
        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.CLEAR_APP_CACHE, null);
        mHandler.post(() -> {
            boolean success = false;
            try {
                freeStorage(volumeUuid, freeStorageSize, storageFlags);
                freeStorage(volumeUuid, freeStorageSize, flags);
                success = true;
            } catch (IOException e) {
                Slog.w(TAG, e);
@@ -2764,13 +2764,13 @@ public class PackageManagerService extends IPackageManager.Stub

    @Override
    public void freeStorage(final String volumeUuid, final long freeStorageSize,
            final int storageFlags, final IntentSender pi) {
            final @StorageManager.AllocateFlags int flags, final IntentSender pi) {
        mContext.enforceCallingOrSelfPermission(
                android.Manifest.permission.CLEAR_APP_CACHE, TAG);
        mHandler.post(() -> {
            boolean success = false;
            try {
                freeStorage(volumeUuid, freeStorageSize, storageFlags);
                freeStorage(volumeUuid, freeStorageSize, flags);
                success = true;
            } catch (IOException e) {
                Slog.w(TAG, e);
@@ -2789,7 +2789,8 @@ public class PackageManagerService extends IPackageManager.Stub
     * Blocking call to clear various types of cached data across the system
     * until the requested bytes are available.
     */
    public void freeStorage(String volumeUuid, long bytes, int storageFlags) throws IOException {
    public void freeStorage(String volumeUuid, long bytes,
            @StorageManager.AllocateFlags int flags) throws IOException {
        final StorageManager storage = mInjector.getSystemService(StorageManager.class);
        final File file = storage.findPathForUuid(volumeUuid);
        if (file.getUsableSpace() >= bytes) return;
@@ -2797,8 +2798,7 @@ public class PackageManagerService extends IPackageManager.Stub
        if (mEnableFreeCacheV2) {
            final boolean internalVolume = Objects.equals(StorageManager.UUID_PRIVATE_INTERNAL,
                    volumeUuid);
            final boolean aggressive = (storageFlags
                    & StorageManager.FLAG_ALLOCATE_AGGRESSIVE) != 0;
            final boolean aggressive = (flags & StorageManager.FLAG_ALLOCATE_AGGRESSIVE) != 0;

            // 1. Pre-flight to determine if we have any chance to succeed
            // 2. Consider preloaded data (after 1w honeymoon, unless aggressive)
@@ -8311,9 +8311,9 @@ public class PackageManagerService extends IPackageManager.Stub
        }

        @Override
        public void freeStorage(String volumeUuid, long bytes, int storageFlags)
                throws IOException {
            PackageManagerService.this.freeStorage(volumeUuid, bytes, storageFlags);
        public void freeStorage(String volumeUuid, long bytes,
                @StorageManager.AllocateFlags int flags) throws IOException {
            PackageManagerService.this.freeStorage(volumeUuid, bytes, flags);
        }

        @Override
@@ -8695,7 +8695,8 @@ public class PackageManagerService extends IPackageManager.Stub
        }

        @Override
        public void reconcileAppsData(int userId, int flags, boolean migrateAppsData) {
        public void reconcileAppsData(int userId, @StorageManager.StorageFlags int flags,
                boolean migrateAppsData) {
            PackageManagerService.this.mAppDataHelper.reconcileAppsData(userId, flags,
                    migrateAppsData);
        }