1 /*
2  * Copyright (C) 2021 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 import android.annotation.NonNull;
18 import android.annotation.Nullable;
19 import android.app.admin.DevicePolicyManager;
20 import android.content.ComponentName;
21 import android.os.Bundle;
22 import android.os.Handler;
23 import android.os.RemoteCallback;
24 import android.os.UserHandle;
25 
26 import java.util.List;
27 
28 public class DevicePolicyManagerCompat {
29     public static final String EXTRA_BUGREPORT_NOTIFICATION_TYPE =
30             DevicePolicyManager.EXTRA_BUGREPORT_NOTIFICATION_TYPE;
31 
32     public static final int NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED =
33             DevicePolicyManager.NOTIFICATION_BUGREPORT_FINISHED_NOT_ACCEPTED;
34 
35     public static final String ACTION_BUGREPORT_SHARING_ACCEPTED =
36             DevicePolicyManager.ACTION_BUGREPORT_SHARING_ACCEPTED;
37 
38     /**
39      * Action: Bugreport sharing with device owner has been declined by the user.
40      */
41     public static final String ACTION_BUGREPORT_SHARING_DECLINED =
42             "com.android.server.action.REMOTE_BUGREPORT_SHARING_DECLINED";
43 
44     public static final String ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED =
45             "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
46 
47     public static final int NOTIFICATION_BUGREPORT_STARTED =
48             DevicePolicyManager.NOTIFICATION_BUGREPORT_STARTED;
49 
50     public static final int NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED =
51             DevicePolicyManager.NOTIFICATION_BUGREPORT_ACCEPTED_NOT_FINISHED;
52 
53     private final DevicePolicyManager mManager;
54 
DevicePolicyManagerCompat(DevicePolicyManager manager)55     public DevicePolicyManagerCompat(DevicePolicyManager manager) {
56         this.mManager = manager;
57     }
58 
getDeviceOwnerUserId()59     public int getDeviceOwnerUserId() {
60         return this.mManager.getDeviceOwnerUserId();
61     }
62 
63     public static final String POLICY_SUSPEND_PACKAGES =
64             DevicePolicyManager.POLICY_SUSPEND_PACKAGES;
65 
isCurrentInputMethodSetByOwner()66     public boolean isCurrentInputMethodSetByOwner() {
67         return this.mManager.isCurrentInputMethodSetByOwner();
68     }
69 
hasUserSetupCompleted()70     public boolean hasUserSetupCompleted() {
71         return this.mManager.hasUserSetupCompleted();
72     }
73 
getOwnerInstalledCaCerts(@onNull UserHandle user)74     public List<String> getOwnerInstalledCaCerts(@NonNull UserHandle user) {
75         return this.mManager.getOwnerInstalledCaCerts(user);
76     }
77 
78     public @Nullable
getProfileOwnerOrDeviceOwnerSupervisionComponent( @onNull UserHandle user)79     ComponentName getProfileOwnerOrDeviceOwnerSupervisionComponent(
80             @NonNull UserHandle user) {
81         return this.mManager.getProfileOwnerOrDeviceOwnerSupervisionComponent(user);
82     }
83 
84     public @Nullable
getActiveAdminsAsUser(int userId)85     List<ComponentName> getActiveAdminsAsUser(int userId) {
86         return this.mManager.getActiveAdminsAsUser(userId);
87     }
88 
getMaximumFailedPasswordsForWipe(@ullable ComponentName admin, int userHandle)89     public int getMaximumFailedPasswordsForWipe(@Nullable ComponentName admin, int userHandle) {
90         return this.mManager.getMaximumFailedPasswordsForWipe(admin, userHandle);
91     }
92 
getDeviceOwnerComponentOnCallingUser()93     public ComponentName getDeviceOwnerComponentOnCallingUser() {
94         return this.mManager.getDeviceOwnerComponentOnCallingUser();
95     }
96 
97     public @Nullable
getProfileOwnerAsUser(final int userId)98     ComponentName getProfileOwnerAsUser(final int userId) {
99         return this.mManager.getProfileOwnerAsUser(userId);
100     }
101 
getLastSecurityLogRetrievalTime()102     public long getLastSecurityLogRetrievalTime() {
103         return this.mManager.getLastSecurityLogRetrievalTime();
104     }
105 
getLastBugReportRequestTime()106     public long getLastBugReportRequestTime() {
107         return this.mManager.getLastBugReportRequestTime();
108     }
109 
getLastNetworkLogRetrievalTime()110     public long getLastNetworkLogRetrievalTime() {
111         return this.mManager.getLastNetworkLogRetrievalTime();
112     }
113 
114     public @Nullable
getDeviceOwnerOrganizationName()115     CharSequence getDeviceOwnerOrganizationName() {
116         return this.mManager.getDeviceOwnerOrganizationName();
117     }
118 
119     public @Nullable
getShortSupportMessageForUser( @onNull ComponentName admin, int userHandle)120     CharSequence getShortSupportMessageForUser(
121             @NonNull ComponentName admin, int userHandle) {
122         return this.mManager.getShortSupportMessageForUser(admin, userHandle);
123     }
124 
125     public @NonNull
getParentProfileInstance(UserInfoCompat uInfo)126     DevicePolicyManager getParentProfileInstance(UserInfoCompat uInfo) {
127         return this.mManager.getParentProfileInstance(uInfo.mUserInfo);
128     }
129 
isRemovingAdmin(@onNull ComponentName admin, int userId)130     public boolean isRemovingAdmin(@NonNull ComponentName admin, int userId) {
131         return this.mManager.isRemovingAdmin(admin, userId);
132     }
133 
setActiveAdmin(@onNull ComponentName policyReceiver, boolean refreshing)134     public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing) {
135         this.mManager.setActiveAdmin(policyReceiver, refreshing);
136     }
137 
setProfileOwner(@onNull ComponentName admin, int userHandle)138     public boolean setProfileOwner(@NonNull ComponentName admin, int userHandle)
139             throws IllegalArgumentException {
140         return this.mManager.setProfileOwner(admin, userHandle);
141     }
142 
uninstallPackageWithActiveAdmins(String packageName)143     public void uninstallPackageWithActiveAdmins(String packageName) {
144         this.mManager.uninstallPackageWithActiveAdmins(packageName);
145     }
146 
147     public interface onResultListener {
onResult(Bundle result)148         void onResult(Bundle result);
149     }
150 
getRemoveWarning(@ullable ComponentName admin, onResultListener listener, Handler handler)151     public void getRemoveWarning(@Nullable ComponentName admin, onResultListener listener,
152             Handler handler) {
153         this.mManager.getRemoveWarning(admin, new RemoteCallback(
154                 new RemoteCallback.OnResultListener() {
155                     @Override
156                     public void onResult(Bundle result) {
157                         listener.onResult(result);
158                     }
159                 }, handler));
160     }
161 
162     public @Nullable
getLongSupportMessageForUser( @onNull ComponentName admin, int userHandle)163     CharSequence getLongSupportMessageForUser(
164             @NonNull ComponentName admin, int userHandle) {
165         return this.mManager.getLongSupportMessageForUser(admin, userHandle);
166     }
167 
isAdminActiveAsUser(@onNull ComponentName admin, int userId)168     public boolean isAdminActiveAsUser(@NonNull ComponentName admin, int userId) {
169         return this.mManager.isAdminActiveAsUser(admin, userId);
170     }
171 }
172