@@ -69,6 +69,7 @@ final class ShellCommand {
69
69
"get-user-control-disabled-packages" ;
70
70
private static final String CMD_REMOVE_ACTIVE_ADMIN = "remove-active-admin" ;
71
71
private static final String CMD_CLEAR_DEVICE_OWNER = "clear-device-owner" ;
72
+ private static final String CMD_CLEAR_PROFILE_OWNER = "clear-profile-owner" ;
72
73
73
74
private static final String ARG_FLAGS = "--flags" ;
74
75
@@ -163,6 +164,9 @@ public void run() {
163
164
case CMD_CLEAR_DEVICE_OWNER :
164
165
execute (() -> clearDeviceOwner ());
165
166
break ;
167
+ case CMD_CLEAR_PROFILE_OWNER :
168
+ execute (() -> clearProfileOwner ());
169
+ break ;
166
170
default :
167
171
mWriter .printf ("Invalid command: %s\n \n " , cmd );
168
172
showUsage ();
@@ -208,13 +212,14 @@ private void showUsage() {
208
212
mWriter .printf ("\t %s [NAME] - set the organization name; use it without a name to reset\n " ,
209
213
CMD_SET_ORGANIZATION_NAME );
210
214
mWriter .printf ("\t %s - get the organization name\n " , CMD_GET_ORGANIZATION_NAME );
211
- mWriter .printf ("\t %s [PKG1] [PKG2] [PKGN] - sets the packages that the user cannot force \n "
212
- + "\t stop or clear data. Use no args to reset it.\n " ,
215
+ mWriter .printf ("\t %s [PKG1] [PKG2] [PKGN] - sets the packages that the user cannot\n "
216
+ + "\t \t force stop or clear data. Use no args to reset it.\n " ,
213
217
CMD_SET_USER_CONTROL_DISABLED_PACKAGES );
214
218
mWriter .printf ("\t %s - gets the packages that the user cannot force stop or "
215
219
+ "clear data\n " , CMD_GET_USER_CONTROL_DISABLED_PACKAGES );
216
220
mWriter .printf ("\t %s - remove itself as an admin\n " , CMD_REMOVE_ACTIVE_ADMIN );
217
221
mWriter .printf ("\t %s - clear itself as device owner \n " , CMD_CLEAR_DEVICE_OWNER );
222
+ mWriter .printf ("\t %s - clear itself as profile owner \n " , CMD_CLEAR_PROFILE_OWNER );
218
223
}
219
224
220
225
private void createUser () {
@@ -447,6 +452,15 @@ private void clearDeviceOwner() {
447
452
(e ) -> onError (e , "Error removing %s as device owner" , pkg ));
448
453
}
449
454
455
+ private void clearProfileOwner () {
456
+ Log .i (TAG , "clearProfileOwner()" );
457
+
458
+ String pkg = mDevicePolicyManagerGateway .getAdmin ().getPackageName ();
459
+ mDevicePolicyManagerGateway .clearProfileOwner (
460
+ (v ) -> onSuccess ("Removed %s as profile owner" , pkg ),
461
+ (e ) -> onError (e , "Error removing %s as profile owner" , pkg ));
462
+ }
463
+
450
464
private void execute (@ NonNull Runnable r ) {
451
465
try {
452
466
r .run ();
0 commit comments