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