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

Commit 1e8c37a0 authored by Winson's avatar Winson
Browse files

Refactor legacy domain verification code

Moves everything to com.android.server.pm.intent.verify.legacy, in
preparation for replacement with new classes.

No functional changes were made, although the code may be slightly
slower since lambdas are now passed around to do locking.

Eventually the entire legacy package will be deleted. Any attempts at
backwards compatbility will involve a brand new wrapper of the v1 APIs
which delegate into the v2 methods.

Exempt-From-Owner-Approval: Already approved by owners on main branch

Bug: 163565078

Test: atest IntentFilterVerificationTest
Test: manual, verify with `dumpsys package d` that an app auto verifies

Change-Id: Id7d428b939cab6dd887567abcc7ba0e8f3fb7638
parent debc58e0
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.IntFunction;

/**
@@ -599,6 +600,20 @@ public class ArrayUtils {
        return cur;
    }

    /**
     * Similar to {@link Set#addAll(Collection)}}, but with support for set values of {@code null}.
     */
    public static @NonNull <T> ArraySet<T> addAll(@Nullable ArraySet<T> cur,
            @Nullable Collection<T> val) {
        if (cur == null) {
            cur = new ArraySet<>();
        }
        if (val != null) {
            cur.addAll(val);
        }
        return cur;
    }

    public static @Nullable <T> ArraySet<T> remove(@Nullable ArraySet<T> cur, T val) {
        if (cur == null) {
            return null;
+198 −689

File changed.

Preview size limit exceeded, changes collapsed.

+5 −5
Original line number Diff line number Diff line
@@ -644,11 +644,11 @@ public abstract class PackageSettingBase extends SettingBase {
        return excludedUserIds;
    }

    IntentFilterVerificationInfo getIntentFilterVerificationInfo() {
    public IntentFilterVerificationInfo getIntentFilterVerificationInfo() {
        return verificationInfo;
    }

    void setIntentFilterVerificationInfo(IntentFilterVerificationInfo info) {
    public void setIntentFilterVerificationInfo(IntentFilterVerificationInfo info) {
        verificationInfo = info;
        onChanged();
    }
@@ -657,14 +657,14 @@ public abstract class PackageSettingBase extends SettingBase {
    //
    // high 'int'-sized word: link status: undefined/ask/never/always.
    // low 'int'-sized word: relative priority among 'always' results.
    long getDomainVerificationStatusForUser(int userId) {
    public long getDomainVerificationStatusForUser(int userId) {
        PackageUserState state = readUserState(userId);
        long result = (long) state.appLinkGeneration;
        result |= ((long) state.domainVerificationStatus) << 32;
        return result;
    }

    void setDomainVerificationStatusForUser(final int status, int generation, int userId) {
    public void setDomainVerificationStatusForUser(final int status, int generation, int userId) {
        PackageUserState state = modifyUserState(userId);
        state.domainVerificationStatus = status;
        if (status == PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS) {
@@ -673,7 +673,7 @@ public abstract class PackageSettingBase extends SettingBase {
        }
    }

    void clearDomainVerificationStatusForUser(int userId) {
    public void clearDomainVerificationStatusForUser(int userId) {
        modifyUserState(userId).domainVerificationStatus =
                PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED;
    }
+32 −270

File changed.

Preview size limit exceeded, changes collapsed.

+64 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.pm.intent.verify.legacy;

/**
 * This is the key for the map of {@link android.content.pm.IntentFilterVerificationInfo}s
 * maintained by the  {@link com.android.server.pm.PackageManagerService}
 */
class IntentFilterVerificationKey {
    public String domains;
    public String packageName;
    public String className;

    public IntentFilterVerificationKey(String[] domains, String packageName, String className) {
        StringBuilder sb = new StringBuilder();
        for (String host : domains) {
            sb.append(host);
        }
        this.domains = sb.toString();
        this.packageName = packageName;
        this.className = className;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        IntentFilterVerificationKey that = (IntentFilterVerificationKey) o;

        if (domains != null ? !domains.equals(that.domains) : that.domains != null) return false;
        if (className != null ? !className.equals(that.className) : that.className != null) {
            return false;
        }
        if (packageName != null ? !packageName.equals(that.packageName)
                : that.packageName != null) {
            return false;
        }

        return true;
    }

    @Override
    public int hashCode() {
        int result = domains != null ? domains.hashCode() : 0;
        result = 31 * result + (packageName != null ? packageName.hashCode() : 0);
        result = 31 * result + (className != null ? className.hashCode() : 0);
        return result;
    }
}
Loading