Skip to content

Commit e1bd329

Browse files
committed
Incorporate some feedback
1 parent 0b6a977 commit e1bd329

File tree

3 files changed

+15
-31
lines changed

3 files changed

+15
-31
lines changed

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/impl/FirebaseAppDistributionImpl.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.google.android.gms.tasks.TaskCompletionSource;
3333
import com.google.android.gms.tasks.Tasks;
3434
import com.google.firebase.FirebaseApp;
35+
import com.google.firebase.annotations.concurrent.Lightweight;
3536
import com.google.firebase.appdistribution.AppDistributionRelease;
3637
import com.google.firebase.appdistribution.BinaryType;
3738
import com.google.firebase.appdistribution.FirebaseAppDistribution;
@@ -40,7 +41,6 @@
4041
import com.google.firebase.appdistribution.UpdateProgress;
4142
import com.google.firebase.appdistribution.UpdateStatus;
4243
import com.google.firebase.appdistribution.UpdateTask;
43-
import com.google.firebase.concurrent.FirebaseExecutors;
4444
import java.util.concurrent.Executor;
4545

4646
/**
@@ -61,7 +61,7 @@ class FirebaseAppDistributionImpl implements FirebaseAppDistribution {
6161
private final SequentialReference<AppDistributionReleaseInternal> cachedNewRelease;
6262
private TaskCache<UpdateTask> updateIfNewReleaseAvailableTaskCache = new TaskCache<>();
6363
private TaskCache<Task<AppDistributionRelease>> checkForNewReleaseTaskCache = new TaskCache<>();
64-
private Executor lightweightExecutor;
64+
@Lightweight private Executor lightweightExecutor;
6565
private AlertDialog updateConfirmationDialog;
6666
private AlertDialog signInConfirmationDialog;
6767
@Nullable private Activity dialogHostActivity = null;
@@ -81,15 +81,15 @@ class FirebaseAppDistributionImpl implements FirebaseAppDistribution {
8181
@NonNull AabUpdater aabUpdater,
8282
@NonNull SignInStorage signInStorage,
8383
@NonNull FirebaseAppDistributionLifecycleNotifier lifecycleNotifier,
84-
@NonNull Executor lightweightExecutor) {
84+
@NonNull @Lightweight Executor lightweightExecutor) {
8585
this.firebaseApp = firebaseApp;
8686
this.testerSignInManager = testerSignInManager;
8787
this.newReleaseFetcher = newReleaseFetcher;
8888
this.apkUpdater = apkUpdater;
8989
this.aabUpdater = aabUpdater;
9090
this.signInStorage = signInStorage;
9191
this.lifecycleNotifier = lifecycleNotifier;
92-
this.cachedNewRelease = SequentialReference.withBaseExecutor(lightweightExecutor);
92+
this.cachedNewRelease = new SequentialReference<>(lightweightExecutor);
9393
this.lightweightExecutor = lightweightExecutor;
9494
lifecycleNotifier.addOnActivityDestroyedListener(this::onActivityDestroyed);
9595
lifecycleNotifier.addOnActivityPausedListener(this::onActivityPaused);
@@ -220,8 +220,7 @@ public Task<Void> signInTester() {
220220
public void signOutTester() {
221221
cachedNewRelease
222222
.set(null)
223-
.addOnSuccessListener(
224-
FirebaseExecutors.directExecutor(), unused -> signInStorage.setSignInStatus(false));
223+
.addOnSuccessListener(lightweightExecutor, unused -> signInStorage.setSignInStatus(false));
225224
}
226225

227226
@Override
@@ -240,7 +239,7 @@ public synchronized Task<AppDistributionRelease> checkForNewRelease() {
240239
.checkForNewRelease()
241240
.onSuccessTask(lightweightExecutor, release -> cachedNewRelease.set(release))
242241
.onSuccessTask(
243-
FirebaseExecutors.directExecutor(),
242+
lightweightExecutor,
244243
release ->
245244
Tasks.forResult(ReleaseUtils.convertToAppDistributionRelease(release)))
246245
.addOnFailureListener(

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/impl/SequentialReference.java

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
package com.google.firebase.appdistribution.impl;
1616

17-
import androidx.annotation.VisibleForTesting;
18-
import com.google.android.gms.tasks.OnSuccessListener;
1917
import com.google.android.gms.tasks.Task;
2018
import com.google.android.gms.tasks.TaskCompletionSource;
2119
import com.google.firebase.concurrent.FirebaseExecutors;
@@ -30,21 +28,12 @@ class SequentialReference<T> {
3028
private final Executor sequentialExecutor;
3129
private T value;
3230

33-
/** Get a {@link SequentialReference} that controls access uses the given sequential executor. */
34-
static SequentialReference withSequentialExecutor(Executor sequentialExecutor) {
35-
return new SequentialReference(sequentialExecutor);
36-
}
37-
3831
/**
39-
* Get a {@link SequentialReference} that controls access using its own sequential executor backed
40-
* by the given base executor.
32+
* Constructor for a {@link SequentialReference} that controls access using its own sequential
33+
* executor backed by the given base executor.
4134
*/
42-
static SequentialReference withBaseExecutor(Executor baseExecutor) {
43-
return new SequentialReference(FirebaseExecutors.newSequentialExecutor(baseExecutor));
44-
}
45-
46-
private SequentialReference(Executor sequentialExecutor) {
47-
this.sequentialExecutor = sequentialExecutor;
35+
SequentialReference(Executor baseExecutor) {
36+
this.sequentialExecutor = FirebaseExecutors.newSequentialExecutor(baseExecutor);
4837
}
4938

5039
/**
@@ -65,18 +54,12 @@ Task<T> set(T newValue) {
6554
/**
6655
* Gets a {@link Task} that will complete with the value.
6756
*
68-
* <p>Unless a direct executer is passed to {@link Task#addOnSuccessListener(Executor,
69-
* OnSuccessListener)} or similar methods, be aware that the value may have changed by the time it
70-
* is used.
57+
* <p>In some cases the value may have changed by the time any callbacks attached to the returned
58+
* {@link Task} are called.
7159
*/
7260
Task<T> get() {
7361
TaskCompletionSource<T> taskCompletionSource = new TaskCompletionSource<>();
7462
sequentialExecutor.execute(() -> taskCompletionSource.setResult(value));
7563
return taskCompletionSource.getTask();
7664
}
77-
78-
@VisibleForTesting
79-
T getSnapshot() {
80-
return value;
81-
}
8265
}

firebase-appdistribution/src/test/java/com/google/firebase/appdistribution/impl/FirebaseAppDistributionServiceImplTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,9 @@ public void checkForNewRelease_whenCheckForNewReleaseSucceeds_returnsRelease()
221221
awaitTask(task);
222222

223223
assertEquals(TEST_RELEASE_NEWER_AAB, task.getResult());
224-
assertEquals(internalRelease, firebaseAppDistribution.getCachedNewRelease().getSnapshot());
224+
AppDistributionReleaseInternal cachedNewRelease =
225+
awaitTask(firebaseAppDistribution.getCachedNewRelease().get());
226+
assertEquals(internalRelease, cachedNewRelease);
225227
}
226228

227229
@Test

0 commit comments

Comments
 (0)