Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 769e9a2c authored by Kholoud Mohamed's avatar Kholoud Mohamed
Browse files

Expose device policy identifiers for migrated policies

Also added AccountTypePolicyKey required for migrating setAccountManagementDisabled,
and additional failure reasons.

Bug: 232918480
Test: N/A
Change-Id: I12883632cb914be52f30b72ef56b80147bae4f07
parent 15c346f7
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -7750,6 +7750,26 @@ package android.app.admin {
    method public final android.os.IBinder onBind(android.content.Intent);
  }
  public final class DevicePolicyIdentifiers {
    method @NonNull public static String getIdentifierForUserRestriction(@NonNull String);
    field public static final String ACCOUNT_MANAGEMENT_DISABLED_POLICY = "accountManagementDisabled";
    field public static final String APPLICATION_HIDDEN_POLICY = "applicationHidden";
    field public static final String APPLICATION_RESTRICTIONS_POLICY = "applicationRestrictions";
    field public static final String AUTO_TIMEZONE_POLICY = "autoTimezone";
    field public static final String AUTO_TIME_POLICY = "autoTime";
    field public static final String BACKUP_SERVICE_POLICY = "backupService";
    field public static final String CAMERA_DISABLED_POLICY = "cameraDisabled";
    field public static final String KEYGUARD_DISABLED_FEATURES_POLICY = "keyguardDisabledFeatures";
    field public static final String LOCK_TASK_POLICY = "lockTask";
    field public static final String PACKAGES_SUSPENDED_POLICY = "packagesSuspended";
    field public static final String PACKAGE_UNINSTALL_BLOCKED_POLICY = "packageUninstallBlocked";
    field public static final String PERMISSION_GRANT_POLICY = "permissionGrant";
    field public static final String PERSISTENT_PREFERRED_ACTIVITY_POLICY = "persistentPreferredActivity";
    field public static final String RESET_PASSWORD_TOKEN_POLICY = "resetPasswordToken";
    field public static final String STATUS_BAR_DISABLED_POLICY = "statusBarDisabled";
    field public static final String USER_CONTROL_DISABLED_PACKAGES_POLICY = "userControlDisabledPackages";
  }
  public class DevicePolicyManager {
    method public void acknowledgeDeviceCompliant();
    method public void addCrossProfileIntentFilter(@NonNull android.content.ComponentName, android.content.IntentFilter, int);
@@ -8303,6 +8323,8 @@ package android.app.admin {
    ctor public PolicyUpdateResult(int);
    method public int getResultCode();
    field public static final int RESULT_FAILURE_CONFLICTING_ADMIN_POLICY = 1; // 0x1
    field public static final int RESULT_FAILURE_HARDWARE_LIMITATION = 4; // 0x4
    field public static final int RESULT_FAILURE_STORAGE_LIMIT_REACHED = 3; // 0x3
    field public static final int RESULT_FAILURE_UNKNOWN = -1; // 0xffffffff
    field public static final int RESULT_POLICY_CLEARED = 2; // 0x2
    field public static final int RESULT_SUCCESS = 0; // 0x0
@@ -8315,6 +8337,7 @@ package android.app.admin {
    method public final void onReceive(android.content.Context, android.content.Intent);
    field public static final String ACTION_DEVICE_POLICY_CHANGED = "android.app.admin.action.DEVICE_POLICY_CHANGED";
    field public static final String ACTION_DEVICE_POLICY_SET_RESULT = "android.app.admin.action.DEVICE_POLICY_SET_RESULT";
    field public static final String EXTRA_ACCOUNT_TYPE = "android.app.admin.extra.ACCOUNT_TYPE";
    field public static final String EXTRA_INTENT_FILTER = "android.app.admin.extra.INTENT_FILTER";
    field public static final String EXTRA_PACKAGE_NAME = "android.app.admin.extra.PACKAGE_NAME";
    field public static final String EXTRA_PERMISSION_NAME = "android.app.admin.extra.PERMISSION_NAME";
+7 −0
Original line number Diff line number Diff line
@@ -1205,6 +1205,13 @@ package android.app {
package android.app.admin {
  public final class AccountTypePolicyKey extends android.app.admin.PolicyKey {
    method public int describeContents();
    method @NonNull public String getAccountType();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.app.admin.AccountTypePolicyKey> CREATOR;
  }
  public abstract class Authority implements android.os.Parcelable {
    method public int describeContents();
  }
+154 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.PolicyUpdatesReceiver.EXTRA_ACCOUNT_TYPE;
import static android.app.admin.PolicyUpdatesReceiver.EXTRA_POLICY_BUNDLE_KEY;
import static android.app.admin.PolicyUpdatesReceiver.EXTRA_POLICY_KEY;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.os.Bundle;
import android.os.Parcel;

import com.android.modules.utils.TypedXmlPullParser;
import com.android.modules.utils.TypedXmlSerializer;

import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.util.Objects;

/**
 * Class used to identify a policy that relates to a certain account type
 * (e.g. {@link DevicePolicyManager#setAccountManagementDisabled}).
 *
 * @hide
 */
@SystemApi
public final class AccountTypePolicyKey extends PolicyKey {
    private static final String ATTR_ACCOUNT_TYPE = "account-type";

    private final String mAccountType;

    /**
     * @hide
     */
    public AccountTypePolicyKey(@NonNull String key, @NonNull String accountType) {
        super(key);
        mAccountType = Objects.requireNonNull((accountType));
    }

    private AccountTypePolicyKey(Parcel source) {
        super(source.readString());
        mAccountType = source.readString();
    }

    /**
     * @hide
     */
    public AccountTypePolicyKey(String key) {
        super(key);
        mAccountType = null;
    }

    /**
     * Returns the account type this policy relates to.
     */
    @NonNull
    public String getAccountType() {
        return mAccountType;
    }

    /**
     * @hide
     */
    @Override
    public void saveToXml(TypedXmlSerializer serializer) throws IOException {
        serializer.attribute(/* namespace= */ null, ATTR_POLICY_IDENTIFIER, getIdentifier());
        serializer.attribute(/* namespace= */ null, ATTR_ACCOUNT_TYPE, mAccountType);
    }

    /**
     * @hide
     */
    @Override
    public AccountTypePolicyKey readFromXml(TypedXmlPullParser parser)
            throws XmlPullParserException, IOException {
        String policyKey = parser.getAttributeValue(/* namespace= */ null,
                ATTR_POLICY_IDENTIFIER);
        String accountType = parser.getAttributeValue(/* namespace= */ null, ATTR_ACCOUNT_TYPE);
        return new AccountTypePolicyKey(policyKey, accountType);
    }

    /**
     * @hide
     */
    @Override
    public void writeToBundle(Bundle bundle) {
        bundle.putString(EXTRA_POLICY_KEY, getIdentifier());
        Bundle extraPolicyParams = new Bundle();
        extraPolicyParams.putString(EXTRA_ACCOUNT_TYPE, mAccountType);
        bundle.putBundle(EXTRA_POLICY_BUNDLE_KEY, extraPolicyParams);
    }

    @Override
    public boolean equals(@Nullable Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        AccountTypePolicyKey other = (AccountTypePolicyKey) o;
        return Objects.equals(getIdentifier(), other.getIdentifier())
                && Objects.equals(mAccountType, other.mAccountType);
    }

    @Override
    public int hashCode() {
        return Objects.hash(getIdentifier(), mAccountType);
    }

    @Override
    public String toString() {
        return "AccountTypePolicyKey{mPolicyKey= " + getIdentifier()
                + "; mAccountType= " + mAccountType + "}";
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        dest.writeString(getIdentifier());
        dest.writeString(mAccountType);
    }

    @NonNull
    public static final Creator<AccountTypePolicyKey> CREATOR =
            new Creator<AccountTypePolicyKey>() {
                @Override
                public AccountTypePolicyKey createFromParcel(Parcel source) {
                    return new AccountTypePolicyKey(source);
                }

                @Override
                public AccountTypePolicyKey[] newArray(int size) {
                    return new AccountTypePolicyKey[size];
                }
            };
}
+174 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.NonNull;
import android.os.UserManager;

import java.util.Objects;

/**
 * Class containing identifiers for policy APIs in {@link DevicePolicyManager}, for example they
 * will be passed in {@link PolicyUpdatesReceiver#onPolicySetResult} and
 * {@link PolicyUpdatesReceiver#onPolicyChanged} to communicate updates of a certain policy back
 * to the admin.
 */
public final class DevicePolicyIdentifiers {

    private DevicePolicyIdentifiers() {}

    /**
     * String identifier for {@link DevicePolicyManager#setAutoTimeZoneEnabled}.
     */
    public static final String AUTO_TIMEZONE_POLICY = "autoTimezone";

    /**
     * String identifier for {@link DevicePolicyManager#setPermissionGrantState}.
     */
    public static final String PERMISSION_GRANT_POLICY = "permissionGrant";

    /**
     * String identifier for {@link DevicePolicyManager#setLockTaskPackages}.
     */
    public static final String LOCK_TASK_POLICY = "lockTask";

    /**
     * String identifier for {@link DevicePolicyManager#setUserControlDisabledPackages}.
     */
    public static final String USER_CONTROL_DISABLED_PACKAGES_POLICY =
            "userControlDisabledPackages";

    /**
     * String identifier for {@link DevicePolicyManager#addPersistentPreferredActivity}.
     */
    public static final String PERSISTENT_PREFERRED_ACTIVITY_POLICY =
            "persistentPreferredActivity";

    /**
     * String identifier for {@link DevicePolicyManager#setUninstallBlocked}.
     */
    public static final String PACKAGE_UNINSTALL_BLOCKED_POLICY = "packageUninstallBlocked";

    /**
     * String identifier for {@link DevicePolicyManager#setApplicationRestrictions}.
     */
    public static final String APPLICATION_RESTRICTIONS_POLICY = "applicationRestrictions";

    /**
     * String identifier for {@link DevicePolicyManager#setResetPasswordToken}.
     */
    public static final String RESET_PASSWORD_TOKEN_POLICY = "resetPasswordToken";

    /**
     * String identifier for {@link DevicePolicyManager#setAccountManagementDisabled}.
     */
    public static final String ACCOUNT_MANAGEMENT_DISABLED_POLICY = "accountManagementDisabled";

    /**
     * String identifier for {@link DevicePolicyManager#setApplicationHidden}.
     */
    public static final String APPLICATION_HIDDEN_POLICY = "applicationHidden";

    /**
     * String identifier for {@link DevicePolicyManager#setCameraDisabled}.
     */
    public static final String CAMERA_DISABLED_POLICY = "cameraDisabled";

    /**
     * String identifier for {@link DevicePolicyManager#setStatusBarDisabled}.
     */
    public static final String STATUS_BAR_DISABLED_POLICY = "statusBarDisabled";

    /**
     * String identifier for {@link DevicePolicyManager#setPackagesSuspended}.
     */
    public static final String PACKAGES_SUSPENDED_POLICY = "packagesSuspended";

    /**
     * String identifier for {@link DevicePolicyManager#setKeyguardDisabledFeatures}.
     */
    public static final String KEYGUARD_DISABLED_FEATURES_POLICY = "keyguardDisabledFeatures";

    /**
     * String identifier for {@link DevicePolicyManager#setAutoTimeEnabled}.
     */
    public static final String AUTO_TIME_POLICY = "autoTime";

    /**
     * String identifier for {@link DevicePolicyManager#setBackupServiceEnabled}.
     */
    public static final String BACKUP_SERVICE_POLICY = "backupService";

    /**
     * String identifier for {@link DevicePolicyManager#setPermittedInputMethods}.
     *
     * @hide
     */
    public static final String PERMITTED_INPUT_METHODS_POLICY = "permittedInputMethods";

    /**
     * String identifier for {@link DevicePolicyManager#setPersonalAppsSuspended}.
     *
     * @hide
     */
    public static final String PERSONAL_APPS_SUSPENDED_POLICY = "personalAppsSuspended";

    /**
     * String identifier for {@link DevicePolicyManager#setScreenCaptureDisabled}.
     *
     * @hide
     */
    public static final String SCREEN_CAPTURE_DISABLED_POLICY = "screenCaptureDisabled";

    /**
     * String identifier for {@link DevicePolicyManager#setTrustAgentConfiguration}.
     *
     * @hide
     */
    public static final String TRUST_AGENT_CONFIGURATION_POLICY = "trustAgentConfiguration";

    /**
     * String identifier for {@link DevicePolicyManager#addCrossProfileIntentFilter}.
     *
     * @hide
     */
    public static final String CROSS_PROFILE_INTENT_FILTER_POLICY = "crossProfileIntentFilter";

    /**
     * String identifier for {@link DevicePolicyManager#addCrossProfileWidgetProvider}.
     *
     * @hide
     */
    public static final String CROSS_PROFILE_WIDGET_PROVIDER_POLICY = "crossProfileWidgetProvider";

    /**
     * @hide
     */
    public static final String USER_RESTRICTION_PREFIX = "userRestriction_";

    /**
     * Returns a string identifier for the provided user restrictions, see
     * {@link DevicePolicyManager#addUserRestriction} and {@link UserManager} for the list of
     * available restrictions.
     */
    @NonNull
    public static String getIdentifierForUserRestriction(
            @UserManager.UserRestrictionKey @NonNull String restriction) {
        Objects.requireNonNull(restriction);
        return USER_RESTRICTION_PREFIX + restriction;
    }
}
+0 −52
Original line number Diff line number Diff line
@@ -4029,58 +4029,6 @@ public class DevicePolicyManager {
        return MTE_NOT_CONTROLLED_BY_POLICY;
    }
    // TODO: Expose this as a public API
    /**
     * @hide
     */
    public static final String AUTO_TIMEZONE_POLICY = "autoTimezone";
    // TODO: Expose this as a public API
    /**
     * @hide
     */
    public static final String PERMISSION_GRANT_POLICY = "permissionGrant";
    // TODO: Expose this as a public API
    /**
     * @hide
     */
    public static final String LOCK_TASK_POLICY = "lockTask";
    // TODO: Expose this as a public API
    /**
     * @hide
     */
    public static final String USER_CONTROL_DISABLED_PACKAGES_POLICY =
            "userControlDisabledPackages";
    // TODO: Expose this as a public API
    /**
     * @hide
     */
    public static final String PERSISTENT_PREFERRED_ACTIVITY_POLICY =
            "persistentPreferredActivity";
    // TODO: Expose this as a public API
    /**
     * @hide
     */
    public static final String PACKAGE_UNINSTALL_BLOCKED_POLICY = "packageUninstallBlocked";
    // TODO: Expose this as a public API
    /**
     * @hide
     */
    public static final String APPLICATION_RESTRICTIONS_POLICY = "applicationRestrictions";
    // TODO: Expose this as a public API
    /**
     * @hide
     */
    public static final String RESET_PASSWORD_TOKEN_POLICY = "resetPasswordToken";
    /**
     * This object is a single place to tack on invalidation and disable calls.  All
     * binder caches in this class derive from this Config, so all can be invalidated or
Loading