1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.content.pm; 18 19 import android.annotation.NonNull; 20 21 import com.android.internal.util.FunctionalUtils; 22 import com.android.server.pm.PackageManagerService; 23 import com.android.server.pm.PackageSetting; 24 25 import java.util.function.Consumer; 26 import java.util.function.Function; 27 28 /** @hide */ 29 public interface PackageSettingsSnapshotProvider { 30 31 /** 32 * Run a function block that requires access to {@link PackageSetting} data. This will 33 * ensure the {@link PackageManagerService} lock is taken before any caller's internal lock 34 * to avoid deadlock. Note that this method may or may not lock. If a snapshot is available 35 * and valid, it will iterate the snapshot set of data. 36 */ withPackageSettingsSnapshot( @onNull Consumer<Function<String, PackageSetting>> block)37 void withPackageSettingsSnapshot( 38 @NonNull Consumer<Function<String, PackageSetting>> block); 39 40 /** 41 * Variant which returns a value to the caller. 42 * @see #withPackageSettingsSnapshot(Consumer) 43 */ withPackageSettingsSnapshotReturning( @onNull FunctionalUtils.ThrowingFunction<Function<String, PackageSetting>, Output> block)44 <Output> Output withPackageSettingsSnapshotReturning( 45 @NonNull FunctionalUtils.ThrowingFunction<Function<String, PackageSetting>, Output> 46 block); 47 48 /** 49 * Variant which throws. 50 * @see #withPackageSettingsSnapshot(Consumer) 51 */ withPackageSettingsSnapshotThrowing( @onNull FunctionalUtils.ThrowingCheckedConsumer<Function<String, PackageSetting>, ExceptionType> block)52 <ExceptionType extends Exception> void withPackageSettingsSnapshotThrowing( 53 @NonNull FunctionalUtils.ThrowingCheckedConsumer<Function<String, PackageSetting>, 54 ExceptionType> block) throws ExceptionType; 55 56 /** 57 * Variant which throws 2 exceptions. 58 * @see #withPackageSettingsSnapshot(Consumer) 59 */ 60 <ExceptionOne extends Exception, ExceptionTwo extends Exception> void withPackageSettingsSnapshotThrowing2( @onNull FunctionalUtils.ThrowingChecked2Consumer< Function<String, PackageSetting>, ExceptionOne, ExceptionTwo> block)61 withPackageSettingsSnapshotThrowing2( 62 @NonNull FunctionalUtils.ThrowingChecked2Consumer< 63 Function<String, PackageSetting>, ExceptionOne, ExceptionTwo> block) 64 throws ExceptionOne, ExceptionTwo; 65 66 /** 67 * Variant which returns a value to the caller and throws. 68 * @see #withPackageSettingsSnapshot(Consumer) 69 */ 70 <Output, ExceptionType extends Exception> Output withPackageSettingsSnapshotReturningThrowing( @onNull FunctionalUtils.ThrowingCheckedFunction< Function<String, PackageSetting>, Output, ExceptionType> block)71 withPackageSettingsSnapshotReturningThrowing( 72 @NonNull FunctionalUtils.ThrowingCheckedFunction< 73 Function<String, PackageSetting>, Output, ExceptionType> block) 74 throws ExceptionType; 75 } 76