Skip to content

Commit ec07e81

Browse files
committed
Migrate executors in fad/in-app-feedback
1 parent 56e2e2d commit ec07e81

File tree

4 files changed

+28
-30
lines changed

4 files changed

+28
-30
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class FirebaseAppDistributionImpl implements FirebaseAppDistribution {
6868
private final SequentialReference<AppDistributionReleaseInternal> cachedNewRelease;
6969
private final ReleaseIdentifier releaseIdentifier;
7070
private final ScreenshotTaker screenshotTaker;
71-
private final Executor taskExecutor;
71+
private final Executor blockingExecutor;
7272
private final FirebaseAppDistributionNotificationsManager notificationsManager;
7373
private TaskCache<UpdateTask> updateIfNewReleaseAvailableTaskCache = new TaskCache<>();
7474
private TaskCache<Task<AppDistributionRelease>> checkForNewReleaseTaskCache = new TaskCache<>();
@@ -94,7 +94,7 @@ class FirebaseAppDistributionImpl implements FirebaseAppDistribution {
9494
@NonNull ReleaseIdentifier releaseIdentifier,
9595
@NonNull ScreenshotTaker screenshotTaker,
9696
@NonNull @Lightweight Executor lightweightExecutor,
97-
@NonNull Executor taskExecutor) {
97+
@NonNull Executor blockingExecutor) {
9898
this.firebaseApp = firebaseApp;
9999
this.testerSignInManager = testerSignInManager;
100100
this.newReleaseFetcher = newReleaseFetcher;
@@ -106,7 +106,7 @@ class FirebaseAppDistributionImpl implements FirebaseAppDistribution {
106106
this.cachedNewRelease = new SequentialReference<>(lightweightExecutor);
107107
this.lightweightExecutor = lightweightExecutor;
108108
this.screenshotTaker = screenshotTaker;
109-
this.taskExecutor = taskExecutor;
109+
this.blockingExecutor = blockingExecutor;
110110
this.notificationsManager =
111111
new FirebaseAppDistributionNotificationsManager(firebaseApp.getApplicationContext());
112112
lifecycleNotifier.addOnActivityDestroyedListener(this::onActivityDestroyed);
@@ -332,13 +332,13 @@ public void startFeedback(@NonNull CharSequence infoText) {
332332
screenshotTaker
333333
.takeScreenshot()
334334
.addOnFailureListener(
335-
taskExecutor,
335+
blockingExecutor,
336336
e -> {
337337
LogWrapper.w(TAG, "Failed to take screenshot for feedback", e);
338338
doStartFeedback(infoText, null);
339339
})
340340
.addOnSuccessListener(
341-
taskExecutor, screenshotUri -> doStartFeedback(infoText, screenshotUri));
341+
blockingExecutor, screenshotUri -> doStartFeedback(infoText, screenshotUri));
342342
}
343343

344344
@Override
@@ -378,17 +378,18 @@ private void doStartFeedback(CharSequence infoText, @Nullable Uri screenshotUri)
378378
testerSignInManager
379379
.signInTester()
380380
.addOnFailureListener(
381-
taskExecutor,
381+
blockingExecutor,
382382
e -> {
383383
feedbackInProgress.set(false);
384384
LogWrapper.e(TAG, "Failed to sign in tester. Could not collect feedback.", e);
385385
})
386386
.onSuccessTask(
387-
taskExecutor,
387+
blockingExecutor,
388388
unused ->
389389
releaseIdentifier
390390
.identifyRelease()
391391
.addOnFailureListener(
392+
blockingExecutor,
392393
e -> {
393394
feedbackInProgress.set(false);
394395
LogWrapper.e(TAG, "Failed to identify release", e);
@@ -399,11 +400,12 @@ private void doStartFeedback(CharSequence infoText, @Nullable Uri screenshotUri)
399400
.show();
400401
})
401402
.onSuccessTask(
402-
taskExecutor,
403+
blockingExecutor,
403404
releaseName ->
404405
// in development-mode the releaseName might be null
405406
launchFeedbackActivity(releaseName, infoText, screenshotUri)
406407
.addOnFailureListener(
408+
blockingExecutor,
407409
e -> {
408410
feedbackInProgress.set(false);
409411
LogWrapper.e(TAG, "Failed to launch feedback flow", e);

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import androidx.annotation.Keep;
2121
import androidx.annotation.NonNull;
2222
import com.google.firebase.FirebaseApp;
23+
import com.google.firebase.annotations.concurrent.Background;
2324
import com.google.firebase.annotations.concurrent.Blocking;
2425
import com.google.firebase.annotations.concurrent.Lightweight;
2526
import com.google.firebase.appdistribution.FirebaseAppDistribution;
@@ -34,10 +35,9 @@
3435
import java.util.Arrays;
3536
import java.util.List;
3637
import java.util.concurrent.Executor;
37-
import java.util.concurrent.Executors;
3838

3939
/**
40-
* Registers FirebaseAppDistribution.
40+
* Registers FirebaseAppDistribution and related components.
4141
*
4242
* @hide
4343
*/
@@ -49,6 +49,7 @@ public class FirebaseAppDistributionRegistrar implements ComponentRegistrar {
4949

5050
@Override
5151
public @NonNull List<Component<?>> getComponents() {
52+
Qualified<Executor> backgroundExecutor = Qualified.qualified(Background.class, Executor.class);
5253
Qualified<Executor> blockingExecutor = Qualified.qualified(Blocking.class, Executor.class);
5354
Qualified<Executor> lightweightExecutor =
5455
Qualified.qualified(Lightweight.class, Executor.class);
@@ -57,16 +58,18 @@ public class FirebaseAppDistributionRegistrar implements ComponentRegistrar {
5758
.name(LIBRARY_NAME)
5859
.add(Dependency.required(FirebaseApp.class))
5960
.add(Dependency.requiredProvider(FirebaseInstallationsApi.class))
61+
.add(Dependency.required(backgroundExecutor))
6062
.add(Dependency.required(blockingExecutor))
6163
.add(Dependency.required(lightweightExecutor))
62-
.factory(c -> buildFirebaseAppDistribution(c, blockingExecutor, lightweightExecutor))
64+
.factory(c -> buildFirebaseAppDistribution(c, backgroundExecutor, blockingExecutor, lightweightExecutor))
6365
// construct FirebaseAppDistribution instance on startup so we can register for
6466
// activity lifecycle callbacks before the API is called
6567
.alwaysEager()
6668
.build(),
6769
Component.builder(FeedbackSender.class)
6870
.add(Dependency.required(FirebaseApp.class))
6971
.add(Dependency.requiredProvider(FirebaseInstallationsApi.class))
72+
.add(Dependency.required(backgroundExecutor))
7073
.add(Dependency.required(blockingExecutor))
7174
.factory(c -> buildFeedbackSender(c, c.get(blockingExecutor)))
7275
.build(),
@@ -87,13 +90,13 @@ private FeedbackSender buildFeedbackSender(
8790
return new FeedbackSender(testerApiClient, blockingExecutor);
8891
}
8992

90-
// TODO(b/258264924): Migrate to go/firebase-android-executors
91-
@SuppressLint("ThreadPoolCreation")
9293
private FirebaseAppDistribution buildFirebaseAppDistribution(
9394
ComponentContainer container,
95+
Qualified<Executor> backgroundExecutorType,
9496
Qualified<Executor> blockingExecutorType,
9597
Qualified<Executor> lightweightExecutorType) {
9698
FirebaseApp firebaseApp = container.get(FirebaseApp.class);
99+
Executor backgroundExecutor = container.get(backgroundExecutorType);
97100
Executor blockingExecutor = container.get(blockingExecutorType);
98101
Executor lightweightExecutor = container.get(lightweightExecutorType);
99102
Context context = firebaseApp.getApplicationContext();
@@ -120,9 +123,9 @@ private FirebaseAppDistribution buildFirebaseAppDistribution(
120123
signInStorage,
121124
lifecycleNotifier,
122125
releaseIdentifier,
123-
new ScreenshotTaker(firebaseApp, lifecycleNotifier),
126+
new ScreenshotTaker(firebaseApp, lifecycleNotifier, backgroundExecutor),
124127
lightweightExecutor,
125-
Executors.newSingleThreadExecutor());
128+
blockingExecutor);
126129

127130
if (context instanceof Application) {
128131
Application firebaseApplication = (Application) context;

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

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

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

17-
import android.annotation.SuppressLint;
1817
import android.annotation.TargetApi;
1918
import android.app.Activity;
2019
import android.content.Context;
@@ -37,7 +36,6 @@
3736
import java.io.FileOutputStream;
3837
import java.io.IOException;
3938
import java.util.concurrent.Executor;
40-
import java.util.concurrent.Executors;
4139

4240
/** A class that takes screenshots of the host app. */
4341
class ScreenshotTaker {
@@ -47,23 +45,15 @@ class ScreenshotTaker {
4745

4846
private final FirebaseApp firebaseApp;
4947
private final FirebaseAppDistributionLifecycleNotifier lifecycleNotifier;
50-
private final Executor taskExecutor;
48+
private final Executor backgroundExecutor;
5149

52-
// TODO(b/258264924): Migrate to go/firebase-android-executors
53-
@SuppressLint("ThreadPoolCreation")
54-
ScreenshotTaker(
55-
FirebaseApp firebaseApp, FirebaseAppDistributionLifecycleNotifier lifecycleNotifier) {
56-
this(firebaseApp, lifecycleNotifier, Executors.newSingleThreadExecutor());
57-
}
58-
59-
@VisibleForTesting
6050
ScreenshotTaker(
6151
FirebaseApp firebaseApp,
6252
FirebaseAppDistributionLifecycleNotifier lifecycleNotifier,
63-
Executor taskExecutor) {
53+
Executor backgroundExecutor) {
6454
this.firebaseApp = firebaseApp;
6555
this.lifecycleNotifier = lifecycleNotifier;
66-
this.taskExecutor = taskExecutor;
56+
this.backgroundExecutor = backgroundExecutor;
6757
}
6858

6959
/**
@@ -83,7 +73,7 @@ Task<Uri> takeScreenshot() {
8373
/** Deletes any previously taken screenshot. */
8474
Task<Void> deleteScreenshot() {
8575
return TaskUtils.runAsyncInTask(
86-
taskExecutor,
76+
backgroundExecutor,
8777
() -> {
8878
firebaseApp.getApplicationContext().deleteFile(SCREENSHOT_FILE_NAME);
8979
return null;
@@ -159,7 +149,7 @@ private Task<Uri> writeToFile(@Nullable Bitmap bitmap) {
159149
return Tasks.forResult(null);
160150
}
161151
return TaskUtils.runAsyncInTask(
162-
taskExecutor,
152+
backgroundExecutor,
163153
() -> {
164154
try (FileOutputStream outputStream = openFileOutputStream()) {
165155
// PNG is a lossless format, the compression factor (100) is ignored

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class SignInStorage {
3030
this.signInSharedPreferences =
3131
new Lazy(
3232
() ->
33+
// TODO(lkellogg): This constructs a SharedPreferences object, which touches disk
34+
// and therefore should be run on a @Background executor. This could ideally be
35+
// done by a new shared component.
3336
applicationContext.getSharedPreferences(
3437
SIGNIN_PREFERENCES_NAME, Context.MODE_PRIVATE));
3538
}

0 commit comments

Comments
 (0)