Skip to content

Commit 1f25801

Browse files
authored
Check for a specific flutter asset file instead of listing the path (#3631)
1 parent 26c905b commit 1f25801

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/DevelopmentPlatformProviderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void testDevelopmentPlatformInfo_withUnity_returnsPlatformAndVersion() th
4242
}
4343

4444
public void testDevelopmentPlatformInfo_withFlutter_returnsPlatformAndNoVersion() {
45-
Context context = getContext(); // has asset in DevelopmentPlatformProvider.FLUTTER_ASSETS_PATH
45+
Context context = getContext(); // has asset DevelopmentPlatformProvider.FLUTTER_ASSET_FILE
4646

4747
DevelopmentPlatformProvider provider = new DevelopmentPlatformProvider(context);
4848

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/DevelopmentPlatformProvider.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
import android.content.Context;
2020
import androidx.annotation.Nullable;
2121
import java.io.IOException;
22+
import java.io.InputStream;
2223

2324
/** Provider for the development platform info. */
2425
public class DevelopmentPlatformProvider {
2526
private static final String UNITY_PLATFORM = "Unity";
2627
private static final String FLUTTER_PLATFORM = "Flutter";
2728

2829
private static final String UNITY_VERSION_FIELD = "com.google.firebase.crashlytics.unity_version";
29-
private static final String FLUTTER_ASSETS_PATH = "flutter_assets";
30+
private static final String FLUTTER_ASSET_FILE = "flutter_assets/NOTICES.Z";
3031

3132
private final Context context;
3233
@Nullable private DevelopmentPlatform developmentPlatform;
@@ -66,14 +67,13 @@ public static boolean isUnity(Context context) {
6667
return getResourcesIdentifier(context, UNITY_VERSION_FIELD, "string") != 0;
6768
}
6869

69-
/** Quickly and safely check if the given asset path exists. */
70-
private boolean assetPathExists(String path) {
71-
try {
72-
if (context.getAssets() == null) {
73-
return false;
74-
}
75-
String[] list = context.getAssets().list(path);
76-
return list != null && list.length > 0;
70+
/** Quickly and safely check if the given asset file exists. */
71+
private boolean assetFileExists(String file) {
72+
if (context.getAssets() == null) {
73+
return false;
74+
}
75+
try (InputStream ignored = context.getAssets().open(file)) {
76+
return true;
7777
} catch (IOException ex) {
7878
return false;
7979
}
@@ -101,7 +101,7 @@ private DevelopmentPlatform() {
101101
}
102102

103103
// Flutter
104-
if (assetPathExists(FLUTTER_ASSETS_PATH)) {
104+
if (assetFileExists(FLUTTER_ASSET_FILE)) {
105105
developmentPlatform = FLUTTER_PLATFORM;
106106
// TODO: Get the version when available - https://github.com/flutter/flutter/issues/92681
107107
developmentPlatformVersion = null;

0 commit comments

Comments
 (0)