FileDocCategorySizeDatePackage
DeviceAdminInfo.javaAPI DocAndroid 5.1 API18535Thu Mar 12 22:22:10 GMT 2015android.app.admin

DeviceAdminInfo

public final class DeviceAdminInfo extends Object implements android.os.Parcelable
This class is used to specify meta information of a device administrator component.

Fields Summary
static final String
TAG
public static final int
USES_POLICY_DEVICE_OWNER
A type of policy that this device admin can use: device owner meta-policy for an admin that is designated as owner of the device.
public static final int
USES_POLICY_PROFILE_OWNER
A type of policy that this device admin can use: profile owner meta-policy for admins that have been installed as owner of some user profile.
public static final int
USES_POLICY_LIMIT_PASSWORD
A type of policy that this device admin can use: limit the passwords that the user can select, via {@link DevicePolicyManager#setPasswordQuality} and {@link DevicePolicyManager#setPasswordMinimumLength}.

To control this policy, the device admin must have a "limit-password" tag in the "uses-policies" section of its meta-data.

public static final int
USES_POLICY_WATCH_LOGIN
A type of policy that this device admin can use: able to watch login attempts from the user, via {@link DeviceAdminReceiver#ACTION_PASSWORD_FAILED}, {@link DeviceAdminReceiver#ACTION_PASSWORD_SUCCEEDED}, and {@link DevicePolicyManager#getCurrentFailedPasswordAttempts}.

To control this policy, the device admin must have a "watch-login" tag in the "uses-policies" section of its meta-data.

public static final int
USES_POLICY_RESET_PASSWORD
A type of policy that this device admin can use: able to reset the user's password via {@link DevicePolicyManager#resetPassword}.

To control this policy, the device admin must have a "reset-password" tag in the "uses-policies" section of its meta-data.

public static final int
USES_POLICY_FORCE_LOCK
A type of policy that this device admin can use: able to force the device to lock via{@link DevicePolicyManager#lockNow} or limit the maximum lock timeout for the device via {@link DevicePolicyManager#setMaximumTimeToLock}.

To control this policy, the device admin must have a "force-lock" tag in the "uses-policies" section of its meta-data.

public static final int
USES_POLICY_WIPE_DATA
A type of policy that this device admin can use: able to factory reset the device, erasing all of the user's data, via {@link DevicePolicyManager#wipeData}.

To control this policy, the device admin must have a "wipe-data" tag in the "uses-policies" section of its meta-data.

public static final int
USES_POLICY_SETS_GLOBAL_PROXY
A type of policy that this device admin can use: able to specify the device Global Proxy, via {@link DevicePolicyManager#setGlobalProxy}.

To control this policy, the device admin must have a "set-global-proxy" tag in the "uses-policies" section of its meta-data.

public static final int
USES_POLICY_EXPIRE_PASSWORD
A type of policy that this device admin can use: force the user to change their password after an administrator-defined time limit.

To control this policy, the device admin must have an "expire-password" tag in the "uses-policies" section of its meta-data.

public static final int
USES_ENCRYPTED_STORAGE
A type of policy that this device admin can use: require encryption of stored data.

To control this policy, the device admin must have a "encrypted-storage" tag in the "uses-policies" section of its meta-data.

public static final int
USES_POLICY_DISABLE_CAMERA
A type of policy that this device admin can use: disables use of all device cameras.

To control this policy, the device admin must have a "disable-camera" tag in the "uses-policies" section of its meta-data.

public static final int
USES_POLICY_DISABLE_KEYGUARD_FEATURES
A type of policy that this device admin can use: disables use of keyguard features.

To control this policy, the device admin must have a "disable-keyguard-features" tag in the "uses-policies" section of its meta-data.

static ArrayList
sPoliciesDisplayOrder
static HashMap
sKnownPolicies
static android.util.SparseArray
sRevKnownPolicies
final android.content.pm.ResolveInfo
mReceiver
The BroadcastReceiver that implements this device admin component.
boolean
mVisible
Whether this should be visible to the user.
int
mUsesPolicies
The policies this administrator needs access to.
public static final Parcelable.Creator
CREATOR
Used to make this class parcelable.
Constructors Summary
public DeviceAdminInfo(android.content.Context context, android.content.pm.ResolveInfo receiver)
Constructor.

param
context The Context in which we are parsing the device admin.
param
receiver The ResolveInfo returned from the package manager about this device admin's component.

        mReceiver = receiver;
        ActivityInfo ai = receiver.activityInfo;

        PackageManager pm = context.getPackageManager();

        XmlResourceParser parser = null;
        try {
            parser = ai.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);

            AttributeSet attrs = Xml.asAttributeSet(parser);

            int type;
            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
                    && type != XmlPullParser.START_TAG) {
            }

            String nodeName = parser.getName();
            if (!"device-admin".equals(nodeName)) {
                throw new XmlPullParserException(
                        "Meta-data does not start with device-admin tag");
            }

            TypedArray sa = res.obtainAttributes(attrs,
                    com.android.internal.R.styleable.DeviceAdmin);

            mVisible = sa.getBoolean(
                    com.android.internal.R.styleable.DeviceAdmin_visible, true);

            sa.recycle();

            int outerDepth = parser.getDepth();
            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
                   && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
                    continue;
                }
                String tagName = parser.getName();
                if (tagName.equals("uses-policies")) {
                    int innerDepth = parser.getDepth();
                    while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
                           && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
                        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
                            continue;
                        }
                        String policyName = parser.getName();
                        Integer val = sKnownPolicies.get(policyName);
                        if (val != null) {
                            mUsesPolicies |= 1 << val.intValue();
                        } else {
                            Log.w(TAG, "Unknown tag under uses-policies of "
                                    + getComponent() + ": " + policyName);
                        }
                    }
                }
            }
        } catch (NameNotFoundException e) {
            throw new XmlPullParserException(
                    "Unable to create context for: " + ai.packageName);
        } finally {
            if (parser != null) parser.close();
        }
    
