Skip to content

Catch RuntimeException when getting analytics Bundle. #3564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.
package com.google.firebase.messaging;

import static com.google.firebase.messaging.Constants.TAG;

import android.app.Activity;
import android.app.Application;
import android.content.Intent;
Expand All @@ -21,6 +23,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import java.util.Collections;
import java.util.Set;
import java.util.WeakHashMap;
Expand Down Expand Up @@ -74,12 +77,19 @@ public void onActivityResumed(Activity activity) {}
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {}

private void logNotificationOpen(Intent startingIntent) {
Bundle extras = startingIntent.getExtras();
if (extras != null) {
Bundle analyticsData = extras.getBundle(Constants.MessageNotificationKeys.ANALYTICS_DATA);
if (MessagingAnalytics.shouldUploadScionMetrics(analyticsData)) {
MessagingAnalytics.logNotificationOpen(analyticsData);
Bundle analyticsData = null;
try {
Bundle extras = startingIntent.getExtras();
if (extras != null) {
analyticsData = extras.getBundle(Constants.MessageNotificationKeys.ANALYTICS_DATA);
}
} catch (RuntimeException e) {
// Don't crash if there was a problem trying to get the analytics data Bundle since the
// Intent could be coming from anywhere and could be incorrectly formatted.
Log.w(TAG, "Failed trying to get analytics data from Intent extras.", e);
}
if (MessagingAnalytics.shouldUploadScionMetrics(analyticsData)) {
MessagingAnalytics.logNotificationOpen(analyticsData);
}
}
}