OSDN Git Service

Send ACTION_DEVICE_OWNER_CHANGED broadcast after clearing device owner
authorTony Mak <tonymak@google.com>
Tue, 30 Aug 2016 16:41:48 +0000 (17:41 +0100)
committerTony Mak <tonymak@google.com>
Tue, 30 Aug 2016 16:41:48 +0000 (17:41 +0100)
Change-Id: Iaac182c69a30e941da3a017a923247d813881521
Fix: 27261692

core/java/android/app/admin/DevicePolicyManager.java
services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java

index 851cf50..cfc4519 100644 (file)
@@ -878,7 +878,7 @@ public class DevicePolicyManager {
             = "android.app.action.DEVICE_POLICY_MANAGER_STATE_CHANGED";
 
     /**
-     * Broadcast action: sent when the device owner is set or changed.
+     * Broadcast action: sent when the device owner is set, changed or cleared.
      *
      * This broadcast is sent only to the primary user.
      * @see #ACTION_PROVISION_MANAGED_DEVICE
index 9c4b94e..f5fcc64 100644 (file)
@@ -5883,6 +5883,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
             try {
                 clearDeviceOwnerLocked(admin, deviceOwnerUserId);
                 removeActiveAdminLocked(deviceOwnerComponent, deviceOwnerUserId);
+                Intent intent = new Intent(DevicePolicyManager.ACTION_DEVICE_OWNER_CHANGED);
+                mContext.sendBroadcastAsUser(intent, UserHandle.of(deviceOwnerUserId));
             } finally {
                 mInjector.binderRestoreCallingIdentity(ident);
             }
index 0fd1286..01b2c3b 100644 (file)
@@ -839,6 +839,12 @@ public class DevicePolicyManagerTest extends DpmTestBase {
         );
 
         assertFalse(dpm.isAdminActiveAsUser(admin1, UserHandle.USER_SYSTEM));
+
+        // ACTION_DEVICE_OWNER_CHANGED should be sent twice, once for setting the device owner
+        // and once for clearing it.
+        verify(mContext.spiedContext, times(2)).sendBroadcastAsUser(
+                MockUtils.checkIntentAction(DevicePolicyManager.ACTION_DEVICE_OWNER_CHANGED),
+                MockUtils.checkUserHandle(UserHandle.USER_SYSTEM));
         // TODO Check other calls.
     }