/* * 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.admin; import static android.app.admin.flags.Flags.FLAG_HEADLESS_DEVICE_OWNER_SINGLE_USER_ENABLED; import android.annotation.FlaggedApi; import android.annotation.IntDef; import android.annotation.NonNull; import android.app.admin.flags.Flags; import android.compat.annotation.UnsupportedAppUsage; import android.content.ComponentName; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; 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.graphics.drawable.Drawable; import android.os.Build; 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 com.android.modules.utils.TypedXmlPullParser; import com.android.modules.utils.TypedXmlSerializer; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; 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#setPasswordQuality} * and {@link DevicePolicyManager#setPasswordMinimumLength}. * *
To control this policy, the device admin must be a device owner or profile owner, * and must have a "limit-password" tag in the "uses-policies" section of its meta-data. * If used by a device owner, the policy only affects the primary user and its profiles, * but not any secondary users on the device. */ 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 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_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 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_FORCE_LOCK = 3; /** * 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 = 4; /** * 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. * @hide */ public static final int USES_POLICY_SETS_GLOBAL_PROXY = 5; /** * 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 be a device owner or profile owner, * and must have an "expire-password" tag in the "uses-policies" section of its meta-data. * If used by a device owner, the policy only affects the primary user and its profiles, * but not any secondary users on the device. */ public static final int USES_POLICY_EXPIRE_PASSWORD = 6; /** * 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_ENCRYPTED_STORAGE = 7; /** * A type of policy that this device admin can use: disables use of all device cameras. * *
To control this policy, the device admin must be a device owner or profile owner, * and must have a "disable-camera" tag in the "uses-policies" section of its meta-data. * If used by a device owner, the policy affects all users on the device. */ public static final int USES_POLICY_DISABLE_CAMERA = 8; /** * A type of policy that this device admin can use: disables use of keyguard features. * *
To control this policy, the device admin must be a device owner or profile owner, * and must have a "disable-keyguard-features" tag in the "uses-policies" section of its * meta-data. If used by a device owner, the policy only affects the primary user and * its profiles, but not any secondary users on the device. */ public static final int USES_POLICY_DISABLE_KEYGUARD_FEATURES = 9; /** * Value for {@link #getHeadlessDeviceOwnerMode} which indicates that this DPC should not * be provisioned into Device Owner mode on a Headless System User Mode device. */ public static final int HEADLESS_DEVICE_OWNER_MODE_UNSUPPORTED = 0; /** * Value for {@link #getHeadlessDeviceOwnerMode} which indicates that this DPC should be * provisioned into "affiliated" mode when on a Headless System User Mode device. * *
This mode adds a Profile Owner to all users other than the user the Device Owner is on. * *
Starting from Android version {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM}, * DPCs should set the value of attribute "headless-device-owner-mode" inside the * "headless-system-user" tag as "affiliated". */ public static final int HEADLESS_DEVICE_OWNER_MODE_AFFILIATED = 1; /** * Value for {@link #getHeadlessDeviceOwnerMode} which indicates that this DPC should be * provisioned into the first secondary user when on a Headless System User Mode device. * *
This mode only allows a single secondary user on the device blocking the creation of * additional secondary users. * *
Starting from Android version {@link android.os.Build.VERSION_CODES#VANILLA_ICE_CREAM},
* DPCs should set the value of attribute "headless-device-owner-mode" inside the
* "headless-system-user" tag as "single_user".
*/
@FlaggedApi(FLAG_HEADLESS_DEVICE_OWNER_SINGLE_USER_ENABLED)
public static final int HEADLESS_DEVICE_OWNER_MODE_SINGLE_USER = 2;
/**
* @hide
*/
@IntDef({HEADLESS_DEVICE_OWNER_MODE_UNSUPPORTED, HEADLESS_DEVICE_OWNER_MODE_AFFILIATED,
HEADLESS_DEVICE_OWNER_MODE_SINGLE_USER})
@Retention(RetentionPolicy.SOURCE)
public @interface HeadlessDeviceOwnerMode {}
/** @hide */
public static class PolicyInfo {
public final int ident;
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
public final String tag;
public final int label;
public final int description;
public final int labelForSecondaryUsers;
public final int descriptionForSecondaryUsers;
public PolicyInfo(int ident, String tag, int label, int description) {
this(ident, tag, label, description, label, description);
}
public PolicyInfo(int ident, String tag, int label, int description,
int labelForSecondaryUsers, int descriptionForSecondaryUsers) {
this.ident = ident;
this.tag = tag;
this.label = label;
this.description = description;
this.labelForSecondaryUsers = labelForSecondaryUsers;
this.descriptionForSecondaryUsers = descriptionForSecondaryUsers;
}
}
static ArrayList