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 android.content.Intent; 20 21 import androidx.annotation.IntDef; 22 23 import com.google.common.util.concurrent.ListenableFuture; 24 25 import java.lang.annotation.ElementType; 26 import java.lang.annotation.Retention; 27 import java.lang.annotation.RetentionPolicy; 28 import java.lang.annotation.Target; 29 30 /** 31 * Interface for the policy controller that is responsible for applying policies based 32 * on state. 33 */ 34 public interface DevicePolicyController { 35 36 /** 37 * Factory resets the device when the setup has failed and cannot continue. 38 * Returns true if action was successful. 39 * <p> 40 * Using the new {@code DevicePolicyManager#wipeDevice()} introduced in Android U to 41 * reset the device. This is because the {@code DevicePolicyManager#wipeData()} no longer resets 42 * the device when called as the device owner, as it used to do in earlier Android versions. 43 */ wipeDevice()44 boolean wipeDevice(); 45 46 /** 47 * Enforce current policies. 48 */ enforceCurrentPolicies()49 ListenableFuture<Void> enforceCurrentPolicies(); 50 51 /** 52 * Enforce current policies. This is only used in an attempts to restore previous enforced 53 * policies in the case enforceCurrentPolicies() fails. 54 */ enforceCurrentPoliciesForCriticalFailure()55 ListenableFuture<Void> enforceCurrentPoliciesForCriticalFailure(); 56 57 /** 58 * Get the launch intent for current enforced state. 59 */ getLaunchIntentForCurrentState()60 ListenableFuture<Intent> getLaunchIntentForCurrentState(); 61 62 /** 63 * Called by {@link com.android.devicelockcontroller.DeviceLockControllerService} to call 64 * encryption-aware components. 65 */ onUserUnlocked()66 ListenableFuture<Void> onUserUnlocked(); 67 68 /** 69 * Called when a user has completed set-up wizard. 70 */ onUserSetupCompleted()71 ListenableFuture<Void> onUserSetupCompleted(); 72 73 /** 74 * Called by {@link com.android.devicelockcontroller.DeviceLockControllerService} when the 75 * controller or kiosk app crashed. 76 */ onAppCrashed(boolean isKiosk)77 ListenableFuture<Void> onAppCrashed(boolean isKiosk); 78 79 @Target(ElementType.TYPE_USE) 80 @Retention(RetentionPolicy.SOURCE) 81 @IntDef({ 82 LockTaskType.UNDEFINED, 83 LockTaskType.NOT_IN_LOCK_TASK, 84 LockTaskType.LANDING_ACTIVITY, 85 LockTaskType.CRITICAL_ERROR, 86 LockTaskType.KIOSK_SETUP_ACTIVITY, 87 LockTaskType.KIOSK_LOCK_ACTIVITY 88 }) 89 @interface LockTaskType { 90 91 int UNDEFINED = -1; 92 /* Not in lock task mode */ 93 int NOT_IN_LOCK_TASK = 0; 94 95 /* Device lock controller landing activity */ 96 int LANDING_ACTIVITY = 1; 97 98 /* Hit a critical error during policy enforcement, device will be reset */ 99 int CRITICAL_ERROR = 2; 100 101 /* Kiosk app setup activity */ 102 int KIOSK_SETUP_ACTIVITY = 3; 103 104 /* Kiosk app lock activity */ 105 int KIOSK_LOCK_ACTIVITY = 4; 106 } 107 } 108