Skip to content

Commit de52e94

Browse files
committed
Only allow one feedback flow to be active
1 parent d91d9aa commit de52e94

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import com.google.firebase.appdistribution.UpdateStatus;
4747
import com.google.firebase.appdistribution.UpdateTask;
4848
import java.util.concurrent.Executor;
49+
import java.util.concurrent.atomic.AtomicBoolean;
4950

5051
/**
5152
* This class is the "real" implementation of the Firebase App Distribution API which should only be
@@ -87,6 +88,8 @@ class FirebaseAppDistributionImpl implements FirebaseAppDistribution {
8788
private TaskCompletionSource<Void> showSignInDialogTask = null;
8889
private TaskCompletionSource<Void> showUpdateDialogTask = null;
8990

91+
private AtomicBoolean feedbackInProgress = new AtomicBoolean(false);
92+
9093
@VisibleForTesting
9194
FirebaseAppDistributionImpl(
9295
@NonNull FirebaseApp firebaseApp,
@@ -318,6 +321,12 @@ public void startFeedback(int infoTextResourceId) {
318321

319322
@Override
320323
public void startFeedback(@NonNull CharSequence infoText) {
324+
if (!feedbackInProgress.compareAndSet(/* expect= */ false, /* update= */ true)) {
325+
LogWrapper.getInstance()
326+
.i("Ignoring startFeedback() call because feedback is already in progress");
327+
return;
328+
}
329+
LogWrapper.getInstance().i("Starting feedback");
321330
screenshotTaker
322331
.takeScreenshot()
323332
.addOnFailureListener(
@@ -349,7 +358,10 @@ public void startFeedback(@NonNull CharSequence infoText, @Nullable Uri screensh
349358
taskExecutor,
350359
releaseName -> launchFeedbackActivity(releaseName, infoText, screenshotUri))
351360
.addOnFailureListener(
352-
taskExecutor, e -> LogWrapper.getInstance().e("Failed to launch feedback flow", e));
361+
e -> {
362+
LogWrapper.getInstance().e("Failed to launch feedback flow", e);
363+
feedbackInProgress.set(false);
364+
});
353365
}
354366

355367
private Task<Void> launchFeedbackActivity(
@@ -412,10 +424,13 @@ void onActivityDestroyed(@NonNull Activity activity) {
412424
dialogHostActivity = null;
413425
}
414426

415-
// If the feedback activity finishes, clean up the screenshot that was taken before starting
416-
// the activity. If this does not happen for some reason it will be cleaned up the next time
417-
// before taking a new screenshot.
418427
if (activity instanceof FeedbackActivity) {
428+
LogWrapper.getInstance().i("FeedbackActivity destroyed");
429+
feedbackInProgress.set(false);
430+
431+
// If the feedback activity finishes, clean up the screenshot that was taken before starting
432+
// the activity. If this does not happen for some reason it will be cleaned up the next time
433+
// before taking a new screenshot.
419434
screenshotTaker.deleteScreenshot();
420435
}
421436
}

0 commit comments

Comments
 (0)