1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.app.admin;
import static java.util.Objects.requireNonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.annotation.TestApi;
import android.content.ComponentName;
import android.os.Parcel;
import android.os.Parcelable;
import android.stats.devicepolicy.DevicePolicyEnums;
import java.util.Locale;
/**
* Params required to provision a fully managed device, see
* {@link DevicePolicyManager#provisionFullyManagedDevice}.
* @hide
*/
@TestApi
public final class FullyManagedDeviceProvisioningParams implements Parcelable {
private static final String LEAVE_ALL_SYSTEM_APPS_ENABLED_PARAM =
"LEAVE_ALL_SYSTEM_APPS_ENABLED";
private static final String CAN_DEVICE_OWNER_GRANT_SENSOR_PERMISSIONS_PARAM =
"CAN_DEVICE_OWNER_GRANT_SENSOR_PERMISSIONS";
private static final String TIME_ZONE_PROVIDED_PARAM = "TIME_ZONE_PROVIDED";
private static final String LOCALE_PROVIDED_PARAM = "LOCALE_PROVIDED";
@NonNull private final ComponentName mDeviceAdminComponentName;
@NonNull private final String mOwnerName;
private final boolean mLeaveAllSystemAppsEnabled;
@Nullable private final String mTimeZone;
private final long mLocalTime;
@SuppressLint("UseIcu")
@Nullable private final Locale mLocale;
private final boolean mDeviceOwnerCanGrantSensorsPermissions;
private FullyManagedDeviceProvisioningParams(
@NonNull ComponentName deviceAdminComponentName,
@NonNull String ownerName,
boolean leaveAllSystemAppsEnabled,
@Nullable String timeZone,
long localTime,
@Nullable @SuppressLint("UseIcu") Locale locale,
boolean deviceOwnerCanGrantSensorsPermissions) {
this.mDeviceAdminComponentName = requireNonNull(deviceAdminComponentName);
this.mOwnerName = requireNonNull(ownerName);
this.mLeaveAllSystemAppsEnabled = leaveAllSystemAppsEnabled;
this.mTimeZone = timeZone;
this.mLocalTime = localTime;
this.mLocale = locale;
this.mDeviceOwnerCanGrantSensorsPermissions =
deviceOwnerCanGrantSensorsPermissions;
}
private FullyManagedDeviceProvisioningParams(
@NonNull ComponentName deviceAdminComponentName,
@NonNull String ownerName,
boolean leaveAllSystemAppsEnabled,
@Nullable String timeZone,
long localTime,
@Nullable String localeStr,
boolean deviceOwnerCanGrantSensorsPermissions) {
this(deviceAdminComponentName,
ownerName,
leaveAllSystemAppsEnabled,
timeZone,
localTime,
getLocale(localeStr),
deviceOwnerCanGrantSensorsPermissions);
}
@Nullable
private static Locale getLocale(String localeStr) {
return localeStr == null ? null : Locale.forLanguageTag(localeStr);
}
@NonNull
public ComponentName getDeviceAdminComponentName() {
return mDeviceAdminComponentName;
}
@NonNull
public String getOwnerName() {
return mOwnerName;
}
public boolean isLeaveAllSystemAppsEnabled() {
return mLeaveAllSystemAppsEnabled;
}
@Nullable
public String getTimeZone() {
return mTimeZone;
}
public long getLocalTime() {
return mLocalTime;
}
@Nullable
public @SuppressLint("UseIcu") Locale getLocale() {
return mLocale;
}
/**
* @return true if the device owner can control sensor-related permission grants, false
* if the device owner has opted out of it.
*/
public boolean canDeviceOwnerGrantSensorsPermissions() {
return mDeviceOwnerCanGrantSensorsPermissions;
}
/**
* Logs the provisioning params using {@link DevicePolicyEventLogger}.
*/
public void logParams(@NonNull String callerPackage) {
requireNonNull(callerPackage);
logParam(callerPackage, LEAVE_ALL_SYSTEM_APPS_ENABLED_PARAM, mLeaveAllSystemAppsEnabled);
logParam(callerPackage, CAN_DEVICE_OWNER_GRANT_SENSOR_PERMISSIONS_PARAM,
mDeviceOwnerCanGrantSensorsPermissions);
logParam(callerPackage, TIME_ZONE_PROVIDED_PARAM, /* value= */ mTimeZone != null);
logParam(callerPackage, LOCALE_PROVIDED_PARAM, /* value= */ mLocale != null);
}
private void logParam(String callerPackage, String param, boolean value) {
DevicePolicyEventLogger
.createEvent(DevicePolicyEnums.PLATFORM_PROVISIONING_PARAM)
.setStrings(callerPackage)
.setAdmin(mDeviceAdminComponentName)
.setStrings(param)
.setBoolean(value)
.write();
}
/**
* Builder class for {@link FullyManagedDeviceProvisioningParams} objects.
*/
public static final class Builder {
@NonNull private final ComponentName mDeviceAdminComponentName;
@NonNull private final String mOwnerName;
private boolean mLeaveAllSystemAppsEnabled;
@Nullable private String mTimeZone;
private long mLocalTime;
@SuppressLint("UseIcu")
@Nullable private Locale mLocale;
// Default to allowing control over sensor permission grants.
boolean mDeviceOwnerCanGrantSensorsPermissions = true;
/**
* Initialize a new {@link Builder} to construct a
* {@link FullyManagedDeviceProvisioningParams}.
* <p>
* See {@link DevicePolicyManager#provisionFullyManagedDevice}
*
* @param deviceAdminComponentName The admin {@link ComponentName} to be set as the device
* owner.
* @param ownerName The name of the device owner.
*
* @throws NullPointerException if {@code deviceAdminComponentName} or
* {@code ownerName} are null.
*/
public Builder(
@NonNull ComponentName deviceAdminComponentName, @NonNull String ownerName) {
this.mDeviceAdminComponentName = requireNonNull(deviceAdminComponentName);
this.mOwnerName = requireNonNull(ownerName);
}
/**
* Sets whether non-required system apps should be installed on
* the created profile when
* {@link DevicePolicyManager#provisionFullyManagedDevice}
* is called. Defaults to {@code false} if not set.
*/
@NonNull
public Builder setLeaveAllSystemAppsEnabled(boolean leaveAllSystemAppsEnabled) {
this.mLeaveAllSystemAppsEnabled = leaveAllSystemAppsEnabled;
return this;
}
/**
* Sets {@code timeZone} on the device. If not set or set to {@code null},
* {@link DevicePolicyManager#provisionFullyManagedDevice} will not set a timezone
*/
@NonNull
public Builder setTimeZone(@Nullable String timeZone) {
this.mTimeZone = timeZone;
return this;
}
/**
* Sets {@code localTime} on the device, If not set or set to
* {@code 0}, {@link DevicePolicyManager#provisionFullyManagedDevice} will not set a
* local time.
*/
@NonNull
public Builder setLocalTime(long localTime) {
this.mLocalTime = localTime;
return this;
}
/**
* Sets {@link Locale} on the device, If not set or set to {@code null},
* {@link DevicePolicyManager#provisionFullyManagedDevice} will not set a locale.
*/
@NonNull
public Builder setLocale(@SuppressLint("UseIcu") @Nullable Locale locale) {
this.mLocale = locale;
return this;
}
/**
* Marks that the Device Owner may grant permissions related to device sensors.
* See {@link DevicePolicyManager#EXTRA_PROVISIONING_SENSORS_PERMISSION_GRANT_OPT_OUT}.
*/
@NonNull
@SuppressLint("MissingGetterMatchingBuilder")
public Builder setDeviceOwnerCanGrantSensorsPermissions(boolean mayGrant) {
mDeviceOwnerCanGrantSensorsPermissions = mayGrant;
return this;
}
/**
* Combines all of the attributes that have been set on this {@code Builder}
*
* @return a new {@link FullyManagedDeviceProvisioningParams} object.
*/
@NonNull
public FullyManagedDeviceProvisioningParams build() {
return new FullyManagedDeviceProvisioningParams(
mDeviceAdminComponentName,
mOwnerName,
mLeaveAllSystemAppsEnabled,
mTimeZone,
mLocalTime,
mLocale,
mDeviceOwnerCanGrantSensorsPermissions);
}
}
@Override
public int describeContents() {
return 0;
}
@Override
public String toString() {
return "FullyManagedDeviceProvisioningParams{"
+ "mDeviceAdminComponentName=" + mDeviceAdminComponentName
+ ", mOwnerName=" + mOwnerName
+ ", mLeaveAllSystemAppsEnabled=" + mLeaveAllSystemAppsEnabled
+ ", mTimeZone=" + (mTimeZone == null ? "null" : mTimeZone)
+ ", mLocalTime=" + mLocalTime
+ ", mLocale=" + (mLocale == null ? "null" : mLocale)
+ ", mDeviceOwnerCanGrantSensorsPermissions="
+ mDeviceOwnerCanGrantSensorsPermissions
+ '}';
}
@Override
public void writeToParcel(@NonNull Parcel dest, @Nullable int flags) {
dest.writeTypedObject(mDeviceAdminComponentName, flags);
dest.writeString(mOwnerName);
dest.writeBoolean(mLeaveAllSystemAppsEnabled);
dest.writeString(mTimeZone);
dest.writeLong(mLocalTime);
dest.writeString(mLocale == null ? null : mLocale.toLanguageTag());
dest.writeBoolean(mDeviceOwnerCanGrantSensorsPermissions);
}
@NonNull
public static final Creator<FullyManagedDeviceProvisioningParams> CREATOR =
new Creator<FullyManagedDeviceProvisioningParams>() {
@Override
public FullyManagedDeviceProvisioningParams createFromParcel(Parcel in) {
ComponentName componentName = in.readTypedObject(ComponentName.CREATOR);
String ownerName = in.readString();
boolean leaveAllSystemAppsEnabled = in.readBoolean();
String timeZone = in.readString();
long localtime = in.readLong();
String locale = in.readString();
boolean deviceOwnerCanGrantSensorsPermissions = in.readBoolean();
return new FullyManagedDeviceProvisioningParams(
componentName,
ownerName,
leaveAllSystemAppsEnabled,
timeZone,
localtime,
locale,
deviceOwnerCanGrantSensorsPermissions);
}
@Override
public FullyManagedDeviceProvisioningParams[] newArray(int size) {
return new FullyManagedDeviceProvisioningParams[size];
}
};
}
|