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 <>();
@@ -79,8 +79,11 @@ String extractApkHash(PackageInfo packageInfo) {
79
79
80
80
@ Nullable
81
81
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 ());
82
+ LogWrapper .getInstance ()
83
+ .v (
84
+ TAG ,
85
+ String .format (
86
+ "Calculating release id for %s (%d bytes)" , file .getPath (), file .length ()));
84
87
85
88
long start = System .currentTimeMillis ();
86
89
long entries = 0 ;
@@ -92,8 +95,7 @@ String calculateApkHash(@NonNull File file) {
92
95
// Since calculating the codeHash returned from the release backend is computationally
93
96
// expensive, we has the existing checksum data from the ZipFile and compare it to
94
97
// (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
98
+ // the full codehash, and compare that to the codehash to the backend
97
99
ZipFile zis = new ZipFile (file );
98
100
try {
99
101
Enumeration <? extends ZipEntry > zipEntries = zis .entries ();
@@ -116,23 +118,16 @@ String calculateApkHash(@NonNull File file) {
116
118
zipFingerprint = sb .toString ();
117
119
118
120
} catch (IOException | NoSuchAlgorithmException e ) {
119
- LogWrapper .getInstance ().v (TAG + "id calculation failed for " + file .getPath ());
121
+ LogWrapper .getInstance ().v (TAG , "id calculation failed for " + file .getPath ());
120
122
return null ;
121
123
} finally {
122
124
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
125
LogWrapper .getInstance ()
135
- .v (TAG + String .format ("%s hashes to %s" , file .getPath (), zipFingerprint ));
126
+ .v (
127
+ TAG ,
128
+ String .format (
129
+ "Computed hash of %s (%d entries, %d ms elapsed): %s" ,
130
+ file .getPath (), entries , elapsed , zipFingerprint ));
136
131
}
137
132
138
133
return zipFingerprint ;
0 commit comments