Skip to content

Commit bec32df

Browse files
committed
Address Kai's feedback
1 parent 10ea377 commit bec32df

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import android.app.Activity;
1818
import android.content.Intent;
1919
import androidx.annotation.Nullable;
20+
import androidx.annotation.VisibleForTesting;
2021
import com.google.android.gms.tasks.Task;
2122
import com.google.android.gms.tasks.TaskCompletionSource;
2223
import com.google.firebase.annotations.concurrent.Lightweight;
@@ -32,6 +33,7 @@ class ApkInstaller {
3233
private final TaskCompletionSourceCache<Void> installTaskCompletionSourceCache;
3334
private final @Lightweight Executor lightweightExecutor;
3435

36+
@VisibleForTesting
3537
ApkInstaller(
3638
FirebaseAppDistributionLifecycleNotifier lifeCycleNotifier,
3739
@Lightweight Executor lightweightExecutor) {
@@ -49,7 +51,10 @@ void onActivityDestroyed(@Nullable Activity activity) {
4951
if (activity instanceof InstallActivity) {
5052
// Since install activity is destroyed but app is still active, installation has failed /
5153
// cancelled.
52-
this.trySetInstallTaskError();
54+
installTaskCompletionSourceCache.setException(
55+
new FirebaseAppDistributionException(
56+
ErrorMessages.APK_INSTALLATION_FAILED,
57+
FirebaseAppDistributionException.Status.INSTALLATION_FAILURE));
5358
}
5459
}
5560

@@ -67,11 +72,4 @@ private void startInstallActivity(String path, Activity currentActivity) {
6772
currentActivity.startActivity(intent);
6873
LogWrapper.v(TAG, "Prompting tester with install activity");
6974
}
70-
71-
void trySetInstallTaskError() {
72-
installTaskCompletionSourceCache.setException(
73-
new FirebaseAppDistributionException(
74-
ErrorMessages.APK_INSTALLATION_FAILED,
75-
FirebaseAppDistributionException.Status.INSTALLATION_FAILURE));
76-
}
7775
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ interface TaskCompletionSourceProducer<T> {
4343
* Constructor for a {@link TaskCompletionSourceCache} that controls access using its own
4444
* sequential executor backed by the given base executor.
4545
*
46-
* @param baseExecutor Executor (typically {@link Lightweight}) to back the sequential executor.
46+
* @param baseExecutor Executor to back the sequential executor. This can be a {@link Lightweight}
47+
* executor unless the {@link TaskCompletionSourceProducer} passed to {@link
48+
* #getOrCreateTaskFromCompletionSource} needs to be executed on a different executor.
4749
*/
4850
TaskCompletionSourceCache(Executor baseExecutor) {
4951
sequentialExecutor = FirebaseExecutors.newSequentialExecutor(baseExecutor);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ static <T> UpdateTask onSuccessUpdateTask(
147147

148148
/** Set a {@link TaskCompletionSource} to be resolved with the result of another {@link Task}. */
149149
static <T> void shadowTask(TaskCompletionSource<T> taskCompletionSource, Task<T> task) {
150+
// Using direct executor here ensures that any handlers that were themselves added using a
151+
// direct executor will behave as expected: they'll be executed on the thread that sets the
152+
// result.
150153
task.addOnSuccessListener(FirebaseExecutors.directExecutor(), taskCompletionSource::setResult)
151154
.addOnFailureListener(
152155
FirebaseExecutors.directExecutor(), taskCompletionSource::setException);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ void updateProgress(@NonNull UpdateProgress updateProgress) {
7070
* progress or completing this task with the same changes.
7171
*/
7272
void shadow(UpdateTask updateTask) {
73+
// Using direct executor here ensures that any handlers that were themselves added using a
74+
// direct executor will behave as expected: they'll be executed on the thread that sets the
75+
// result or updates progress.
7376
updateTask
7477
.addOnProgressListener(FirebaseExecutors.directExecutor(), this::updateProgress)
7578
.addOnSuccessListener(FirebaseExecutors.directExecutor(), unused -> this.setResult())

0 commit comments

Comments
 (0)