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