blob: 9dede3bdf0d1e81ef58ffe4d7d96dc38fee028aa [file] [log] [blame]
Rubin Xu0cbc19e2016-12-09 14:00:21 +00001/*
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
17package com.android.server;
18
19import android.app.NotificationManager;
Rubin Xu8b30ec32017-03-05 00:47:09 +000020import android.app.admin.DevicePolicyManager;
Rubin Xu0cbc19e2016-12-09 14:00:21 +000021import android.content.Context;
22import android.content.ContextWrapper;
23import android.os.UserManager;
Rubin Xuee67b612017-04-27 17:01:05 +010024import android.os.storage.StorageManager;
Rubin Xu0cbc19e2016-12-09 14:00:21 +000025
26public class MockLockSettingsContext extends ContextWrapper {
27
28 private UserManager mUserManager;
29 private NotificationManager mNotificationManager;
Rubin Xu8b30ec32017-03-05 00:47:09 +000030 private DevicePolicyManager mDevicePolicyManager;
Rubin Xuee67b612017-04-27 17:01:05 +010031 private StorageManager mStorageManager;
Rubin Xu0cbc19e2016-12-09 14:00:21 +000032
33 public MockLockSettingsContext(Context base, UserManager userManager,
Rubin Xuee67b612017-04-27 17:01:05 +010034 NotificationManager notificationManager, DevicePolicyManager devicePolicyManager,
35 StorageManager storageManager) {
Rubin Xu0cbc19e2016-12-09 14:00:21 +000036 super(base);
37 mUserManager = userManager;
38 mNotificationManager = notificationManager;
Rubin Xu8b30ec32017-03-05 00:47:09 +000039 mDevicePolicyManager = devicePolicyManager;
Rubin Xuee67b612017-04-27 17:01:05 +010040 mStorageManager = storageManager;
Rubin Xu0cbc19e2016-12-09 14:00:21 +000041 }
42
43 @Override
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;
Rubin Xu8b30ec32017-03-05 00:47:09 +000049 } else if (DEVICE_POLICY_SERVICE.equals(name)) {
50 return mDevicePolicyManager;
Rubin Xuee67b612017-04-27 17:01:05 +010051 } else if (STORAGE_SERVICE.equals(name)) {
52 return mStorageManager;
Rubin Xu0cbc19e2016-12-09 14:00:21 +000053 } else {
54 throw new RuntimeException("System service not mocked: " + name);
55 }
56 }
57
58 @Override
59 public void enforceCallingOrSelfPermission(String permission, String message) {
60 // Skip permission checks for unit tests.
61 }
62
63}