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

Commit 47f7108c authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Prepare user storage just before using it.

Wire up preparing of user-specific app storage to existing user
lifecycle hooks.  This way we're sure the storage is ready to roll
just before we start reconciling app data directories.

This also has the nice property that we only prepare storage when
we know that keys are unlocked.

Bug: 25796509
Change-Id: Ic7df9ddbcfb1e20649d11b6cf68d424e3c365ee1
parent 2343f8df
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -74,6 +74,9 @@ public final class UserHandle implements Parcelable {
    /** @hide A user id constant to indicate the "system" user of the device */
    public static final @UserIdInt int USER_SYSTEM = 0;

    /** @hide A user serial constant to indicate the "system" user of the device */
    public static final int USER_SERIAL_SYSTEM = 0;

    /** @hide A user handle to indicate the "system" user of the device */
    public static final UserHandle SYSTEM = new UserHandle(USER_SYSTEM);

+5 −5
Original line number Diff line number Diff line
@@ -1284,7 +1284,7 @@ public interface IMountService extends IInterface {

            @Override
            public void prepareUserStorage(
                    String volumeUuid, int userId, int serialNumber, boolean ephemeral)
                    String volumeUuid, int userId, int serialNumber, int flags)
                    throws RemoteException {
                Parcel _data = Parcel.obtain();
                Parcel _reply = Parcel.obtain();
@@ -1293,7 +1293,7 @@ public interface IMountService extends IInterface {
                    _data.writeString(volumeUuid);
                    _data.writeInt(userId);
                    _data.writeInt(serialNumber);
                    _data.writeInt(ephemeral ? 1 : 0);
                    _data.writeInt(flags);
                    mRemote.transact(Stub.TRANSACTION_prepareUserStorage, _data, _reply, 0);
                    _reply.readException();
                } finally {
@@ -2055,8 +2055,8 @@ public interface IMountService extends IInterface {
                    String volumeUuid = data.readString();
                    int userId = data.readInt();
                    int serialNumber = data.readInt();
                    boolean ephemeral = data.readInt() != 0;
                    prepareUserStorage(volumeUuid, userId, serialNumber, ephemeral);
                    int _flags = data.readInt();
                    prepareUserStorage(volumeUuid, userId, serialNumber, _flags);
                    reply.writeNoException();
                    return true;
                }
@@ -2389,7 +2389,7 @@ public interface IMountService extends IInterface {
    public boolean isUserKeyUnlocked(int userId) throws RemoteException;

    public void prepareUserStorage(String volumeUuid, int userId, int serialNumber,
            boolean ephemeral) throws RemoteException;
            int flags) throws RemoteException;

    public ParcelFileDescriptor mountAppFuse(String name) throws RemoteException;
}
+9 −4
Original line number Diff line number Diff line
@@ -92,8 +92,14 @@ public class StorageManager {
    /** {@hide} */
    public static final int DEBUG_EMULATE_FBE = 1 << 1;

    // NOTE: keep in sync with installd
    /** {@hide} */
    public static final int FLAG_FOR_WRITE = 1 << 0;
    public static final int FLAG_STORAGE_DE = 1 << 0;
    /** {@hide} */
    public static final int FLAG_STORAGE_CE = 1 << 1;

    /** {@hide} */
    public static final int FLAG_FOR_WRITE = 1 << 8;

    private final Context mContext;
    private final ContentResolver mResolver;
@@ -1003,10 +1009,9 @@ public class StorageManager {
    }

    /** {@hide} */
    public void prepareUserStorage(
            String volumeUuid, int userId, int serialNumber, boolean ephemeral) {
    public void prepareUserStorage(String volumeUuid, int userId, int serialNumber, int flags) {
        try {
            mMountService.prepareUserStorage(volumeUuid, userId, serialNumber, ephemeral);
            mMountService.prepareUserStorage(volumeUuid, userId, serialNumber, flags);
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
+2 −3
Original line number Diff line number Diff line
@@ -2800,14 +2800,13 @@ class MountService extends IMountService.Stub
    }

    @Override
    public void prepareUserStorage(
            String volumeUuid, int userId, int serialNumber, boolean ephemeral) {
    public void prepareUserStorage(String volumeUuid, int userId, int serialNumber, int flags) {
        enforcePermission(android.Manifest.permission.STORAGE_INTERNAL);
        waitForReady();

        try {
            mCryptConnector.execute("cryptfs", "prepare_user_storage", escapeNull(volumeUuid),
                    userId, serialNumber, ephemeral ? 1 : 0);
                    userId, serialNumber, flags);
        } catch (NativeDaemonConnectorException e) {
            throw e.rethrowAsParcelableException();
        }
+4 −17
Original line number Diff line number Diff line
@@ -16,11 +16,11 @@

package com.android.server.pm;

import android.annotation.IntDef;
import android.annotation.Nullable;
import android.content.Context;
import android.content.pm.PackageStats;
import android.os.Build;
import android.os.storage.StorageManager;
import android.util.Slog;

import com.android.internal.os.InstallerConnection;
@@ -29,9 +29,6 @@ import com.android.server.SystemService;

import dalvik.system.VMRuntime;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public final class Installer extends SystemService {
    private static final String TAG = "Installer";

@@ -52,19 +49,9 @@ public final class Installer extends SystemService {
    /** This is an OTA update dexopt */
    public static final int DEXOPT_OTA          = 1 << 6;

    /** @hide */
    @IntDef(flag = true, value = {
            FLAG_DE_STORAGE,
            FLAG_CE_STORAGE,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface StorageFlags {}

    public static final int FLAG_DE_STORAGE = 1 << 0;
    public static final int FLAG_CE_STORAGE = 1 << 1;

    public static final int FLAG_CLEAR_CACHE_ONLY = 1 << 2;
    public static final int FLAG_CLEAR_CODE_CACHE_ONLY = 1 << 3;
    // NOTE: keep in sync with installd
    public static final int FLAG_CLEAR_CACHE_ONLY = 1 << 8;
    public static final int FLAG_CLEAR_CODE_CACHE_ONLY = 1 << 9;

    private final InstallerConnection mInstaller;

Loading