summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorarangelov <arangelov@google.com>2018-01-04 17:10:21 +0000
committerarangelov <arangelov@google.com>2018-01-24 19:20:36 +0000
commit91201bdbcab8a1010bf66e3dd03375bc4082ab18 (patch)
tree0a2fa40a27ef2729975476ee125375cf4c20ceda /core/java
parentff73b83831f03e0912e55096961ce42dbfa164f9 (diff)
Make owner transfer an atomic operation.
Test: bit FrameworksServicesTests:com.android.server.devicepolicy.TransferOwnershipMetadataManagerTest Test: runtest -x frameworks/base/services/tests/servicestests/src/com/android/server/devicepolicy/OwnerTransferParamsManagerTest.java Test: bit FrameworksServicesTests:com.android.server.devicepolicy.DevicePolicyManagerTest#testRevertDeviceOwnership_noMetadataFile Test: bit FrameworksServicesTests:com.android.server.devicepolicy.DevicePolicyManagerTest#testRevertDeviceOwnership_adminAndDeviceMigrated Test: bit FrameworksServicesTests:com.android.server.devicepolicy.DevicePolicyManagerTest#testRevertDeviceOwnership_deviceNotMigrated Test: bit FrameworksServicesTests:com.android.server.devicepolicy.DevicePolicyManagerTest#testRevertDeviceOwnership_adminAndDeviceNotMigrated Test: bit FrameworksServicesTests:com.android.server.devicepolicy.DevicePolicyManagerTest#testRevertProfileOwnership_noMetadataFile Test: bit FrameworksServicesTests:com.android.server.devicepolicy.DevicePolicyManagerTest#testRevertProfileOwnership_adminAndProfileMigrated Test: bit FrameworksServicesTests:com.android.server.devicepolicy.DevicePolicyManagerTest#testRevertProfileOwnership_profileNotMigrated Test: bit FrameworksServicesTests:com.android.server.devicepolicy.DevicePolicyManagerTest#testRevertProfileOwnership_adminAndProfileNotMigrated Bug: 69543005 (cherry picked from commit 5a6d391dedcdec13fcc4cf1770e7bf9fc1be8643) Change-Id: Ic2d729d48fdb47b0ebd60030b45615b0cec174a2
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/app/admin/DeviceAdminReceiver.java9
-rw-r--r--core/java/android/app/admin/DevicePolicyManager.java34
-rw-r--r--core/java/android/app/admin/IDevicePolicyManager.aidl2
3 files changed, 35 insertions, 10 deletions
diff --git a/core/java/android/app/admin/DeviceAdminReceiver.java b/core/java/android/app/admin/DeviceAdminReceiver.java
index ffb3affb03b3..d65545d504d7 100644
--- a/core/java/android/app/admin/DeviceAdminReceiver.java
+++ b/core/java/android/app/admin/DeviceAdminReceiver.java
@@ -487,15 +487,14 @@ public class DeviceAdminReceiver extends BroadcastReceiver {
* allows a mobile device management application to pass data to the management application
* instance after owner transfer.
*
- * <p>
- * If the transfer is successful, the new device owner receives the data in
+ * <p>If the transfer is successful, the new owner receives the data in
* {@link DeviceAdminReceiver#onTransferOwnershipComplete(Context, PersistableBundle)}.
* The bundle is not changed during the ownership transfer.
*
* @see DevicePolicyManager#transferOwnership(ComponentName, ComponentName, PersistableBundle)
*/
- public static final String EXTRA_TRANSFER_OWNER_ADMIN_EXTRAS_BUNDLE =
- "android.app.extra.TRANSFER_OWNER_ADMIN_EXTRAS_BUNDLE";
+ public static final String EXTRA_TRANSFER_OWNERSHIP_ADMIN_EXTRAS_BUNDLE =
+ "android.app.extra.TRANSFER_OWNERSHIP_ADMIN_EXTRAS_BUNDLE";
/**
* Name under which a device administration component indicates whether it supports transfer of
@@ -1063,7 +1062,7 @@ public class DeviceAdminReceiver extends BroadcastReceiver {
onUserSwitched(context, intent, intent.getParcelableExtra(Intent.EXTRA_USER));
} else if (ACTION_TRANSFER_OWNERSHIP_COMPLETE.equals(action)) {
PersistableBundle bundle =
- intent.getParcelableExtra(EXTRA_TRANSFER_OWNER_ADMIN_EXTRAS_BUNDLE);
+ intent.getParcelableExtra(EXTRA_TRANSFER_OWNERSHIP_ADMIN_EXTRAS_BUNDLE);
onTransferOwnershipComplete(context, bundle);
}
}
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index 95e7fe059bb9..204325e3ce82 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -9144,9 +9144,13 @@ public class DevicePolicyManager {
* <li>A profile owner can only be transferred to a new profile owner</li>
* </ul>
*
- * <p>Use the {@code bundle} parameter to pass data to the new administrator. The parameters
+ * <p>Use the {@code bundle} parameter to pass data to the new administrator. The data
* will be received in the
- * {@link DeviceAdminReceiver#onTransferOwnershipComplete(Context, PersistableBundle)} callback.
+ * {@link DeviceAdminReceiver#onTransferOwnershipComplete(Context, PersistableBundle)}
+ * callback of the new administrator.
+ *
+ * <p>The transfer has failed if the original administrator is still the corresponding owner
+ * after calling this method.
*
* <p>The incoming target administrator must have the
* {@link DeviceAdminReceiver#SUPPORT_TRANSFER_OWNERSHIP_META_DATA} <code>meta-data</code> tag
@@ -9157,11 +9161,11 @@ public class DevicePolicyManager {
* @param target which {@link DeviceAdminReceiver} we want the new administrator to be
* @param bundle data to be sent to the new administrator
* @throws SecurityException if {@code admin} is not a device owner nor a profile owner
- * @throws IllegalArgumentException if {@code admin} or {@code target} is {@code null},
- * both are components in the same package or {@code target} is not an active admin
+ * @throws IllegalArgumentException if {@code admin} or {@code target} is {@code null}, they
+ * are components in the same package or {@code target} is not an active admin
*/
public void transferOwnership(@NonNull ComponentName admin, @NonNull ComponentName target,
- PersistableBundle bundle) {
+ @Nullable PersistableBundle bundle) {
throwIfParentInstance("transferOwnership");
try {
mService.transferOwnership(admin, target, bundle);
@@ -9434,4 +9438,24 @@ public class DevicePolicyManager {
}
return false;
}
+
+ /**
+ * Returns the data passed from the current administrator to the new administrator during an
+ * ownership transfer. This is the same {@code bundle} passed in
+ * {@link #transferOwnership(ComponentName, ComponentName, PersistableBundle)}.
+ *
+ * <p>Returns <code>null</code> if no ownership transfer was started for the calling user.
+ *
+ * @see #transferOwnership
+ * @see DeviceAdminReceiver#onTransferOwnershipComplete(Context, PersistableBundle)
+ */
+ @Nullable
+ public PersistableBundle getTransferOwnershipBundle() {
+ throwIfParentInstance("getTransferOwnershipBundle");
+ try {
+ return mService.getTransferOwnershipBundle();
+ } catch (RemoteException re) {
+ throw re.rethrowFromSystemServer();
+ }
+ }
}
diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl
index a5ca4cf12ffa..5606d8535208 100644
--- a/core/java/android/app/admin/IDevicePolicyManager.aidl
+++ b/core/java/android/app/admin/IDevicePolicyManager.aidl
@@ -391,7 +391,9 @@ interface IDevicePolicyManager {
boolean isLogoutEnabled();
List<String> getDisallowedSystemApps(in ComponentName admin, int userId, String provisioningAction);
+
void transferOwnership(in ComponentName admin, in ComponentName target, in PersistableBundle bundle);
+ PersistableBundle getTransferOwnershipBundle();
void setStartUserSessionMessage(in ComponentName admin, in CharSequence startUserSessionMessage);
void setEndUserSessionMessage(in ComponentName admin, in CharSequence endUserSessionMessage);