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