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

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

Merge "Setup user restrictions for demo user" into nyc-mr1-dev

parents a5e81480 52c21e34
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -360,7 +360,7 @@ public class KeyguardViewMediator extends SystemUI {
            mSwitchingUser = false;
            if (userId != UserHandle.USER_SYSTEM) {
                UserInfo info = UserManager.get(mContext).getUserInfo(userId);
                if (info != null && info.isGuest()) {
                if (info != null && (info.isGuest() || info.isDemo())) {
                    // If we just switched to a guest, try to dismiss keyguard.
                    dismiss();
                }
+20 −6
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.util.Slog;

import com.android.internal.os.BackgroundThread;
import com.android.internal.R;
import com.android.internal.widget.LockPatternUtils;
import com.android.server.ServiceThread;
import com.android.server.SystemService;
import com.android.server.pm.UserManagerService;
@@ -56,8 +57,8 @@ public class RetailDemoModeService extends SystemService {
    private static final long SCREEN_WAKEUP_DELAY = 5000;

    private ActivityManagerService mAms;
    private UserManagerService mUms;
    private NotificationManager mNm;
    private UserManager mUm;
    private PowerManager mPm;
    private PowerManager.WakeLock mWakeLock;
    private Handler mHandler;
@@ -123,12 +124,26 @@ public class RetailDemoModeService extends SystemService {
                UserInfo demoUser = getUserManager().createUser(DEMO_USER_NAME,
                        UserInfo.FLAG_DEMO | UserInfo.FLAG_EPHEMERAL);
                if (demoUser != null) {
                    setupDemoUser(demoUser);
                    getActivityManager().switchUser(demoUser.id);
                }
            }
        });
    }

    void setupDemoUser(UserInfo userInfo) {
        UserManager um = getUserManager();
        UserHandle user = UserHandle.of(userInfo.id);
        LockPatternUtils lockPatternUtils = new LockPatternUtils(getContext());
        lockPatternUtils.setLockScreenDisabled(true, userInfo.id);
        um.setUserRestriction(UserManager.DISALLOW_CONFIG_WIFI, true, user);
        um.setUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, true, user);
        um.setUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS, true, user);
        um.setUserRestriction(UserManager.DISALLOW_USB_FILE_TRANSFER, true, user);
        Settings.Secure.putIntForUser(getContext().getContentResolver(),
                Settings.Secure.SKIP_FIRST_USE_HINTS, 1, userInfo.id);
    }

    private ActivityManagerService getActivityManager() {
        if (mAms == null) {
            mAms = (ActivityManagerService) ActivityManagerNative.getDefault();
@@ -136,12 +151,11 @@ public class RetailDemoModeService extends SystemService {
        return mAms;
    }

    private UserManagerService getUserManager() {
        if (mUms == null) {
            mUms = (UserManagerService) UserManagerService.Stub
                    .asInterface(ServiceManager.getService(Context.USER_SERVICE));
    private UserManager getUserManager() {
        if (mUm == null) {
            mUm = getContext().getSystemService(UserManager.class);
        }
        return mUms;
        return mUm;
    }

    private void registerSettingsChangeObserver() {
+3 −2
Original line number Diff line number Diff line
@@ -2035,6 +2035,7 @@ public class UserManagerService extends IUserManager.Stub {
        final boolean isGuest = (flags & UserInfo.FLAG_GUEST) != 0;
        final boolean isManagedProfile = (flags & UserInfo.FLAG_MANAGED_PROFILE) != 0;
        final boolean isRestricted = (flags & UserInfo.FLAG_RESTRICTED) != 0;
        final boolean isDemo = (flags & UserInfo.FLAG_DEMO) != 0;
        final long ident = Binder.clearCallingIdentity();
        UserInfo userInfo;
        UserData userData;
@@ -2052,8 +2053,8 @@ public class UserManagerService extends IUserManager.Stub {
                    Log.e(LOG_TAG, "Cannot add more managed profiles for user " + parentId);
                    return null;
                }
                if (!isGuest && !isManagedProfile && isUserLimitReached()) {
                    // If we're not adding a guest user or a managed profile and the limit has
                if (!isGuest && !isManagedProfile && !isDemo && isUserLimitReached()) {
                    // If we're not adding a guest/demo user or a managed profile and the limit has
                    // been reached, cannot add a user.
                    return null;
                }
+3 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings;
import android.service.vr.IVrManager;
import android.service.vr.IVrStateCallbacks;
@@ -142,7 +143,8 @@ public class ImmersiveModeConfirmation {
            if (!disabled
                    && (DEBUG_SHOW_EVERY_TIME || !mConfirmed)
                    && userSetupComplete
                    && !mVrModeEnabled) {
                    && !mVrModeEnabled
                    && !UserManager.isDeviceInDemoMode(mContext)) {
                mHandler.sendEmptyMessageDelayed(H.SHOW, mShowDelayMs);
            }
        } else {