Skip to content

Commit f5d22e5

Browse files
authored
Merge 3831b52 into dfd0d7c
2 parents dfd0d7c + 3831b52 commit f5d22e5

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

firebase-crashlytics/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Unreleased
2+
* [changed] Internal changes to read version control info more efficiently [6754]
23
* [fixed] Fixed NoSuchMethodError when getting process info on Android 13 [#6720]
34

45
# 19.4.1

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/CommonUtils.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public class CommonUtils {
6969
"com.google.firebase.crashlytics.build_ids_arch";
7070
static final String BUILD_IDS_BUILD_ID_RESOURCE_NAME =
7171
"com.google.firebase.crashlytics.build_ids_build_id";
72+
static final String VERSION_CONTROL_INFO_RESOURCE_NAME =
73+
"com.google.firebase.crashlytics.version_control_info";
7274

7375
// TODO: Maybe move this method into a more appropriate class.
7476
public static SharedPreferences getSharedPrefs(Context context) {
@@ -525,6 +527,15 @@ public static List<BuildIdInfo> getBuildIdInfo(Context context) {
525527
return buildIdInfoList;
526528
}
527529

530+
@Nullable
531+
public static String getVersionControlInfo(Context context) {
532+
int id = getResourcesIdentifier(context, VERSION_CONTROL_INFO_RESOURCE_NAME, "string");
533+
if (id == 0) {
534+
return null;
535+
}
536+
return context.getResources().getString(id);
537+
}
538+
528539
public static void closeQuietly(Closeable closeable) {
529540
if (closeable != null) {
530541
try {

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/CrashlyticsController.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import java.io.FilenameFilter;
4949
import java.io.IOException;
5050
import java.io.InputStream;
51+
import java.nio.charset.Charset;
5152
import java.util.ArrayList;
5253
import java.util.List;
5354
import java.util.Locale;
@@ -77,6 +78,8 @@ class CrashlyticsController {
7778
private static final String VERSION_CONTROL_INFO_FILE = "version-control-info.textproto";
7879
private static final String META_INF_FOLDER = "META-INF/";
7980

81+
private static final Charset UTF_8 = Charset.forName("UTF-8");
82+
8083
private final Context context;
8184
private final DataCollectionArbiter dataCollectionArbiter;
8285
private final CrashlyticsFileMarker crashMarker;
@@ -628,13 +631,23 @@ void saveVersionControlInfo() {
628631
}
629632

630633
String getVersionControlInfo() throws IOException {
631-
InputStream is = getResourceAsStream(META_INF_FOLDER + VERSION_CONTROL_INFO_FILE);
632-
if (is == null) {
633-
return null;
634+
// Attempt to read from an Android string resource
635+
String versionControlInfo = CommonUtils.getVersionControlInfo(context);
636+
if (versionControlInfo != null) {
637+
Logger.getLogger().d("Read version control info from string resource");
638+
return Base64.encodeToString(versionControlInfo.getBytes(UTF_8), 0);
639+
}
640+
641+
// Fallback to reading the file
642+
try (InputStream is = getResourceAsStream(META_INF_FOLDER + VERSION_CONTROL_INFO_FILE)) {
643+
if (is != null) {
644+
Logger.getLogger().d("Read version control info from file");
645+
return Base64.encodeToString(readResource(is), 0);
646+
}
634647
}
635648

636-
Logger.getLogger().d("Read version control info");
637-
return Base64.encodeToString(readResource(is), 0);
649+
Logger.getLogger().i("No version control information found");
650+
return null;
638651
}
639652

640653
private InputStream getResourceAsStream(String resource) {
@@ -644,13 +657,7 @@ private InputStream getResourceAsStream(String resource) {
644657
return null;
645658
}
646659

647-
InputStream is = classLoader.getResourceAsStream(resource);
648-
if (is == null) {
649-
Logger.getLogger().i("No version control information found");
650-
return null;
651-
}
652-
653-
return is;
660+
return classLoader.getResourceAsStream(resource);
654661
}
655662

656663
private static byte[] readResource(InputStream is) throws IOException {

0 commit comments

Comments
 (0)