1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.launcher3.shadows; 18 19 import android.os.UserHandle; 20 import android.os.UserManager; 21 import android.util.SparseBooleanArray; 22 23 import org.robolectric.annotation.Implementation; 24 import org.robolectric.annotation.Implements; 25 import org.robolectric.shadows.ShadowUserManager; 26 27 /** 28 * Extension of {@link ShadowUserManager} with missing shadow methods 29 */ 30 @Implements(value = UserManager.class) 31 public class LShadowUserManager extends ShadowUserManager { 32 33 private final SparseBooleanArray mQuietUsers = new SparseBooleanArray(); 34 private final SparseBooleanArray mLockedUsers = new SparseBooleanArray(); 35 36 @Implementation isQuietModeEnabled(UserHandle userHandle)37 protected boolean isQuietModeEnabled(UserHandle userHandle) { 38 return mQuietUsers.get(userHandle.hashCode()); 39 } 40 setQuietModeEnabled(UserHandle userHandle, boolean enabled)41 public void setQuietModeEnabled(UserHandle userHandle, boolean enabled) { 42 mQuietUsers.put(userHandle.hashCode(), enabled); 43 } 44 45 @Implementation isUserUnlocked(UserHandle userHandle)46 protected boolean isUserUnlocked(UserHandle userHandle) { 47 return !mLockedUsers.get(userHandle.hashCode()); 48 } 49 setUserLocked(UserHandle userHandle, boolean enabled)50 public void setUserLocked(UserHandle userHandle, boolean enabled) { 51 mLockedUsers.put(userHandle.hashCode(), enabled); 52 } 53 } 54