DeviceAdminInfo(android.os.Parcel source)

        mReceiver = ResolveInfo.CREATOR.createFromParcel(source);
        mUsesPolicies = source.readInt();
    
Methods Summary
public intdescribeContents()


       
        return 0;
    
public voiddump(android.util.Printer pw, java.lang.String prefix)

        pw.println(prefix + "Receiver:");
        mReceiver.dump(pw, prefix + "  ");
    
public android.content.pm.ActivityInfogetActivityInfo()
Return the raw information about the receiver implementing this device admin. Do not modify the returned object.

        return mReceiver.activityInfo;
    
public android.content.ComponentNamegetComponent()
Return the component of the receiver that implements this device admin.

        return new ComponentName(mReceiver.activityInfo.packageName,
                mReceiver.activityInfo.name);
    
public java.lang.StringgetPackageName()
Return the .apk package that implements this device admin.

        return mReceiver.activityInfo.packageName;
    
public java.lang.StringgetReceiverName()
Return the class name of the receiver component that implements this device admin.

        return mReceiver.activityInfo.name;
    
public java.lang.StringgetTagForPolicy(int policyIdent)
Return the XML tag name for the given policy identifier. Valid identifiers are as per {@link #usesPolicy(int)}. If the given identifier is not known, null is returned.

        return sRevKnownPolicies.get(policyIdent).tag;
    
public java.util.ArrayListgetUsedPolicies()

hide

        ArrayList<PolicyInfo> res = new ArrayList<PolicyInfo>();
        for (int i=0; i<sPoliciesDisplayOrder.size(); i++) {
            PolicyInfo pi = sPoliciesDisplayOrder.get(i);
            if (usesPolicy(pi.ident)) {
                res.add(pi);
            }
        }
        return res;
    
public booleanisVisible()
Returns whether this device admin would like to be visible to the user, even when it is not enabled.

        return mVisible;
    
public java.lang.CharSequenceloadDescription(android.content.pm.PackageManager pm)
Load user-visible description associated with this device admin.

param
pm Supply a PackageManager used to load the device admin's resources.

        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);
        }
        throw new NotFoundException();
    
public android.graphics.drawable.DrawableloadIcon(android.content.pm.PackageManager pm)
Load the user-displayed icon for this device admin.

param
pm Supply a PackageManager used to load the device admin's resources.

        return mReceiver.loadIcon(pm);
    
public java.lang.CharSequenceloadLabel(android.content.pm.PackageManager pm)
Load the user-displayed label for this device admin.

param
pm Supply a PackageManager used to load the device admin's resources.

        return mReceiver.loadLabel(pm);
    
public voidreadPoliciesFromXml(org.xmlpull.v1.XmlPullParser parser)

hide

        mUsesPolicies = Integer.parseInt(
                parser.getAttributeValue(null, "flags"));
    
public java.lang.StringtoString()

        return "DeviceAdminInfo{" + mReceiver.activityInfo.name + "}";
    
public booleanusesPolicy(int policyIdent)
Return true if the device admin has requested that it be able to use the given policy control. The possible policy identifier inputs are: {@link #USES_POLICY_LIMIT_PASSWORD}, {@link #USES_POLICY_WATCH_LOGIN}, {@link #USES_POLICY_RESET_PASSWORD}, {@link #USES_POLICY_FORCE_LOCK}, {@link #USES_POLICY_WIPE_DATA}, {@link #USES_POLICY_EXPIRE_PASSWORD}, {@link #USES_ENCRYPTED_STORAGE}, {@link #USES_POLICY_DISABLE_CAMERA}.

        return (mUsesPolicies & (1<<policyIdent)) != 0;
    
public voidwritePoliciesToXml(org.xmlpull.v1.XmlSerializer out)

hide

        out.attribute(null, "flags", Integer.toString(mUsesPolicies));
    
public voidwriteToParcel(android.os.Parcel dest, int flags)
Used to package this object into a {@link Parcel}.

param
dest The {@link Parcel} to be written.
param
flags The flags used for parceling.

        mReceiver.writeToParcel(dest, flags);
        dest.writeInt(mUsesPolicies);