• 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     private static boolean sIsSystemAlertWindowEnabled;
42 
43     @Implementation
enforceSameOwner(Context context, int userId)44     protected static int enforceSameOwner(Context context, int userId) {
45         return userId;
46     }
47 
48     @Implementation
getFingerprintManagerOrNull(Context context)49     protected static FingerprintManager getFingerprintManagerOrNull(Context context) {
50         return sFingerprintManager;
51     }
52 
setFingerprintManager(FingerprintManager fingerprintManager)53     public static void setFingerprintManager(FingerprintManager fingerprintManager) {
54         sFingerprintManager = fingerprintManager;
55     }
56 
reset()57     public static void reset() {
58         sFingerprintManager = null;
59         sIsUserAMonkey = false;
60         sIsDemoUser = false;
61     }
62 
setIsDemoUser(boolean isDemoUser)63     public static void setIsDemoUser(boolean isDemoUser) {
64         sIsDemoUser = isDemoUser;
65     }
66 
67     @Implementation
isDemoUser(Context context)68     public static boolean isDemoUser(Context context) {
69         return sIsDemoUser;
70     }
71 
setIsUserAMonkey(boolean isUserAMonkey)72     public static void setIsUserAMonkey(boolean isUserAMonkey) {
73         sIsUserAMonkey = isUserAMonkey;
74     }
75 
76     /**
77      * Returns true if Monkey is running.
78      */
79     @Implementation
isMonkeyRunning()80     protected static boolean isMonkeyRunning() {
81         return sIsUserAMonkey;
82     }
83 
setDeviceOwnerComponent(ComponentName componentName)84     public static void setDeviceOwnerComponent(ComponentName componentName) {
85         sDeviceOwnerComponentName = componentName;
86     }
87 
88     @Implementation
getDeviceOwnerComponent(Context context)89     protected static ComponentName getDeviceOwnerComponent(Context context) {
90         return sDeviceOwnerComponentName;
91     }
92 
93     @Implementation
getManagedProfileId(UserManager um, int parentUserId)94     protected static int getManagedProfileId(UserManager um, int parentUserId) {
95         return UserHandle.USER_NULL;
96     }
97 
98     @Implementation
getApplicationLabel(Context context, String packageName)99     protected static CharSequence getApplicationLabel(Context context, String packageName) {
100         if (sAppNameMap != null) {
101             return sAppNameMap.get(packageName);
102         }
103         return null;
104     }
105 
106     @Implementation
isPackageEnabled(Context context, String packageName)107     protected static boolean isPackageEnabled(Context context, String packageName) {
108         return true;
109     }
110 
setApplicationLabel(String packageName, String appLabel)111     public static void setApplicationLabel(String packageName, String appLabel) {
112         if (sAppNameMap == null) {
113             sAppNameMap = new HashMap<>();
114         }
115         sAppNameMap.put(packageName, appLabel);
116     }
117 
118     @Implementation
isSystemAlertWindowEnabled(Context context)119     protected static boolean isSystemAlertWindowEnabled(Context context) {
120         return sIsSystemAlertWindowEnabled;
121     }
122 
setIsSystemAlertWindowEnabled(boolean enabled)123     public static void setIsSystemAlertWindowEnabled(boolean enabled) {
124         sIsSystemAlertWindowEnabled = enabled;
125     }
126 }
127