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

Commit e5a44570 authored by Kholoud Mohamed's avatar Kholoud Mohamed
Browse files

Migrate persistent preferred activity policy to the policy engine

Bug: 258442623
Bug: 232918480
Test: atest om.android.cts.devicepolicy.MixedProfileOwnerTest#testPersistentIntentResolving
Change-Id: If66a2ad55d2b59c30181645cca0faf523c9bd350
parent c1de6541
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -8052,6 +8052,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_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";
    field public static final int POLICY_SET_RESULT_FAILURE = -1; // 0xffffffff
+7 −0
Original line number Diff line number Diff line
@@ -4013,6 +4013,13 @@ public class DevicePolicyManager {
     */
    public static final String USER_CONTROL_DISABLED_PACKAGES = "userControlDisabledPackages";
    // TODO: Expose this as SystemAPI once we add the query API
    /**
     * @hide
     */
    public static final String PERSISTENT_PREFERRED_ACTIVITY = "persistentPreferredActivity";
    /**
     * 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
+8 −0
Original line number Diff line number Diff line
@@ -124,6 +124,14 @@ public abstract class PolicyUpdatesReceiver extends BroadcastReceiver {
    public static final String EXTRA_PERMISSION_NAME =
            "android.app.admin.extra.PERMISSION_NAME";

    /**
     * An {@link android.content.IntentFilter} extra holding the intent filter the policy relates
     * to, (see {@link PolicyUpdatesReceiver#onPolicyChanged} and
     * {@link PolicyUpdatesReceiver#onPolicySetResult})
     */
    public static final String EXTRA_INTENT_FILTER =
            "android.app.admin.extra.INTENT_FILTER";

    /**
     * @hide
     */
+60 −0
Original line number Diff line number Diff line
/*
 * 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 com.android.server.devicepolicy;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.ComponentName;
import android.util.Log;

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

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

final class ComponentNamePolicySerializer extends PolicySerializer<ComponentName> {
    private static final String ATTR_PACKAGE_NAME = ":package-name";
    private static final String ATTR_CLASS_NAME = ":class-name";

    @Override
    void saveToXml(
            TypedXmlSerializer serializer, String attributeNamePrefix, @NonNull ComponentName value)
            throws IOException {
        Objects.requireNonNull(value);
        serializer.attribute(
                /* namespace= */ null,
                attributeNamePrefix + ATTR_PACKAGE_NAME, value.getPackageName());
        serializer.attribute(
                /* namespace= */ null,
                attributeNamePrefix + ATTR_CLASS_NAME, value.getClassName());
    }

    @Nullable
    @Override
    ComponentName readFromXml(TypedXmlPullParser parser, String attributeNamePrefix) {
        String packageName = parser.getAttributeValue(
                /* namespace= */ null, attributeNamePrefix + ATTR_PACKAGE_NAME);
        String className = parser.getAttributeValue(
                /* namespace= */ null, attributeNamePrefix + ATTR_CLASS_NAME);
        if (packageName == null || className == null) {
            Log.e(DevicePolicyEngine.TAG, "Error parsing ComponentName policy.");
            return null;
        }
        return new ComponentName(packageName, className);
    }
}
+42 −0
Original line number Diff line number Diff line
/*
 * 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 com.android.server.devicepolicy;

import com.android.modules.utils.TypedXmlPullParser;

/**
 * Default implementation for {@link PolicyKey} used to identify a policy that doesn't require any
 * additional arguments to be represented in the policy engine's data structure.
 */
final class DefaultPolicyKey extends PolicyKey {
    private static final String ATTR_GENERIC_POLICY_KEY = "generic-policy-key";

    DefaultPolicyKey(String policyKey) {
        super(policyKey);
    }

    String getKey() {
        return mKey;
    }

    static DefaultPolicyKey readGenericPolicyKeyFromXml(TypedXmlPullParser parser) {
        String genericPolicyKey = parser.getAttributeValue(
                /* namespace= */ null, ATTR_GENERIC_POLICY_KEY);
        return new DefaultPolicyKey(genericPolicyKey);
    }

}
Loading