/* * Copyright (C) 2010 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.app; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; 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.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.util.AttributeSet; import android.util.Log; import android.util.Printer; import android.util.SparseArray; import android.util.Xml; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; /** * This class is used to specify meta information of a device administrator * component. */ public final class DeviceAdminInfo implements Parcelable { static final String TAG = "DeviceAdminInfo"; /** * A type of policy that this device admin can use: limit the passwords * that the user can select, via {@link DevicePolicyManager#setPasswordMode} * and {@link DevicePolicyManager#setMinimumPasswordLength}. * *

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_LIMIT_PASSWORD = 0; /** * A type of policy that this device admin can use: able to watch login * attempts from the user, via {@link DeviceAdmin#ACTION_PASSWORD_FAILED}, * {@link DeviceAdmin#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_WATCH_LOGIN = 1; /** * 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_RESET_PASSWORD = 2; /** * A type of policy that this device admin can use: able to limit the * maximum lock timeout for the device via * {@link DevicePolicyManager#setMaximumTimeToLock}. * *

To control this policy, the device admin must have a "limit-unlock" * tag in the "uses-policies" section of its meta-data. */ public static final int USES_POLICY_LIMIT_UNLOCK = 3; /** * A type of policy that this device admin can use: able to force the device * to lock via{@link DevicePolicyManager#lockNow}. * *

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_FORCE_LOCK = 4; /** * 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_WIPE_DATA = 5; /** @hide */ public static class PolicyInfo { public final int ident; final public String tag; final public int label; final public int description; public PolicyInfo(int identIn, String tagIn, int labelIn, int descriptionIn) { ident = identIn; tag = tagIn; label = labelIn; description = descriptionIn; } } static ArrayList sPoliciesDisplayOrder = new ArrayList(); static HashMap sKnownPolicies = new HashMap(); static SparseArray sRevKnownPolicies = new SparseArray(); static { sPoliciesDisplayOrder.add(new PolicyInfo(USES_POLICY_WIPE_DATA, "wipe-data", com.android.internal.R.string.policylab_wipeData, com.android.internal.R.string.policydesc_wipeData)); sPoliciesDisplayOrder.add(new PolicyInfo(USES_POLICY_RESET_PASSWORD, "reset-password", com.android.internal.R.string.policylab_resetPassword, com.android.internal.R.string.policydesc_resetPassword)); sPoliciesDisplayOrder.add(new PolicyInfo(USES_POLICY_LIMIT_PASSWORD, "limit-password", com.android.internal.R.string.policylab_limitPassword, com.android.internal.R.string.policydesc_limitPassword)); sPoliciesDisplayOrder.add(new PolicyInfo(USES_POLICY_WATCH_LOGIN, "watch-login", com.android.internal.R.string.policylab_watchLogin, com.android.internal.R.string.policydesc_watchLogin)); sPoliciesDisplayOrder.add(new PolicyInfo(USES_POLICY_LIMIT_UNLOCK, "limit-unlock", com.android.internal.R.string.policylab_limitUnlock, com.android.internal.R.string.policydesc_limitUnlock)); sPoliciesDisplayOrder.add(new PolicyInfo(USES_POLICY_FORCE_LOCK, "force-lock", com.android.internal.R.string.policylab_forceLock, com.android.internal.R.string.policydesc_forceLock)); for (int i=0; i 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); } } } } } finally { if (parser != null) parser.close(); } } DeviceAdminInfo(Parcel source) { mReceiver = ResolveInfo.CREATOR.createFromParcel(source); mUsesPolicies = source.readInt(); } /** * Return the .apk package that implements this device admin. */ public String getPackageName() { return mReceiver.activityInfo.packageName; } /** * Return the class name of the receiver component that implements * this device admin. */ public String getReceiverName() { return mReceiver.activityInfo.name; } /** * Return the raw information about the receiver implementing this * device admin. Do not modify the returned object. */ public ActivityInfo getActivityInfo() { return mReceiver.activityInfo; } /** * Return the component of the receiver that implements this device admin. */ public ComponentName getComponent() { return new ComponentName(mReceiver.activityInfo.packageName, mReceiver.activityInfo.name); } /** * Load the user-displayed label for this device admin. * * @param pm Supply a PackageManager used to load the device admin's * resources. */ public CharSequence loadLabel(PackageManager pm) { return mReceiver.loadLabel(pm); } /** * Load user-visible description associated with this device admin. * * @param pm Supply a PackageManager used to load the device admin's * 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); } throw new NotFoundException(); } /** * Load the user-displayed icon for this device admin. * * @param pm Supply a PackageManager used to load the device admin's * resources. */ public Drawable loadIcon(PackageManager pm) { return mReceiver.loadIcon(pm); } /** * 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_LIMIT_UNLOCK}, * {@link #USES_POLICY_FORCE_LOCK}, {@link #USES_POLICY_WIPE_DATA}. */ public boolean usesPolicy(int policyIdent) { return (mUsesPolicies & (1< getUsedPolicies() { ArrayList res = new ArrayList(); for (int i=0; i CREATOR = new Parcelable.Creator() { public DeviceAdminInfo createFromParcel(Parcel source) { return new DeviceAdminInfo(source); } public DeviceAdminInfo[] newArray(int size) { return new DeviceAdminInfo[size]; } }; public int describeContents() { return 0; } }