Skip to content

Commit 63b0f62

Browse files
Treehugger RobotGerrit Code Review
Treehugger Robot
authored and
Gerrit Code Review
committed
Merge "Refine RetryPolicy method names" into androidx-main
2 parents 35d53e9 + 665164c commit 63b0f62

File tree

7 files changed

+93
-93
lines changed

7 files changed

+93
-93
lines changed

Diff for: camera/camera-core/api/current.txt

+10-10
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ package androidx.camera.core {
520520
@SuppressCompatibility @RequiresApi(21) @androidx.camera.core.ExperimentalRetryPolicy public interface RetryPolicy {
521521
method public static long getDefaultRetryTimeoutInMillis();
522522
method public default long getTimeoutInMillis();
523-
method public androidx.camera.core.RetryPolicy.RetryResponse shouldRetry(androidx.camera.core.RetryPolicy.ExecutionState);
523+
method public androidx.camera.core.RetryPolicy.RetryConfig onRetryDecisionRequested(androidx.camera.core.RetryPolicy.ExecutionState);
524524
field public static final androidx.camera.core.RetryPolicy DEFAULT;
525525
field public static final androidx.camera.core.RetryPolicy NEVER;
526526
field public static final androidx.camera.core.RetryPolicy RETRY_UNAVAILABLE_CAMERA;
@@ -542,20 +542,20 @@ package androidx.camera.core {
542542
field public static final int STATUS_UNKNOWN_ERROR = 0; // 0x0
543543
}
544544

545-
@SuppressCompatibility @androidx.camera.core.ExperimentalRetryPolicy public static final class RetryPolicy.RetryResponse {
545+
@SuppressCompatibility @androidx.camera.core.ExperimentalRetryPolicy public static final class RetryPolicy.RetryConfig {
546546
method public static long getDefaultRetryDelayInMillis();
547547
method public long getRetryDelayInMillis();
548548
method public boolean shouldRetry();
549-
field public static final androidx.camera.core.RetryPolicy.RetryResponse DEFAULT_DELAY_RETRY;
550-
field public static final androidx.camera.core.RetryPolicy.RetryResponse MINI_DELAY_RETRY;
551-
field public static final androidx.camera.core.RetryPolicy.RetryResponse NOT_RETRY;
549+
field public static final androidx.camera.core.RetryPolicy.RetryConfig DEFAULT_DELAY_RETRY;
550+
field public static final androidx.camera.core.RetryPolicy.RetryConfig MINI_DELAY_RETRY;
551+
field public static final androidx.camera.core.RetryPolicy.RetryConfig NOT_RETRY;
552552
}
553553

554-
@SuppressCompatibility @androidx.camera.core.ExperimentalRetryPolicy public static final class RetryPolicy.RetryResponse.Builder {
555-
ctor public RetryPolicy.RetryResponse.Builder();
556-
method public androidx.camera.core.RetryPolicy.RetryResponse build();
557-
method public androidx.camera.core.RetryPolicy.RetryResponse.Builder setRetryDelayInMillis(@IntRange(from=100, to=2000) long);
558-
method public androidx.camera.core.RetryPolicy.RetryResponse.Builder setShouldRetry(boolean);
554+
@SuppressCompatibility @androidx.camera.core.ExperimentalRetryPolicy public static final class RetryPolicy.RetryConfig.Builder {
555+
ctor public RetryPolicy.RetryConfig.Builder();
556+
method public androidx.camera.core.RetryPolicy.RetryConfig build();
557+
method public androidx.camera.core.RetryPolicy.RetryConfig.Builder setRetryDelayInMillis(@IntRange(from=100, to=2000) long);
558+
method public androidx.camera.core.RetryPolicy.RetryConfig.Builder setShouldRetry(boolean);
559559
}
560560

561561
@RequiresApi(21) public class SurfaceOrientedMeteringPointFactory extends androidx.camera.core.MeteringPointFactory {

Diff for: camera/camera-core/api/restricted_current.txt

+10-10
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ package androidx.camera.core {
520520
@SuppressCompatibility @RequiresApi(21) @androidx.camera.core.ExperimentalRetryPolicy public interface RetryPolicy {
521521
method public static long getDefaultRetryTimeoutInMillis();
522522
method public default long getTimeoutInMillis();
523-
method public androidx.camera.core.RetryPolicy.RetryResponse shouldRetry(androidx.camera.core.RetryPolicy.ExecutionState);
523+
method public androidx.camera.core.RetryPolicy.RetryConfig onRetryDecisionRequested(androidx.camera.core.RetryPolicy.ExecutionState);
524524
field public static final androidx.camera.core.RetryPolicy DEFAULT;
525525
field public static final androidx.camera.core.RetryPolicy NEVER;
526526
field public static final androidx.camera.core.RetryPolicy RETRY_UNAVAILABLE_CAMERA;
@@ -542,20 +542,20 @@ package androidx.camera.core {
542542
field public static final int STATUS_UNKNOWN_ERROR = 0; // 0x0
543543
}
544544

545-
@SuppressCompatibility @androidx.camera.core.ExperimentalRetryPolicy public static final class RetryPolicy.RetryResponse {
545+
@SuppressCompatibility @androidx.camera.core.ExperimentalRetryPolicy public static final class RetryPolicy.RetryConfig {
546546
method public static long getDefaultRetryDelayInMillis();
547547
method public long getRetryDelayInMillis();
548548
method public boolean shouldRetry();
549-
field public static final androidx.camera.core.RetryPolicy.RetryResponse DEFAULT_DELAY_RETRY;
550-
field public static final androidx.camera.core.RetryPolicy.RetryResponse MINI_DELAY_RETRY;
551-
field public static final androidx.camera.core.RetryPolicy.RetryResponse NOT_RETRY;
549+
field public static final androidx.camera.core.RetryPolicy.RetryConfig DEFAULT_DELAY_RETRY;
550+
field public static final androidx.camera.core.RetryPolicy.RetryConfig MINI_DELAY_RETRY;
551+
field public static final androidx.camera.core.RetryPolicy.RetryConfig NOT_RETRY;
552552
}
553553

554-
@SuppressCompatibility @androidx.camera.core.ExperimentalRetryPolicy public static final class RetryPolicy.RetryResponse.Builder {
555-
ctor public RetryPolicy.RetryResponse.Builder();
556-
method public androidx.camera.core.RetryPolicy.RetryResponse build();
557-
method public androidx.camera.core.RetryPolicy.RetryResponse.Builder setRetryDelayInMillis(@IntRange(from=100, to=2000) long);
558-
method public androidx.camera.core.RetryPolicy.RetryResponse.Builder setShouldRetry(boolean);
554+
@SuppressCompatibility @androidx.camera.core.ExperimentalRetryPolicy public static final class RetryPolicy.RetryConfig.Builder {
555+
ctor public RetryPolicy.RetryConfig.Builder();
556+
method public androidx.camera.core.RetryPolicy.RetryConfig build();
557+
method public androidx.camera.core.RetryPolicy.RetryConfig.Builder setRetryDelayInMillis(@IntRange(from=100, to=2000) long);
558+
method public androidx.camera.core.RetryPolicy.RetryConfig.Builder setShouldRetry(boolean);
559559
}
560560

561561
@RequiresApi(21) public class SurfaceOrientedMeteringPointFactory extends androidx.camera.core.MeteringPointFactory {

Diff for: camera/camera-core/src/main/java/androidx/camera/core/CameraX.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -350,20 +350,20 @@ private void initAndRetryRecursively(
350350
completer.set(null);
351351
} catch (CameraIdListIncorrectException | InitializationException
352352
| RuntimeException e) {
353-
RetryPolicy.RetryResponse response = mRetryPolicy.shouldRetry(
353+
RetryPolicy.RetryConfig retryConfig = mRetryPolicy.onRetryDecisionRequested(
354354
new CameraProviderExecutionState(startMs, attemptCount, e));
355-
if (response.shouldRetry() && attemptCount < Integer.MAX_VALUE) {
355+
if (retryConfig.shouldRetry() && attemptCount < Integer.MAX_VALUE) {
356356
Logger.w(TAG, "Retry init. Start time " + startMs + " current time "
357357
+ SystemClock.elapsedRealtime(), e);
358358
HandlerCompat.postDelayed(mSchedulerHandler, () -> initAndRetryRecursively(
359359
cameraExecutor, startMs, attemptCount + 1, mAppContext,
360-
completer), RETRY_TOKEN, response.getRetryDelayInMillis());
360+
completer), RETRY_TOKEN, retryConfig.getRetryDelayInMillis());
361361

362362
} else {
363363
synchronized (mInitializeLock) {
364364
mInitState = InternalInitState.INITIALIZING_ERROR;
365365
}
366-
if (response.shouldCompleteWithoutFailure()) {
366+
if (retryConfig.shouldCompleteWithoutFailure()) {
367367
// Ignoring camera failure for compatibility reasons. Initialization will
368368
// be marked as complete, but some camera features might be unavailable.
369369
setStateToInitialized();

Diff for: camera/camera-core/src/main/java/androidx/camera/core/RetryPolicy.java

+34-34
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,22 @@
7171
* if (executionState.getExecutedTimeInMillis() > 10000L
7272
* || executionState.getNumOfAttempts() > 10
7373
* || executionState.getStatus() == ExecutionState.STATUS_CONFIGURATION_FAIL) {
74-
* return RetryResponse.NOT_RETRY;
74+
* return RetryConfig.NOT_RETRY;
7575
* } else if (executionState.getStatus() == ExecutionState.STATUS_CAMERA_UNAVAILABLE) {
76-
* return RetryResponse.DEFAULT_DELAY_RETRY;
76+
* return RetryConfig.DEFAULT_DELAY_RETRY;
7777
* } else {
7878
* Log.d("CameraX", "Unknown error occur: " + executionState.getCause());
79-
* return RetryResponse.MINI_DELAY_RETRY;
79+
* return RetryConfig.MINI_DELAY_RETRY;
8080
* }
8181
* }).build());
8282
* ...
8383
* }</pre>
8484
* In the second example, the custom retry policy retries the initialization up to 10 times or
8585
* for a maximum of 10 seconds. If an unknown error occurs, the retry policy delays the next
86-
* retry after a delay defined by {@link RetryResponse#MINI_DELAY_RETRY}. The retry process
86+
* retry after a delay defined by {@link RetryConfig#MINI_DELAY_RETRY}. The retry process
8787
* stops if the status is {@link ExecutionState#STATUS_CONFIGURATION_FAIL}. For
8888
* {@link ExecutionState#STATUS_CAMERA_UNAVAILABLE}, the retry policy applies
89-
* {@link RetryResponse#DEFAULT_DELAY_RETRY}.
89+
* {@link RetryConfig#DEFAULT_DELAY_RETRY}.
9090
*/
9191
@RequiresApi(21) // TODO(b/200306659): Remove and replace with annotation on package-info.java
9292
@ExperimentalRetryPolicy
@@ -103,7 +103,7 @@ public interface RetryPolicy {
103103
* immediately halts the initialization upon encountering an error.
104104
*/
105105
@NonNull
106-
RetryPolicy NEVER = executionState -> RetryResponse.NOT_RETRY;
106+
RetryPolicy NEVER = executionState -> RetryConfig.NOT_RETRY;
107107

108108
/**
109109
* This retry policy increases initialization success by automatically retrying upon
@@ -154,13 +154,14 @@ static long getDefaultRetryTimeoutInMillis() {
154154
}
155155

156156
/**
157-
* Determines whether to retry the initialization.
157+
* Called to request a decision on whether to retry the initialization process.
158158
*
159-
* @param executionState The information about the execution state of the camera initialization.
160-
* @return A RetryResponse indicating whether to retry the initialization.
159+
* @param executionState Information about the current execution state of the camera
160+
* initialization.
161+
* @return A RetryConfig indicating whether to retry, along with any associated delay.
161162
*/
162163
@NonNull
163-
RetryResponse shouldRetry(@NonNull ExecutionState executionState);
164+
RetryConfig onRetryDecisionRequested(@NonNull ExecutionState executionState);
164165

165166
/**
166167
* Returns the maximum allowed retry duration in milliseconds. Initialization will
@@ -208,7 +209,7 @@ public Builder(@NonNull RetryPolicy basePolicy) {
208209

209210
/**
210211
* Sets a timeout in milliseconds. If retries exceed this duration, they will be
211-
* terminated with {@link RetryPolicy.RetryResponse#NOT_RETRY}.
212+
* terminated with {@link RetryConfig#NOT_RETRY}.
212213
*
213214
* @param timeoutInMillis The maximum duration for retries in milliseconds. A value of 0
214215
* indicates no timeout.
@@ -332,26 +333,26 @@ interface ExecutionState {
332333
* Represents the outcome of a {@link RetryPolicy} decision.
333334
*/
334335
@ExperimentalRetryPolicy
335-
final class RetryResponse {
336+
final class RetryConfig {
336337

337338
private static final long MINI_DELAY_MILLIS = 100L;
338339
private static final long DEFAULT_DELAY_MILLIS = 500L;
339340

340-
/** A RetryResponse indicating that no further retries should be attempted. */
341+
/** A RetryConfig indicating that no further retries should be attempted. */
341342
@NonNull
342-
public static final RetryResponse NOT_RETRY = new RetryResponse(false, 0L);
343+
public static final RetryConfig NOT_RETRY = new RetryConfig(false, 0L);
343344

344345
/**
345-
* A RetryResponse indicating that the initialization should be retried after the default
346+
* A RetryConfig indicating that the initialization should be retried after the default
346347
* delay (determined by {@link #getDefaultRetryDelayInMillis()}). This delay provides
347348
* sufficient time for typical device recovery processes, balancing retry efficiency
348349
* and minimizing user wait time.
349350
*/
350351
@NonNull
351-
public static final RetryResponse DEFAULT_DELAY_RETRY = new RetryResponse(true);
352+
public static final RetryConfig DEFAULT_DELAY_RETRY = new RetryConfig(true);
352353

353354
/**
354-
* A RetryResponse indicating that the initialization should be retried after a minimum
355+
* A RetryConfig indicating that the initialization should be retried after a minimum
355356
* delay of 100 milliseconds.
356357
*
357358
* This short delay serves two purposes:
@@ -365,18 +366,17 @@ final class RetryResponse {
365366
* fastest possible camera restoration.
366367
*/
367368
@NonNull
368-
public static final RetryResponse MINI_DELAY_RETRY = new RetryResponse(true,
369-
MINI_DELAY_MILLIS);
369+
public static final RetryConfig MINI_DELAY_RETRY = new RetryConfig(true, MINI_DELAY_MILLIS);
370370

371371
/**
372-
* A RetryResponse indicating that the initialization should be considered complete
373-
* without retrying. This response is intended for internal use and is not intended to
372+
* A RetryConfig indicating that the initialization should be considered complete
373+
* without retrying. This config is intended for internal use and is not intended to
374374
* trigger further retries. It represents the legacy behavior of not failing the
375375
* initialization task for minor issues.
376376
*/
377377
@RestrictTo(RestrictTo.Scope.LIBRARY)
378378
@NonNull
379-
public static RetryResponse COMPLETE_WITHOUT_FAILURE = new RetryResponse(false, 0, true);
379+
public static RetryConfig COMPLETE_WITHOUT_FAILURE = new RetryConfig(false, 0, true);
380380

381381
/**
382382
* Returns the recommended default delay to optimize retry attempts and camera recovery.
@@ -400,11 +400,11 @@ public static long getDefaultRetryDelayInMillis() {
400400
private final boolean mShouldRetry;
401401
private final boolean mCompleteWithoutFailure;
402402

403-
private RetryResponse(boolean shouldRetry) {
404-
this(shouldRetry, RetryResponse.getDefaultRetryDelayInMillis());
403+
private RetryConfig(boolean shouldRetry) {
404+
this(shouldRetry, RetryConfig.getDefaultRetryDelayInMillis());
405405
}
406406

407-
private RetryResponse(boolean shouldRetry, long delayInMillis) {
407+
private RetryConfig(boolean shouldRetry, long delayInMillis) {
408408
this(shouldRetry, delayInMillis, false);
409409
}
410410

@@ -420,7 +420,7 @@ private RetryResponse(boolean shouldRetry, long delayInMillis) {
420420
* When this flag is set to true, `shouldRetry` must be
421421
* false.
422422
*/
423-
private RetryResponse(boolean shouldRetry, long delayInMillis,
423+
private RetryConfig(boolean shouldRetry, long delayInMillis,
424424
boolean completeWithoutFailure) {
425425
mShouldRetry = shouldRetry;
426426
mDelayInMillis = delayInMillis;
@@ -452,7 +452,7 @@ public long getRetryDelayInMillis() {
452452
/**
453453
* Signals to treat initialization errors as successful for legacy behavior compatibility.
454454
*
455-
* <p>This response is intended for internal use and is not intended to trigger further
455+
* <p>This config is intended for internal use and is not intended to trigger further
456456
* retries.
457457
*
458458
* @return true if initialization should be deemed complete without additional retries,
@@ -464,17 +464,17 @@ public boolean shouldCompleteWithoutFailure() {
464464
}
465465

466466
/**
467-
* A builder class for creating and customizing {@link RetryResponse} objects.
467+
* A builder class for creating and customizing {@link RetryConfig} objects.
468468
*
469-
* <p>While predefined responses like {@link RetryResponse#DEFAULT_DELAY_RETRY} are
469+
* <p>While predefined configs like {@link RetryConfig#DEFAULT_DELAY_RETRY} are
470470
* recommended for typical recovery scenarios, this builder allows for fine-tuned control
471471
* when specific requirements necessitate a different approach.
472472
*/
473473
@ExperimentalRetryPolicy
474474
public static final class Builder {
475475

476476
private boolean mShouldRetry = true;
477-
private long mTimeoutInMillis = RetryResponse.getDefaultRetryDelayInMillis();
477+
private long mTimeoutInMillis = RetryConfig.getDefaultRetryDelayInMillis();
478478

479479
/**
480480
* Specifies whether a retry should be attempted.
@@ -508,13 +508,13 @@ public Builder setRetryDelayInMillis(
508508
}
509509

510510
/**
511-
* Builds the customized {@link RetryResponse} object.
511+
* Builds the customized {@link RetryConfig} object.
512512
*
513-
* @return The configured RetryResponse.
513+
* @return The configured RetryConfig.
514514
*/
515515
@NonNull
516-
public RetryResponse build() {
517-
return new RetryResponse(mShouldRetry, mTimeoutInMillis);
516+
public RetryConfig build() {
517+
return new RetryConfig(mShouldRetry, mTimeoutInMillis);
518518
}
519519
}
520520
}

0 commit comments

Comments
 (0)