Skip to content

Commit 0e0612f

Browse files
kaibolaylfkellogg
authored andcommitted
clean up logging (#4465)
- make `LogWrapper` static - ensure `TAG` is passed uniformly
1 parent 84cc647 commit 0e0612f

19 files changed

+126
-183
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
/** Class that handles updateApp functionality for AABs in {@link FirebaseAppDistribution}. */
3636
class AabUpdater {
37-
private static final String TAG = "AabUpdater:";
37+
private static final String TAG = "AabUpdater";
3838

3939
private final FirebaseAppDistributionLifecycleNotifier lifecycleNotifier;
4040
private final HttpsUrlConnectionFactory httpsUrlConnectionFactory;
@@ -152,7 +152,7 @@ private void openRedirectUrlInPlay(String redirectUrl, Activity hostActivity) {
152152
Intent updateIntent = new Intent(Intent.ACTION_VIEW);
153153
updateIntent.setData(Uri.parse(redirectUrl));
154154
updateIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
155-
LogWrapper.getInstance().v(TAG + "Redirecting to play");
155+
LogWrapper.v(TAG, "Redirecting to play");
156156

157157
// Launch the intent before the synchronized block to avoid failing to update in the rare
158158
// scenario where the activity moves to the background while we're awaiting the lock.

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727

2828
/** Class that handles installing APKs in {@link FirebaseAppDistribution}. */
2929
class ApkInstaller {
30-
private static final String TAG = "ApkInstaller:";
30+
private static final String TAG = "ApkInstaller";
31+
3132
private final FirebaseAppDistributionLifecycleNotifier lifeCycleNotifier;
3233

3334
@GuardedBy("installTaskLock")
@@ -79,7 +80,7 @@ private void startInstallActivity(String path, Activity currentActivity) {
7980
Intent intent = new Intent(currentActivity, InstallActivity.class);
8081
intent.putExtra("INSTALL_PATH", path);
8182
currentActivity.startActivity(intent);
82-
LogWrapper.getInstance().v(TAG + "Prompting tester with install activity ");
83+
LogWrapper.v(TAG, "Prompting tester with install activity");
8384
}
8485

8586
void trySetInstallTaskError() {

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@
4242

4343
/** Class that handles updateApp functionality for APKs in {@link FirebaseAppDistribution}. */
4444
class ApkUpdater {
45-
45+
private static final String TAG = "ApkUpdater";
4646
private static final int UPDATE_INTERVAL_MS = 250;
47-
private static final String TAG = "ApkUpdater:";
4847
private static final String REQUEST_METHOD_GET = "GET";
4948
private static final String DEFAULT_APK_FILE_NAME = "downloaded_release.apk";
5049

@@ -185,7 +184,7 @@ private void makeApkDownloadRequest(
185184
postUpdateProgress(
186185
responseLength, 0, UpdateStatus.PENDING, showNotification, R.string.downloading_app_update);
187186
String fileName = getApkFileName();
188-
LogWrapper.getInstance().v(TAG + "Attempting to download APK to disk");
187+
LogWrapper.v(TAG, "Attempting to download APK to disk");
189188

190189
long bytesDownloaded = downloadToDisk(connection, responseLength, fileName, showNotification);
191190

@@ -271,11 +270,9 @@ private String getApkFileName() {
271270
context.getApplicationInfo().loadLabel(context.getPackageManager()).toString();
272271
return applicationName + ".apk";
273272
} catch (Exception e) {
274-
LogWrapper.getInstance()
275-
.w(
276-
TAG
277-
+ "Unable to retrieve app name. Using generic file name for APK: "
278-
+ DEFAULT_APK_FILE_NAME);
273+
LogWrapper.w(
274+
TAG,
275+
"Unable to retrieve app name. Using generic file name for APK: " + DEFAULT_APK_FILE_NAME);
279276
return DEFAULT_APK_FILE_NAME;
280277
}
281278
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import androidx.core.content.ContextCompat;
2424

2525
class AppIconSource {
26-
private static final String TAG = "AppIconSource: ";
26+
private static final String TAG = "AppIconSource";
2727

2828
private static final int DEFAULT_ICON = android.R.drawable.sym_def_app_icon;
2929

@@ -50,8 +50,8 @@ int getNonAdaptiveIconOrDefault(Context context) {
5050
}
5151

5252
if (isAdaptiveIcon(icon)) {
53-
LogWrapper.getInstance()
54-
.e(TAG + "Adaptive icons cannot be used in notifications. Ignoring icon id: " + iconId);
53+
LogWrapper.e(
54+
TAG, "Adaptive icons cannot be used in notifications. Ignoring icon id: " + iconId);
5555
return DEFAULT_ICON;
5656
}
5757

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private void setupScreenshot() {
112112
v -> imageView.setVisibility(checkBox.isChecked() ? VISIBLE : GONE));
113113
});
114114
} else {
115-
LogWrapper.getInstance().e(TAG, "No screenshot available");
115+
LogWrapper.e(TAG, "No screenshot available");
116116
runOnUiThread(
117117
() -> {
118118
CheckBox checkBox = findViewById(R.id.screenshotCheckBox);
@@ -135,12 +135,11 @@ private Bitmap readScreenshot() {
135135
SCREENSHOT_TARGET_WIDTH_PX,
136136
SCREENSHOT_TARGET_HEIGHT_PX);
137137
} catch (IOException | SecurityException e) {
138-
LogWrapper.getInstance()
139-
.e(TAG, "Could not read screenshot image from URI: " + screenshotUri, e);
138+
LogWrapper.e(TAG, "Could not read screenshot image from URI: " + screenshotUri, e);
140139
return null;
141140
}
142141
if (bitmap == null) {
143-
LogWrapper.getInstance().e(TAG, "Could not decode screenshot image: " + screenshotUri);
142+
LogWrapper.e(TAG, "Could not decode screenshot image: " + screenshotUri);
144143
}
145144
return bitmap;
146145
}
@@ -162,13 +161,13 @@ public void submitFeedback(View view) {
162161
screenshotCheckBox.isChecked() ? screenshotUri : null)
163162
.addOnSuccessListener(
164163
unused -> {
165-
LogWrapper.getInstance().i(TAG, "Feedback submitted");
164+
LogWrapper.i(TAG, "Feedback submitted");
166165
Toast.makeText(this, "Feedback submitted", Toast.LENGTH_LONG).show();
167166
finish();
168167
})
169168
.addOnFailureListener(
170169
e -> {
171-
LogWrapper.getInstance().e(TAG, "Failed to submit feedback", e);
170+
LogWrapper.e(TAG, "Failed to submit feedback", e);
172171
Toast.makeText(this, "Error submitting feedback", Toast.LENGTH_LONG).show();
173172
setSubmittingStateEnabled(false);
174173
});

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
*/
5656
class FirebaseAppDistributionImpl implements FirebaseAppDistribution {
5757

58+
private static final String TAG = "Impl";
5859
private static final int UNKNOWN_RELEASE_FILE_SIZE = -1;
5960

6061
private final FirebaseApp firebaseApp;
@@ -295,13 +296,13 @@ private UpdateTask updateApp(boolean showDownloadInNotificationManager) {
295296
lightweightExecutor,
296297
release -> {
297298
if (release == null) {
298-
LogWrapper.getInstance().v("New release not found.");
299+
LogWrapper.v(TAG, "New release not found.");
299300
return getErrorUpdateTask(
300301
new FirebaseAppDistributionException(
301302
ErrorMessages.RELEASE_NOT_FOUND_ERROR, UPDATE_NOT_AVAILABLE));
302303
}
303304
if (release.getDownloadUrl() == null) {
304-
LogWrapper.getInstance().v("Download failed to execute.");
305+
LogWrapper.v(TAG, "Download failed to execute.");
305306
return getErrorUpdateTask(
306307
new FirebaseAppDistributionException(
307308
ErrorMessages.DOWNLOAD_URL_NOT_FOUND,
@@ -324,17 +325,16 @@ public void startFeedback(@StringRes int infoTextResourceId) {
324325
@Override
325326
public void startFeedback(@NonNull CharSequence infoText) {
326327
if (!feedbackInProgress.compareAndSet(/* expect= */ false, /* update= */ true)) {
327-
LogWrapper.getInstance()
328-
.i("Ignoring startFeedback() call because feedback is already in progress");
328+
LogWrapper.i(TAG, "Ignoring startFeedback() call because feedback is already in progress");
329329
return;
330330
}
331-
LogWrapper.getInstance().i("Starting feedback");
331+
LogWrapper.i(TAG, "Starting feedback");
332332
screenshotTaker
333333
.takeScreenshot()
334334
.addOnFailureListener(
335335
taskExecutor,
336336
e -> {
337-
LogWrapper.getInstance().w("Failed to take screenshot for feedback", e);
337+
LogWrapper.w(TAG, "Failed to take screenshot for feedback", e);
338338
doStartFeedback(infoText, null);
339339
})
340340
.addOnSuccessListener(
@@ -349,8 +349,7 @@ public void startFeedback(@StringRes int infoTextResourceId, @Nullable Uri scree
349349
@Override
350350
public void startFeedback(@NonNull CharSequence infoText, @Nullable Uri screenshotUri) {
351351
if (!feedbackInProgress.compareAndSet(/* expect= */ false, /* update= */ true)) {
352-
LogWrapper.getInstance()
353-
.i("Ignoring startFeedback() call because feedback is already in progress");
352+
LogWrapper.i(TAG, "Ignoring startFeedback() call because feedback is already in progress");
354353
return;
355354
}
356355
doStartFeedback(infoText, screenshotUri);
@@ -380,8 +379,7 @@ private void doStartFeedback(CharSequence infoText, @Nullable Uri screenshotUri)
380379
taskExecutor,
381380
e -> {
382381
feedbackInProgress.set(false);
383-
LogWrapper.getInstance()
384-
.e("Failed to sign in tester. Could not collect feedback.", e);
382+
LogWrapper.e(TAG, "Failed to sign in tester. Could not collect feedback.", e);
385383
})
386384
.onSuccessTask(
387385
taskExecutor,
@@ -391,7 +389,7 @@ private void doStartFeedback(CharSequence infoText, @Nullable Uri screenshotUri)
391389
.addOnFailureListener(
392390
e -> {
393391
feedbackInProgress.set(false);
394-
LogWrapper.getInstance().e("Failed to identify release", e);
392+
LogWrapper.e(TAG, "Failed to identify release", e);
395393
Toast.makeText(
396394
firebaseApp.getApplicationContext(),
397395
R.string.feedback_unidentified_release,
@@ -406,8 +404,7 @@ private void doStartFeedback(CharSequence infoText, @Nullable Uri screenshotUri)
406404
.addOnFailureListener(
407405
e -> {
408406
feedbackInProgress.set(false);
409-
LogWrapper.getInstance()
410-
.e("Failed to launch feedback flow", e);
407+
LogWrapper.e(TAG, "Failed to launch feedback flow", e);
411408
Toast.makeText(
412409
firebaseApp.getApplicationContext(),
413410
R.string.feedback_launch_failed,
@@ -420,7 +417,7 @@ private Task<Void> launchFeedbackActivity(
420417
@Nullable String releaseName, CharSequence infoText, @Nullable Uri screenshotUri) {
421418
return lifecycleNotifier.consumeForegroundActivity(
422419
activity -> {
423-
LogWrapper.getInstance().i("Launching feedback activity");
420+
LogWrapper.i(TAG, "Launching feedback activity");
424421
Intent intent = new Intent(activity, FeedbackActivity.class);
425422
// in development-mode the releaseName might be null
426423
intent.putExtra(FeedbackActivity.RELEASE_NAME_KEY, releaseName);
@@ -486,7 +483,7 @@ void onActivityDestroyed(@NonNull Activity activity) {
486483
}
487484

488485
if (activity instanceof FeedbackActivity) {
489-
LogWrapper.getInstance().i("FeedbackActivity destroyed");
486+
LogWrapper.i(TAG, "FeedbackActivity destroyed");
490487
if (activity.isFinishing()) {
491488
feedbackInProgress.set(false);
492489

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import com.google.firebase.appdistribution.InterruptionLevel;
3232

3333
class FirebaseAppDistributionNotificationsManager {
34-
private static final String TAG = "FirebaseAppDistributionNotificationsManager";
34+
private static final String TAG = "NotificationsManager";
3535

3636
private static final String PACKAGE_PREFIX = "com.google.firebase.appdistribution";
3737

@@ -73,7 +73,7 @@ void showAppUpdateNotification(long totalBytes, long downloadedBytes, int string
7373
// Create the NotificationChannel, but only on API 26+ because
7474
// the NotificationChannel class is new and not in the support library
7575
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
76-
LogWrapper.getInstance().i(TAG, "Creating app update notification channel group");
76+
LogWrapper.i(TAG, "Creating app update notification channel group");
7777
createChannel(
7878
Notification.APP_UPDATE,
7979
R.string.app_update_notification_channel_name,
@@ -82,8 +82,8 @@ void showAppUpdateNotification(long totalBytes, long downloadedBytes, int string
8282
}
8383

8484
if (!notificationManager.areNotificationsEnabled()) {
85-
LogWrapper.getInstance()
86-
.w("Not showing app update notifications because app notifications are disabled");
85+
LogWrapper.w(
86+
TAG, "Not showing app update notifications because app notifications are disabled");
8787
return;
8888
}
8989

@@ -109,7 +109,7 @@ private PendingIntent createAppLaunchIntent() {
109109
// Query the package manager for the best launch intent for the app
110110
Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
111111
if (intent == null) {
112-
LogWrapper.getInstance().w(TAG, "No activity found to launch app");
112+
LogWrapper.w(TAG, "No activity found to launch app");
113113
return null;
114114
}
115115
return getPendingIntent(intent, PendingIntent.FLAG_ONE_SHOT);
@@ -129,7 +129,7 @@ public void showFeedbackNotification(
129129
// Create the NotificationChannel, but only on API 26+ because
130130
// the NotificationChannel class is new and not in the support library
131131
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
132-
LogWrapper.getInstance().i(TAG, "Creating feedback notification channel group");
132+
LogWrapper.i(TAG, "Creating feedback notification channel group");
133133
createChannel(
134134
Notification.FEEDBACK,
135135
R.string.feedback_notification_channel_name,
@@ -138,8 +138,7 @@ public void showFeedbackNotification(
138138
}
139139

140140
if (!notificationManager.areNotificationsEnabled()) {
141-
LogWrapper.getInstance()
142-
.w(TAG, "Not showing notification because app notifications are disabled");
141+
LogWrapper.w(TAG, "Not showing notification because app notifications are disabled");
143142
return;
144143
}
145144

@@ -159,13 +158,13 @@ public void showFeedbackNotification(
159158
.setOnlyAlertOnce(true)
160159
.setAutoCancel(false)
161160
.setContentIntent(getPendingIntent(intent, /* extraFlags= */ 0));
162-
LogWrapper.getInstance().i(TAG, "Showing feedback notification");
161+
LogWrapper.i(TAG, "Showing feedback notification");
163162
notificationManager.notify(
164163
Notification.FEEDBACK.tag, Notification.FEEDBACK.id, builder.build());
165164
}
166165

167166
public void cancelFeedbackNotification() {
168-
LogWrapper.getInstance().i(TAG, "Cancelling feedback notification");
167+
LogWrapper.i(TAG, "Cancelling feedback notification");
169168
NotificationManagerCompat.from(context)
170169
.cancel(Notification.FEEDBACK.tag, Notification.FEEDBACK.id);
171170
}

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
public class FirebaseAppDistributionRegistrar implements ComponentRegistrar {
4646
private static final String LIBRARY_NAME = "fire-appdistribution";
4747

48-
private static String TAG = "FirebaseAppDistributionRegistrar";
48+
private static String TAG = "Registrar";
4949

5050
@Override
5151
public @NonNull List<Component<?>> getComponents() {
@@ -128,13 +128,12 @@ private FirebaseAppDistribution buildFirebaseAppDistribution(
128128
Application firebaseApplication = (Application) context;
129129
firebaseApplication.registerActivityLifecycleCallbacks(lifecycleNotifier);
130130
} else {
131-
LogWrapper.getInstance()
132-
.e(
133-
TAG,
134-
String.format(
135-
"Context %s was not an Application, can't register for lifecycle callbacks. SDK"
136-
+ " might not function correctly.",
137-
context));
131+
LogWrapper.e(
132+
TAG,
133+
String.format(
134+
"Context %s was not an Application, can't register for lifecycle callbacks. SDK"
135+
+ " might not function correctly.",
136+
context));
138137
}
139138

140139
return appDistribution;

0 commit comments

Comments
 (0)