Skip to content

Commit a566d15

Browse files
committed
Address Kai's feedback
1 parent 487e263 commit a566d15

File tree

2 files changed

+41
-18
lines changed

2 files changed

+41
-18
lines changed

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/impl/ApkHashExtractor.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
/** Extracts a hash of the installed APK. */
4040
class ApkHashExtractor {
4141

42-
private static final String TAG = "ApkHashExtractor:";
42+
private static final String TAG = "ApkHashExtractor";
4343
private static final int BYTES_IN_LONG = 8;
4444

4545
private final ConcurrentMap<String, String> cachedApkHashes = new ConcurrentHashMap<>();
@@ -79,8 +79,11 @@ String extractApkHash(PackageInfo packageInfo) {
7979

8080
@Nullable
8181
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()));
8487

8588
long start = System.currentTimeMillis();
8689
long entries = 0;
@@ -92,8 +95,7 @@ String calculateApkHash(@NonNull File file) {
9295
// Since calculating the codeHash returned from the release backend is computationally
9396
// expensive, we has the existing checksum data from the ZipFile and compare it to
9497
// (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
9799
ZipFile zis = new ZipFile(file);
98100
try {
99101
Enumeration<? extends ZipEntry> zipEntries = zis.entries();
@@ -116,23 +118,16 @@ String calculateApkHash(@NonNull File file) {
116118
zipFingerprint = sb.toString();
117119

118120
} 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());
120122
return null;
121123
} finally {
122124
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));
134125
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));
136131
}
137132

138133
return zipFingerprint;

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/impl/LogWrapper.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,42 @@ void d(@NonNull String msg) {
3636
Log.d(LOG_TAG, msg);
3737
}
3838

39+
void d(@NonNull String additionalTag, @NonNull String msg) {
40+
Log.d(LOG_TAG, prependTag(additionalTag, msg));
41+
}
42+
3943
void v(@NonNull String msg) {
4044
Log.v(LOG_TAG, msg);
4145
}
4246

47+
void v(@NonNull String additionalTag, @NonNull String msg) {
48+
Log.v(LOG_TAG, prependTag(additionalTag, msg));
49+
}
50+
4351
void i(@NonNull String msg) {
4452
Log.i(LOG_TAG, msg);
4553
}
4654

55+
void i(@NonNull String additionalTag, @NonNull String msg) {
56+
Log.i(LOG_TAG, prependTag(additionalTag, msg));
57+
}
58+
4759
void w(@NonNull String msg) {
4860
Log.w(LOG_TAG, msg);
4961
}
5062

63+
void w(@NonNull String additionalTag, @NonNull String msg) {
64+
Log.w(LOG_TAG, prependTag(additionalTag, msg));
65+
}
66+
5167
void w(@NonNull String msg, @NonNull Throwable tr) {
5268
Log.w(LOG_TAG, msg, tr);
5369
}
5470

71+
void w(@NonNull String additionalTag, @NonNull String msg, @NonNull Throwable tr) {
72+
Log.w(LOG_TAG, prependTag(additionalTag, msg), tr);
73+
}
74+
5575
void e(@NonNull String msg) {
5676
Log.e(LOG_TAG, msg);
5777
}
@@ -60,5 +80,13 @@ void e(@NonNull String msg, @NonNull Throwable tr) {
6080
Log.e(LOG_TAG, msg, tr);
6181
}
6282

83+
void e(@NonNull String additionalTag, @NonNull String msg, @NonNull Throwable tr) {
84+
Log.e(LOG_TAG, prependTag(additionalTag, msg), tr);
85+
}
86+
87+
private String prependTag(String tag, String msg) {
88+
return String.format("%s: %s", tag, msg);
89+
}
90+
6391
private LogWrapper() {}
6492
}

0 commit comments

Comments
 (0)