|
19 | 19 | import android.content.Context;
|
20 | 20 | import androidx.annotation.Nullable;
|
21 | 21 | import java.io.IOException;
|
| 22 | +import java.io.InputStream; |
22 | 23 |
|
23 | 24 | /** Provider for the development platform info. */
|
24 | 25 | public class DevelopmentPlatformProvider {
|
25 | 26 | private static final String UNITY_PLATFORM = "Unity";
|
26 | 27 | private static final String FLUTTER_PLATFORM = "Flutter";
|
27 | 28 |
|
28 | 29 | 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"; |
30 | 31 |
|
31 | 32 | private final Context context;
|
32 | 33 | @Nullable private DevelopmentPlatform developmentPlatform;
|
@@ -66,14 +67,13 @@ public static boolean isUnity(Context context) {
|
66 | 67 | return getResourcesIdentifier(context, UNITY_VERSION_FIELD, "string") != 0;
|
67 | 68 | }
|
68 | 69 |
|
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; |
77 | 77 | } catch (IOException ex) {
|
78 | 78 | return false;
|
79 | 79 | }
|
@@ -101,7 +101,7 @@ private DevelopmentPlatform() {
|
101 | 101 | }
|
102 | 102 |
|
103 | 103 | // Flutter
|
104 |
| - if (assetPathExists(FLUTTER_ASSETS_PATH)) { |
| 104 | + if (assetFileExists(FLUTTER_ASSET_FILE)) { |
105 | 105 | developmentPlatform = FLUTTER_PLATFORM;
|
106 | 106 | // TODO: Get the version when available - https://github.com/flutter/flutter/issues/92681
|
107 | 107 | developmentPlatformVersion = null;
|
|
0 commit comments