Skip to content

Commit 7efb067

Browse files
committed
OSInFocusDisplayOption fixes, clean-up, fallback icon
1 parent 4c32a65 commit 7efb067

21 files changed

+199
-88
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2016 OneSignal
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* 1. The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* 2. All copies of substantial portions of the Software may only be used in connection
17+
* with services provided by OneSignal.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
package com.onesignal.example;
29+
30+
import java.lang.reflect.Field;
31+
32+
public class DebuggingHelper {
33+
34+
static void printObject(Object obj) {
35+
for (Field field : obj.getClass().getDeclaredFields()) {
36+
String name = field.getName();
37+
try {
38+
Object value = field.get(obj);
39+
System.out.printf("Field name: %s, Field value: %s%n", name, value);
40+
} catch (Throwable t){}
41+
}
42+
}
43+
}

OneSignalSDK/app/src/main/java/com/onesignal/example/NotificationExtenderServiceTest.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public class NotificationExtenderServiceTest extends NotificationExtenderService
1313

1414
@Override
1515
protected boolean onNotificationProcessing(OSNotificationReceivedResult notification) {
16-
printObject(notification);
16+
DebuggingHelper.printObject(notification);
1717
if (notification.payload.actionButtons != null) {
1818
for(OSNotificationPayload.ActionButton button : notification.payload.actionButtons) {
1919
// System.out.println("button:");
20-
printObject(button);
20+
DebuggingHelper.printObject(button);
2121
}
2222
}
2323

@@ -34,14 +34,4 @@ public NotificationCompat.Builder extend(NotificationCompat.Builder builder) {
3434

3535
return true;
3636
}
37-
38-
static void printObject(Object obj) {
39-
for (Field field : obj.getClass().getDeclaredFields()) {
40-
String name = field.getName();
41-
try {
42-
Object value = field.get(obj);
43-
System.out.printf("Field name: %s, Field value: %s%n", name, value);
44-
} catch (Throwable t){}
45-
}
46-
}
4737
}

OneSignalSDK/app/src/main/java/com/onesignal/example/OneSignalExampleApp.java

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2016 OneSignal
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* 1. The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* 2. All copies of substantial portions of the Software may only be used in connection
17+
* with services provided by OneSignal.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
128
package com.onesignal.example;
229

330
import android.app.Application;
@@ -19,36 +46,41 @@ public void onCreate() {
1946

2047
OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE);
2148
OneSignal.startInit(this)
22-
// .autoPromptLocation(true)
49+
.autoPromptLocation(true)
2350
.setNotificationOpenedHandler(new ExampleNotificationOpenedHandler())
2451
.setNotificationReceivedHandler(new ExampleNotificationReceivedHandler())
2552
.init();
2653
}
2754

2855
private class ExampleNotificationReceivedHandler implements OneSignal.NotificationReceivedHandler {
56+
/**
57+
* Callback to implement in your app to handle when a notification is received while your app running
58+
* in the foreground or background.
59+
*
60+
* Use a NotificationExtenderService instead to receive an event even when your app is closed (not 'forced stopped')
61+
* or to override notification properties.
62+
*
63+
* @param notification Contains information about the notification received.
64+
*/
2965
@Override
3066
public void notificationReceived(OSNotification notification) {
31-
System.out.println("notificationReceived!!!!!!");
32-
NotificationExtenderServiceTest.printObject(notification);
67+
Log.w("OneSignalExample", "notificationReceived!!!!!!");
68+
DebuggingHelper.printObject(notification);
69+
DebuggingHelper.printObject(notification.payload);
3370
}
3471
}
3572

