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

Commit db6cf3a7 authored by Amith Yamasani's avatar Amith Yamasani Committed by Android (Google) Code Review
Browse files

Merge "Guest user first iteration"

parents 7f2cd8df 1e9c2187
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -39,9 +39,6 @@ interface IUserManager {
    UserInfo getProfileParent(int userHandle);
    UserInfo getUserInfo(int userHandle);
    boolean isRestricted();
    void setGuestEnabled(boolean enable);
    boolean isGuestEnabled();
    void wipeUser(int userHandle);
    int getUserSerialNumber(int userHandle);
    int getUserHandle(int userSerialNumber);
    Bundle getUserRestrictions(int userHandle);
+26 −44
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.graphics.Bitmap.Config;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.provider.Settings;
import android.util.Log;

import com.android.internal.R;
@@ -360,6 +361,16 @@ public class UserManager {
        }
    }

    /**
     * Checks if the calling app is running as a guest user.
     * @return whether the caller is a guest user.
     * @hide
     */
    public boolean isGuestUser() {
        UserInfo user = getUserInfo(UserHandle.myUserId());
        return user != null ? user.isGuest() : false;
    }

    /**
     * Return whether the given user is actively running.  This means that
     * the user is in the "started" state, not "stopped" -- it is currently
@@ -549,6 +560,21 @@ public class UserManager {
        }
    }

    /**
     * Creates a guest user and configures it.
     * @param context an application context
     * @param name the name to set for the user
     * @hide
     */
    public UserInfo createGuest(Context context, String name) {
        UserInfo guest = createUser(name, UserInfo.FLAG_GUEST);
        if (guest != null) {
            Settings.Secure.putStringForUser(context.getContentResolver(),
                    Settings.Secure.SKIP_FIRST_USE_HINTS, "1", guest.id);
        }
        return guest;
    }

    /**
     * Creates a user with the specified name and options as a profile of another user.
     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
@@ -826,50 +852,6 @@ public class UserManager {
        }
    }

    /**
     * Enable or disable the use of a guest account. If disabled, the existing guest account
     * will be wiped.
     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
     * @param enable whether to enable a guest account.
     * @hide
     */
    public void setGuestEnabled(boolean enable) {
        try {
            mService.setGuestEnabled(enable);
        } catch (RemoteException re) {
            Log.w(TAG, "Could not change guest account availability to " + enable);
        }
    }

    /**
     * Checks if a guest user is enabled for this device.
     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
     * @return whether a guest user is enabled
     * @hide
     */
    public boolean isGuestEnabled() {
        try {
            return mService.isGuestEnabled();
        } catch (RemoteException re) {
            Log.w(TAG, "Could not retrieve guest enabled state");
            return false;
        }
    }

    /**
     * Wipes all the data for a user, but doesn't remove the user.
     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
     * @param userHandle
     * @hide
     */
    public void wipeUser(int userHandle) {
        try {
            mService.wipeUser(userHandle);
        } catch (RemoteException re) {
            Log.w(TAG, "Could not wipe user " + userHandle);
        }
    }

    /**
     * Returns the maximum number of users that can be created on this device. A return value
     * of 1 means that it is a single user device.
+18 −0
Original line number Diff line number Diff line
@@ -4575,6 +4575,16 @@ public final class Settings {
         */
        public static final String DISPLAY_INTERCEPTED_NOTIFICATIONS = "display_intercepted_notifications";

        /**
         * If enabled, apps should try to skip any introductory hints on first launch. This might
         * apply to users that are already familiar with the environment or temporary users, like
         * guests.
         * <p>
         * Type : int (0 to show hints, 1 to skip showing hints)
         * @hide
         */
        public static final String SKIP_FIRST_USE_HINTS = "skip_first_use_hints";

        /**
         * This are the settings to be backed up.
         *
@@ -6215,6 +6225,14 @@ public final class Settings {
         */
        public static final String DEVICE_NAME = "device_name";

        /**
         * Whether it should be possible to create a guest user on the device.
         * <p>
         * Type: int (0 for disabled, 1 for enabled)
         * @hide
         */
        public static final String GUEST_USER_ENABLED = "guest_user_enabled";

        /**
         * Settings to backup. This is here so that it's in the same place as the settings
         * keys and easy to update.
+3 −0
Original line number Diff line number Diff line
@@ -195,4 +195,7 @@
    <!-- Default for Settings.Secure.WAKE_GESTURE_ENABLED -->
    <bool name="def_wake_gesture_enabled">true</bool>

    <!-- Default for Settings.Global.GUEST_USER_ENABLED -->
    <bool name="def_guest_user_enabled">true</bool>

</resources>
+21 −1
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
    // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion'
    // is properly propagated through your change.  Not doing so will result in a loss of user
    // settings.
    private static final int DATABASE_VERSION = 104;
    private static final int DATABASE_VERSION = 105;

    private Context mContext;
    private int mUserHandle;
@@ -1677,6 +1677,24 @@ public class DatabaseHelper extends SQLiteOpenHelper {
            upgradeVersion = 104;
        }

        if (upgradeVersion < 105) {
            if (mUserHandle == UserHandle.USER_OWNER) {
                db.beginTransaction();
                SQLiteStatement stmt = null;
                try {
                    stmt = db.compileStatement("INSERT OR IGNORE INTO global(name,value)"
                            + " VALUES(?,?);");
                    loadBooleanSetting(stmt, Settings.Global.GUEST_USER_ENABLED,
                            R.bool.def_guest_user_enabled);
                    db.setTransactionSuccessful();
                } finally {
                    db.endTransaction();
                    if (stmt != null) stmt.close();
                }
            }
            upgradeVersion = 105;
        }

        // *** Remember to update DATABASE_VERSION above!

        if (upgradeVersion != currentVersion) {
@@ -2410,6 +2428,8 @@ public class DatabaseHelper extends SQLiteOpenHelper {

            loadSetting(stmt, Settings.Global.DEVICE_NAME, getDefaultDeviceName());

            loadBooleanSetting(stmt, Settings.Global.GUEST_USER_ENABLED,
                    R.bool.def_guest_user_enabled);
            // --- New global settings start here
        } finally {
            if (stmt != null) stmt.close();
Loading