• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.settings.testutils.shadow;
18 
19 import android.content.ComponentName;
20 import android.content.Context;
21 import android.hardware.fingerprint.FingerprintManager;
22 import android.os.UserHandle;
23 import android.os.UserManager;
24 
25 import com.android.settings.Utils;
26 
27 import org.robolectric.annotation.Implementation;
28 import org.robolectric.annotation.Implements;
29 
30 import java.util.HashMap;
31 import java.util.Map;
32 
33 @Implements(Utils.class)
34 public class ShadowUtils {
35 
36     private static FingerprintManager sFingerprintManager = null;
37     private static boolean sIsUserAMonkey;
38     private static boolean sIsDemoUser;
39     private static ComponentName sDeviceOwnerComponentName;
40     private static Map<String, String> sAppNameMap;
41 
42     @Implementation
enforceSameOwner(Context context, int userId)43     public static int enforceSameOwner(Context context, int userId) {
44         return userId;
45     }
46 
47     @Implementation
getFingerprintManagerOrNull(Context context)48     public static FingerprintManager getFingerprintManagerOrNull(Context context) {
49         return sFingerprintManager;
50     }
51 
setFingerprintManager(FingerprintManager fingerprintManager)52     public static void setFingerprintManager(FingerprintManager fingerprintManager) {
53         sFingerprintManager = fingerprintManager;
54     }
55 
reset()56     public static void reset() {
57         sFingerprintManager = null;
58         sIsUserAMonkey = false;
59         sIsDemoUser = false;
60     }
61 
setIsDemoUser(boolean isDemoUser)62     public static void setIsDemoUser(boolean isDemoUser) {
63         sIsDemoUser = isDemoUser;
64     }
65 
66     @Implementation
isDemoUser(Context context)67     public static boolean isDemoUser(Context context) {
68         return sIsDemoUser;
69     }
70 
setIsUserAMonkey(boolean isUserAMonkey)71     public static void setIsUserAMonkey(boolean isUserAMonkey) {
72         sIsUserAMonkey = isUserAMonkey;
73     }
74 
75     /**
76      * Returns true if Monkey is running.
77      */
78     @Implementation
isMonkeyRunning()79     public static boolean isMonkeyRunning() {
80         return sIsUserAMonkey;
81     }
82 
setDeviceOwnerComponent(ComponentName componentName)83     public static void setDeviceOwnerComponent(ComponentName componentName) {
84         sDeviceOwnerComponentName = componentName;
85     }
86 
87     @Implementation
getDeviceOwnerComponent(Context context)88     public static ComponentName getDeviceOwnerComponent(Context context) {
89         return sDeviceOwnerComponentName;
90     }
91 
92     @Implementation
getManagedProfileId(UserManager um, int parentUserId)93     public static int getManagedProfileId(UserManager um, int parentUserId) {
94         return UserHandle.USER_NULL;
95     }
96 
97     @Implementation
getApplicationLabel(Context context, String packageName)98     public static CharSequence getApplicationLabel(Context context, String packageName) {
99         if (sAppNameMap != null) {
100             return sAppNameMap.get(packageName);
101         }
102         return null;
103     }
104 
setApplicationLabel(String packageName, String appLabel)105     public static void setApplicationLabel(String packageName, String appLabel) {
106         if (sAppNameMap == null) {
107             sAppNameMap = new HashMap<>();
108         }
109         sAppNameMap.put(packageName, appLabel);
110     }
111 }
112