Skip to content

Commit 56b0cd3

Browse files
authored
Catch RuntimeException when getting analytics Bundle. (#3564)
#3538 * Added catching RuntimeException when trying to get the analytics data Bundle from the Activity Intent since it's possible that the extras could contain invalid or incorrectly formatted data that will throw an Exception when trying to get the Bundle.
1 parent 1667f33 commit 56b0cd3

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

firebase-messaging/src/main/java/com/google/firebase/messaging/FcmLifecycleCallbacks.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// limitations under the License.
1414
package com.google.firebase.messaging;
1515

16+
import static com.google.firebase.messaging.Constants.TAG;
17+
1618
import android.app.Activity;
1719
import android.app.Application;
1820
import android.content.Intent;
@@ -21,6 +23,7 @@
2123
import android.os.Bundle;
2224
import android.os.Handler;
2325
import android.os.Looper;
26+
import android.util.Log;
2427
import java.util.Collections;
2528
import java.util.Set;
2629
import java.util.WeakHashMap;
@@ -74,12 +77,19 @@ public void onActivityResumed(Activity activity) {}
7477
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {}
7578

7679
private void logNotificationOpen(Intent startingIntent) {
77-
Bundle extras = startingIntent.getExtras();
78-
if (extras != null) {
79-
Bundle analyticsData = extras.getBundle(Constants.MessageNotificationKeys.ANALYTICS_DATA);
80-
if (MessagingAnalytics.shouldUploadScionMetrics(analyticsData)) {
81-
MessagingAnalytics.logNotificationOpen(analyticsData);
80+
Bundle analyticsData = null;
81+
try {
82+
Bundle extras = startingIntent.getExtras();
83+
if (extras != null) {
84+
analyticsData = extras.getBundle(Constants.MessageNotificationKeys.ANALYTICS_DATA);
8285
}
86+
} catch (RuntimeException e) {
87+
// Don't crash if there was a problem trying to get the analytics data Bundle since the
88+
// Intent could be coming from anywhere and could be incorrectly formatted.
89+
Log.w(TAG, "Failed trying to get analytics data from Intent extras.", e);
90+
}
91+
if (MessagingAnalytics.shouldUploadScionMetrics(analyticsData)) {
92+
MessagingAnalytics.logNotificationOpen(analyticsData);
8393
}
8494
}
8595
}

0 commit comments

Comments
 (0)