/* * Copyright (C) 2022 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 android.annotation.IntDef; import android.annotation.NonNull; import android.os.Parcel; import android.os.Parcelable; import android.util.ArraySet; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.Collections; import java.util.Objects; import java.util.Set; /** * A generic class that defines which APK packages are in scope for some device policy. *
* The packages can be defined using either an allowlist or a blocklist. * In allowlist mode, it could optionally include all system packages * that meet the specific criteria of the device policy in question. */ public final class PackagePolicy implements Parcelable { /** * PackagePolicy type indicator for {@link PackagePolicy} *
* This constant indicates that all packages are allowed except for the packages returned by * {@link PackagePolicy#getPackageNames()}, which acts as a denylist. * @see #PACKAGE_POLICY_ALLOWLIST_AND_SYSTEM * @see #PACKAGE_POLICY_ALLOWLIST */ public static final int PACKAGE_POLICY_BLOCKLIST = 1; /** * PackagePolicy type indicator for {@link PackagePolicy} *
* This constant indicates system packages are allowed in addition to the packages returned by * {@link PackagePolicy#getPackageNames()}, which acts as an allowlist. * *
Functions that accept {@link PackagePolicy} will further clarify * how this policy is interpreted. * * @see #PACKAGE_POLICY_BLOCKLIST * @see #PACKAGE_POLICY_ALLOWLIST */ public static final int PACKAGE_POLICY_ALLOWLIST_AND_SYSTEM = 2; /** * PackagePolicy type indicator for {@link PackagePolicy} *
* This constant indicates that all packages are denied except for the packages returned by
* {@link PackagePolicy#getPackageNames()}, which acts as an allowlist.
*
* @see #PACKAGE_POLICY_BLOCKLIST
* @see #PACKAGE_POLICY_ALLOWLIST_AND_SYSTEM
*/
public static final int PACKAGE_POLICY_ALLOWLIST = 3;
/**
*
* @hide
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = {"PACKAGE_POLICY_"}, value = {
PACKAGE_POLICY_BLOCKLIST,
PACKAGE_POLICY_ALLOWLIST_AND_SYSTEM,
PACKAGE_POLICY_ALLOWLIST
})
public @interface PackagePolicyType {}
private @PackagePolicyType int mPolicyType;
private ArraySet