3673
private class ExampleNotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {
3774
/**
38-
* Callback to implement in your app to handle when a notification is opened from the Android status bar or
39-
* a new one comes in while the app is running.
40-
* This method is located in this activity as an example, you may have any class you wish implement NotificationOpenedHandler and define this method.
75+
* Callback to implement in your app to handle when a notification is opened from the Android status bar or in app alert
4176
*
42-
* @param openedResult The message string the user seen/should see in the Android status bar.
77+
* @param openedResult Contains information about the notification opened and the action taken on it.
4378
*/
4479
@Override
4580
public void notificationOpened(OSNotificationOpenResult openedResult) {
46-
System.out.println("notificationOpened!!!!!!");
47-
NotificationExtenderServiceTest.printObject(openedResult);
48-
49-
// Log.e("OneSignalExample", "body: " + openedResult.notification.payload.body);
50-
// Log.e("OneSignalExample", "additional data: " + openedResult.notification.payload.additionalData);
51-
//Log.e("OneSignalExample", "additionalData: " + additionalData.toString());
81+
Log.w("OneSignalExample", "notificationOpened!!!!!!");
82+
DebuggingHelper.printObject(openedResult.action);
83+
DebuggingHelper.printObject(openedResult.notification);
5284
}
5385
}
5486
}

OneSignalSDK/app/src/test/java/com/onesignal/ShadowOneSignalRestClient.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ static void put(String url, JSONObject jsonBody, OneSignalRestClient.ResponseHan
138138
safeInterrupt();
139139
}
140140

