Merge "Support safe mode properly." into nyc-dev am: a4fae1545a
am: 04d8eca54a
* commit '04d8eca54af9d46e793134a9168f658b9d68017f':
Support safe mode properly.
This commit is contained in:
@@ -240,7 +240,7 @@ public final class DeviceAdminInfo implements Parcelable {
|
||||
/**
|
||||
* The BroadcastReceiver that implements this device admin component.
|
||||
*/
|
||||
final ResolveInfo mReceiver;
|
||||
final ActivityInfo mActivityInfo;
|
||||
|
||||
/**
|
||||
* Whether this should be visible to the user.
|
||||
@@ -252,29 +252,42 @@ public final class DeviceAdminInfo implements Parcelable {
|
||||
*/
|
||||
int mUsesPolicies;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param context The Context in which we are parsing the device admin.
|
||||
* @param receiver The ResolveInfo returned from the package manager about
|
||||
* @param resolveInfo The ResolveInfo returned from the package manager about
|
||||
* this device admin's component.
|
||||
*/
|
||||
public DeviceAdminInfo(Context context, ResolveInfo receiver)
|
||||
public DeviceAdminInfo(Context context, ResolveInfo resolveInfo)
|
||||
throws XmlPullParserException, IOException {
|
||||
mReceiver = receiver;
|
||||
ActivityInfo ai = receiver.activityInfo;
|
||||
this(context, resolveInfo.activityInfo);
|
||||
}
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param context The Context in which we are parsing the device admin.
|
||||
* @param activityInfo The ActivityInfo returned from the package manager about
|
||||
* this device admin's component.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public DeviceAdminInfo(Context context, ActivityInfo activityInfo)
|
||||
throws XmlPullParserException, IOException {
|
||||
mActivityInfo = activityInfo;
|
||||
|
||||
PackageManager pm = context.getPackageManager();
|
||||
|
||||
XmlResourceParser parser = null;
|
||||
try {
|
||||
parser = ai.loadXmlMetaData(pm, DeviceAdminReceiver.DEVICE_ADMIN_META_DATA);
|
||||
parser = mActivityInfo.loadXmlMetaData(pm, DeviceAdminReceiver.DEVICE_ADMIN_META_DATA);
|
||||
if (parser == null) {
|
||||
throw new XmlPullParserException("No "
|
||||
+ DeviceAdminReceiver.DEVICE_ADMIN_META_DATA + " meta-data");
|
||||
}
|
||||
|
||||
Resources res = pm.getResourcesForApplication(ai.applicationInfo);
|
||||
Resources res = pm.getResourcesForApplication(mActivityInfo.applicationInfo);
|
||||
|
||||
AttributeSet attrs = Xml.asAttributeSet(parser);
|
||||
|
||||
@@ -324,14 +337,14 @@ public final class DeviceAdminInfo implements Parcelable {
|
||||
}
|
||||
} catch (NameNotFoundException e) {
|
||||
throw new XmlPullParserException(
|
||||
"Unable to create context for: " + ai.packageName);
|
||||
"Unable to create context for: " + mActivityInfo.packageName);
|
||||
} finally {
|
||||
if (parser != null) parser.close();
|
||||
}
|
||||
}
|
||||
|
||||
DeviceAdminInfo(Parcel source) {
|
||||
mReceiver = ResolveInfo.CREATOR.createFromParcel(source);
|
||||
mActivityInfo = ActivityInfo.CREATOR.createFromParcel(source);
|
||||
mUsesPolicies = source.readInt();
|
||||
}
|
||||
|
||||
@@ -339,7 +352,7 @@ public final class DeviceAdminInfo implements Parcelable {
|
||||
* Return the .apk package that implements this device admin.
|
||||
*/
|
||||
public String getPackageName() {
|
||||
return mReceiver.activityInfo.packageName;
|
||||
return mActivityInfo.packageName;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -347,7 +360,7 @@ public final class DeviceAdminInfo implements Parcelable {
|
||||
* this device admin.
|
||||
*/
|
||||
public String getReceiverName() {
|
||||
return mReceiver.activityInfo.name;
|
||||
return mActivityInfo.name;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -355,7 +368,7 @@ public final class DeviceAdminInfo implements Parcelable {
|
||||
* device admin. Do not modify the returned object.
|
||||
*/
|
||||
public ActivityInfo getActivityInfo() {
|
||||
return mReceiver.activityInfo;
|
||||
return mActivityInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -363,8 +376,8 @@ public final class DeviceAdminInfo implements Parcelable {
|
||||
*/
|
||||
@NonNull
|
||||
public ComponentName getComponent() {
|
||||
return new ComponentName(mReceiver.activityInfo.packageName,
|
||||
mReceiver.activityInfo.name);
|
||||
return new ComponentName(mActivityInfo.packageName,
|
||||
mActivityInfo.name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -374,7 +387,7 @@ public final class DeviceAdminInfo implements Parcelable {
|
||||
* resources.
|
||||
*/
|
||||
public CharSequence loadLabel(PackageManager pm) {
|
||||
return mReceiver.loadLabel(pm);
|
||||
return mActivityInfo.loadLabel(pm);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -384,15 +397,9 @@ public final class DeviceAdminInfo implements Parcelable {
|
||||
* resources.
|
||||
*/
|
||||
public CharSequence loadDescription(PackageManager pm) throws NotFoundException {
|
||||
if (mReceiver.activityInfo.descriptionRes != 0) {
|
||||
String packageName = mReceiver.resolvePackageName;
|
||||
ApplicationInfo applicationInfo = null;
|
||||
if (packageName == null) {
|
||||
packageName = mReceiver.activityInfo.packageName;
|
||||
applicationInfo = mReceiver.activityInfo.applicationInfo;
|
||||
}
|
||||
return pm.getText(packageName,
|
||||
mReceiver.activityInfo.descriptionRes, applicationInfo);
|
||||
if (mActivityInfo.descriptionRes != 0) {
|
||||
return pm.getText(mActivityInfo.packageName,
|
||||
mActivityInfo.descriptionRes, mActivityInfo.applicationInfo);
|
||||
}
|
||||
throw new NotFoundException();
|
||||
}
|
||||
@@ -404,7 +411,7 @@ public final class DeviceAdminInfo implements Parcelable {
|
||||
* resources.
|
||||
*/
|
||||
public Drawable loadIcon(PackageManager pm) {
|
||||
return mReceiver.loadIcon(pm);
|
||||
return mActivityInfo.loadIcon(pm);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -464,12 +471,12 @@ public final class DeviceAdminInfo implements Parcelable {
|
||||
|
||||
public void dump(Printer pw, String prefix) {
|
||||
pw.println(prefix + "Receiver:");
|
||||
mReceiver.dump(pw, prefix + " ");
|
||||
mActivityInfo.dump(pw, prefix + " ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DeviceAdminInfo{" + mReceiver.activityInfo.name + "}";
|
||||
return "DeviceAdminInfo{" + mActivityInfo.name + "}";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -479,7 +486,7 @@ public final class DeviceAdminInfo implements Parcelable {
|
||||
* @param flags The flags used for parceling.
|
||||
*/
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
mReceiver.writeToParcel(dest, flags);
|
||||
mActivityInfo.writeToParcel(dest, flags);
|
||||
dest.writeInt(mUsesPolicies);
|
||||
}
|
||||
|
||||
|
||||
@@ -3171,31 +3171,6 @@ public class DevicePolicyManager {
|
||||
setActiveAdmin(policyReceiver, refreshing, myUserId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the DeviceAdminInfo as defined by the administrator's package info & meta-data
|
||||
* @hide
|
||||
*/
|
||||
public DeviceAdminInfo getAdminInfo(@NonNull ComponentName cn) {
|
||||
ActivityInfo ai;
|
||||
try {
|
||||
ai = mContext.getPackageManager().getReceiverInfo(cn,
|
||||
PackageManager.GET_META_DATA);
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Log.w(TAG, "Unable to retrieve device policy " + cn, e);
|
||||
return null;
|
||||
}
|
||||
|
||||
ResolveInfo ri = new ResolveInfo();
|
||||
ri.activityInfo = ai;
|
||||
|
||||
try {
|
||||
return new DeviceAdminInfo(mContext, ri);
|
||||
} catch (XmlPullParserException | IOException e) {
|
||||
Log.w(TAG, "Unable to parse device policy " + cn, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user