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

Commit b8140085 authored by Lenka Trochtova's avatar Lenka Trochtova Committed by Android (Google) Code Review
Browse files

Merge "Introduce ephemeral users."

parents 8ff2f095 c4dd0213
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -16,11 +16,11 @@

package com.android.commands.pm;

import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED;
import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ASK;
import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS;
import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS_ASK;
import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ASK;
import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER;
import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED;

import android.accounts.IAccountManager;
import android.app.ActivityManager;
@@ -798,6 +798,10 @@ public final class Pm {
                flags |= UserInfo.FLAG_MANAGED_PROFILE;
            } else if ("--restricted".equals(opt)) {
                flags |= UserInfo.FLAG_RESTRICTED;
            } else if ("--ephemeral".equals(opt)) {
                flags |= UserInfo.FLAG_EPHEMERAL;
            } else if ("--guest".equals(opt)) {
                flags |= UserInfo.FLAG_GUEST;
            } else {
                System.err.println("Error: unknown option " + opt);
                return showUsage();
@@ -1356,7 +1360,7 @@ public final class Pm {
        System.err.println("       pm get-install-location");
        System.err.println("       pm set-permission-enforced PERMISSION [true|false]");
        System.err.println("       pm trim-caches DESIRED_FREE_SPACE [internal|UUID]");
        System.err.println("       pm create-user [--profileOf USER_ID] [--managed] [--restricted] USER_NAME");
        System.err.println("       pm create-user [--profileOf USER_ID] [--managed] [--restricted] [--ephemeral] [--guest] USER_NAME");
        System.err.println("       pm remove-user USER_ID");
        System.err.println("       pm get-max-users");
        System.err.println("");
+11 −0
Original line number Diff line number Diff line
@@ -78,6 +78,12 @@ public class UserInfo implements Parcelable {

    public static final int FLAG_QUIET_MODE = 0x00000080;

    /**
     * Indicates that this user is ephemeral. I.e. the user will be removed after leaving
     * the foreground.
     */
    public static final int FLAG_EPHEMERAL = 0x00000100;

    public static final int NO_PROFILE_GROUP_ID = UserHandle.USER_NULL;

    public int id;
@@ -134,6 +140,11 @@ public class UserInfo implements Parcelable {
    public boolean isQuietModeEnabled() {
        return (flags & FLAG_QUIET_MODE) == FLAG_QUIET_MODE;
    }

    public boolean isEphemeral() {
        return (flags & FLAG_EPHEMERAL) == FLAG_EPHEMERAL;
    }

    /**
     * Returns true if the user is a split system user.
     * <p>If {@link UserManager#isSplitSystemUser split system user mode} is not enabled,
+19 −0
Original line number Diff line number Diff line
@@ -720,6 +720,25 @@ public class UserManager {
        return user != null ? user.isManagedProfile() : false;
    }

    /**
     * Checks if the calling app is running as an ephemeral user.
     *
     * @return whether the caller is an ephemeral user.
     * @hide
     */
    public boolean isEphemeralUser() {
        return isUserEphemeral(UserHandle.myUserId());
    }

    /**
     * Returns whether the specified user is ephemeral.
     * @hide
     */
    public boolean isUserEphemeral(int userId) {
        final UserInfo user = getUserInfo(userId);
        return user != null && user.isEphemeral();
    }

    /**
     * Return whether the given user is actively running.  This means that
     * the user is in the "started" state, not "stopped" -- it is currently
+14 −9
Original line number Diff line number Diff line
@@ -25,8 +25,6 @@ import android.os.ParcelFileDescriptor;
import android.os.Parcelable;
import android.os.RemoteException;

import java.io.FileDescriptor;

/**
 * WARNING! Update IMountService.h and IMountService.cpp if you change this
 * file. In particular, the ordering of the methods below must match the
@@ -1202,13 +1200,15 @@ public interface IMountService extends IInterface {
            }

            @Override
            public void createUserKey(int userId, int serialNumber) throws RemoteException {
            public void createUserKey(int userId, int serialNumber, boolean ephemeral)
                    throws RemoteException {
                Parcel _data = Parcel.obtain();
                Parcel _reply = Parcel.obtain();
                try {
                    _data.writeInterfaceToken(DESCRIPTOR);
                    _data.writeInt(userId);
                    _data.writeInt(serialNumber);
                    _data.writeInt(ephemeral ? 1 : 0);
                    mRemote.transact(Stub.TRANSACTION_createUserKey, _data, _reply, 0);
                    _reply.readException();
                } finally {
@@ -1283,7 +1283,8 @@ public interface IMountService extends IInterface {
            }

            @Override
            public void prepareUserStorage(String volumeUuid, int userId, int serialNumber)
            public void prepareUserStorage(
                    String volumeUuid, int userId, int serialNumber, boolean ephemeral)
                    throws RemoteException {
                Parcel _data = Parcel.obtain();
                Parcel _reply = Parcel.obtain();
@@ -1292,6 +1293,7 @@ public interface IMountService extends IInterface {
                    _data.writeString(volumeUuid);
                    _data.writeInt(userId);
                    _data.writeInt(serialNumber);
                    _data.writeInt(ephemeral ? 1 : 0);
                    mRemote.transact(Stub.TRANSACTION_prepareUserStorage, _data, _reply, 0);
                    _reply.readException();
                } finally {
@@ -2012,7 +2014,8 @@ public interface IMountService extends IInterface {
                    data.enforceInterface(DESCRIPTOR);
                    int userId = data.readInt();
                    int serialNumber = data.readInt();
                    createUserKey(userId, serialNumber);
                    boolean ephemeral = data.readInt() != 0;
                    createUserKey(userId, serialNumber, ephemeral);
                    reply.writeNoException();
                    return true;
                }
@@ -2052,7 +2055,8 @@ public interface IMountService extends IInterface {
                    String volumeUuid = data.readString();
                    int userId = data.readInt();
                    int serialNumber = data.readInt();
                    prepareUserStorage(volumeUuid, userId, serialNumber);
                    boolean ephemeral = data.readInt() != 0;
                    prepareUserStorage(volumeUuid, userId, serialNumber, ephemeral);
                    reply.writeNoException();
                    return true;
                }
@@ -2376,15 +2380,16 @@ public interface IMountService extends IInterface {
    public void setPrimaryStorageUuid(String volumeUuid, IPackageMoveObserver callback)
            throws RemoteException;

    public void createUserKey(int userId, int serialNumber) throws RemoteException;
    public void createUserKey(int userId, int serialNumber, boolean ephemeral)
            throws RemoteException;
    public void destroyUserKey(int userId) throws RemoteException;

    public void unlockUserKey(int userId, int serialNumber, byte[] token) throws RemoteException;
    public void lockUserKey(int userId) throws RemoteException;
    public boolean isUserKeyUnlocked(int userId) throws RemoteException;

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

    public ParcelFileDescriptor mountAppFuse(String name) throws RemoteException;
}
+5 −4
Original line number Diff line number Diff line
@@ -966,9 +966,9 @@ public class StorageManager {
    }

    /** {@hide} */
    public void createUserKey(int userId, int serialNumber) {
    public void createUserKey(int userId, int serialNumber, boolean ephemeral) {
        try {
            mMountService.createUserKey(userId, serialNumber);
            mMountService.createUserKey(userId, serialNumber, ephemeral);
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
@@ -1002,9 +1002,10 @@ public class StorageManager {
    }

    /** {@hide} */
    public void prepareUserStorage(String volumeUuid, int userId, int serialNumber) {
    public void prepareUserStorage(
            String volumeUuid, int userId, int serialNumber, boolean ephemeral) {
        try {
            mMountService.prepareUserStorage(volumeUuid, userId, serialNumber);
            mMountService.prepareUserStorage(volumeUuid, userId, serialNumber, ephemeral);
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
        }
Loading