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

Commit 018a0099 authored by Winson's avatar Winson
Browse files

Add DomainVerificationService skeleton

Just the basic SystemService so that future CLs can add methods. Starts
the service in SystemServer, but effectively does nothing.

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

Bug: 163565712

Test: none, just a skeleton

Change-Id: I1388423894e1e96511ab0f7de8ac5a7c2eea6de0
parent 477f87d5
Loading
Loading
Loading
Loading
+25 −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.domain.verify;

import android.content.pm.domain.verify.DomainVerificationManager;

public interface DomainVerificationManagerInternal extends DomainVerificationManager {

    // TODO(b/159952358): Skeleton checked in to prepare for future internal methods

}
+121 −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.domain.verify;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.domain.verify.DomainVerificationManager.InvalidDomainSetException;
import android.content.pm.domain.verify.DomainVerificationManagerImpl;
import android.content.pm.domain.verify.DomainVerificationSet;
import android.content.pm.domain.verify.DomainVerificationUserSelection;
import android.content.pm.domain.verify.IDomainVerificationManager;
import android.os.ServiceSpecificException;
import android.util.ArraySet;

import java.util.List;
import java.util.UUID;

class DomainVerificationManagerStub extends IDomainVerificationManager.Stub {

    @NonNull
    private DomainVerificationService mService;

    DomainVerificationManagerStub(DomainVerificationService service) {
        mService = service;
    }

    @NonNull
    @Override
    public List<String> getValidVerificationPackageNames() {
        try {
            return mService.getValidVerificationPackageNames();
        } catch (Exception e) {
            throw rethrow(e);
        }
    }

    @Nullable
    @Override
    public DomainVerificationSet getDomainVerificationSet(String packageName) {
        try {
            return mService.getDomainVerificationSet(packageName);
        } catch (Exception e) {
            throw rethrow(e);
        }
    }

    @Override
    public void setDomainVerificationStatus(String domainSetId, List<String> domains,
            int state) {
        try {
            mService.setDomainVerificationStatus(UUID.fromString(domainSetId),
                            new ArraySet<>(domains), state);
        } catch (Exception e) {
            throw rethrow(e);
        }
    }

    @Override
    public void setDomainVerificationLinkHandlingAllowed(String packageName, boolean allowed,
            @UserIdInt int userId) {
        try {
            mService.setDomainVerificationLinkHandlingAllowed(packageName, allowed, userId);
        } catch (Exception e) {
            throw rethrow(e);
        }
    }

    @Override
    public void setDomainVerificationUserSelection(String domainSetId, List<String> domains,
            boolean enabled, @UserIdInt int userId) {
        try {
            mService.setDomainVerificationUserSelection(UUID.fromString(domainSetId),
                            new ArraySet<>(domains), enabled, userId);
        } catch (Exception e) {
            throw rethrow(e);
        }
    }

    @Nullable
    @Override
    public DomainVerificationUserSelection getDomainVerificationUserSelection(
            String packageName, @UserIdInt int userId) {
        try {
            return mService.getDomainVerificationUserSelection(packageName, userId);
        } catch (Exception e) {
            throw rethrow(e);
        }
    }

    private RuntimeException rethrow(Exception exception) throws RuntimeException {
        if (exception instanceof InvalidDomainSetException) {
            int packedErrorCode = DomainVerificationManagerImpl.ERROR_INVALID_DOMAIN_SET;
            packedErrorCode |= ((InvalidDomainSetException) exception).getReason() << 16;
            return new ServiceSpecificException(packedErrorCode,
                    ((InvalidDomainSetException) exception).getPackageName());
        } else if (exception instanceof NameNotFoundException) {
            return new ServiceSpecificException(
                    DomainVerificationManagerImpl.ERROR_NAME_NOT_FOUND);
        } else if (exception instanceof RuntimeException) {
            return (RuntimeException) exception;
        } else {
            return new RuntimeException(exception);
        }
    }
}
+116 −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.domain.verify;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.domain.verify.DomainVerificationSet;
import android.content.pm.domain.verify.DomainVerificationUserSelection;
import android.content.pm.domain.verify.IDomainVerificationManager;
import android.util.Singleton;

