Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 17 | package android.app.admin; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 18 | |
| 19 | import org.xmlpull.v1.XmlPullParser; |
| 20 | import org.xmlpull.v1.XmlPullParserException; |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 21 | import org.xmlpull.v1.XmlSerializer; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 22 | |
| 23 | import android.content.ComponentName; |
| 24 | import android.content.Context; |
| 25 | import android.content.pm.ActivityInfo; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 26 | import android.content.pm.ApplicationInfo; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 27 | import android.content.pm.PackageManager; |
| 28 | import android.content.pm.ResolveInfo; |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 29 | import android.content.pm.PackageManager.NameNotFoundException; |
| 30 | import android.content.res.Resources; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 31 | import android.content.res.TypedArray; |
| 32 | import android.content.res.XmlResourceParser; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 33 | import android.content.res.Resources.NotFoundException; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 34 | import android.graphics.drawable.Drawable; |
| 35 | import android.os.Parcel; |
| 36 | import android.os.Parcelable; |
| 37 | import android.util.AttributeSet; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 38 | import android.util.Log; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 39 | import android.util.Printer; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 40 | import android.util.SparseArray; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 41 | import android.util.Xml; |
| 42 | |
| 43 | import java.io.IOException; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 44 | import java.util.ArrayList; |
| 45 | import java.util.HashMap; |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * This class is used to specify meta information of a device administrator |
| 49 | * component. |
| 50 | */ |
| 51 | public final class DeviceAdminInfo implements Parcelable { |
| 52 | static final String TAG = "DeviceAdminInfo"; |
| 53 | |
| 54 | /** |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 55 | * A type of policy that this device admin can use: limit the passwords |
Dianne Hackborn | 9327f4f | 2010-01-29 10:38:29 -0800 | [diff] [blame] | 56 | * that the user can select, via {@link DevicePolicyManager#setPasswordQuality} |
Dianne Hackborn | 254cb44 | 2010-01-27 19:23:59 -0800 | [diff] [blame] | 57 | * and {@link DevicePolicyManager#setPasswordMinimumLength}. |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 58 | * |
| 59 | * <p>To control this policy, the device admin must have a "limit-password" |
| 60 | * tag in the "uses-policies" section of its meta-data. |
| 61 | */ |
| 62 | public static final int USES_POLICY_LIMIT_PASSWORD = 0; |
| 63 | |
| 64 | /** |
| 65 | * A type of policy that this device admin can use: able to watch login |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 66 | * attempts from the user, via {@link DeviceAdminReceiver#ACTION_PASSWORD_FAILED}, |
| 67 | * {@link DeviceAdminReceiver#ACTION_PASSWORD_SUCCEEDED}, and |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 68 | * {@link DevicePolicyManager#getCurrentFailedPasswordAttempts}. |
| 69 | * |
| 70 | * <p>To control this policy, the device admin must have a "watch-login" |
| 71 | * tag in the "uses-policies" section of its meta-data. |
| 72 | */ |
| 73 | public static final int USES_POLICY_WATCH_LOGIN = 1; |
| 74 | |
| 75 | /** |
| 76 | * A type of policy that this device admin can use: able to reset the |
| 77 | * user's password via |
| 78 | * {@link DevicePolicyManager#resetPassword}. |
| 79 | * |
| 80 | * <p>To control this policy, the device admin must have a "reset-password" |
| 81 | * tag in the "uses-policies" section of its meta-data. |
| 82 | */ |
| 83 | public static final int USES_POLICY_RESET_PASSWORD = 2; |
| 84 | |
| 85 | /** |
Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 86 | * A type of policy that this device admin can use: able to force the device |
| 87 | * to lock via{@link DevicePolicyManager#lockNow} or limit the |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 88 | * maximum lock timeout for the device via |
| 89 | * {@link DevicePolicyManager#setMaximumTimeToLock}. |
| 90 | * |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 91 | * <p>To control this policy, the device admin must have a "force-lock" |
| 92 | * tag in the "uses-policies" section of its meta-data. |
| 93 | */ |
Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 94 | public static final int USES_POLICY_FORCE_LOCK = 3; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * A type of policy that this device admin can use: able to factory |
| 98 | * reset the device, erasing all of the user's data, via |
| 99 | * {@link DevicePolicyManager#wipeData}. |
| 100 | * |
| 101 | * <p>To control this policy, the device admin must have a "wipe-data" |
| 102 | * tag in the "uses-policies" section of its meta-data. |
| 103 | */ |
Dianne Hackborn | 315ada7 | 2010-02-11 12:14:08 -0800 | [diff] [blame] | 104 | public static final int USES_POLICY_WIPE_DATA = 4; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 105 | |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 106 | /** |
| 107 | * A type of policy that this device admin can use: able to specify the |
| 108 | * device Global Proxy, via {@link DevicePolicyManager#setGlobalProxy}. |
| 109 | * |
| 110 | * <p>To control this policy, the device admin must have a "set-global-proxy" |
| 111 | * tag in the "uses-policies" section of its meta-data. |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 112 | */ |
| 113 | public static final int USES_POLICY_SETS_GLOBAL_PROXY = 5; |
| 114 | |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 115 | /** @hide */ |
| 116 | public static class PolicyInfo { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 117 | public final int ident; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 118 | final public String tag; |
| 119 | final public int label; |
| 120 | final public int description; |
| 121 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 122 | public PolicyInfo(int identIn, String tagIn, int labelIn, int descriptionIn) { |
| 123 | ident = identIn; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 124 | tag = tagIn; |
| 125 | label = labelIn; |
| 126 | description = descriptionIn; |
| 127 | } |
| 128 | } |
| 129 | |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 130 | static ArrayList<PolicyInfo> sPoliciesDisplayOrder = new ArrayList<PolicyInfo>(); |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 131 | static HashMap<String, Integer> sKnownPolicies = new HashMap<String, Integer>(); |
| 132 | static SparseArray<PolicyInfo> sRevKnownPolicies = new SparseArray<PolicyInfo>(); |
| 133 | |
| 134 | static { |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 135 | sPoliciesDisplayOrder.add(new PolicyInfo(USES_POLICY_WIPE_DATA, "wipe-data", |
| 136 | com.android.internal.R.string.policylab_wipeData, |
| 137 | com.android.internal.R.string.policydesc_wipeData)); |
| 138 | sPoliciesDisplayOrder.add(new PolicyInfo(USES_POLICY_RESET_PASSWORD, "reset-password", |
| 139 | com.android.internal.R.string.policylab_resetPassword, |
| 140 | com.android.internal.R.string.policydesc_resetPassword)); |
| 141 | sPoliciesDisplayOrder.add(new PolicyInfo(USES_POLICY_LIMIT_PASSWORD, "limit-password", |
| 142 | com.android.internal.R.string.policylab_limitPassword, |
| 143 | com.android.internal.R.string.policydesc_limitPassword)); |
| 144 | sPoliciesDisplayOrder.add(new PolicyInfo(USES_POLICY_WATCH_LOGIN, "watch-login", |
| 145 | com.android.internal.R.string.policylab_watchLogin, |
| 146 | com.android.internal.R.string.policydesc_watchLogin)); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 147 | sPoliciesDisplayOrder.add(new PolicyInfo(USES_POLICY_FORCE_LOCK, "force-lock", |
| 148 | com.android.internal.R.string.policylab_forceLock, |
| 149 | com.android.internal.R.string.policydesc_forceLock)); |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 150 | sPoliciesDisplayOrder.add(new PolicyInfo(USES_POLICY_SETS_GLOBAL_PROXY, "set-global-proxy", |
| 151 | com.android.internal.R.string.policylab_setGlobalProxy, |
| 152 | com.android.internal.R.string.policydesc_setGlobalProxy)); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 153 | |
| 154 | for (int i=0; i<sPoliciesDisplayOrder.size(); i++) { |
| 155 | PolicyInfo pi = sPoliciesDisplayOrder.get(i); |
| 156 | sRevKnownPolicies.put(pi.ident, pi); |
| 157 | sKnownPolicies.put(pi.tag, pi.ident); |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | |
| 161 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 162 | * The BroadcastReceiver that implements this device admin component. |
| 163 | */ |
| 164 | final ResolveInfo mReceiver; |
| 165 | |
| 166 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 167 | * Whether this should be visible to the user. |
| 168 | */ |
| 169 | boolean mVisible; |
| 170 | |
| 171 | /** |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 172 | * The policies this administrator needs access to. |
| 173 | */ |
| 174 | int mUsesPolicies; |
| 175 | |
| 176 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 177 | * Constructor. |
| 178 | * |
| 179 | * @param context The Context in which we are parsing the device admin. |
| 180 | * @param receiver The ResolveInfo returned from the package manager about |
| 181 | * this device admin's component. |
| 182 | */ |
| 183 | public DeviceAdminInfo(Context context, ResolveInfo receiver) |
| 184 | throws XmlPullParserException, IOException { |
| 185 | mReceiver = receiver; |
| 186 | ActivityInfo ai = receiver.activityInfo; |
| 187 | |
| 188 | PackageManager pm = context.getPackageManager(); |
| 189 | |
| 190 | XmlResourceParser parser = null; |
| 191 | try { |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 192 | parser = ai.loadXmlMetaData(pm, DeviceAdminReceiver.DEVICE_ADMIN_META_DATA); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 193 | if (parser == null) { |
| 194 | throw new XmlPullParserException("No " |
Dianne Hackborn | ef6b22f | 2010-02-16 20:38:49 -0800 | [diff] [blame] | 195 | + DeviceAdminReceiver.DEVICE_ADMIN_META_DATA + " meta-data"); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 196 | } |
| 197 | |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 198 | Resources res = pm.getResourcesForApplication(ai.applicationInfo); |
| 199 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 200 | AttributeSet attrs = Xml.asAttributeSet(parser); |
| 201 | |
| 202 | int type; |
| 203 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 204 | && type != XmlPullParser.START_TAG) { |
| 205 | } |
| 206 | |
| 207 | String nodeName = parser.getName(); |
| 208 | if (!"device-admin".equals(nodeName)) { |
| 209 | throw new XmlPullParserException( |
| 210 | "Meta-data does not start with device-admin tag"); |
| 211 | } |
| 212 | |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 213 | TypedArray sa = res.obtainAttributes(attrs, |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 214 | com.android.internal.R.styleable.DeviceAdmin); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 215 | |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 216 | mVisible = sa.getBoolean( |
| 217 | com.android.internal.R.styleable.DeviceAdmin_visible, true); |
| 218 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 219 | sa.recycle(); |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 220 | |
| 221 | int outerDepth = parser.getDepth(); |
| 222 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 223 | && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) { |
| 224 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 225 | continue; |
| 226 | } |
| 227 | String tagName = parser.getName(); |
| 228 | if (tagName.equals("uses-policies")) { |
| 229 | int innerDepth = parser.getDepth(); |
| 230 | while ((type=parser.next()) != XmlPullParser.END_DOCUMENT |
| 231 | && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) { |
| 232 | if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) { |
| 233 | continue; |
| 234 | } |
| 235 | String policyName = parser.getName(); |
| 236 | Integer val = sKnownPolicies.get(policyName); |
| 237 | if (val != null) { |
| 238 | mUsesPolicies |= 1 << val.intValue(); |
| 239 | } else { |
| 240 | Log.w(TAG, "Unknown tag under uses-policies of " |
| 241 | + getComponent() + ": " + policyName); |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | } |
Dianne Hackborn | 20cb56e | 2010-03-04 00:58:29 -0800 | [diff] [blame] | 246 | } catch (NameNotFoundException e) { |
| 247 | throw new XmlPullParserException( |
| 248 | "Unable to create context for: " + ai.packageName); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 249 | } finally { |
| 250 | if (parser != null) parser.close(); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | DeviceAdminInfo(Parcel source) { |
| 255 | mReceiver = ResolveInfo.CREATOR.createFromParcel(source); |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 256 | mUsesPolicies = source.readInt(); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Return the .apk package that implements this device admin. |
| 261 | */ |
| 262 | public String getPackageName() { |
| 263 | return mReceiver.activityInfo.packageName; |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * Return the class name of the receiver component that implements |
| 268 | * this device admin. |
| 269 | */ |
| 270 | public String getReceiverName() { |
| 271 | return mReceiver.activityInfo.name; |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * Return the raw information about the receiver implementing this |
| 276 | * device admin. Do not modify the returned object. |
| 277 | */ |
| 278 | public ActivityInfo getActivityInfo() { |
| 279 | return mReceiver.activityInfo; |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Return the component of the receiver that implements this device admin. |
| 284 | */ |
| 285 | public ComponentName getComponent() { |
| 286 | return new ComponentName(mReceiver.activityInfo.packageName, |
| 287 | mReceiver.activityInfo.name); |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Load the user-displayed label for this device admin. |
| 292 | * |
| 293 | * @param pm Supply a PackageManager used to load the device admin's |
| 294 | * resources. |
| 295 | */ |
| 296 | public CharSequence loadLabel(PackageManager pm) { |
| 297 | return mReceiver.loadLabel(pm); |
| 298 | } |
| 299 | |
| 300 | /** |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 301 | * Load user-visible description associated with this device admin. |
| 302 | * |
| 303 | * @param pm Supply a PackageManager used to load the device admin's |
| 304 | * resources. |
| 305 | */ |
| 306 | public CharSequence loadDescription(PackageManager pm) throws NotFoundException { |
| 307 | if (mReceiver.activityInfo.descriptionRes != 0) { |
| 308 | String packageName = mReceiver.resolvePackageName; |
| 309 | ApplicationInfo applicationInfo = null; |
| 310 | if (packageName == null) { |
| 311 | packageName = mReceiver.activityInfo.packageName; |
| 312 | applicationInfo = mReceiver.activityInfo.applicationInfo; |
| 313 | } |
| 314 | return pm.getText(packageName, |
| 315 | mReceiver.activityInfo.descriptionRes, applicationInfo); |
| 316 | } |
| 317 | throw new NotFoundException(); |
| 318 | } |
| 319 | |
| 320 | /** |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 321 | * Load the user-displayed icon for this device admin. |
| 322 | * |
| 323 | * @param pm Supply a PackageManager used to load the device admin's |
| 324 | * resources. |
| 325 | */ |
| 326 | public Drawable loadIcon(PackageManager pm) { |
| 327 | return mReceiver.loadIcon(pm); |
| 328 | } |
| 329 | |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 330 | /** |
Dianne Hackborn | 87bba1e | 2010-02-26 17:25:54 -0800 | [diff] [blame] | 331 | * Returns whether this device admin would like to be visible to the |
| 332 | * user, even when it is not enabled. |
| 333 | */ |
| 334 | public boolean isVisible() { |
| 335 | return mVisible; |
| 336 | } |
| 337 | |
| 338 | /** |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 339 | * Return true if the device admin has requested that it be able to use |
| 340 | * the given policy control. The possible policy identifier inputs are: |
| 341 | * {@link #USES_POLICY_LIMIT_PASSWORD}, {@link #USES_POLICY_WATCH_LOGIN}, |
Raphael | dc2df32 | 2010-02-11 17:01:16 -0800 | [diff] [blame] | 342 | * {@link #USES_POLICY_RESET_PASSWORD}, {@link #USES_POLICY_FORCE_LOCK}, |
Oscar Montemayor | 69238c6 | 2010-08-03 10:51:06 -0700 | [diff] [blame] | 343 | * {@link #USES_POLICY_WIPE_DATA}, {@link #USES_POLICY_SETS_GLOBAL_PROXY}. |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 344 | */ |
| 345 | public boolean usesPolicy(int policyIdent) { |
| 346 | return (mUsesPolicies & (1<<policyIdent)) != 0; |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * Return the XML tag name for the given policy identifier. Valid identifiers |
| 351 | * are as per {@link #usesPolicy(int)}. If the given identifier is not |
| 352 | * known, null is returned. |
| 353 | */ |
| 354 | public String getTagForPolicy(int policyIdent) { |
| 355 | return sRevKnownPolicies.get(policyIdent).tag; |
| 356 | } |
| 357 | |
| 358 | /** @hide */ |
| 359 | public ArrayList<PolicyInfo> getUsedPolicies() { |
| 360 | ArrayList<PolicyInfo> res = new ArrayList<PolicyInfo>(); |
Dianne Hackborn | 8ea138c | 2010-01-26 18:01:04 -0800 | [diff] [blame] | 361 | for (int i=0; i<sPoliciesDisplayOrder.size(); i++) { |
| 362 | PolicyInfo pi = sPoliciesDisplayOrder.get(i); |
| 363 | if (usesPolicy(pi.ident)) { |
| 364 | res.add(pi); |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | return res; |
| 368 | } |
| 369 | |
Dianne Hackborn | 21f1bd1 | 2010-02-19 17:02:21 -0800 | [diff] [blame] | 370 | /** @hide */ |
| 371 | public void writePoliciesToXml(XmlSerializer out) |
| 372 | throws IllegalArgumentException, IllegalStateException, IOException { |
| 373 | out.attribute(null, "flags", Integer.toString(mUsesPolicies)); |
| 374 | } |
| 375 | |
| 376 | /** @hide */ |
| 377 | public void readPoliciesFromXml(XmlPullParser parser) |
| 378 | throws XmlPullParserException, IOException { |
| 379 | mUsesPolicies = Integer.parseInt( |
| 380 | parser.getAttributeValue(null, "flags")); |
| 381 | } |
| 382 | |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 383 | public void dump(Printer pw, String prefix) { |
| 384 | pw.println(prefix + "Receiver:"); |
| 385 | mReceiver.dump(pw, prefix + " "); |
| 386 | } |
| 387 | |
| 388 | @Override |
| 389 | public String toString() { |
| 390 | return "DeviceAdminInfo{" + mReceiver.activityInfo.name + "}"; |
| 391 | } |
| 392 | |
| 393 | /** |
| 394 | * Used to package this object into a {@link Parcel}. |
| 395 | * |
| 396 | * @param dest The {@link Parcel} to be written. |
| 397 | * @param flags The flags used for parceling. |
| 398 | */ |
| 399 | public void writeToParcel(Parcel dest, int flags) { |
| 400 | mReceiver.writeToParcel(dest, flags); |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 401 | dest.writeInt(mUsesPolicies); |
Dianne Hackborn | d684784 | 2010-01-12 18:14:19 -0800 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | /** |
| 405 | * Used to make this class parcelable. |
| 406 | */ |
| 407 | public static final Parcelable.Creator<DeviceAdminInfo> CREATOR = |
| 408 | new Parcelable.Creator<DeviceAdminInfo>() { |
| 409 | public DeviceAdminInfo createFromParcel(Parcel source) { |
| 410 | return new DeviceAdminInfo(source); |
| 411 | } |
| 412 | |
| 413 | public DeviceAdminInfo[] newArray(int size) { |
| 414 | return new DeviceAdminInfo[size]; |
| 415 | } |
| 416 | }; |
| 417 | |
| 418 | public int describeContents() { |
| 419 | return 0; |
| 420 | } |
| 421 | } |