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 android.app.admin;
18 
19 import android.annotation.IntDef;
20 
21 import java.lang.annotation.Retention;
22 import java.lang.annotation.RetentionPolicy;
23 
24 /**
25  * Class containing the reason for the policy (set from {@link DevicePolicyManager}) update (e.g.
26  * success, failure reasons, etc.). This is passed in to
27  * {@link PolicyUpdateReceiver#onPolicySetResult}) and
28  * {@link PolicyUpdateReceiver#onPolicyChanged}).
29  */
30 public final class PolicyUpdateResult {
31 
32     /**
33      * Result code to indicate that the policy has not been enforced or has changed for an unknown
34      * reason.
35      */
36     public static final int RESULT_FAILURE_UNKNOWN = -1;
37 
38     /**
39      * Result code to indicate that the policy has been changed to the desired value set by
40      * the admin.
41      */
42     public static final int RESULT_POLICY_SET = 0;
43 
44     /**
45      * Result code to indicate that the policy has not been enforced or has changed because another
46      * admin has set a conflicting policy on the device.
47      *
48      * <p>The system will automatically try to enforce the policy when it can without additional
49      * calls from the admin.
50      */
51     public static final int RESULT_FAILURE_CONFLICTING_ADMIN_POLICY = 1;
52 
53     /**
54      * Result code to indicate that the policy set by the admin has been successfully cleared,
55      * admins will no longer receive policy updates for this policy after this point.
56      *
57      * <p>Note that the policy can still be enforced by some other admin.
58      */
59     public static final int RESULT_POLICY_CLEARED = 2;
60 
61     /**
62      * Result code to indicate that the policy set by the admin has not been enforced because the
63      * local storage has reached its max limit.
64      *
65      * <p>The system will NOT try to automatically store and enforce this policy again.
66      */
67     public static final int RESULT_FAILURE_STORAGE_LIMIT_REACHED = 3;
68 
69     /**
70      * Result code to indicate that the policy set by the admin has not been enforced because of a
71      * permanent hardware limitation/issue.
72      *
73      * <p>The system will NOT try to automatically store and enforce this policy again.
74      */
75     public static final int RESULT_FAILURE_HARDWARE_LIMITATION = 4;
76 
77     /**
78      * Reason codes for {@link #getResultCode()}.
79      *
80      * @hide
81      */
82     @Retention(RetentionPolicy.SOURCE)
83     @IntDef(prefix = { "RESULT_" }, value = {
84             RESULT_FAILURE_UNKNOWN,
85             RESULT_POLICY_SET,
86             RESULT_FAILURE_CONFLICTING_ADMIN_POLICY,
87             RESULT_POLICY_CLEARED,
88             RESULT_FAILURE_STORAGE_LIMIT_REACHED,
89             RESULT_FAILURE_HARDWARE_LIMITATION
90     })
91     public @interface ResultCode {}
92 
93     private final int mResultCode;
94 
95     /**
96      * Constructor for {@code PolicyUpdateResult} that takes in a result code describing why the
97      * policy has changed.
98      *
99      * @param resultCode Describes why the policy has changed.
100      */
PolicyUpdateResult(@esultCode int resultCode)101     public PolicyUpdateResult(@ResultCode int resultCode) {
102         this.mResultCode = resultCode;
103     }
104 
105     /**
106      * Returns result code describing why the policy has changed.
107      */
108     @ResultCode
getResultCode()109     public int getResultCode() {
110         return mResultCode;
111     }
112 }
113