Skip to content

Commit 5ae822b

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

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
lines changed

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

Lines changed: 14 additions & 20 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<>();
@@ -64,8 +64,7 @@ String extractApkHash() throws FirebaseAppDistributionException {
6464
return installedReleaseApkHash;
6565
}
6666

67-
@VisibleForTesting
68-
String extractApkHash(PackageInfo packageInfo) {
67+
private String extractApkHash(PackageInfo packageInfo) {
6968
File sourceFile = new File(packageInfo.applicationInfo.sourceDir);
7069

7170
String key =
@@ -79,8 +78,11 @@ String extractApkHash(PackageInfo packageInfo) {
7978

8079
@Nullable
8180
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()));
8486

8587
long start = System.currentTimeMillis();
8688
long entries = 0;
@@ -92,8 +94,7 @@ String calculateApkHash(@NonNull File file) {
9294
// Since calculating the codeHash returned from the release backend is computationally
9395
// expensive, we has the existing checksum data from the ZipFile and compare it to
9496
// (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
9798
ZipFile zis = new ZipFile(file);
9899
try {
99100
Enumeration<? extends ZipEntry> zipEntries = zis.entries();
@@ -116,23 +117,16 @@ String calculateApkHash(@NonNull File file) {
116117
zipFingerprint = sb.toString();
117118

118119
} 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());
120121
return null;
121122
} finally {
122123
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));
134124
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));
136130
}
137131

138132
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)