1/*
2 * Copyright (C) 2018 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
17package com.android.settingslib.testutils.shadow;
18
19import android.content.Context;
20import android.content.pm.UserInfo;
21import android.os.UserManager;
22
23import org.robolectric.RuntimeEnvironment;
24import org.robolectric.annotation.Implementation;
25import org.robolectric.annotation.Implements;
26import org.robolectric.annotation.Resetter;
27import org.robolectric.shadow.api.Shadow;
28
29import java.util.ArrayList;
30import java.util.List;
31
32@Implements(value = UserManager.class, inheritImplementationMethods = true)
33public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager {
34
35    private boolean mAdminUser;
36
37    public void setIsAdminUser(boolean isAdminUser) {
38        mAdminUser = isAdminUser;
39    }
40
41    @Resetter
42    public void reset() {
43        mAdminUser = false;
44    }
45
46    @Implementation
47    public boolean isAdminUser() {
48        return mAdminUser;
49    }
50
51    @Implementation
52    public static UserManager get(Context context) {
53        return (UserManager) context.getSystemService(Context.USER_SERVICE);
54    }
55
56    @Implementation
57    public int[] getProfileIdsWithDisabled(int userId) {
58        return new int[] { 0 };
59    }
60
61    @Implementation
62    public List<UserInfo> getProfiles() {
63        UserInfo userInfo = new UserInfo();
64        userInfo.id = 0;
65        List<UserInfo> userInfos = new ArrayList<>();
66        userInfos.add(userInfo);
67        return userInfos;
68    }
69
70    public static ShadowUserManager getShadow() {
71        return (ShadowUserManager) Shadow.extract(
72                RuntimeEnvironment.application.getSystemService(UserManager.class));
73    }
74}