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

Commit 0e62384c authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Prepare app data only when storage is available.

Before this change, scanning a package aggressively tried checking
to ensure that private app data was prepared.  However, in an FBE
world we may not have access to that data at scan time.  So this
change shifts the preparing of private app data until later: it
prepares DE storage when a user is started, and CE storage when a
user is unlocked.  Wire ourselves into the user lifecycle so we can
prepare storage at both user start and unlock.

When DE/CE storage becomes available, this change reconciles any
found packages against known installed apps, and deletes any orphaned
data directories.

We now need to store the last-restorecon hash in an xattr on a
per-user directory basis, since we can't restorecon CE storage until
it's unlocked, or adopted storage until it's mounted.  Remove a
bunch of used logic for loading dynamic SELinux policy at runtime;
our policy always comes from the system image.

Bug: 26466827, 26544104
Change-Id: I8d0a4ef862c35f4e4ef5c7f20d3bb8f12ba3fd4b
parent ab3bdf09
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -766,9 +766,13 @@ public class UserManager {
     * @param user The user to retrieve the running state for.
     */
    public boolean isUserRunning(UserHandle user) {
        return isUserRunning(user.getIdentifier());
    }

    /** {@hide} */
    public boolean isUserRunning(int userId) {
        try {
            return ActivityManagerNative.getDefault().isUserRunning(
                    user.getIdentifier(), 0);
            return ActivityManagerNative.getDefault().isUserRunning(userId, 0);
        } catch (RemoteException e) {
            return false;
        }
+0 −1
Original line number Diff line number Diff line
@@ -12684,7 +12684,6 @@ public final class ActivityManagerService extends ActivityManagerNative
        if (goingCallback != null) goingCallback.run();
        mBatteryStatsService.noteEvent(BatteryStats.HistoryItem.EVENT_USER_RUNNING_START,
                Integer.toString(currentUserId), currentUserId);
        mBatteryStatsService.noteEvent(BatteryStats.HistoryItem.EVENT_USER_FOREGROUND_START,
+5 −1
Original line number Diff line number Diff line
@@ -249,6 +249,9 @@ final class UserController {
            if (uss.state == UserState.STATE_RUNNING_LOCKED) {
                uss.setState(UserState.STATE_RUNNING);

                // Give user manager a chance to prepare app storage
                mUserManager.onBeforeUnlockUser(userId);

                mHandler.sendMessage(mHandler.obtainMessage(SYSTEM_USER_UNLOCK_MSG, userId, 0));

                final Intent unlockedIntent = new Intent(Intent.ACTION_USER_UNLOCKED);
@@ -651,7 +654,8 @@ final class UserController {
                }

                if (uss.state == UserState.STATE_BOOTING) {
                    // Let user manager propagate user restrictions to other services.
                    // Give user manager a chance to propagate user restrictions
                    // to other services and prepare app storage
                    getUserManager().onBeforeStartUser(userId);

                    // Booting up a new user, need to tell system services about it.
+13 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server.pm;

import android.annotation.IntDef;
import android.annotation.Nullable;
import android.content.Context;
import android.content.pm.PackageStats;
@@ -28,6 +29,9 @@ 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";

@@ -46,8 +50,17 @@ public final class Installer extends SystemService {
    /** Run the application with the JIT compiler */
    public static final int DEXOPT_USEJIT       = 1 << 5;

    /** @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;

+5 −0
Original line number Diff line number Diff line
@@ -25,6 +25,11 @@ import com.android.internal.os.InstallerConnection.InstallerException;
public class PackageManagerException extends Exception {
    public final int error;

    public PackageManagerException(String detailMessage) {
        super(detailMessage);
        this.error = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
    }

    public PackageManagerException(int error, String detailMessage) {
        super(detailMessage);
        this.error = error;
Loading