48
48
import java .io .FilenameFilter ;
49
49
import java .io .IOException ;
50
50
import java .io .InputStream ;
51
+ import java .nio .charset .Charset ;
51
52
import java .util .ArrayList ;
52
53
import java .util .List ;
53
54
import java .util .Locale ;
@@ -77,6 +78,8 @@ class CrashlyticsController {
77
78
private static final String VERSION_CONTROL_INFO_FILE = "version-control-info.textproto" ;
78
79
private static final String META_INF_FOLDER = "META-INF/" ;
79
80
81
+ private static final Charset UTF_8 = Charset .forName ("UTF-8" );
82
+
80
83
private final Context context ;
81
84
private final DataCollectionArbiter dataCollectionArbiter ;
82
85
private final CrashlyticsFileMarker crashMarker ;
@@ -628,13 +631,23 @@ void saveVersionControlInfo() {
628
631
}
629
632
630
633
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
+ }
634
647
}
635
648
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 ;
638
651
}
639
652
640
653
private InputStream getResourceAsStream (String resource ) {
@@ -644,13 +657,7 @@ private InputStream getResourceAsStream(String resource) {
644
657
return null ;
645
658
}
646
659
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 );
654
661
}
655
662
656
663
private static byte [] readResource (InputStream is ) throws IOException {
0 commit comments