1 /* 2 * Copyright 2020 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 androidx.camera.core.impl; 18 19 import android.os.Handler; 20 21 import com.google.auto.value.AutoValue; 22 23 import org.jspecify.annotations.NonNull; 24 25 import java.util.concurrent.Executor; 26 27 /** 28 * Configuration options for threads used by the camera stack implementation. 29 */ 30 @AutoValue 31 public abstract class CameraThreadConfig { 32 33 /** 34 * Creates a thread configuration given an executor and a scheduling handler. 35 * @param cameraExecutor Executor used to run all camera-related tasks. 36 * @param schedulerHandler Handler used for scheduling future tasks (such as with a delay) 37 * and for legacy APIs that require a handler. Tasks that are 38 * scheduled with this handler should always be executed by 39 * cameraExecutor. No business logic should be executed directly by 40 * this handler. 41 * @return the camera thread configuration. 42 */ create(@onNull Executor cameraExecutor, @NonNull Handler schedulerHandler)43 public static @NonNull CameraThreadConfig create(@NonNull Executor cameraExecutor, 44 @NonNull Handler schedulerHandler) { 45 return new AutoValue_CameraThreadConfig(cameraExecutor, schedulerHandler); 46 } 47 48 /** 49 * Returns the executor used to run all camera-related tasks. 50 */ getCameraExecutor()51 public abstract @NonNull Executor getCameraExecutor(); 52 53 /** 54 * Returns the handler used for scheduling future tasks (such as with a delay). 55 * 56 * <p>This scheduler may also be used for legacy APIs which require a {@link Handler}. Tasks 57 * that are scheduled with this handler should always be executed by cameraExecutor. No 58 * business logic should be executed directly by this handler. 59 */ getSchedulerHandler()60 public abstract @NonNull Handler getSchedulerHandler(); 61 } 62