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.server;
18 
19 import android.app.NotificationManager;
20 import android.app.admin.DevicePolicyManager;
21 import android.content.Context;
22 import android.content.ContextWrapper;
23 import android.os.UserManager;
24 import android.os.storage.StorageManager;
25 
26 public class MockLockSettingsContext extends ContextWrapper {
27 
28     private UserManager mUserManager;
29     private NotificationManager mNotificationManager;
30     private DevicePolicyManager mDevicePolicyManager;
31     private StorageManager mStorageManager;
32 
MockLockSettingsContext(Context base, UserManager userManager, NotificationManager notificationManager, DevicePolicyManager devicePolicyManager, StorageManager storageManager)33     public MockLockSettingsContext(Context base, UserManager userManager,
34             NotificationManager notificationManager, DevicePolicyManager devicePolicyManager,
35             StorageManager storageManager) {
36         super(base);
37         mUserManager = userManager;
38         mNotificationManager = notificationManager;
39         mDevicePolicyManager = devicePolicyManager;
40         mStorageManager = storageManager;
41     }
42 
43     @Override
getSystemService(String name)44     public Object getSystemService(String name) {
45         if (USER_SERVICE.equals(name)) {
46             return mUserManager;
47         } else if (NOTIFICATION_SERVICE.equals(name)) {
48             return mNotificationManager;
49         } else if (DEVICE_POLICY_SERVICE.equals(name)) {
50             return mDevicePolicyManager;
51         } else if (STORAGE_SERVICE.equals(name)) {
52             return mStorageManager;
53         } else {
54             throw new RuntimeException("System service not mocked: " + name);
55         }
56     }
57 
58     @Override
enforceCallingOrSelfPermission(String permission, String message)59     public void enforceCallingOrSelfPermission(String permission, String message) {
60         // Skip permission checks for unit tests.
61     }
62 
63 }
64