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

Commit 1e9c2187 authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Guest user first iteration

Setting for controlling if guest is enabled on the device.
Setting to hint to apps that they should skip showing first use clings.

User switcher handles creation and deletion of the guest user.
Some tweaks to the user switcher to show some feedback and make the icons
circular.

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


import com.android.internal.R;
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
     * Return whether the given user is actively running.  This means that
     * the user is in the "started" state, not "stopped" -- it is currently
     * 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.
     * Creates a user with the specified name and options as a profile of another user.
     * Requires {@link android.Manifest.permission#MANAGE_USERS} permission.
     * 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
     * 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.
     * of 1 means that it is a single user device.
+18 −0
Original line number Original line Diff line number Diff line
@@ -4575,6 +4575,16 @@ public final class Settings {
         */
         */
        public static final String DISPLAY_INTERCEPTED_NOTIFICATIONS = "display_intercepted_notifications";
        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.
         * This are the settings to be backed up.
         *
         *
@@ -6215,6 +6225,14 @@ public final class Settings {
         */
         */
        public static final String DEVICE_NAME = "device_name";
        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
         * Settings to backup. This is here so that it's in the same place as the settings
         * keys and easy to update.
         * keys and easy to update.
+3 −0
Original line number Original line Diff line number Diff line
@@ -195,4 +195,7 @@
    <!-- Default for Settings.Secure.WAKE_GESTURE_ENABLED -->
    <!-- Default for Settings.Secure.WAKE_GESTURE_ENABLED -->
    <bool name="def_wake_gesture_enabled">true</bool>
    <bool name="def_wake_gesture_enabled">true</bool>


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

</resources>
</resources>
+21 −1
Original line number Original line 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'
    // 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
    // is properly propagated through your change.  Not doing so will result in a loss of user
    // settings.
    // settings.
    private static final int DATABASE_VERSION = 104;
    private static final int DATABASE_VERSION = 105;


    private Context mContext;
    private Context mContext;
    private int mUserHandle;
    private int mUserHandle;
@@ -1677,6 +1677,24 @@ public class DatabaseHelper extends SQLiteOpenHelper {
            upgradeVersion = 104;
            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!
        // *** Remember to update DATABASE_VERSION above!


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


            loadSetting(stmt, Settings.Global.DEVICE_NAME, getDefaultDeviceName());
            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
            // --- New global settings start here
        } finally {
        } finally {
            if (stmt != null) stmt.close();
            if (stmt != null) stmt.close();
Loading