71
71
* if (executionState.getExecutedTimeInMillis() > 10000L
72
72
* || executionState.getNumOfAttempts() > 10
73
73
* || executionState.getStatus() == ExecutionState.STATUS_CONFIGURATION_FAIL) {
74
- * return RetryResponse .NOT_RETRY;
74
+ * return RetryConfig .NOT_RETRY;
75
75
* } else if (executionState.getStatus() == ExecutionState.STATUS_CAMERA_UNAVAILABLE) {
76
- * return RetryResponse .DEFAULT_DELAY_RETRY;
76
+ * return RetryConfig .DEFAULT_DELAY_RETRY;
77
77
* } else {
78
78
* Log.d("CameraX", "Unknown error occur: " + executionState.getCause());
79
- * return RetryResponse .MINI_DELAY_RETRY;
79
+ * return RetryConfig .MINI_DELAY_RETRY;
80
80
* }
81
81
* }).build());
82
82
* ...
83
83
* }</pre>
84
84
* In the second example, the custom retry policy retries the initialization up to 10 times or
85
85
* 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
87
87
* stops if the status is {@link ExecutionState#STATUS_CONFIGURATION_FAIL}. For
88
88
* {@link ExecutionState#STATUS_CAMERA_UNAVAILABLE}, the retry policy applies
89
- * {@link RetryResponse #DEFAULT_DELAY_RETRY}.
89
+ * {@link RetryConfig #DEFAULT_DELAY_RETRY}.
90
90
*/
91
91
@ RequiresApi (21 ) // TODO(b/200306659): Remove and replace with annotation on package-info.java
92
92
@ ExperimentalRetryPolicy
@@ -103,7 +103,7 @@ public interface RetryPolicy {
103
103
* immediately halts the initialization upon encountering an error.
104
104
*/
105
105
@ NonNull
106
- RetryPolicy NEVER = executionState -> RetryResponse .NOT_RETRY ;
106
+ RetryPolicy NEVER = executionState -> RetryConfig .NOT_RETRY ;
107
107
108
108
/**
109
109
* This retry policy increases initialization success by automatically retrying upon
@@ -154,13 +154,14 @@ static long getDefaultRetryTimeoutInMillis() {
154
154
}
155
155
156
156
/**
157
- * Determines whether to retry the initialization.
157
+ * Called to request a decision on whether to retry the initialization process .
158
158
*
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.
161
162
*/
162
163
@ NonNull
163
- RetryResponse shouldRetry (@ NonNull ExecutionState executionState );
164
+ RetryConfig onRetryDecisionRequested (@ NonNull ExecutionState executionState );
164
165
165
166
/**
166
167
* Returns the maximum allowed retry duration in milliseconds. Initialization will
@@ -208,7 +209,7 @@ public Builder(@NonNull RetryPolicy basePolicy) {
208
209
209
210
/**
210
211
* 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}.
212
213
*
213
214
* @param timeoutInMillis The maximum duration for retries in milliseconds. A value of 0
214
215
* indicates no timeout.
@@ -332,26 +333,26 @@ interface ExecutionState {
332
333
* Represents the outcome of a {@link RetryPolicy} decision.
333
334
*/
334
335
@ ExperimentalRetryPolicy
335
- final class RetryResponse {
336
+ final class RetryConfig {
336
337
337
338
private static final long MINI_DELAY_MILLIS = 100L ;
338
339
private static final long DEFAULT_DELAY_MILLIS = 500L ;
339
340
340
- /** A RetryResponse indicating that no further retries should be attempted. */
341
+ /** A RetryConfig indicating that no further retries should be attempted. */
341
342
@ NonNull
342
- public static final RetryResponse NOT_RETRY = new RetryResponse (false , 0L );
343
+ public static final RetryConfig NOT_RETRY = new RetryConfig (false , 0L );
343
344
344
345
/**
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
346
347
* delay (determined by {@link #getDefaultRetryDelayInMillis()}). This delay provides
347
348
* sufficient time for typical device recovery processes, balancing retry efficiency
348
349
* and minimizing user wait time.
349
350
*/
350
351
@ NonNull
351
- public static final RetryResponse DEFAULT_DELAY_RETRY = new RetryResponse (true );
352
+ public static final RetryConfig DEFAULT_DELAY_RETRY = new RetryConfig (true );
352
353
353
354
/**
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
355
356
* delay of 100 milliseconds.
356
357
*
357
358
* This short delay serves two purposes:
@@ -365,18 +366,17 @@ final class RetryResponse {
365
366
* fastest possible camera restoration.
366
367
*/
367
368
@ 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 );
370
370
371
371
/**
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
374
374
* trigger further retries. It represents the legacy behavior of not failing the
375
375
* initialization task for minor issues.
376
376
*/
377
377
@ RestrictTo (RestrictTo .Scope .LIBRARY )
378
378
@ 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 );
380
380
381
381
/**
382
382
* Returns the recommended default delay to optimize retry attempts and camera recovery.
@@ -400,11 +400,11 @@ public static long getDefaultRetryDelayInMillis() {
400
400
private final boolean mShouldRetry ;
401
401
private final boolean mCompleteWithoutFailure ;
402
402
403
- private RetryResponse (boolean shouldRetry ) {
404
- this (shouldRetry , RetryResponse .getDefaultRetryDelayInMillis ());
403
+ private RetryConfig (boolean shouldRetry ) {
404
+ this (shouldRetry , RetryConfig .getDefaultRetryDelayInMillis ());
405
405
}
406
406
407
- private RetryResponse (boolean shouldRetry , long delayInMillis ) {
407
+ private RetryConfig (boolean shouldRetry , long delayInMillis ) {
408
408
this (shouldRetry , delayInMillis , false );
409
409
}
410
410
@@ -420,7 +420,7 @@ private RetryResponse(boolean shouldRetry, long delayInMillis) {
420
420
* When this flag is set to true, `shouldRetry` must be
421
421
* false.
422
422
*/
423
- private RetryResponse (boolean shouldRetry , long delayInMillis ,
423
+ private RetryConfig (boolean shouldRetry , long delayInMillis ,
424
424
boolean completeWithoutFailure ) {
425
425
mShouldRetry = shouldRetry ;
426
426
mDelayInMillis = delayInMillis ;
@@ -452,7 +452,7 @@ public long getRetryDelayInMillis() {
452
452
/**
453
453
* Signals to treat initialization errors as successful for legacy behavior compatibility.
454
454
*
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
456
456
* retries.
457
457
*
458
458
* @return true if initialization should be deemed complete without additional retries,
@@ -464,17 +464,17 @@ public boolean shouldCompleteWithoutFailure() {
464
464
}
465
465
466
466
/**
467
- * A builder class for creating and customizing {@link RetryResponse } objects.
467
+ * A builder class for creating and customizing {@link RetryConfig } objects.
468
468
*
469
- * <p>While predefined responses like {@link RetryResponse #DEFAULT_DELAY_RETRY} are
469
+ * <p>While predefined configs like {@link RetryConfig #DEFAULT_DELAY_RETRY} are
470
470
* recommended for typical recovery scenarios, this builder allows for fine-tuned control
471
471
* when specific requirements necessitate a different approach.
472
472
*/
473
473
@ ExperimentalRetryPolicy
474
474
public static final class Builder {
475
475
476
476
private boolean mShouldRetry = true ;
477
- private long mTimeoutInMillis = RetryResponse .getDefaultRetryDelayInMillis ();
477
+ private long mTimeoutInMillis = RetryConfig .getDefaultRetryDelayInMillis ();
478
478
479
479
/**
480
480
* Specifies whether a retry should be attempted.
@@ -508,13 +508,13 @@ public Builder setRetryDelayInMillis(
508
508
}
509
509
510
510
/**
511
- * Builds the customized {@link RetryResponse } object.
511
+ * Builds the customized {@link RetryConfig } object.
512
512
*
513
- * @return The configured RetryResponse .
513
+ * @return The configured RetryConfig .
514
514
*/
515
515
@ NonNull
516
- public RetryResponse build () {
517
- return new RetryResponse (mShouldRetry , mTimeoutInMillis );
516
+ public RetryConfig build () {
517
+ return new RetryConfig (mShouldRetry , mTimeoutInMillis );
518
518
}
519
519
}
520
520
}
0 commit comments