Skip to content

Commit

Permalink
Fixed some properties not assigning on NotificationExtenderService
Browse files Browse the repository at this point in the history
  • Loading branch information
jkasten2 committed Jun 2, 2016
1 parent 3f96c51 commit 7ffb98f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
Binary file modified OneSignalSDK.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.onesignal.OneSignalDbHelper;
import com.onesignal.OneSignalPackagePrivateHelper;
import com.onesignal.ShadowBadgeCountUpdater;
import com.onesignal.ShadowOneSignal;
import com.onesignal.ShadowOneSignalRestClient;
import com.onesignal.ShadowRoboNotificationManager;
import com.onesignal.ShadowRoboNotificationManager.PostedNotification;
Expand Down Expand Up @@ -280,6 +281,7 @@ public void shouldGenerate2BasicGroupNotifications() throws Exception {
}

@Test
@Config(shadows = {ShadowOneSignal.class})
public void shouldFireNotificationExtenderService() throws Exception {
Bundle bundle = getBaseNotifBundle();

Expand Down Expand Up @@ -332,6 +334,24 @@ public void shouldFireNotificationExtenderService() throws Exception {
Assert.assertEquals("nValue", additionalData.getJSONObject("nested").getString("nKey"));

Assert.assertNotSame(-1, service.notificationId);


// Test a basic notification without anything special.
testIntent = new Intent(RuntimeEnvironment.application, NotificationExtenderServiceTest.class);
testIntent.putExtras(getBaseNotifBundle());
controller.withIntent(testIntent).startCommand(0, 0);
Assert.assertFalse(ShadowOneSignal.messages.contains("Error assigning"));


// Test that a notification is still displayed if the developer's code in onNotificationProcessing throws an Exception.
NotificationExtenderServiceTest.throwInAppCode = true;
testIntent = new Intent(RuntimeEnvironment.application, NotificationExtenderServiceTest.class);
testIntent.putExtras(getBaseNotifBundle("NewUUID1"));
controller.withIntent(testIntent).startCommand(0, 0);

Assert.assertTrue(ShadowOneSignal.messages.contains("onNotificationProcessing throw an exception"));
List<PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications;
Assert.assertEquals(3, postedNotifs.size());
}

private static Bundle getBundleWithAllOptionsSet() {
Expand Down Expand Up @@ -372,6 +392,7 @@ private static Bundle getBundleWithAllOptionsSet() {
public static class NotificationExtenderServiceTest extends NotificationExtenderService {
public OSNotificationPayload notification;
public int notificationId = -1;
public static boolean throwInAppCode;

// Override onStart to manually call onHandleIntent on the main thread.
@Override
Expand All @@ -382,6 +403,9 @@ public void onStart(Intent intent, int startId) {

@Override
protected boolean onNotificationProcessing(OSNotificationPayload notification) {
if (throwInAppCode)
throw new NullPointerException();

this.notification = notification;
notificationId = displayNotification(new OverrideSettings()).notificationId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected final OSNotificationDisplayedResult displayNotification(OverrideSettin
if (osNotificationDisplayedResult != null || overrideSettings == null)
return null;

OSNotificationDisplayedResult osNotificationDisplayedResult = new OSNotificationDisplayedResult();
osNotificationDisplayedResult = new OSNotificationDisplayedResult();
osNotificationDisplayedResult.notificationId = NotificationBundleProcessor.Process(this, currentExtras, overrideSettings);
return osNotificationDisplayedResult;
}
Expand Down Expand Up @@ -119,7 +119,9 @@ private void processIntent(Intent intent) {
notification.groupMessage = currentExtras.getString("grp_msg");
notification.backgroundColor = currentExtras.getString("bgac");
notification.ledColor = currentExtras.getString("ledc");
notification.visibility = Integer.parseInt(currentExtras.getString("vis"));
String visibility = currentExtras.getString("vis");
if (visibility != null)
notification.visibility = Integer.parseInt(visibility);
notification.backgroundData = "1".equals(currentExtras.getString("bgn"));
notification.fromProjectNumber = currentExtras.getString("from");

Expand All @@ -143,7 +145,17 @@ private void processIntent(Intent intent) {
}

osNotificationDisplayedResult = null;
boolean developerProcessed = onNotificationProcessing(notification);
boolean developerProcessed = false;
try {
developerProcessed = onNotificationProcessing(notification);
}
catch (Throwable t) {
//noinspection ConstantConditions - displayNotification might have been called by the developer
if (osNotificationDisplayedResult == null)
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "onNotificationProcessing throw an exception. Displaying normal OneSignal notification. ", t);
else
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "onNotificationProcessing throw an exception. Extended notification displayed but custom processing did not finish.", t);
}

// If developer did not call displayNotification from onNotificationProcessing
if (osNotificationDisplayedResult == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void init() {
private static TrackGooglePurchase trackGooglePurchase;
private static TrackAmazonPurchase trackAmazonPurchase;

public static final String VERSION = "020400";
public static final String VERSION = "020401";

private static AdvertisingIdentifierProvider mainAdIdProvider = new AdvertisingIdProviderGPS();

Expand Down

0 comments on commit 7ffb98f

Please sign in to comment.