Rubin Xu | 0cbc19e | 2016-12-09 14:00:21 +0000 | [diff] [blame] | 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; |
Rubin Xu | 8b30ec3 | 2017-03-05 00:47:09 +0000 | [diff] [blame] | 20 | import android.app.admin.DevicePolicyManager; |
Rubin Xu | 0cbc19e | 2016-12-09 14:00:21 +0000 | [diff] [blame] | 21 | import android.content.Context; |
| 22 | import android.content.ContextWrapper; |
| 23 | import android.os.UserManager; |
Rubin Xu | ee67b61 | 2017-04-27 17:01:05 +0100 | [diff] [blame] | 24 | import android.os.storage.StorageManager; |
Rubin Xu | 0cbc19e | 2016-12-09 14:00:21 +0000 | [diff] [blame] | 25 | |
| 26 | public class MockLockSettingsContext extends ContextWrapper { |
| 27 | |
| 28 | private UserManager mUserManager; |
| 29 | private NotificationManager mNotificationManager; |
Rubin Xu | 8b30ec3 | 2017-03-05 00:47:09 +0000 | [diff] [blame] | 30 | private DevicePolicyManager mDevicePolicyManager; |
Rubin Xu | ee67b61 | 2017-04-27 17:01:05 +0100 | [diff] [blame] | 31 | private StorageManager mStorageManager; |
Rubin Xu | 0cbc19e | 2016-12-09 14:00:21 +0000 | [diff] [blame] | 32 | |
| 33 | public MockLockSettingsContext(Context base, UserManager userManager, |
Rubin Xu | ee67b61 | 2017-04-27 17:01:05 +0100 | [diff] [blame] | 34 | NotificationManager notificationManager, DevicePolicyManager devicePolicyManager, |
| 35 | StorageManager storageManager) { |
Rubin Xu | 0cbc19e | 2016-12-09 14:00:21 +0000 | [diff] [blame] | 36 | super(base); |
| 37 | mUserManager = userManager; |
| 38 | mNotificationManager = notificationManager; |
Rubin Xu | 8b30ec3 | 2017-03-05 00:47:09 +0000 | [diff] [blame] | 39 | mDevicePolicyManager = devicePolicyManager; |
Rubin Xu | ee67b61 | 2017-04-27 17:01:05 +0100 | [diff] [blame] | 40 | mStorageManager = storageManager; |
Rubin Xu | 0cbc19e | 2016-12-09 14:00:21 +0000 | [diff] [blame] | 41 | } |
| 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 Xu | 8b30ec3 | 2017-03-05 00:47:09 +0000 | [diff] [blame] | 49 | } else if (DEVICE_POLICY_SERVICE.equals(name)) { |
| 50 | return mDevicePolicyManager; |
Rubin Xu | ee67b61 | 2017-04-27 17:01:05 +0100 | [diff] [blame] | 51 | } else if (STORAGE_SERVICE.equals(name)) { |
| 52 | return mStorageManager; |
Rubin Xu | 0cbc19e | 2016-12-09 14:00:21 +0000 | [diff] [blame] | 53 | } 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 | } |