Skip to content

Commit

Permalink
[android][notifications] Fix NPE when rescheduling notifications #1013
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbianca committed Apr 24, 2018
1 parent 3b634a8 commit 7614f5b
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.RemoteInput;
import android.support.v4.content.LocalBroadcastManager;
Expand Down Expand Up @@ -634,7 +635,7 @@ private NotificationChannel parseChannelMap(ReadableMap channelMap) {
return null;
}

private void scheduleNotification(Bundle notification, Promise promise) {
private void scheduleNotification(Bundle notification, @Nullable Promise promise) {
if (!notification.containsKey("notificationId")) {
if (promise == null) {
Log.e(TAG, "Missing notificationId");
Expand Down Expand Up @@ -664,7 +665,11 @@ private void scheduleNotification(Bundle notification, Promise promise) {
JSONObject json = BundleJSONConverter.convertToJSON(notification);
preferences.edit().putString(notificationId, json.toString()).apply();
} catch (JSONException e) {
promise.reject("notification/schedule_notification_error", "Failed to store notification", e);
if (promise == null) {
Log.e(TAG, "Failed to store notification");
} else {
promise.reject("notification/schedule_notification_error", "Failed to store notification", e);
}
return;
}

Expand Down Expand Up @@ -694,7 +699,11 @@ private void scheduleNotification(Bundle notification, Promise promise) {
}

if (interval == null) {
promise.reject("notification/schedule_notification_error", "Invalid interval");
if (promise == null) {
Log.e(TAG, "Invalid interval");
} else {
promise.reject("notification/schedule_notification_error", "Invalid interval");
}
return;
}

Expand All @@ -709,6 +718,8 @@ private void scheduleNotification(Bundle notification, Promise promise) {
}
}

promise.resolve(null);
if (promise != null) {
promise.resolve(null);
}
}
}

0 comments on commit 7614f5b

Please sign in to comment.