1 /*
2  * Copyright (C) 2019 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 com.android.server.devicepolicy;
17 
18 import android.app.admin.DeviceStateCache;
19 
20 import com.android.internal.annotations.GuardedBy;
21 import com.android.internal.util.IndentingPrintWriter;
22 
23 /**
24  * Implementation of {@link DeviceStateCache}, to which {@link DevicePolicyManagerService} pushes
25  * device state.
26  *
27  */
28 public class DeviceStateCacheImpl extends DeviceStateCache {
29     /**
30      * Lock object. For simplicity we just always use this as the lock. We could use each object
31      * as a lock object to make it more fine-grained, but that'd make copy-paste error-prone.
32      */
33     private final Object mLock = new Object();
34 
35     @GuardedBy("mLock")
36     private boolean mIsDeviceProvisioned = false;
37 
38     @Override
isDeviceProvisioned()39     public boolean isDeviceProvisioned() {
40         return mIsDeviceProvisioned;
41     }
42 
43     /** Update the device provisioned flag for USER_SYSTEM */
setDeviceProvisioned(boolean provisioned)44     public void setDeviceProvisioned(boolean provisioned) {
45         synchronized (mLock) {
46             mIsDeviceProvisioned = provisioned;
47         }
48     }
49 
50     /** Dump content */
dump(IndentingPrintWriter pw)51     public void dump(IndentingPrintWriter pw) {
52         pw.println("Device state cache:");
53         pw.increaseIndent();
54         pw.println("Device provisioned: " + mIsDeviceProvisioned);
55         pw.decreaseIndent();
56     }
57 }
58