Skip to content

Commit 82b02af

Browse files
manny-jimenezManny Jimenez
andauthored
FAD Adding in logging (#2932)
* Adding in logging * Fixing log that always ran * Cleaning up code * Responding to comments * Responding to comments logs Co-authored-by: Manny Jimenez <[email protected]>
1 parent cd6d1bc commit 82b02af

11 files changed

+108
-28
lines changed

firebase-app-distribution/src/main/java/com/google/firebase/appdistribution/CheckForUpdateClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
class CheckForUpdateClient {
4040
private static final int UPDATE_THREAD_POOL_SIZE = 4;
41+
private static final String TAG = "CheckForUpdateClient:";
4142

4243
private final FirebaseApp firebaseApp;
4344
private final FirebaseAppDistributionTesterApiClient firebaseAppDistributionTesterApiClient;
@@ -134,6 +135,7 @@ AppDistributionReleaseInternal getLatestReleaseFromClient(
134135
return null;
135136
}
136137
} catch (NumberFormatException e) {
138+
LogWrapper.getInstance().e(TAG + "Error parsing buildVersion.", e);
137139
throw new FirebaseAppDistributionException(
138140
Constants.ErrorMessages.NETWORK_ERROR,
139141
FirebaseAppDistributionException.Status.NETWORK_FAILURE,
@@ -169,6 +171,7 @@ private long getInstalledAppVersionCode(Context context) throws FirebaseAppDistr
169171
try {
170172
pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
171173
} catch (PackageManager.NameNotFoundException e) {
174+
LogWrapper.getInstance().e(TAG + "Unable to locate Firebase App.", e);
172175
throw new FirebaseAppDistributionException(
173176
Constants.ErrorMessages.UNKNOWN_ERROR,
174177
FirebaseAppDistributionException.Status.UNKNOWN,
@@ -208,6 +211,7 @@ private boolean hasSameCodeHashAsInstallledRelease(AppDistributionReleaseInterna
208211
// of the installed release, then they are the same release.
209212
return externalCodeHash.equals(latestRelease.getCodeHash());
210213
} catch (PackageManager.NameNotFoundException e) {
214+
LogWrapper.getInstance().e(TAG + "Unable to locate App.", e);
211215
return false;
212216
}
213217
}

firebase-app-distribution/src/main/java/com/google/firebase/appdistribution/FirebaseAppDistribution.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import android.app.Application;
2222
import android.content.Context;
2323
import android.os.Bundle;
24-
import android.util.Log;
2524
import androidx.annotation.NonNull;
2625
import androidx.annotation.VisibleForTesting;
2726
import com.google.android.gms.common.internal.Preconditions;
@@ -34,7 +33,6 @@
3433
import org.jetbrains.annotations.Nullable;
3534

3635
public class FirebaseAppDistribution implements Application.ActivityLifecycleCallbacks {
37-
private static final String TAG = "FirebaseAppDistribution";
3836

3937
private final FirebaseApp firebaseApp;
4038
private final TesterSignInClient testerSignInClient;
@@ -145,6 +143,7 @@ public Task<Void> signInTester() {
145143
@NonNull
146144
public synchronized Task<AppDistributionRelease> checkForUpdate() {
147145
if (cachedCheckForUpdateTask != null && !cachedCheckForUpdateTask.isComplete()) {
146+
LogWrapper.getInstance().v("Response in progress");
148147
return cachedCheckForUpdateTask;
149148
}
150149

@@ -203,22 +202,23 @@ public void signOutTester() {
203202

204203
@Override
205204
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {
206-
Log.d(TAG, "Created activity: " + activity.getClass().getName());
205+
LogWrapper.getInstance().v("Created activity: " + activity.getClass().getName());
207206
// if SignInResultActivity is created, sign-in was successful
208207
if (activity instanceof SignInResultActivity) {
208+
LogWrapper.getInstance().v("Sign in completed");
209209
this.testerSignInClient.setSuccessfulSignInResult();
210210
this.signInStorage.setSignInStatus(true);
211211
}
212212
}
213213

214214
@Override
215215
public void onActivityStarted(@NonNull Activity activity) {
216-
Log.d(TAG, "Started activity: " + activity.getClass().getName());
216+
LogWrapper.getInstance().d("Started activity: " + activity.getClass().getName());
217217
}
218218

219219
@Override
220220
public void onActivityResumed(@NonNull Activity activity) {
221-
Log.d(TAG, "Resumed activity: " + activity.getClass().getName());
221+
LogWrapper.getInstance().d("Resumed activity: " + activity.getClass().getName());
222222
// If app resumes and aab update task is in progress, assume that installation didn't happen so
223223
// cancel the task
224224
updateAppClient.tryCancelAabUpdateTask();
@@ -231,6 +231,7 @@ public void onActivityResumed(@NonNull Activity activity) {
231231

232232
// Throw error if app reentered during sign in
233233
if (this.testerSignInClient.isCurrentlySigningIn()) {
234+
LogWrapper.getInstance().e("App Resumed without sign in flow completing.");
234235
testerSignInClient.setCanceledAuthenticationError();
235236
}
236237

@@ -241,22 +242,22 @@ public void onActivityResumed(@NonNull Activity activity) {
241242

242243
@Override
243244
public void onActivityPaused(@NonNull Activity activity) {
244-
Log.d(TAG, "Paused activity: " + activity.getClass().getName());
245+
LogWrapper.getInstance().d("Paused activity: " + activity.getClass().getName());
245246
}
246247

247248
@Override
248249
public void onActivityStopped(@NonNull Activity activity) {
249-
Log.d(TAG, "Stopped activity: " + activity.getClass().getName());
250+
LogWrapper.getInstance().d("Stopped activity: " + activity.getClass().getName());
250251
}
251252

252253
@Override
253254
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle bundle) {
254-
Log.d(TAG, "Saved activity: " + activity.getClass().getName());
255+
LogWrapper.getInstance().d("Saved activity: " + activity.getClass().getName());
255256
}
256257

257258
@Override
258259
public void onActivityDestroyed(@NonNull Activity activity) {
259-
Log.d(TAG, "Destroyed activity: " + activity.getClass().getName());
260+
LogWrapper.getInstance().d("Destroyed activity: " + activity.getClass().getName());
260261
if (this.currentActivity == activity) {
261262
this.currentActivity = null;
262263
this.updateAppClient.setCurrentActivity(null);

firebase-app-distribution/src/main/java/com/google/firebase/appdistribution/FirebaseAppDistributionNotificationsManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@
2424
import android.graphics.drawable.Drawable;
2525
import android.os.Build;
2626
import android.os.Build.VERSION;
27-
import android.util.Log;
2827
import androidx.annotation.VisibleForTesting;
2928
import androidx.core.app.NotificationCompat;
3029
import androidx.core.content.ContextCompat;
3130
import com.google.firebase.FirebaseApp;
3231

3332
class FirebaseAppDistributionNotificationsManager {
34-
private static final String TAG = "FADNotificationsManager";
33+
private static final String TAG = "NotificationsManager:";
3534
private static final String NOTIFICATION_CHANNEL_ID =
3635
"com.google.firebase.app.distribution.notification_channel_id";
3736

@@ -99,7 +98,7 @@ private PendingIntent createPendingIntent() {
9998
Context context = firebaseApp.getApplicationContext();
10099
Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
101100
if (intent == null) {
102-
Log.w(TAG, "No activity found to launch app");
101+
LogWrapper.getInstance().w(TAG + "No activity found to launch app");
103102
}
104103
return PendingIntent.getActivity(
105104
firebaseApp.getApplicationContext(), 0, intent, PendingIntent.FLAG_ONE_SHOT);
@@ -123,7 +122,8 @@ private boolean isAdaptiveIcon(int iconId) {
123122
try {
124123
Drawable icon = ContextCompat.getDrawable(firebaseApp.getApplicationContext(), iconId);
125124
if (VERSION.SDK_INT >= Build.VERSION_CODES.O && icon instanceof AdaptiveIconDrawable) {
126-
Log.e(TAG, "Adaptive icons cannot be used in notifications. Ignoring icon id: " + iconId);
125+
LogWrapper.getInstance()
126+
.e(TAG + "Adaptive icons cannot be used in notifications. Ignoring icon id: " + iconId);
127127
return true;
128128
} else {
129129
// AdaptiveIcons were introduced in API 26

firebase-app-distribution/src/main/java/com/google/firebase/appdistribution/FirebaseAppDistributionRegistrar.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package com.google.firebase.appdistribution;
1616

1717
import android.app.Application;
18-
import android.util.Log;
1918
import androidx.annotation.Keep;
2019
import androidx.annotation.NonNull;
2120
import com.google.firebase.FirebaseApp;
@@ -36,7 +35,7 @@
3635
@Keep
3736
public class FirebaseAppDistributionRegistrar implements ComponentRegistrar {
3837

39-
private static String TAG = "FadRegistrar";
38+
private static String TAG = "Registrar:";
4039

4140
@Override
4241
public @NonNull List<Component<?>> getComponents() {
@@ -59,9 +58,10 @@ private FirebaseAppDistribution buildFirebaseAppDistribution(ComponentContainer
5958
Application firebaseApplication = (Application) firebaseApp.getApplicationContext();
6059
firebaseApplication.registerActivityLifecycleCallbacks(appDistribution);
6160
} else {
62-
Log.e(
63-
TAG,
64-
"Error registering app to ActivityLifecycleCallbacks. SDK might not function correctly.");
61+
LogWrapper.getInstance()
62+
.e(
63+
TAG
64+
+ "Error registering app to ActivityLifecycleCallbacks. SDK might not function correctly.");
6565
}
6666

6767
return appDistribution;

firebase-app-distribution/src/main/java/com/google/firebase/appdistribution/FirebaseAppDistributionTesterApiClient.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class FirebaseAppDistributionTesterApiClient {
4343
private static final String CODE_HASH_KEY = "codeHash";
4444
private static final String IAS_ARTIFACT_ID_KEY = "iasArtifactId";
4545
private static final String DOWNLOAD_URL_KEY = "downloadUrl";
46+
private static final String TAG = "TesterApiClient:";
4647
public static final int DEFAULT_BUFFER_SIZE = 8192;
4748

4849
public @NonNull AppDistributionReleaseInternal fetchLatestRelease(
@@ -82,10 +83,10 @@ class FirebaseAppDistributionTesterApiClient {
8283

8384
} catch (IOException | JSONException e) {
8485
if (e instanceof JSONException) {
86+
LogWrapper.getInstance().e(TAG + "Error parsing the latest release.", e);
8587
throw new FirebaseAppDistributionException(
8688
Constants.ErrorMessages.JSON_PARSING_ERROR, NETWORK_FAILURE, e);
8789
}
88-
8990
throw getExceptionForHttpResponse(connection);
9091
} finally {
9192
connection.disconnect();
@@ -97,6 +98,7 @@ class FirebaseAppDistributionTesterApiClient {
9798
private FirebaseAppDistributionException getExceptionForHttpResponse(
9899
HttpsURLConnection connection) {
99100
try {
101+
LogWrapper.getInstance().e(TAG + "Failed due to " + connection.getResponseCode());
100102
switch (connection.getResponseCode()) {
101103
case 401:
102104
return new FirebaseAppDistributionException(
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2021 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.appdistribution;
16+
17+
import android.util.Log;
18+
19+
/** Wrapper that handles Android logcat logging. */
20+
class LogWrapper {
21+
22+
private static final String LOG_TAG = "FirebaseAppDistribution";
23+
private static LogWrapper instance;
24+
25+
public static synchronized LogWrapper getInstance() {
26+
if (instance == null) {
27+
instance = new LogWrapper();
28+
}
29+
30+
return instance;
31+
}
32+
33+
void d(String msg) {
34+
Log.d(LOG_TAG, msg);
35+
}
36+
37+
void v(String msg) {
38+
Log.v(LOG_TAG, msg);
39+
}
40+
41+
void i(String msg) {
42+
Log.i(LOG_TAG, msg);
43+
}
44+
45+
void w(String msg) {
46+
Log.w(LOG_TAG, msg);
47+
}
48+
49+
void e(String msg) {
50+
Log.e(LOG_TAG, msg);
51+
}
52+
53+
void e(String msg, Throwable tr) {
54+
Log.e(LOG_TAG, msg, tr);
55+
}
56+
57+
private LogWrapper() {}
58+
}

firebase-app-distribution/src/main/java/com/google/firebase/appdistribution/SignInResultActivity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
* when SignInResultActivity is created.
2424
*/
2525
public class SignInResultActivity extends AppCompatActivity {
26+
private static final String TAG = "SignInResultActivity:";
2627

2728
@Override
2829
public void onCreate(@NonNull Bundle savedInstanceBundle) {
2930
super.onCreate(savedInstanceBundle);
30-
31+
LogWrapper.getInstance().v(TAG + "The User is signing in");
3132
// While this does not appear to be achieving much, handling the redirect in this way
3233
// ensures that we can remove the browser tab from the back stack. See the documentation
3334
// on AuthorizationManagementActivity for more details.

firebase-app-distribution/src/main/java/com/google/firebase/appdistribution/TaskUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@
1818
import com.google.android.gms.tasks.Tasks;
1919

2020
class TaskUtils {
21+
private static final String TAG = "TaskUtils:";
22+
2123
static <TResult> Task<TResult> handleTaskFailure(
2224
Task<TResult> task,
2325
String defaultErrorMessage,
2426
FirebaseAppDistributionException.Status defaultErrorStatus) {
2527
if (task.isComplete() && !task.isSuccessful()) {
2628
Exception e = task.getException();
29+
LogWrapper.getInstance().e(TAG + "Task failed to complete due to " + e.getMessage(), e);
2730
if (e instanceof FirebaseAppDistributionException) {
2831
return task;
2932
}
30-
3133
return Tasks.forException(
3234
new FirebaseAppDistributionException(defaultErrorMessage, defaultErrorStatus, e));
3335
}

firebase-app-distribution/src/main/java/com/google/firebase/appdistribution/TesterSignInClient.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import android.content.Intent;
2525
import android.content.pm.ResolveInfo;
2626
import android.net.Uri;
27-
import android.util.Log;
2827
import androidx.annotation.GuardedBy;
2928
import androidx.annotation.NonNull;
3029
import androidx.annotation.Nullable;
@@ -40,7 +39,7 @@
4039
import java.util.List;
4140

4241
class TesterSignInClient {
43-
private static final String TAG = "FADSignInTester";
42+
private static final String TAG = "TesterSignIn:";
4443

4544
private TaskCompletionSource<Void> signInTaskCompletionSource = null;
4645
private final String SIGNIN_REDIRECT_URL =
@@ -66,15 +65,19 @@ class TesterSignInClient {
6665
@NonNull
6766
public synchronized Task<Void> signInTester() {
6867
if (signInStorage.getSignInStatus()) {
68+
LogWrapper.getInstance().v(TAG + "Tester is already signed in.");
6969
return Tasks.forResult(null);
7070
}
7171

7272
if (this.isCurrentlySigningIn()) {
73+
LogWrapper.getInstance()
74+
.v(TAG + "Detected In-Progress sign in task. Returning the same task.");
7375
return signInTaskCompletionSource.getTask();
7476
}
7577

7678
Activity currentActivity = getCurrentActivity();
7779
if (currentActivity == null) {
80+
LogWrapper.getInstance().e(TAG + "No foreground activity found.");
7881
return Tasks.forException(
7982
new FirebaseAppDistributionException(
8083
ErrorMessages.APP_BACKGROUNDED,
@@ -120,6 +123,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
120123
new OnFailureListener() {
121124
@Override
122125
public void onFailure(@NonNull Exception e) {
126+
LogWrapper.getInstance().e(TAG + "Fid retrieval failed.", e);
123127
setSignInTaskCompletionError(
124128
new FirebaseAppDistributionException(
125129
Constants.ErrorMessages.AUTHENTICATION_ERROR,
@@ -135,6 +139,7 @@ public void onFailure(@NonNull Exception e) {
135139
new DialogInterface.OnClickListener() {
136140
@Override
137141
public void onClick(DialogInterface dialogInterface, int i) {
142+
LogWrapper.getInstance().v("Sign in has been canceled.");
138143
setSignInTaskCompletionError(
139144
new FirebaseAppDistributionException(
140145
ErrorMessages.AUTHENTICATION_CANCELED, AUTHENTICATION_CANCELED));
@@ -172,12 +177,13 @@ private static String getApplicationName(Context context) {
172177
try {
173178
return context.getApplicationInfo().loadLabel(context.getPackageManager()).toString();
174179
} catch (Exception e) {
175-
Log.e(TAG, "Unable to retrieve App name");
180+
LogWrapper.getInstance().e(TAG + "Unable to retrieve App name", e);
176181
return "";
177182
}
178183
}
179184

180185
private void openSignInFlowInBrowser(Activity currentActivity, Uri uri) {
186+
LogWrapper.getInstance().v(TAG + "Opening sign in flow in browser at " + uri);
181187
if (supportsCustomTabs(firebaseApp.getApplicationContext())) {
182188
// If we can launch a chrome view, try that.
183189
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().build();

0 commit comments

Comments
 (0)