import com.android.server.SystemService;

import java.util.List;
import java.util.Set;
import java.util.UUID;

public class DomainVerificationService extends SystemService
        implements DomainVerificationManagerInternal {

    private static final String TAG = "DomainVerificationService";

    @NonNull
    private final Singleton<Connection> mConnection;

    @NonNull
    private final IDomainVerificationManager.Stub mStub = new DomainVerificationManagerStub(this);

    public DomainVerificationService(@NonNull Context context,
            @NonNull Singleton<Connection> connection) {
        super(context);
        mConnection = connection;
    }

    @Override
    public void onStart() {
        publishBinderService(Context.DOMAIN_VERIFICATION_SERVICE, mStub);
    }

    @NonNull
    @Override
    public List<String> getValidVerificationPackageNames() {
        return null;
    }

    @Nullable
    @Override
    public DomainVerificationSet getDomainVerificationSet(@NonNull String packageName)
            throws NameNotFoundException {
        return null;
    }

    @Override
    public void setDomainVerificationStatus(@NonNull UUID domainSetId, @NonNull Set<String> domains,
            int state) throws InvalidDomainSetException, NameNotFoundException {

    }

    @Override
    public void setDomainVerificationLinkHandlingAllowed(@NonNull String packageName,
            boolean allowed) throws NameNotFoundException {

    }

    public void setDomainVerificationLinkHandlingAllowed(@NonNull String packageName,
            boolean allowed, @UserIdInt int userId) throws NameNotFoundException {

    }

    @Override
    public void setDomainVerificationUserSelection(@NonNull UUID domainSetId,
            @NonNull Set<String> domains, boolean enabled)
            throws InvalidDomainSetException, NameNotFoundException {

    }

    public void setDomainVerificationUserSelection(@NonNull UUID domainSetId,
            @NonNull Set<String> domains, boolean enabled, @UserIdInt int userId)
            throws InvalidDomainSetException, NameNotFoundException {

    }

    @Nullable
    @Override
    public DomainVerificationUserSelection getDomainVerificationUserSelection(
            @NonNull String packageName) throws NameNotFoundException {
        return null;
    }

    @Nullable
    public DomainVerificationUserSelection getDomainVerificationUserSelection(
            @NonNull String packageName, @UserIdInt int userId) throws NameNotFoundException {
        return null;
    }

    public interface Connection {

    }
}
+14 −0
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ import android.util.DisplayMetrics;
import android.util.EventLog;
import android.util.IndentingPrintWriter;
import android.util.Pair;
import android.util.Singleton;
import android.util.Slog;
import android.util.TimeUtils;
import android.view.contentcapture.ContentCaptureManager;
@@ -160,6 +161,7 @@ import com.android.server.pm.PackageManagerService;
import com.android.server.pm.ShortcutService;
import com.android.server.pm.UserManagerService;
import com.android.server.pm.dex.SystemServerDexLoadReporter;
import com.android.server.pm.domain.verify.DomainVerificationService;
import com.android.server.policy.PermissionPolicyService;
import com.android.server.policy.PhoneWindowManager;
import com.android.server.policy.role.RoleServicePlatformHelperImpl;
@@ -1060,6 +1062,18 @@ public final class SystemServer implements Dumpable {
                    SystemClock.elapsedRealtime());
        }

        t.traceBegin("StartDomainVerificationService");
        DomainVerificationService domainVerificationService = new DomainVerificationService(
                mSystemContext, new Singleton<DomainVerificationService.Connection>() {
            @Override
            protected DomainVerificationService.Connection create() {
                // TODO(b/159952358): Hook up to PackageManagerService
                return null;
            }
        });
        mSystemServiceManager.startService(domainVerificationService);
        t.traceEnd();

        t.traceBegin("StartPackageManagerService");
        try {
            Watchdog.getInstance().pauseWatchingCurrentThread("packagemanagermain");