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

Commit 675daefc authored by Winson Chiu's avatar Winson Chiu Committed by Android (Google) Code Review
Browse files

Merge "Remove PMS snapshot lambdas" into tm-dev

parents 1afc1f40 664792c2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ import java.util.function.Consumer;
 *
 * @hide Only for use within the system server.
 */
public abstract class PackageManagerInternal implements PackageSettingsSnapshotProvider {
public abstract class PackageManagerInternal {
    @IntDef(prefix = "PACKAGE_", value = {
            PACKAGE_SYSTEM,
            PACKAGE_SETUP_WIZARD,
+0 −77
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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.content.pm;

import android.annotation.NonNull;

import com.android.internal.util.FunctionalUtils;
import com.android.server.pm.PackageManagerService;
import com.android.server.pm.PackageSetting;
import com.android.server.pm.pkg.PackageStateInternal;

import java.util.function.Consumer;
import java.util.function.Function;

/** @hide */
public interface PackageSettingsSnapshotProvider {

    /**
     * Run a function block that requires access to {@link PackageStateInternal} data. This will
     * ensure the {@link PackageManagerService} lock is taken before any caller's internal lock
     * to avoid deadlock. Note that this method may or may not lock. If a snapshot is available
     * and valid, it will iterate the snapshot set of data.
     */
    void withPackageSettingsSnapshot(
            @NonNull Consumer<Function<String, PackageStateInternal>> block);

    /**
     * Variant which returns a value to the caller.
     * @see #withPackageSettingsSnapshot(Consumer)
     */
    <Output> Output withPackageSettingsSnapshotReturning(
            @NonNull FunctionalUtils.ThrowingFunction<Function<String, PackageStateInternal>,
                    Output> block);

    /**
     * Variant which throws.
     * @see #withPackageSettingsSnapshot(Consumer)
     */
    <ExceptionType extends Exception> void withPackageSettingsSnapshotThrowing(
            @NonNull FunctionalUtils.ThrowingCheckedConsumer<Function<String, PackageStateInternal>,
                    ExceptionType> block) throws ExceptionType;

    /**
     * Variant which throws 2 exceptions.
     * @see #withPackageSettingsSnapshot(Consumer)
     */
    <ExceptionOne extends Exception, ExceptionTwo extends Exception> void
            withPackageSettingsSnapshotThrowing2(
                    @NonNull FunctionalUtils.ThrowingChecked2Consumer<
                            Function<String, PackageStateInternal>,
                            ExceptionOne, ExceptionTwo> block)
            throws ExceptionOne, ExceptionTwo;

    /**
     * Variant which returns a value to the caller and throws.
     * @see #withPackageSettingsSnapshot(Consumer)
     */
    <Output, ExceptionType extends Exception> Output
            withPackageSettingsSnapshotReturningThrowing(
                    @NonNull FunctionalUtils.ThrowingCheckedFunction<
                            Function<String, PackageStateInternal>, Output, ExceptionType> block)
            throws ExceptionType;
}
+2 −2
Original line number Diff line number Diff line
@@ -3134,8 +3134,8 @@ public class ComputerEngine implements Computer {
                writer.println("Domain verification status:");
                writer.increaseIndent();
                try {
                    mDomainVerificationManager.printState(writer, packageName,
                            UserHandle.USER_ALL, mSettings::getPackage);
                    mDomainVerificationManager.printState(this, writer, packageName,
                            UserHandle.USER_ALL);
                } catch (Exception e) {
                    pw.println("Failure printing domain verification information");
                    Slog.e(TAG, "Failure printing domain verification information", e);
+2 −1
Original line number Diff line number Diff line
@@ -453,7 +453,8 @@ final class DeletePackageHelper {
        }
        for (final int affectedUserId : affectedUserIds) {
            if (hadSuspendAppsPermission.get(affectedUserId)) {
                mPm.unsuspendForSuspendingPackage(packageName, affectedUserId);
                mPm.unsuspendForSuspendingPackage(mPm.snapshotComputer(), packageName,
                        affectedUserId);
                mPm.removeAllDistractingPackageRestrictions(affectedUserId);
            }
        }
+3 −42
Original line number Diff line number Diff line
@@ -26,17 +26,12 @@ import android.os.Binder;
import android.os.Message;
import android.os.UserHandle;

import com.android.internal.util.FunctionalUtils;
import com.android.server.DeviceIdleInternal;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import com.android.server.pm.pkg.PackageStateInternal;
import com.android.server.pm.verify.domain.DomainVerificationService;
import com.android.server.pm.verify.domain.proxy.DomainVerificationProxyV1;
import com.android.server.pm.verify.domain.proxy.DomainVerificationProxyV2;

import java.util.function.Consumer;
import java.util.function.Function;

public final class DomainVerificationConnection implements DomainVerificationService.Connection,
        DomainVerificationProxyV1.Connection, DomainVerificationProxyV2.Connection {
    final PackageManagerService mPm;
@@ -111,42 +106,8 @@ public final class DomainVerificationConnection implements DomainVerificationSer
        return mUmInternal.exists(userId);
    }

    @Override
    public void withPackageSettingsSnapshot(
            @NonNull Consumer<Function<String, PackageStateInternal>> block) {
        mPmInternal.withPackageSettingsSnapshot(block);
    }

    @Override
    public <Output> Output withPackageSettingsSnapshotReturning(
            @NonNull FunctionalUtils.ThrowingFunction<Function<String, PackageStateInternal>,
                    Output> block) {
        return mPmInternal.withPackageSettingsSnapshotReturning(block);
    }

    @Override
    public <ExceptionType extends Exception> void withPackageSettingsSnapshotThrowing(
            @NonNull FunctionalUtils.ThrowingCheckedConsumer<Function<String, PackageStateInternal>,
                    ExceptionType> block) throws ExceptionType {
        mPmInternal.withPackageSettingsSnapshotThrowing(block);
    }

    @Override
    public <ExceptionOne extends Exception, ExceptionTwo extends Exception> void
            withPackageSettingsSnapshotThrowing2(
                    @NonNull FunctionalUtils.ThrowingChecked2Consumer<
                            Function<String, PackageStateInternal>, ExceptionOne,
                            ExceptionTwo> block)
            throws ExceptionOne, ExceptionTwo {
        mPmInternal.withPackageSettingsSnapshotThrowing2(block);
    }

    @Override
    public <Output, ExceptionType extends Exception> Output
            withPackageSettingsSnapshotReturningThrowing(
            @NonNull FunctionalUtils.ThrowingCheckedFunction<
                    Function<String, PackageStateInternal>, Output, ExceptionType> block)
            throws ExceptionType {
        return mPmInternal.withPackageSettingsSnapshotReturningThrowing(block);
    @NonNull
    public Computer snapshot() {
        return (Computer) mPmInternal.snapshot();
    }
}
Loading