Merge "Move the support_transfer_ownership_metadata inside the device admin descriptor XML." into pi-dev

This commit is contained in:
Antoan Angelov
2018-03-15 19:40:13 +00:00
committed by Android (Google) Code Review
5 changed files with 34 additions and 38 deletions

View File

@@ -6331,6 +6331,7 @@ package android.app.admin {
method public java.lang.CharSequence loadDescription(android.content.pm.PackageManager) throws android.content.res.Resources.NotFoundException;
method public android.graphics.drawable.Drawable loadIcon(android.content.pm.PackageManager);
method public java.lang.CharSequence loadLabel(android.content.pm.PackageManager);
method public boolean supportsTransferOwnership();
method public boolean usesPolicy(int);
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.app.admin.DeviceAdminInfo> CREATOR;
@@ -6395,7 +6396,6 @@ package android.app.admin {
field public static final java.lang.String EXTRA_DISABLE_WARNING = "android.app.extra.DISABLE_WARNING";
field public static final java.lang.String EXTRA_LOCK_TASK_PACKAGE = "android.app.extra.LOCK_TASK_PACKAGE";
field public static final java.lang.String EXTRA_TRANSFER_OWNERSHIP_ADMIN_EXTRAS_BUNDLE = "android.app.extra.TRANSFER_OWNERSHIP_ADMIN_EXTRAS_BUNDLE";
field public static final java.lang.String SUPPORT_TRANSFER_OWNERSHIP_META_DATA = "android.app.support_transfer_ownership";
}
public class DeviceAdminService extends android.app.Service {

View File

@@ -16,31 +16,31 @@
package android.app.admin;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
import android.annotation.NonNull;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.content.res.Resources.NotFoundException;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.content.res.Resources.NotFoundException;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.PersistableBundle;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Printer;
import android.util.SparseArray;
import android.util.Xml;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
@@ -266,6 +266,12 @@ public final class DeviceAdminInfo implements Parcelable {
*/
int mUsesPolicies;
/**
* Whether this administrator can be a target in an ownership transfer.
*
* @see DevicePolicyManager#transferOwnership(ComponentName, ComponentName, PersistableBundle)
*/
boolean mSupportsTransferOwnership;
/**
* Constructor.
@@ -347,6 +353,12 @@ public final class DeviceAdminInfo implements Parcelable {
+ getComponent() + ": " + policyName);
}
}
} else if (tagName.equals("support-transfer-ownership")) {
if (parser.next() != XmlPullParser.END_TAG) {
throw new XmlPullParserException(
"support-transfer-ownership tag must be empty.");
}
mSupportsTransferOwnership = true;
}
}
} catch (NameNotFoundException e) {
@@ -360,6 +372,7 @@ public final class DeviceAdminInfo implements Parcelable {
DeviceAdminInfo(Parcel source) {
mActivityInfo = ActivityInfo.CREATOR.createFromParcel(source);
mUsesPolicies = source.readInt();
mSupportsTransferOwnership = source.readBoolean();
}
/**
@@ -458,6 +471,13 @@ public final class DeviceAdminInfo implements Parcelable {
return sRevKnownPolicies.get(policyIdent).tag;
}
/**
* Return true if this administrator can be a target in an ownership transfer.
*/
public boolean supportsTransferOwnership() {
return mSupportsTransferOwnership;
}
/** @hide */
public ArrayList<PolicyInfo> getUsedPolicies() {
ArrayList<PolicyInfo> res = new ArrayList<PolicyInfo>();
@@ -502,6 +522,7 @@ public final class DeviceAdminInfo implements Parcelable {
public void writeToParcel(Parcel dest, int flags) {
mActivityInfo.writeToParcel(dest, flags);
dest.writeInt(mUsesPolicies);
dest.writeBoolean(mSupportsTransferOwnership);
}
/**

View File

@@ -505,31 +505,6 @@ public class DeviceAdminReceiver extends BroadcastReceiver {
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
* ownership. This meta-data is of type <code>boolean</code>. A value of <code>true</code>
* allows this administrator to be used as a target administrator for a transfer. If the value
* is <code>false</code>, ownership cannot be transferred to this administrator. The default
* value is <code>false</code>.
* <p>This metadata is used to avoid ownership transfer migration to an administrator with a
* version which does not yet support it.
* <p>Usage:
* <pre>
* &lt;receiver name="..." android:permission="android.permission.BIND_DEVICE_ADMIN"&gt;
* &lt;meta-data
* android:name="android.app.device_admin"
* android:resource="@xml/..." /&gt;
* &lt;meta-data
* android:name="android.app.support_transfer_ownership"
* android:value="true" /&gt;
* &lt;/receiver&gt;
* </pre>
*
* @see DevicePolicyManager#transferOwnership(ComponentName, ComponentName, PersistableBundle)
*/
public static final String SUPPORT_TRANSFER_OWNERSHIP_META_DATA =
"android.app.support_transfer_ownership";
private DevicePolicyManager mManager;
private ComponentName mWho;

View File

@@ -9302,9 +9302,10 @@ public class DevicePolicyManager {
* after calling this method.
*
* <p>The incoming target administrator must have the
* {@link DeviceAdminReceiver#SUPPORT_TRANSFER_OWNERSHIP_META_DATA} <code>meta-data</code> tag
* included in its corresponding <code>receiver</code> component with a value of {@code true}.
* Otherwise an {@link IllegalArgumentException} will be thrown.
* <code>&lt;support-transfer-ownership /&gt;</code> tag inside the
* <code>&lt;device-admin&gt;&lt;/device-admin&gt;</code> tags in the xml file referenced by
* {@link DeviceAdminReceiver#DEVICE_ADMIN_META_DATA}. Otherwise an
* {@link IllegalArgumentException} will be thrown.
*
* @param admin which {@link DeviceAdminReceiver} this request is associated with
* @param target which {@link DeviceAdminReceiver} we want the new administrator to be

View File

@@ -12658,8 +12658,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
final DeviceAdminInfo incomingDeviceInfo = findAdmin(target, callingUserId,
/* throwForMissingPermission= */ true);
checkActiveAdminPrecondition(target, incomingDeviceInfo, policy);
if (!incomingDeviceInfo.getActivityInfo().metaData
.getBoolean(DeviceAdminReceiver.SUPPORT_TRANSFER_OWNERSHIP_META_DATA, false)) {
if (!incomingDeviceInfo.supportsTransferOwnership()) {
throw new IllegalArgumentException("Provided target does not support "
+ "ownership transfer.");
}