39
39
/** Extracts a hash of the installed APK. */
40
40
class ApkHashExtractor {
41
41
42
- private static final String TAG = "ApkHashExtractor: " ;
42
+ private static final String TAG = "ApkHashExtractor" ;
43
43
private static final int BYTES_IN_LONG = 8 ;
44
44
45
45
private final ConcurrentMap <String , String > cachedApkHashes = new ConcurrentHashMap <>();
@@ -64,8 +64,7 @@ String extractApkHash() throws FirebaseAppDistributionException {
64
64
return installedReleaseApkHash ;
65
65
}
66
66
67
- @ VisibleForTesting
68
- String extractApkHash (PackageInfo packageInfo ) {
67
+ private String extractApkHash (PackageInfo packageInfo ) {
69
68
File sourceFile = new File (packageInfo .applicationInfo .sourceDir );
70
69
71
70
String key =
@@ -79,8 +78,11 @@ String extractApkHash(PackageInfo packageInfo) {
79
78
80
79
@ Nullable
81
80
String calculateApkHash (@ NonNull File file ) {
82
- LogWrapper .getInstance ().v (TAG + "Calculating release id for " + file .getPath ());
83
- LogWrapper .getInstance ().v (TAG + "File size: " + file .length ());
81
+ LogWrapper .getInstance ()
82
+ .v (
83
+ TAG ,
84
+ String .format (
85
+ "Calculating release id for %s (%d bytes)" , file .getPath (), file .length ()));
84
86
85
87
long start = System .currentTimeMillis ();
86
88
long entries = 0 ;
@@ -92,8 +94,7 @@ String calculateApkHash(@NonNull File file) {
92
94
// Since calculating the codeHash returned from the release backend is computationally
93
95
// expensive, we has the existing checksum data from the ZipFile and compare it to
94
96
// (1) the apk hash returned by the backend, or (2) look up a mapping from the apk zip hash to
95
- // the
96
- // full codehash, and compare that to the codehash to the backend
97
+ // the full codehash, and compare that to the codehash to the backend
97
98
ZipFile zis = new ZipFile (file );
98
99
try {
99
100
Enumeration <? extends ZipEntry > zipEntries = zis .entries ();
@@ -116,23 +117,16 @@ String calculateApkHash(@NonNull File file) {
116
117
zipFingerprint = sb .toString ();
117
118
118
119
} catch (IOException | NoSuchAlgorithmException e ) {
119
- LogWrapper .getInstance ().v (TAG + "id calculation failed for " + file .getPath ());
120
+ LogWrapper .getInstance ().v (TAG , "id calculation failed for " + file .getPath ());
120
121
return null ;
121
122
} finally {
122
123
long elapsed = System .currentTimeMillis () - start ;
123
- if (elapsed > 2 * 1000 ) {
124
- LogWrapper .getInstance ()
125
- .v (
126
- TAG
127
- + String .format (
128
- "Long id calculation time %d ms and %d entries for %s" ,
129
- elapsed , entries , file .getPath ()));
130
- }
131
-
132
- LogWrapper .getInstance ()
133
- .v (TAG + String .format ("Finished calculating %d entries in %d ms" , entries , elapsed ));
134
124
LogWrapper .getInstance ()
135
- .v (TAG + String .format ("%s hashes to %s" , file .getPath (), zipFingerprint ));
125
+ .v (
126
+ TAG ,
127
+ String .format (
128
+ "Computed hash of %s (%d entries, %d ms elapsed): %s" ,
129
+ file .getPath (), entries , elapsed , zipFingerprint ));
136
130
}
137
131
138
132
return zipFingerprint ;
0 commit comments