Home | History | Annotate | Download | only in admin
      1 /*
      2  * Copyright (C) 2018 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 package android.app.admin;
     17 
     18 import android.annotation.UserIdInt;
     19 
     20 import com.android.server.LocalServices;
     21 
     22 /**
     23  * Stores a copy of the set of device policies maintained by {@link DevicePolicyManager} that
     24  * can be accessed from any place without risking dead locks.
     25  *
     26  * @hide
     27  */
     28 public abstract class DevicePolicyCache {
     29     protected DevicePolicyCache() {
     30     }
     31 
     32     /**
     33      * @return the instance.
     34      */
     35     public static DevicePolicyCache getInstance() {
     36         final DevicePolicyManagerInternal dpmi =
     37                 LocalServices.getService(DevicePolicyManagerInternal.class);
     38         return (dpmi != null) ? dpmi.getDevicePolicyCache() : EmptyDevicePolicyCache.INSTANCE;
     39     }
     40 
     41     /**
     42      * See {@link DevicePolicyManager#getScreenCaptureDisabled}
     43      */
     44     public abstract boolean getScreenCaptureDisabled(@UserIdInt int userHandle);
     45 
     46     /**
     47      * Empty implementation.
     48      */
     49     private static class EmptyDevicePolicyCache extends DevicePolicyCache {
     50         private static final EmptyDevicePolicyCache INSTANCE = new EmptyDevicePolicyCache();
     51 
     52         @Override
     53         public boolean getScreenCaptureDisabled(int userHandle) {
     54             return false;
     55         }
     56     }
     57 }
     58