Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions firebase-crashlytics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Unreleased
* [changed] Internal changes to read version control info more efficiently [6754]
* [fixed] Fixed NoSuchMethodError when getting process info on Android 13 [#6720]

# 19.4.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public class CommonUtils {
"com.google.firebase.crashlytics.build_ids_arch";
static final String BUILD_IDS_BUILD_ID_RESOURCE_NAME =
"com.google.firebase.crashlytics.build_ids_build_id";
static final String VERSION_CONTROL_INFO_RESOURCE_NAME =
"com.google.firebase.crashlytics.version_control_info";

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

@Nullable
public static String getVersionControlInfo(Context context) {
int id = getResourcesIdentifier(context, VERSION_CONTROL_INFO_RESOURCE_NAME, "string");
if (id == 0) {
return null;
}
return context.getResources().getString(id);
}

public static void closeQuietly(Closeable closeable) {
if (closeable != null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -77,6 +78,8 @@ class CrashlyticsController {
private static final String VERSION_CONTROL_INFO_FILE = "version-control-info.textproto";
private static final String META_INF_FOLDER = "META-INF/";

private static final Charset UTF_8 = Charset.forName("UTF-8");

private final Context context;
private final DataCollectionArbiter dataCollectionArbiter;
private final CrashlyticsFileMarker crashMarker;
Expand Down Expand Up @@ -628,13 +631,23 @@ void saveVersionControlInfo() {
}

String getVersionControlInfo() throws IOException {
InputStream is = getResourceAsStream(META_INF_FOLDER + VERSION_CONTROL_INFO_FILE);
if (is == null) {
return null;
// Attempt to read from an Android string resource
String versionControlInfo = CommonUtils.getVersionControlInfo(context);
if (versionControlInfo != null) {
Logger.getLogger().d("Read version control info from string resource");
return Base64.encodeToString(versionControlInfo.getBytes(UTF_8), 0);
}

// Fallback to reading the file
try (InputStream is = getResourceAsStream(META_INF_FOLDER + VERSION_CONTROL_INFO_FILE)) {
if (is != null) {
Logger.getLogger().d("Read version control info from file");
return Base64.encodeToString(readResource(is), 0);
}
}

Logger.getLogger().d("Read version control info");
return Base64.encodeToString(readResource(is), 0);
Logger.getLogger().i("No version control information found");
return null;
}

private InputStream getResourceAsStream(String resource) {
Expand All @@ -644,13 +657,7 @@ private InputStream getResourceAsStream(String resource) {
return null;
}

InputStream is = classLoader.getResourceAsStream(resource);
if (is == null) {
Logger.getLogger().i("No version control information found");
return null;
}

return is;
return classLoader.getResourceAsStream(resource);
}

private static byte[] readResource(InputStream is) throws IOException {
Expand Down
Loading