1 /* 2 * Copyright (C) 2022 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.devicelockcontroller.policy; 18 19 import androidx.annotation.IntDef; 20 21 import com.google.common.util.concurrent.ListenableFuture; 22 23 import java.lang.annotation.ElementType; 24 import java.lang.annotation.Retention; 25 import java.lang.annotation.RetentionPolicy; 26 import java.lang.annotation.Target; 27 28 /** 29 * Interface for lock/unlock and clear state machine. 30 * All users share the same state. 31 */ 32 public interface DeviceStateController { 33 34 /** 35 * Lock the device. 36 */ lockDevice()37 ListenableFuture<Void> lockDevice(); 38 39 /** 40 * Unlock the device. 41 */ unlockDevice()42 ListenableFuture<Void> unlockDevice(); 43 44 /** 45 * Clear the device restrictions. 46 */ clearDevice()47 ListenableFuture<Void> clearDevice(); 48 49 /** Returns true if the device is in locked state. */ isLocked()50 ListenableFuture<Boolean> isLocked(); 51 52 /** 53 * Returns the current {@link DeviceState}. 54 */ getDeviceState()55 ListenableFuture<Integer> getDeviceState(); 56 57 /** Returns true if the device restrictions have been cleared. */ isCleared()58 ListenableFuture<Boolean> isCleared(); 59 60 /** Device state definitions. */ 61 @Target(ElementType.TYPE_USE) 62 @Retention(RetentionPolicy.SOURCE) 63 @IntDef({ 64 DeviceState.UNDEFINED, 65 DeviceState.UNLOCKED, 66 DeviceState.LOCKED, 67 DeviceState.CLEARED, 68 }) 69 @interface DeviceState { 70 int UNDEFINED = 0; 71 int UNLOCKED = 1; 72 int LOCKED = 2; 73 int CLEARED = 3; 74 } 75 } 76