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

Commit adb4993f authored by Martijn Coenen's avatar Martijn Coenen Committed by Android (Google) Code Review
Browse files

Merge changes Ice81ae98,Id7f84655

* changes:
  Fix race condition around CE storage becoming available.
  Revert "Reconcile app data twice to pick up packages installed during unlock"
parents 2d7bb747 7a8bb0d2
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.os.storage;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.os.IVold;

import java.util.List;
@@ -135,4 +136,19 @@ public abstract class StorageManagerInternal {
     * {@link VolumeInfo#isPrimary()}
     */
    public abstract List<String> getPrimaryVolumeIds();

    /**
     * Tells StorageManager that CE storage for this user has been prepared.
     *
     * @param userId userId for which CE storage has been prepared
     */
    public abstract void markCeStoragePrepared(@UserIdInt int userId);

    /**
     * Returns true when CE storage for this user has been prepared.
     *
     * When the user key is unlocked and CE storage has been prepared,
     * it's ok to access and modify CE directories on volumes for this user.
     */
    public abstract boolean isCeStoragePrepared(@UserIdInt int userId);
}
+17 −0
Original line number Diff line number Diff line
@@ -221,6 +221,9 @@ class StorageManagerService extends IStorageManager.Stub
    @GuardedBy("mLock")
    private final Set<Integer> mFuseMountedUser = new ArraySet<>();

    @GuardedBy("mLock")
    private final Set<Integer> mCeStoragePreparedUsers = new ArraySet<>();

    public static class Lifecycle extends SystemService {
        private StorageManagerService mStorageManagerService;

@@ -4854,5 +4857,19 @@ class StorageManagerService extends IStorageManager.Stub
            }
            return primaryVolumeIds;
        }

        @Override
        public void markCeStoragePrepared(int userId) {
            synchronized (mLock) {
                mCeStoragePreparedUsers.add(userId);
            }
        }

        @Override
        public boolean isCeStoragePrepared(int userId) {
            synchronized (mLock) {
                return mCeStoragePreparedUsers.contains(userId);
            }
        }
    }
}
+1 −5
Original line number Diff line number Diff line
@@ -594,7 +594,6 @@ class UserController implements Handler.Callback {

            final TimingsTraceAndSlog t = new TimingsTraceAndSlog();
            t.traceBegin("UM.onBeforeUnlockUser-" + userId);
            final ArraySet<String> reconciledPackages =
            mInjector.getUserManager().onBeforeUnlockUser(userId);
            t.traceEnd();
            synchronized (mLock) {
@@ -604,9 +603,6 @@ class UserController implements Handler.Callback {
                }
            }
            mInjector.getUserManagerInternal().setUserState(userId, uss.state);
            t.traceBegin("UM.onUserStateRunningUnlocking-" + userId);
            mInjector.getUserManager().onUserStateRunningUnlocking(userId, reconciledPackages);
            t.traceEnd();

            uss.mUnlockProgress.setProgress(20);

+10 −26
Original line number Diff line number Diff line
@@ -6957,7 +6957,7 @@ public class PackageManagerService extends IPackageManager.Stub
            }
            List<String> deferPackages = reconcileAppsDataLI(StorageManager.UUID_PRIVATE_INTERNAL,
                    UserHandle.USER_SYSTEM, storageFlags, true /* migrateAppData */,
                    true /* onlyCoreApps */, null);
                    true /* onlyCoreApps */);
            mPrepareAppDataFuture = SystemServerInitThreadPool.submit(() -> {
                TimingsTraceLog traceLog = new TimingsTraceLog("SystemServerTimingAsync",
                        Trace.TRACE_TAG_PACKAGE_MANAGER);
@@ -15625,8 +15625,9 @@ public class PackageManagerService extends IPackageManager.Stub
        removeKeystoreDataIfNeeded(mInjector.getUserManagerInternal(), userId, appId);
        UserManagerInternal umInternal = mInjector.getUserManagerInternal();
        StorageManagerInternal smInternal = mInjector.getLocalService(StorageManagerInternal.class);
        final int flags;
        if (umInternal.isUserUnlockingOrUnlocked(userId)) {
        if (StorageManager.isUserKeyUnlocked(userId) && smInternal.isCeStoragePrepared(userId)) {
            flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE;
        } else if (umInternal.isUserRunning(userId)) {
            flags = StorageManager.FLAG_STORAGE_DE;
@@ -18586,32 +18587,22 @@ public class PackageManagerService extends IPackageManager.Stub
     * <p>
     * Verifies that directories exist and that ownership and labeling is
     * correct for all installed apps on all mounted volumes.
     *
     * @param reconciledPackages A set that will be populated with package names that have
     *                           successfully had their data reconciled. Any package names already
     *                           contained will be skipped. Because this must be mutable when
     *                           non-null, it is typed {@link ArraySet} to prevent accidental
     *                           usage of {@link Collections#emptySet()}. Null can be passed if the
     *                           caller doesn't need this functionality.
     */
    @NonNull
    void reconcileAppsData(int userId, int flags, boolean migrateAppsData,
            @Nullable ArraySet<String> reconciledPackages) {
    void reconcileAppsData(int userId, int flags, boolean migrateAppsData) {
        final StorageManager storage = mInjector.getSystemService(StorageManager.class);
        for (VolumeInfo vol : storage.getWritablePrivateVolumes()) {
            final String volumeUuid = vol.getFsUuid();
            synchronized (mInstallLock) {
                reconcileAppsDataLI(volumeUuid, userId, flags, migrateAppsData,
                        reconciledPackages);
                reconcileAppsDataLI(volumeUuid, userId, flags, migrateAppsData);
            }
        }
    }
    @GuardedBy("mInstallLock")
    void reconcileAppsDataLI(String volumeUuid, int userId, int flags,
            boolean migrateAppData, @Nullable ArraySet<String> reconciledPackages) {
        reconcileAppsDataLI(volumeUuid, userId, flags, migrateAppData, false /* onlyCoreApps */,
                reconciledPackages);
            boolean migrateAppData) {
        reconcileAppsDataLI(volumeUuid, userId, flags, migrateAppData, false /* onlyCoreApps */);
    }
    /**
@@ -18626,8 +18617,7 @@ public class PackageManagerService extends IPackageManager.Stub
     */
    @GuardedBy("mInstallLock")
    private List<String> reconcileAppsDataLI(String volumeUuid, int userId, int flags,
            boolean migrateAppData, boolean onlyCoreApps,
            @Nullable ArraySet<String> reconciledPackages) {
            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;
@@ -18690,9 +18680,6 @@ public class PackageManagerService extends IPackageManager.Stub
        int preparedCount = 0;
        for (PackageSetting ps : packages) {
            final String packageName = ps.name;
            if (reconciledPackages != null && reconciledPackages.contains(packageName)) {
                continue;
            }
            if (ps.pkg == null) {
                Slog.w(TAG, "Odd, missing scanned package " + packageName);
                // TODO: might be due to legacy ASEC apps; we should circle back
@@ -18708,10 +18695,6 @@ public class PackageManagerService extends IPackageManager.Stub
            if (ps.getInstalled(userId)) {
                prepareAppDataAndMigrate(batch, ps.pkg, userId, flags, migrateAppData);
                preparedCount++;
                if (reconciledPackages != null) {
                    reconciledPackages.add(packageName);
                }
            }
        }
        executeBatchLI(batch);
@@ -18745,7 +18728,8 @@ public class PackageManagerService extends IPackageManager.Stub
        StorageManagerInternal smInternal = mInjector.getLocalService(StorageManagerInternal.class);
        for (UserInfo user : mUserManager.getUsers(false /*excludeDying*/)) {
            final int flags;
            if (umInternal.isUserUnlockingOrUnlocked(user.id)) {
            if (StorageManager.isUserKeyUnlocked(user.id)
                    && smInternal.isCeStoragePrepared(user.id)) {
                flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE;
            } else if (umInternal.isUserRunning(user.id)) {
                flags = StorageManager.FLAG_STORAGE_DE;
+6 −3
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.os.FileUtils;
import android.os.UserHandle;
import android.os.storage.StorageEventListener;
import android.os.storage.StorageManager;
import android.os.storage.StorageManagerInternal;
import android.os.storage.VolumeInfo;
import android.text.TextUtils;
import android.util.Log;
@@ -157,9 +158,12 @@ public class StorageEventHelper extends StorageEventListener {
        // Reconcile app data for all started/unlocked users
        final StorageManager sm = mPm.mInjector.getSystemService(StorageManager.class);
        UserManagerInternal umInternal = mPm.mInjector.getUserManagerInternal();
        StorageManagerInternal smInternal = mPm.mInjector.getLocalService(
                StorageManagerInternal.class);
        for (UserInfo user : mPm.mUserManager.getUsers(false /* includeDying */)) {
            final int flags;
            if (umInternal.isUserUnlockingOrUnlocked(user.id)) {
            if (StorageManager.isUserKeyUnlocked(user.id)
                    && smInternal.isCeStoragePrepared(user.id)) {
                flags = StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE;
            } else if (umInternal.isUserRunning(user.id)) {
                flags = StorageManager.FLAG_STORAGE_DE;
@@ -170,8 +174,7 @@ public class StorageEventHelper extends StorageEventListener {
            try {
                sm.prepareUserStorage(volumeUuid, user.id, user.serialNumber, flags);
                synchronized (mPm.mInstallLock) {
                    mPm.reconcileAppsDataLI(volumeUuid, user.id, flags, true /* migrateAppData */,
                            null);
                    mPm.reconcileAppsDataLI(volumeUuid, user.id, flags, true /* migrateAppData */);
                }
            } catch (IllegalStateException e) {
                // Device was probably ejected, and we'll process that event momentarily
Loading