From 665164cb0b04d63712cb02e40ac63756451bee63 Mon Sep 17 00:00:00 2001 From: WenHung_Teng Date: Fri, 8 Mar 2024 10:29:17 +0800 Subject: [PATCH] Refine RetryPolicy method names Based on the recommendation from API review b/328603536 * Rename the RetryResponse to RetryConfig * Rename the shouldRetry to onRetryDecisionRequested Relnote: N/A Bug: 328603536 Test: CameraXInitRetryTest Change-Id: I7034dda8b75bf6248760f4621a5cdc150123b54d --- camera/camera-core/api/current.txt | 20 +++--- camera/camera-core/api/restricted_current.txt | 20 +++--- .../java/androidx/camera/core/CameraX.java | 8 +-- .../androidx/camera/core/RetryPolicy.java | 68 +++++++++---------- .../impl/CameraProviderInitRetryPolicy.java | 22 +++--- .../camera/core/impl/TimeoutRetryPolicy.java | 10 +-- .../camera/core/CameraXInitRetryTest.kt | 38 +++++------ 7 files changed, 93 insertions(+), 93 deletions(-) diff --git a/camera/camera-core/api/current.txt b/camera/camera-core/api/current.txt index a768062aac0e8..2a567c8b30fda 100644 --- a/camera/camera-core/api/current.txt +++ b/camera/camera-core/api/current.txt @@ -520,7 +520,7 @@ package androidx.camera.core { @SuppressCompatibility @RequiresApi(21) @androidx.camera.core.ExperimentalRetryPolicy public interface RetryPolicy { method public static long getDefaultRetryTimeoutInMillis(); method public default long getTimeoutInMillis(); - method public androidx.camera.core.RetryPolicy.RetryResponse shouldRetry(androidx.camera.core.RetryPolicy.ExecutionState); + method public androidx.camera.core.RetryPolicy.RetryConfig onRetryDecisionRequested(androidx.camera.core.RetryPolicy.ExecutionState); field public static final androidx.camera.core.RetryPolicy DEFAULT; field public static final androidx.camera.core.RetryPolicy NEVER; field public static final androidx.camera.core.RetryPolicy RETRY_UNAVAILABLE_CAMERA; @@ -542,20 +542,20 @@ package androidx.camera.core { field public static final int STATUS_UNKNOWN_ERROR = 0; // 0x0 } - @SuppressCompatibility @androidx.camera.core.ExperimentalRetryPolicy public static final class RetryPolicy.RetryResponse { + @SuppressCompatibility @androidx.camera.core.ExperimentalRetryPolicy public static final class RetryPolicy.RetryConfig { method public static long getDefaultRetryDelayInMillis(); method public long getRetryDelayInMillis(); method public boolean shouldRetry(); - field public static final androidx.camera.core.RetryPolicy.RetryResponse DEFAULT_DELAY_RETRY; - field public static final androidx.camera.core.RetryPolicy.RetryResponse MINI_DELAY_RETRY; - field public static final androidx.camera.core.RetryPolicy.RetryResponse NOT_RETRY; + field public static final androidx.camera.core.RetryPolicy.RetryConfig DEFAULT_DELAY_RETRY; + field public static final androidx.camera.core.RetryPolicy.RetryConfig MINI_DELAY_RETRY; + field public static final androidx.camera.core.RetryPolicy.RetryConfig NOT_RETRY; } - @SuppressCompatibility @androidx.camera.core.ExperimentalRetryPolicy public static final class RetryPolicy.RetryResponse.Builder { - ctor public RetryPolicy.RetryResponse.Builder(); - method public androidx.camera.core.RetryPolicy.RetryResponse build(); - method public androidx.camera.core.RetryPolicy.RetryResponse.Builder setRetryDelayInMillis(@IntRange(from=100, to=2000) long); - method public androidx.camera.core.RetryPolicy.RetryResponse.Builder setShouldRetry(boolean); + @SuppressCompatibility @androidx.camera.core.ExperimentalRetryPolicy public static final class RetryPolicy.RetryConfig.Builder { + ctor public RetryPolicy.RetryConfig.Builder(); + method public androidx.camera.core.RetryPolicy.RetryConfig build(); + method public androidx.camera.core.RetryPolicy.RetryConfig.Builder setRetryDelayInMillis(@IntRange(from=100, to=2000) long); + method public androidx.camera.core.RetryPolicy.RetryConfig.Builder setShouldRetry(boolean); } @RequiresApi(21) public class SurfaceOrientedMeteringPointFactory extends androidx.camera.core.MeteringPointFactory { diff --git a/camera/camera-core/api/restricted_current.txt b/camera/camera-core/api/restricted_current.txt index a768062aac0e8..2a567c8b30fda 100644 --- a/camera/camera-core/api/restricted_current.txt +++ b/camera/camera-core/api/restricted_current.txt @@ -520,7 +520,7 @@ package androidx.camera.core { @SuppressCompatibility @RequiresApi(21) @androidx.camera.core.ExperimentalRetryPolicy public interface RetryPolicy { method public static long getDefaultRetryTimeoutInMillis(); method public default long getTimeoutInMillis(); - method public androidx.camera.core.RetryPolicy.RetryResponse shouldRetry(androidx.camera.core.RetryPolicy.ExecutionState); + method public androidx.camera.core.RetryPolicy.RetryConfig onRetryDecisionRequested(androidx.camera.core.RetryPolicy.ExecutionState); field public static final androidx.camera.core.RetryPolicy DEFAULT; field public static final androidx.camera.core.RetryPolicy NEVER; field public static final androidx.camera.core.RetryPolicy RETRY_UNAVAILABLE_CAMERA; @@ -542,20 +542,20 @@ package androidx.camera.core { field public static final int STATUS_UNKNOWN_ERROR = 0; // 0x0 } - @SuppressCompatibility @androidx.camera.core.ExperimentalRetryPolicy public static final class RetryPolicy.RetryResponse { + @SuppressCompatibility @androidx.camera.core.ExperimentalRetryPolicy public static final class RetryPolicy.RetryConfig { method public static long getDefaultRetryDelayInMillis(); method public long getRetryDelayInMillis(); method public boolean shouldRetry(); - field public static final androidx.camera.core.RetryPolicy.RetryResponse DEFAULT_DELAY_RETRY; - field public static final androidx.camera.core.RetryPolicy.RetryResponse MINI_DELAY_RETRY; - field public static final androidx.camera.core.RetryPolicy.RetryResponse NOT_RETRY; + field public static final androidx.camera.core.RetryPolicy.RetryConfig DEFAULT_DELAY_RETRY; + field public static final androidx.camera.core.RetryPolicy.RetryConfig MINI_DELAY_RETRY; + field public static final androidx.camera.core.RetryPolicy.RetryConfig NOT_RETRY; } - @SuppressCompatibility @androidx.camera.core.ExperimentalRetryPolicy public static final class RetryPolicy.RetryResponse.Builder { - ctor public RetryPolicy.RetryResponse.Builder(); - method public androidx.camera.core.RetryPolicy.RetryResponse build(); - method public androidx.camera.core.RetryPolicy.RetryResponse.Builder setRetryDelayInMillis(@IntRange(from=100, to=2000) long); - method public androidx.camera.core.RetryPolicy.RetryResponse.Builder setShouldRetry(boolean); + @SuppressCompatibility @androidx.camera.core.ExperimentalRetryPolicy public static final class RetryPolicy.RetryConfig.Builder { + ctor public RetryPolicy.RetryConfig.Builder(); + method public androidx.camera.core.RetryPolicy.RetryConfig build(); + method public androidx.camera.core.RetryPolicy.RetryConfig.Builder setRetryDelayInMillis(@IntRange(from=100, to=2000) long); + method public androidx.camera.core.RetryPolicy.RetryConfig.Builder setShouldRetry(boolean); } @RequiresApi(21) public class SurfaceOrientedMeteringPointFactory extends androidx.camera.core.MeteringPointFactory { diff --git a/camera/camera-core/src/main/java/androidx/camera/core/CameraX.java b/camera/camera-core/src/main/java/androidx/camera/core/CameraX.java index 9401862ab5d2a..c3c39aa5db538 100644 --- a/camera/camera-core/src/main/java/androidx/camera/core/CameraX.java +++ b/camera/camera-core/src/main/java/androidx/camera/core/CameraX.java @@ -350,20 +350,20 @@ private void initAndRetryRecursively( completer.set(null); } catch (CameraIdListIncorrectException | InitializationException | RuntimeException e) { - RetryPolicy.RetryResponse response = mRetryPolicy.shouldRetry( + RetryPolicy.RetryConfig retryConfig = mRetryPolicy.onRetryDecisionRequested( new CameraProviderExecutionState(startMs, attemptCount, e)); - if (response.shouldRetry() && attemptCount < Integer.MAX_VALUE) { + if (retryConfig.shouldRetry() && attemptCount < Integer.MAX_VALUE) { Logger.w(TAG, "Retry init. Start time " + startMs + " current time " + SystemClock.elapsedRealtime(), e); HandlerCompat.postDelayed(mSchedulerHandler, () -> initAndRetryRecursively( cameraExecutor, startMs, attemptCount + 1, mAppContext, - completer), RETRY_TOKEN, response.getRetryDelayInMillis()); + completer), RETRY_TOKEN, retryConfig.getRetryDelayInMillis()); } else { synchronized (mInitializeLock) { mInitState = InternalInitState.INITIALIZING_ERROR; } - if (response.shouldCompleteWithoutFailure()) { + if (retryConfig.shouldCompleteWithoutFailure()) { // Ignoring camera failure for compatibility reasons. Initialization will // be marked as complete, but some camera features might be unavailable. setStateToInitialized(); diff --git a/camera/camera-core/src/main/java/androidx/camera/core/RetryPolicy.java b/camera/camera-core/src/main/java/androidx/camera/core/RetryPolicy.java index 2fb6980a2e55b..3756d7457b628 100644 --- a/camera/camera-core/src/main/java/androidx/camera/core/RetryPolicy.java +++ b/camera/camera-core/src/main/java/androidx/camera/core/RetryPolicy.java @@ -71,22 +71,22 @@ * if (executionState.getExecutedTimeInMillis() > 10000L * || executionState.getNumOfAttempts() > 10 * || executionState.getStatus() == ExecutionState.STATUS_CONFIGURATION_FAIL) { - * return RetryResponse.NOT_RETRY; + * return RetryConfig.NOT_RETRY; * } else if (executionState.getStatus() == ExecutionState.STATUS_CAMERA_UNAVAILABLE) { - * return RetryResponse.DEFAULT_DELAY_RETRY; + * return RetryConfig.DEFAULT_DELAY_RETRY; * } else { * Log.d("CameraX", "Unknown error occur: " + executionState.getCause()); - * return RetryResponse.MINI_DELAY_RETRY; + * return RetryConfig.MINI_DELAY_RETRY; * } * }).build()); * ... * } * In the second example, the custom retry policy retries the initialization up to 10 times or * for a maximum of 10 seconds. If an unknown error occurs, the retry policy delays the next - * retry after a delay defined by {@link RetryResponse#MINI_DELAY_RETRY}. The retry process + * retry after a delay defined by {@link RetryConfig#MINI_DELAY_RETRY}. The retry process * stops if the status is {@link ExecutionState#STATUS_CONFIGURATION_FAIL}. For * {@link ExecutionState#STATUS_CAMERA_UNAVAILABLE}, the retry policy applies - * {@link RetryResponse#DEFAULT_DELAY_RETRY}. + * {@link RetryConfig#DEFAULT_DELAY_RETRY}. */ @RequiresApi(21) // TODO(b/200306659): Remove and replace with annotation on package-info.java @ExperimentalRetryPolicy @@ -103,7 +103,7 @@ public interface RetryPolicy { * immediately halts the initialization upon encountering an error. */ @NonNull - RetryPolicy NEVER = executionState -> RetryResponse.NOT_RETRY; + RetryPolicy NEVER = executionState -> RetryConfig.NOT_RETRY; /** * This retry policy increases initialization success by automatically retrying upon @@ -154,13 +154,14 @@ static long getDefaultRetryTimeoutInMillis() { } /** - * Determines whether to retry the initialization. + * Called to request a decision on whether to retry the initialization process. * - * @param executionState The information about the execution state of the camera initialization. - * @return A RetryResponse indicating whether to retry the initialization. + * @param executionState Information about the current execution state of the camera + * initialization. + * @return A RetryConfig indicating whether to retry, along with any associated delay. */ @NonNull - RetryResponse shouldRetry(@NonNull ExecutionState executionState); + RetryConfig onRetryDecisionRequested(@NonNull ExecutionState executionState); /** * Returns the maximum allowed retry duration in milliseconds. Initialization will @@ -208,7 +209,7 @@ public Builder(@NonNull RetryPolicy basePolicy) { /** * Sets a timeout in milliseconds. If retries exceed this duration, they will be - * terminated with {@link RetryPolicy.RetryResponse#NOT_RETRY}. + * terminated with {@link RetryConfig#NOT_RETRY}. * * @param timeoutInMillis The maximum duration for retries in milliseconds. A value of 0 * indicates no timeout. @@ -332,26 +333,26 @@ interface ExecutionState { * Represents the outcome of a {@link RetryPolicy} decision. */ @ExperimentalRetryPolicy - final class RetryResponse { + final class RetryConfig { private static final long MINI_DELAY_MILLIS = 100L; private static final long DEFAULT_DELAY_MILLIS = 500L; - /** A RetryResponse indicating that no further retries should be attempted. */ + /** A RetryConfig indicating that no further retries should be attempted. */ @NonNull - public static final RetryResponse NOT_RETRY = new RetryResponse(false, 0L); + public static final RetryConfig NOT_RETRY = new RetryConfig(false, 0L); /** - * A RetryResponse indicating that the initialization should be retried after the default + * A RetryConfig indicating that the initialization should be retried after the default * delay (determined by {@link #getDefaultRetryDelayInMillis()}). This delay provides * sufficient time for typical device recovery processes, balancing retry efficiency * and minimizing user wait time. */ @NonNull - public static final RetryResponse DEFAULT_DELAY_RETRY = new RetryResponse(true); + public static final RetryConfig DEFAULT_DELAY_RETRY = new RetryConfig(true); /** - * A RetryResponse indicating that the initialization should be retried after a minimum + * A RetryConfig indicating that the initialization should be retried after a minimum * delay of 100 milliseconds. * * This short delay serves two purposes: @@ -365,18 +366,17 @@ final class RetryResponse { * fastest possible camera restoration. */ @NonNull - public static final RetryResponse MINI_DELAY_RETRY = new RetryResponse(true, - MINI_DELAY_MILLIS); + public static final RetryConfig MINI_DELAY_RETRY = new RetryConfig(true, MINI_DELAY_MILLIS); /** - * A RetryResponse indicating that the initialization should be considered complete - * without retrying. This response is intended for internal use and is not intended to + * A RetryConfig indicating that the initialization should be considered complete + * without retrying. This config is intended for internal use and is not intended to * trigger further retries. It represents the legacy behavior of not failing the * initialization task for minor issues. */ @RestrictTo(RestrictTo.Scope.LIBRARY) @NonNull - public static RetryResponse COMPLETE_WITHOUT_FAILURE = new RetryResponse(false, 0, true); + public static RetryConfig COMPLETE_WITHOUT_FAILURE = new RetryConfig(false, 0, true); /** * Returns the recommended default delay to optimize retry attempts and camera recovery. @@ -400,11 +400,11 @@ public static long getDefaultRetryDelayInMillis() { private final boolean mShouldRetry; private final boolean mCompleteWithoutFailure; - private RetryResponse(boolean shouldRetry) { - this(shouldRetry, RetryResponse.getDefaultRetryDelayInMillis()); + private RetryConfig(boolean shouldRetry) { + this(shouldRetry, RetryConfig.getDefaultRetryDelayInMillis()); } - private RetryResponse(boolean shouldRetry, long delayInMillis) { + private RetryConfig(boolean shouldRetry, long delayInMillis) { this(shouldRetry, delayInMillis, false); } @@ -420,7 +420,7 @@ private RetryResponse(boolean shouldRetry, long delayInMillis) { * When this flag is set to true, `shouldRetry` must be * false. */ - private RetryResponse(boolean shouldRetry, long delayInMillis, + private RetryConfig(boolean shouldRetry, long delayInMillis, boolean completeWithoutFailure) { mShouldRetry = shouldRetry; mDelayInMillis = delayInMillis; @@ -452,7 +452,7 @@ public long getRetryDelayInMillis() { /** * Signals to treat initialization errors as successful for legacy behavior compatibility. * - *

This response is intended for internal use and is not intended to trigger further + *

This config is intended for internal use and is not intended to trigger further * retries. * * @return true if initialization should be deemed complete without additional retries, @@ -464,9 +464,9 @@ public boolean shouldCompleteWithoutFailure() { } /** - * A builder class for creating and customizing {@link RetryResponse} objects. + * A builder class for creating and customizing {@link RetryConfig} objects. * - *

While predefined responses like {@link RetryResponse#DEFAULT_DELAY_RETRY} are + *

While predefined configs like {@link RetryConfig#DEFAULT_DELAY_RETRY} are * recommended for typical recovery scenarios, this builder allows for fine-tuned control * when specific requirements necessitate a different approach. */ @@ -474,7 +474,7 @@ public boolean shouldCompleteWithoutFailure() { public static final class Builder { private boolean mShouldRetry = true; - private long mTimeoutInMillis = RetryResponse.getDefaultRetryDelayInMillis(); + private long mTimeoutInMillis = RetryConfig.getDefaultRetryDelayInMillis(); /** * Specifies whether a retry should be attempted. @@ -508,13 +508,13 @@ public Builder setRetryDelayInMillis( } /** - * Builds the customized {@link RetryResponse} object. + * Builds the customized {@link RetryConfig} object. * - * @return The configured RetryResponse. + * @return The configured RetryConfig. */ @NonNull - public RetryResponse build() { - return new RetryResponse(mShouldRetry, mTimeoutInMillis); + public RetryConfig build() { + return new RetryConfig(mShouldRetry, mTimeoutInMillis); } } } diff --git a/camera/camera-core/src/main/java/androidx/camera/core/impl/CameraProviderInitRetryPolicy.java b/camera/camera-core/src/main/java/androidx/camera/core/impl/CameraProviderInitRetryPolicy.java index 1efbe47333cce..2ef47e156a484 100644 --- a/camera/camera-core/src/main/java/androidx/camera/core/impl/CameraProviderInitRetryPolicy.java +++ b/camera/camera-core/src/main/java/androidx/camera/core/impl/CameraProviderInitRetryPolicy.java @@ -28,7 +28,7 @@ * Basic retry policy that automatically retries most failures with a standard delay. * *

This policy will initiate a retry with the - * {@link RetryResponse#DEFAULT_DELAY_RETRY} delay for any failure status except + * {@link RetryConfig#DEFAULT_DELAY_RETRY} delay for any failure status except * {@link ExecutionState#STATUS_CONFIGURATION_FAIL}. */ @RequiresApi(21) // TODO(b/200306659): Remove and replace with annotation on package-info.java @@ -41,12 +41,12 @@ public CameraProviderInitRetryPolicy(long timeoutInMillis) { mDelegatePolicy = new TimeoutRetryPolicy(timeoutInMillis, new RetryPolicy() { @NonNull @Override - public RetryResponse shouldRetry(@NonNull ExecutionState executionState) { + public RetryConfig onRetryDecisionRequested(@NonNull ExecutionState executionState) { if (executionState.getStatus() == ExecutionState.STATUS_CONFIGURATION_FAIL) { - return RetryResponse.NOT_RETRY; + return RetryConfig.NOT_RETRY; } - return RetryResponse.DEFAULT_DELAY_RETRY; + return RetryConfig.DEFAULT_DELAY_RETRY; } @Override @@ -58,8 +58,8 @@ public long getTimeoutInMillis() { @NonNull @Override - public RetryResponse shouldRetry(@NonNull ExecutionState executionState) { - return mDelegatePolicy.shouldRetry(executionState); + public RetryConfig onRetryDecisionRequested(@NonNull ExecutionState executionState) { + return mDelegatePolicy.onRetryDecisionRequested(executionState); } @Override @@ -99,8 +99,8 @@ public Legacy(long timeoutInMillis) { @NonNull @Override - public RetryResponse shouldRetry(@NonNull ExecutionState executionState) { - if (!mBasePolicy.shouldRetry(executionState).shouldRetry()) { + public RetryConfig onRetryDecisionRequested(@NonNull ExecutionState executionState) { + if (!mBasePolicy.onRetryDecisionRequested(executionState).shouldRetry()) { Throwable cause = executionState.getCause(); if (cause instanceof CameraIdListIncorrectException) { Logger.e("CameraX", "The device might underreport the amount of the " @@ -110,12 +110,12 @@ public RetryResponse shouldRetry(@NonNull ExecutionState executionState) { // If the initialization task execution time exceeds the timeout // threshold and the error type is CameraIdListIncorrectException, // consider the initialization complete without retrying. - return RetryResponse.COMPLETE_WITHOUT_FAILURE; + return RetryConfig.COMPLETE_WITHOUT_FAILURE; } } - return RetryResponse.NOT_RETRY; + return RetryConfig.NOT_RETRY; } - return RetryResponse.DEFAULT_DELAY_RETRY; + return RetryConfig.DEFAULT_DELAY_RETRY; } @Override diff --git a/camera/camera-core/src/main/java/androidx/camera/core/impl/TimeoutRetryPolicy.java b/camera/camera-core/src/main/java/androidx/camera/core/impl/TimeoutRetryPolicy.java index 139ba82567824..5145b436011f2 100644 --- a/camera/camera-core/src/main/java/androidx/camera/core/impl/TimeoutRetryPolicy.java +++ b/camera/camera-core/src/main/java/androidx/camera/core/impl/TimeoutRetryPolicy.java @@ -27,7 +27,7 @@ * *

This retry policy monitors the total execution time of a task. If the time surpasses the * configured timeout threshold, it immediately stops any further retries by returning - * {@link RetryPolicy.RetryResponse#NOT_RETRY}. + * {@link RetryConfig#NOT_RETRY}. * *

If the task total execution within the timeout, this policy delegates the retry decision to * the underlying {@link RetryPolicy}, allowing for normal retry behavior based on other factors. @@ -56,11 +56,11 @@ public TimeoutRetryPolicy(long timeoutInMillis, @NonNull RetryPolicy delegatePol @NonNull @Override - public RetryResponse shouldRetry(@NonNull ExecutionState executionState) { - RetryResponse response = mDelegatePolicy.shouldRetry(executionState); + public RetryConfig onRetryDecisionRequested(@NonNull ExecutionState executionState) { + RetryConfig retryConfig = mDelegatePolicy.onRetryDecisionRequested(executionState); return getTimeoutInMillis() > 0 && executionState.getExecutedTimeInMillis() - >= getTimeoutInMillis() - response.getRetryDelayInMillis() ? RetryResponse.NOT_RETRY - : response; + >= getTimeoutInMillis() - retryConfig.getRetryDelayInMillis() + ? RetryConfig.NOT_RETRY : retryConfig; } @Override diff --git a/camera/camera-core/src/test/java/androidx/camera/core/CameraXInitRetryTest.kt b/camera/camera-core/src/test/java/androidx/camera/core/CameraXInitRetryTest.kt index 15b652d2503ad..1103c008fba5f 100644 --- a/camera/camera-core/src/test/java/androidx/camera/core/CameraXInitRetryTest.kt +++ b/camera/camera-core/src/test/java/androidx/camera/core/CameraXInitRetryTest.kt @@ -27,7 +27,7 @@ import androidx.camera.core.RetryPolicy.DEFAULT_RETRY_TIMEOUT_IN_MILLIS import androidx.camera.core.RetryPolicy.ExecutionState import androidx.camera.core.RetryPolicy.NEVER import androidx.camera.core.RetryPolicy.RETRY_UNAVAILABLE_CAMERA -import androidx.camera.core.RetryPolicy.RetryResponse +import androidx.camera.core.RetryPolicy.RetryConfig import androidx.camera.core.concurrent.CameraCoordinator import androidx.camera.core.impl.CameraDeviceSurfaceManager import androidx.camera.core.impl.CameraFactory @@ -101,7 +101,7 @@ class CameraXInitRetryTest { val executionStateMutableList = mutableListOf() val policy = RetryPolicy { executionState: ExecutionState -> executionStateMutableList.add(executionState) - return@RetryPolicy DEFAULT.shouldRetry(executionState) + return@RetryPolicy DEFAULT.onRetryDecisionRequested(executionState) } val configBuilder: CameraXConfig.Builder = CameraXConfig.Builder.fromConfig( createCameraXConfig( @@ -196,7 +196,7 @@ class CameraXInitRetryTest { setSchedulerHandler(handler) setCameraProviderInitRetryPolicy { executionState -> callCount++ - NEVER.shouldRetry(executionState) + NEVER.onRetryDecisionRequested(executionState) } } @@ -215,7 +215,7 @@ class CameraXInitRetryTest { } @Test - fun verifyImmediateFailureWithOptionResponseNotRetry() = runTest { + fun verifyImmediateFailureWithOptionRetryConfigNotRetry() = runTest { // Arrange. Set up a simulated environment that no accessible cameras. var callCount = 0 val configBuilder: CameraXConfig.Builder = CameraXConfig.Builder.fromConfig( @@ -230,7 +230,7 @@ class CameraXInitRetryTest { setSchedulerHandler(handler) setCameraProviderInitRetryPolicy { callCount++ - RetryResponse.Builder().setShouldRetry(false).build() + RetryConfig.Builder().setShouldRetry(false).build() } } @@ -283,7 +283,7 @@ class CameraXInitRetryTest { setCameraExecutor(handlerExecutor) setSchedulerHandler(handler) setCameraProviderInitRetryPolicy { executionState: ExecutionState -> - RETRY_UNAVAILABLE_CAMERA.shouldRetry(executionState).also { + RETRY_UNAVAILABLE_CAMERA.onRetryDecisionRequested(executionState).also { executedTime = executionState.executedTimeInMillis } } @@ -302,7 +302,7 @@ class CameraXInitRetryTest { throwableSubject.hasCauseThat().isInstanceOf(CameraUnavailableException::class.java) assertThat(cameraX.isInitialized).isFalse() assertThat(abs(DEFAULT_RETRY_TIMEOUT_IN_MILLIS - executedTime)).isLessThan( - RetryResponse.DEFAULT_DELAY_RETRY.retryDelayInMillis + 100 + RetryConfig.DEFAULT_DELAY_RETRY.retryDelayInMillis + 100 // Allow the tolerance for retry delay + 100ms potential processing time variations. ) } @@ -320,7 +320,7 @@ class CameraXInitRetryTest { @Test fun testTimeoutAdjustment_CustomRetryPolicyMode() = runTest { // Arrange. Set up a RetryPolicy that persistently retries initialization attempts. - val customAlwaysRetryPolicy = RetryPolicy { RetryResponse.MINI_DELAY_RETRY } + val customAlwaysRetryPolicy = RetryPolicy { RetryConfig.MINI_DELAY_RETRY } // Act. & Assert. Confirm that retries cease if the total execution time surpasses the // defined timeout, preventing indefinite loops. @@ -339,7 +339,7 @@ class CameraXInitRetryTest { setCameraExecutor(handlerExecutor) setSchedulerHandler(handler) setCameraProviderInitRetryPolicy { executionState -> - customTimeoutPolicy.shouldRetry(executionState).also { + customTimeoutPolicy.onRetryDecisionRequested(executionState).also { executedTime = executionState.executedTimeInMillis } } @@ -357,7 +357,7 @@ class CameraXInitRetryTest { // Assert. Verify that initialization persists with retries until the total execution // time exhausts the allotted timeout. assertThat(abs(testCustomTimeout - executedTime)).isLessThan( - RetryResponse.DEFAULT_DELAY_RETRY.retryDelayInMillis + 100 + RetryConfig.DEFAULT_DELAY_RETRY.retryDelayInMillis + 100 // Allow the tolerance for retry delay + 100ms potential processing time variations. ) } @@ -367,7 +367,7 @@ class CameraXInitRetryTest { val desiredDelayTime = 900L assertThat( - RetryResponse.Builder().setRetryDelayInMillis(desiredDelayTime) + RetryConfig.Builder().setRetryDelayInMillis(desiredDelayTime) .build().retryDelayInMillis ).isEqualTo( desiredDelayTime @@ -381,12 +381,12 @@ class CameraXInitRetryTest { val timeoutInMs = 10000L val executionStateMutableList = mutableListOf() val policy = object : RetryPolicy { - override fun shouldRetry(executionState: ExecutionState): RetryResponse { + override fun onRetryDecisionRequested(executionState: ExecutionState): RetryConfig { if (executionState.getExecutedTimeInMillis() < timeoutInMillis) { executionStateMutableList.add(executionState) } - return RetryResponse.DEFAULT_DELAY_RETRY + return RetryConfig.DEFAULT_DELAY_RETRY } override fun getTimeoutInMillis(): Long { @@ -437,10 +437,10 @@ class CameraXInitRetryTest { val policy = RetryPolicy { executionState -> if (executionState.getExecutedTimeInMillis() < timeoutInMs) { executionStateMutableList.add(executionState) - return@RetryPolicy RetryResponse.DEFAULT_DELAY_RETRY; + return@RetryPolicy RetryConfig.DEFAULT_DELAY_RETRY; } - return@RetryPolicy RetryResponse.NOT_RETRY + return@RetryPolicy RetryConfig.NOT_RETRY } val configBuilder: CameraXConfig.Builder = CameraXConfig.Builder.fromConfig( createCameraXConfig() @@ -486,10 +486,10 @@ class CameraXInitRetryTest { val policy = RetryPolicy { executionState: ExecutionState -> executionStateMutableList.add(executionState) if (executionState.numOfAttempts < maxAttempts) { - return@RetryPolicy RetryResponse.DEFAULT_DELAY_RETRY; + return@RetryPolicy RetryConfig.DEFAULT_DELAY_RETRY; } - return@RetryPolicy RetryResponse.NOT_RETRY + return@RetryPolicy RetryConfig.NOT_RETRY } val configBuilder: CameraXConfig.Builder = CameraXConfig.Builder.fromConfig( createCameraXConfig() @@ -520,7 +520,7 @@ class CameraXInitRetryTest { val resultList = mutableListOf() val policy = RetryPolicy { executionState: ExecutionState -> resultList.add(executionState) - RETRY_UNAVAILABLE_CAMERA.shouldRetry(executionState) + RETRY_UNAVAILABLE_CAMERA.onRetryDecisionRequested(executionState) } val configBuilder: CameraXConfig.Builder = CameraXConfig.Builder.fromConfig( createCameraXConfig(surfaceManager = null, useCaseConfigFactory = null) @@ -573,7 +573,7 @@ class CameraXInitRetryTest { setSchedulerHandler(handler) setCameraProviderInitRetryPolicy { executionState: ExecutionState -> executionStateMutableList.add(executionState) - RetryResponse.NOT_RETRY + RetryConfig.NOT_RETRY } }