1 /* 2 * Copyright (C) 2020 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.NonNull; 19 import android.app.admin.DevicePolicyManager.DevicePolicyOperation; 20 import android.app.admin.DevicePolicyManager.OperationSafetyReason; 21 22 import com.android.internal.os.IResultReceiver; 23 24 /** 25 * Interface responsible to check if a {@link DevicePolicyManager} API can be safely executed. 26 * 27 * @hide 28 */ 29 public interface DevicePolicySafetyChecker { 30 31 /** 32 * Returns whether the given {@code operation} can be safely executed at the moment. 33 */ 34 @OperationSafetyReason getUnsafeOperationReason(@evicePolicyOperation int operation)35 int getUnsafeOperationReason(@DevicePolicyOperation int operation); 36 37 /** 38 * Return whether it's safe to run operations that can be affected by the given {@code reason}. 39 */ isSafeOperation(@perationSafetyReason int reason)40 boolean isSafeOperation(@OperationSafetyReason int reason); 41 42 /** 43 * Returns a new exception for when the given {@code operation} cannot be safely executed. 44 */ 45 @NonNull newUnsafeStateException(@evicePolicyOperation int operation, @OperationSafetyReason int reason)46 default UnsafeStateException newUnsafeStateException(@DevicePolicyOperation int operation, 47 @OperationSafetyReason int reason) { 48 return new UnsafeStateException(operation, reason); 49 } 50 51 /** 52 * Called when a request was made to factory reset the device, so it can be delayed if it's not 53 * safe to proceed. 54 * 55 * @param callback callback whose {@code send()} method must be called when it's safe to factory 56 * reset. 57 */ onFactoryReset(IResultReceiver callback)58 void onFactoryReset(IResultReceiver callback); 59 } 60