141+
static void get(final String url, final OneSignalRestClient.ResponseHandler responseHandler) {
142+
System.out.println("get: " + url);
143+
networkCallCount++;
144+
doInterruptibleDelay();
145+
responseHandler.onSuccess("{\"awl_list\": {" +
146+
"\"IlIfoQBT5jXgkgn6nBsIrGJn5t0Yd91GqKAGoApIYzk=\": 1," +
147+
"\"Q3zjDf/4NxXU1QpN9WKp/iwVYNPQZ0js2EDDNO+eo0o=\": 1" +
148+
"}}");
149+
150+
safeInterrupt();
151+
}
152+
141153
static void getSync(final String url, final OneSignalRestClient.ResponseHandler responseHandler) {
142154
System.out.println("getSync: " + url);
143155

OneSignalSDK/app/src/test/java/com/test/onesignal/MainOneSignalClassRunner.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public void testPutStillCalledOnChanges() throws Exception {
248248
blankActivityController.resume();
249249
threadAndTaskWait();
250250
Assert.assertNull(ShadowOneSignalRestClient.lastUrl);
251-
Assert.assertEquals(1, ShadowOneSignalRestClient.networkCallCount);
251+
Assert.assertEquals(2, ShadowOneSignalRestClient.networkCallCount);
252252

253253
ShadowOSUtils.carrierName = "test2";
254254

@@ -260,7 +260,7 @@ public void testPutStillCalledOnChanges() throws Exception {
260260
blankActivityController.resume();
261261
threadAndTaskWait();
262262

263-
Assert.assertEquals(2, ShadowOneSignalRestClient.networkCallCount);
263+
Assert.assertEquals(4, ShadowOneSignalRestClient.networkCallCount);
264264
GetIdsAvailable();
265265
Assert.assertEquals("players/" + callBackUseId, ShadowOneSignalRestClient.lastUrl);
266266
Assert.assertEquals("{\"carrier\":\"test2\",\"app_id\":\"b2f7f966-d8cc-11e4-bed1-df8f05be55ba\"}", ShadowOneSignalRestClient.lastPost.toString());
@@ -696,7 +696,7 @@ public void shouldSendTags() throws Exception {
696696
OneSignalInit();
697697
OneSignal.sendTags(new JSONObject("{\"test1\": \"value1\", \"test2\": \"value2\"}"));
698698
threadAndTaskWait();
699-
Assert.assertEquals(1, ShadowOneSignalRestClient.networkCallCount);
699+
Assert.assertEquals(2, ShadowOneSignalRestClient.networkCallCount);
700700
Assert.assertEquals(ONESIGNAL_APP_ID, ShadowOneSignalRestClient.lastPost.getString("app_id"));
701701
Assert.assertEquals("value1", ShadowOneSignalRestClient.lastPost.getJSONObject("tags").getString("test1"));
702702
Assert.assertEquals("value2", ShadowOneSignalRestClient.lastPost.getJSONObject("tags").getString("test2"));
@@ -705,13 +705,13 @@ public void shouldSendTags() throws Exception {
705705
ShadowOneSignalRestClient.lastPost = null;
706706
OneSignal.sendTags(new JSONObject("{\"test1\": \"value1\", \"test2\": \"value2\"}"));
707707
threadAndTaskWait();
708-
Assert.assertEquals(1, ShadowOneSignalRestClient.networkCallCount);
708+
Assert.assertEquals(2, ShadowOneSignalRestClient.networkCallCount);
709709
Assert.assertNull(ShadowOneSignalRestClient.lastPost);
710710

711711
// Should only send changed and new tags
712712
OneSignal.sendTags(new JSONObject("{\"test1\": \"value1.5\", \"test2\": \"value2\", \"test3\": \"value3\"}"));
713713
threadAndTaskWait();
714-
Assert.assertEquals(2, ShadowOneSignalRestClient.networkCallCount);
714+
Assert.assertEquals(3, ShadowOneSignalRestClient.networkCallCount);
715715
JSONObject sentTags = ShadowOneSignalRestClient.lastPost.getJSONObject("tags");
716716
Assert.assertEquals("value1.5", sentTags.getString("test1"));
717717
Assert.assertFalse(sentTags.has(("test2")));
@@ -722,7 +722,7 @@ public void shouldSendTags() throws Exception {
722722
public void shouldSendTagsWithRequestBatching() throws Exception {
723723
OneSignalInit();
724724
threadAndTaskWait();
725-
Assert.assertEquals(1, ShadowOneSignalRestClient.networkCallCount);
725+
Assert.assertEquals(2, ShadowOneSignalRestClient.networkCallCount);
726726
OneSignal.sendTags(new JSONObject("{\"test1\": \"value1\"}"));
727727
OneSignal.sendTags(new JSONObject("{\"test2\": \"value2\"}"));
728728

@@ -732,7 +732,7 @@ public void shouldSendTagsWithRequestBatching() throws Exception {
732732

733733
Assert.assertEquals("value1", lastGetTags.getString("test1"));
734734
Assert.assertEquals("value2", lastGetTags.getString("test2"));
735-
Assert.assertEquals(3, ShadowOneSignalRestClient.networkCallCount);
735+
Assert.assertEquals(4, ShadowOneSignalRestClient.networkCallCount);
736736
}
737737

738738
@Test
@@ -827,7 +827,8 @@ public void shouldSaveToSyncIfKilledBeforeDelayedCompare() throws Exception {
827827
OneSignalPackagePrivateHelper.SyncService_onTaskRemoved();
828828
OneSignalPackagePrivateHelper.resetRunnables();
829829
threadAndTaskWait();
830-
Assert.assertEquals(0, ShadowOneSignalRestClient.networkCallCount);
830+
// Only for awl
831+
Assert.assertEquals(1, ShadowOneSignalRestClient.networkCallCount);
831832

832833
StaticResetHelper.restSetStaticFields();
833834

@@ -845,7 +846,7 @@ public void shouldSyncPendingChangesFromSyncService() throws Exception {
845846
OneSignalPackagePrivateHelper.SyncService_onTaskRemoved();
846847
OneSignalPackagePrivateHelper.resetRunnables();
847848
threadAndTaskWait();
848-
Assert.assertEquals(1, ShadowOneSignalRestClient.networkCallCount);
849+
Assert.assertEquals(2, ShadowOneSignalRestClient.networkCallCount);
849850

850851
StaticResetHelper.restSetStaticFields();
851852

@@ -984,13 +985,13 @@ public void shouldGetTagsFromServerOnFirstCall() throws Exception {
984985
GetTags();
985986
threadAndTaskWait(); threadAndTaskWait();
986987

987-
Assert.assertEquals(2, ShadowOneSignalRestClient.networkCallCount);
988+
Assert.assertEquals(3, ShadowOneSignalRestClient.networkCallCount);
988989
Assert.assertEquals("value1", lastGetTags.getString("test1"));
989990
Assert.assertEquals("value2", lastGetTags.getString("test2"));
990991

991992
GetTags();
992993
threadAndTaskWait();
993-
Assert.assertEquals(2, ShadowOneSignalRestClient.networkCallCount);
994+
Assert.assertEquals(3, ShadowOneSignalRestClient.networkCallCount);
994995
}
995996

996997
@Test
@@ -1001,7 +1002,7 @@ public void getTagsDelayedAfterRegistering() throws Exception {
10011002
ShadowOneSignalRestClient.nextSuccessResponse = "{\"tags\": {\"test1\": \"value1\"}}";
10021003
threadAndTaskWait(); threadAndTaskWait();
10031004

1004-
Assert.assertEquals(2, ShadowOneSignalRestClient.networkCallCount);
1005+
Assert.assertEquals(3, ShadowOneSignalRestClient.networkCallCount);
10051006
Assert.assertEquals("value1", lastGetTags.getString("test1"));
10061007
Assert.assertTrue(ShadowOneSignalRestClient.lastUrl.contains(ShadowOneSignalRestClient.testUserId));
10071008
}
@@ -1018,7 +1019,7 @@ public void sendsOnFocus() throws Exception {
10181019
blankActivityController.pause();
10191020
threadAndTaskWait();
10201021
Assert.assertEquals(60, ShadowOneSignalRestClient.lastPost.getInt("active_time"));
1021-
Assert.assertEquals(2, ShadowOneSignalRestClient.networkCallCount);
1022+
Assert.assertEquals(3, ShadowOneSignalRestClient.networkCallCount);
10221023
}
10231024

10241025
/*

OneSignalSDK/onesignal/src/main/java/com/onesignal/ActivityLifecycleHandler.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ void runRunnable(AppFocusRunnable runnable) {
156156
}
157157

158158
boolean hasBackgrounded() {
159-
if (appFocusRunnable != null)
160-
return appFocusRunnable.backgrounded;
161-
return false;
159+
return appFocusRunnable != null && appFocusRunnable.backgrounded;
162160
}
163161
}
164162

OneSignalSDK/onesignal/src/main/java/com/onesignal/GenerateNotification.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,6 @@ private static Bitmap getLargeIcon(JSONObject gcmBundle) {
550550
Bitmap bitmap = getBitmap(gcmBundle.optString("licon"));
551551
if (bitmap == null)
552552
bitmap = getBitmapFromAssetsOrResourceName("ic_onesignal_large_icon_default");
553-
if (bitmap == null)
554-
bitmap = getBitmapFromAssetsOrResourceName("ic_gamethrive_large_icon_default");
555553

556554
if (bitmap == null)
557555
return null;
@@ -650,20 +648,15 @@ private static int getSmallIconId(JSONObject gcmBundle) {
650648
if (notificationIcon != 0)
651649
return notificationIcon;
652650

653-
notificationIcon = getDrawableId("ic_stat_gamethrive_default");
654-
if (notificationIcon != 0)
655-
return notificationIcon;
656-
657651
notificationIcon = getDrawableId("corona_statusbar_icon_default");
658652
if (notificationIcon != 0)
659653
return notificationIcon;
660654

661-
// Launcher icon
662-
notificationIcon = currentContext.getApplicationInfo().icon;
655+
notificationIcon = getDrawableId("ic_os_notification_fallback_white_24dp");
663656
if (notificationIcon != 0)
664657
return notificationIcon;
665658

666-
return drawable.sym_def_app_icon; // Catches case where icon isn't set in the AndroidManifest.xml
659+
return drawable.ic_popup_reminder;
667660
}
668661

669662
private static int getDrawableId(String name) {
@@ -684,10 +677,6 @@ private static Uri getCustomSound(JSONObject gcmBundle) {
684677
if (soundId != 0)
685678
return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + packageName + "/" + soundId);
686679

687-
soundId = contextResources.getIdentifier("gamethrive_default_sound", "raw", packageName);
688-
if (soundId != 0)
689-
return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + packageName + "/" + soundId);
690-
691680
return null;
692681
}
693682

0 commit comments

Comments
 (0)