Skip to content

Commit 1624ecf

Browse files
committed
Handle the case where we can't identify the release.
1 parent e1fe640 commit 1624ecf

File tree

4 files changed

+55
-13
lines changed

4 files changed

+55
-13
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ private Bitmap readScreenshot() {
112112
}
113113

114114
public void submitFeedback(View view) {
115+
if (releaseName == null) {
116+
Toast.makeText(this, R.string.feedback_no_release, Toast.LENGTH_LONG).show();
117+
finish();
118+
return;
119+
}
115120
setSubmittingStateEnabled(true);
116121
EditText feedbackText = findViewById(R.id.feedbackText);
117122
CheckBox screenshotCheckBox = findViewById(R.id.screenshotCheckBox);

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import android.content.Context;
2727
import android.content.Intent;
2828
import android.net.Uri;
29+
import android.widget.Toast;
2930
import androidx.annotation.GuardedBy;
3031
import androidx.annotation.NonNull;
3132
import androidx.annotation.Nullable;
@@ -313,8 +314,6 @@ private UpdateTask updateApp(boolean showDownloadInNotificationManager) {
313314

314315
@Override
315316
public void startFeedback(@StringRes int infoTextResourceId) {
316-
// TODO(lkellogg): Once we have the real FeedbackActivity view implemented, we should write a
317-
// test that checks that <a> tags are preserved
318317
startFeedback(firebaseApp.getApplicationContext().getText(infoTextResourceId));
319318
}
320319

@@ -378,15 +377,24 @@ private void doStartFeedback(CharSequence infoText, @Nullable Uri screenshotUri)
378377
e ->
379378
LogWrapper.getInstance()
380379
.e("Failed to sign in tester. Could not collect feedback.", e))
381-
.onSuccessTask(taskExecutor, unused -> releaseIdentifier.identifyRelease())
382-
.onSuccessTask(
383-
taskExecutor,
384-
releaseName -> launchFeedbackActivity(releaseName, infoText, screenshotUri))
385-
.addOnFailureListener(
386-
e -> {
387-
LogWrapper.getInstance().e("Failed to launch feedback flow", e);
388-
feedbackInProgress.set(false);
389-
});
380+
.onSuccessTask(taskExecutor, unused -> releaseIdentifier.identifyRelease()
381+
.addOnFailureListener(
382+
e -> {
383+
LogWrapper.getInstance().e("Failed to identify release", e);
384+
feedbackInProgress.set(false);
385+
Toast.makeText(firebaseApp.getApplicationContext(),
386+
R.string.feedback_unidentified_release, Toast.LENGTH_LONG).show();
387+
})
388+
.onSuccessTask(
389+
taskExecutor,
390+
releaseName -> launchFeedbackActivity(releaseName, infoText, screenshotUri)
391+
.addOnFailureListener(
392+
e -> {
393+
LogWrapper.getInstance().e("Failed to launch feedback flow", e);
394+
feedbackInProgress.set(false);
395+
Toast.makeText(firebaseApp.getApplicationContext(),
396+
R.string.feedback_launch_failed, Toast.LENGTH_LONG).show();
397+
})));
390398
}
391399

392400
private Task<Void> launchFeedbackActivity(

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.google.firebase.appdistribution.FirebaseAppDistributionException.Status;
2828
import java.io.File;
2929
import java.io.IOException;
30+
import java.lang.reflect.Method;
3031
import java.nio.ByteBuffer;
3132
import java.security.MessageDigest;
3233
import java.security.NoSuchAlgorithmException;
@@ -46,8 +47,8 @@ class ReleaseIdentifier {
4647
static final String IAS_ARTIFACT_ID_METADATA_KEY = "com.android.vending.internal.apk.id";
4748

4849
private final ConcurrentMap<String, String> cachedApkHashes = new ConcurrentHashMap<>();
49-
private FirebaseApp firebaseApp;
50-
FirebaseAppDistributionTesterApiClient testerApiClient;
50+
private final FirebaseApp firebaseApp;
51+
private final FirebaseAppDistributionTesterApiClient testerApiClient;
5152

5253
ReleaseIdentifier(
5354
FirebaseApp firebaseApp, FirebaseAppDistributionTesterApiClient testerApiClient) {
@@ -57,6 +58,10 @@ class ReleaseIdentifier {
5758

5859
/** Identify the currently installed release, returning the release name. */
5960
Task<String> identifyRelease() {
61+
if (developmentModeEnabled()) {
62+
return Tasks.forResult(null);
63+
}
64+
6065
// Attempt to find release using IAS artifact ID, which identifies app bundle releases
6166
String iasArtifactId = null;
6267
try {
@@ -193,4 +198,25 @@ private static byte[] arrayListToByteArray(ArrayList<Byte> list) {
193198
}
194199
return result;
195200
}
201+
202+
private static boolean developmentModeEnabled() {
203+
return Boolean.valueOf(getSystemProperty("debug.firebase.appdistro.devmode"));
204+
}
205+
206+
@Nullable
207+
@SuppressWarnings({"unchecked", "PrivateApi"})
208+
private static String getSystemProperty(String propertyName) {
209+
String className = "android.os.SystemProperties";
210+
try {
211+
Class<?> sysProps = Class.forName(className);
212+
Method method = sysProps.getDeclaredMethod("get", String.class);
213+
Object result = method.invoke(null, propertyName);
214+
if (result != null && String.class.isAssignableFrom(result.getClass())) {
215+
return (String) result;
216+
}
217+
} catch (Exception e) {
218+
// do nothing
219+
}
220+
return null;
221+
}
196222
}

firebase-appdistribution/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
<string name="notifications_group_name">Firebase App Distribution</string>
3232
<string name="app_update_notification_channel_name">App updates</string>
3333
<string name="app_update_notification_channel_description">Shows progress of in-app updates</string>
34+
<string name="feedback_launch_failed">Failed to launch feedback</string>
35+
<string name="feedback_unidentified_release">Release not accessible. Probably not installed via App Distribution</string>
36+
<string name="feedback_no_release">Would have sent feedback</string>
3437
<string name="feedback_notification_channel_name">Feedback</string>
3538
<string name="feedback_notification_channel_description">Tap to leave feedback</string>
3639
<string name="feedback_notification_title">We want your feedback!</string>

0 commit comments

Comments
 (0)