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.car.settings.testutils;
18 
19 import android.annotation.Nullable;
20 import android.app.admin.DevicePolicyManager;
21 import android.util.ArraySet;
22 
23 import org.robolectric.annotation.Implementation;
24 import org.robolectric.annotation.Implements;
25 import org.robolectric.annotation.Resetter;
26 
27 import java.util.List;
28 import java.util.Set;
29 
30 @Implements(value = DevicePolicyManager.class)
31 public class ShadowDevicePolicyManager extends org.robolectric.shadows.ShadowDevicePolicyManager {
32     @Nullable
33     private static List<String> sPermittedInputMethods;
34 
35     private Set<String> mActiveAdminsPackages = new ArraySet<>();
36     private boolean mIsInstallInQueue;
37 
38     @Resetter
reset()39     public static void reset() {
40         sPermittedInputMethods = null;
41     }
42 
43     @Implementation
44     @Nullable
getPermittedInputMethodsForCurrentUser()45     protected List<String> getPermittedInputMethodsForCurrentUser() {
46         return sPermittedInputMethods;
47     }
48 
setPermittedInputMethodsForCurrentUser(@ullable List<String> inputMethods)49     public static void setPermittedInputMethodsForCurrentUser(@Nullable List<String> inputMethods) {
50         sPermittedInputMethods = inputMethods;
51     }
52 
53     @Implementation
packageHasActiveAdmins(String packageName)54     protected boolean packageHasActiveAdmins(String packageName) {
55         return mActiveAdminsPackages.contains(packageName);
56     }
57 
setPackageHasActiveAdmins(String packageName, boolean hasActiveAdmins)58     public void setPackageHasActiveAdmins(String packageName, boolean hasActiveAdmins) {
59         if (hasActiveAdmins) {
60             mActiveAdminsPackages.add(packageName);
61         } else {
62             mActiveAdminsPackages.remove(packageName);
63         }
64     }
65 
66     @Implementation
isUninstallInQueue(String packageName)67     protected boolean isUninstallInQueue(String packageName) {
68         return mIsInstallInQueue;
69     }
70 
setIsUninstallInQueue(boolean isUninstallInQueue)71     public void setIsUninstallInQueue(boolean isUninstallInQueue) {
72         mIsInstallInQueue = isUninstallInQueue;
73     }
74 }
75