Skip to content

Commit 1d4a539

Browse files
committed
Code cleaning
* Manifest service declaration is not needed anymore since we only depend on metadata * Rename notificationID json key to notificationId * Remove payload object from toJSONObject
1 parent fe65bc6 commit 1d4a539

File tree

5 files changed

+36
-51
lines changed

5 files changed

+36
-51
lines changed

Examples/OneSignalDemo/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,7 @@
1919
tools:ignore="GoogleAppIndexingWarning">
2020

2121
<meta-data android:name="com.onesignal.NotificationServiceExtension"
22-
android:value="com.onesignal.sdktest.notification.AppRemoteNotificationExtensionService" />
23-
24-
<service
25-
android:name=".notification.NotificationServiceExtension"
26-
android:permission="android.permission.BIND_JOB_SERVICE"
27-
android:exported="false">
28-
<intent-filter>
29-
<action android:name="com.onesignal.NotificationExtender" />
30-
</intent-filter>
31-
</service>
22+
android:value="com.onesignal.sdktest.notification.NotificationServiceExtension" />
3223

3324
<activity android:name=".activity.SplashActivity">
3425
<intent-filter>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ static void processFromFCMIntentService(Context context, BundleCompat bundle) {
116116
* in the event where you want to mark a notification as opened or displayed different than the defaults
117117
*/
118118
@WorkerThread
119-
static int processJobForDisplay(OSNotificationGenerationJob notificationJob, boolean callForegroundLogic) {
119+
static int processJobForDisplay(OSNotificationGenerationJob notificationJob, boolean fromBackgroundLogic) {
120120
OSNotificationController notificationController = new OSNotificationController(notificationJob, notificationJob.isRestoring(), true);
121-
return processJobForDisplay(notificationController, false, callForegroundLogic);
121+
return processJobForDisplay(notificationController, false, fromBackgroundLogic);
122122
}
123123

124124
@WorkerThread

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

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -464,39 +464,35 @@ public JSONObject toJSONObject() {
464464
mainObj.put("groupedNotifications", payloadJsonArray);
465465
}
466466

467-
JSONObject payload = new JSONObject();
468-
469-
payload.put("notificationID", notificationId);
470-
payload.put("title", title);
471-
payload.put("body", body);
472-
payload.put("smallIcon", smallIcon);
473-
payload.put("largeIcon", largeIcon);
474-
payload.put("bigPicture", bigPicture);
475-
payload.put("smallIconAccentColor", smallIconAccentColor);
476-
payload.put("launchURL", launchURL);
477-
payload.put("sound", sound);
478-
payload.put("ledColor", ledColor);
479-
payload.put("lockScreenVisibility", lockScreenVisibility);
480-
payload.put("groupKey", groupKey);
481-
payload.put("groupMessage", groupMessage);
482-
payload.put("fromProjectNumber", fromProjectNumber);
483-
payload.put("collapseId", collapseId);
484-
payload.put("priority", priority);
467+
mainObj.put("notificationId", notificationId);
468+
mainObj.put("title", title);
469+
mainObj.put("body", body);
470+
mainObj.put("smallIcon", smallIcon);
471+
mainObj.put("largeIcon", largeIcon);
472+
mainObj.put("bigPicture", bigPicture);
473+
mainObj.put("smallIconAccentColor", smallIconAccentColor);
474+
mainObj.put("launchURL", launchURL);
475+
mainObj.put("sound", sound);
476+
mainObj.put("ledColor", ledColor);
477+
mainObj.put("lockScreenVisibility", lockScreenVisibility);
478+
mainObj.put("groupKey", groupKey);
479+
mainObj.put("groupMessage", groupMessage);
480+
mainObj.put("fromProjectNumber", fromProjectNumber);
481+
mainObj.put("collapseId", collapseId);
482+
mainObj.put("priority", priority);
485483

486484
if (additionalData != null)
487-
payload.put("additionalData", additionalData);
485+
mainObj.put("additionalData", additionalData);
488486

489487
if (actionButtons != null) {
490488
JSONArray actionButtonJsonArray = new JSONArray();
491489
for (ActionButton actionButton : actionButtons) {
492490
actionButtonJsonArray.put(actionButton.toJSONObject());
493491
}
494-
payload.put("actionButtons", actionButtonJsonArray);
492+
mainObj.put("actionButtons", actionButtonJsonArray);
495493
}
496494

497-
payload.put("rawPayload", rawPayload);
498-
499-
mainObj.put("payload", payload);
495+
mainObj.put("rawPayload", rawPayload);
500496
}
501497
catch(JSONException e) {
502498
e.printStackTrace();

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import androidx.annotation.NonNull;
4747
import androidx.annotation.Nullable;
4848
import androidx.annotation.WorkerThread;
49+
import androidx.core.app.NotificationCompat;
4950

5051
import com.onesignal.OneSignalDbContract.NotificationTable;
5152
import com.onesignal.influence.data.OSTrackerFactory;
@@ -134,18 +135,15 @@ public boolean isAppClose() {
134135
}
135136

136137
/**
137-
* Meant to be implemented within a custom made NotificationExtensionService
138-
* Naming can be whatever makes the most sense to the developer, but to actually activate any
139-
* implemented interfaces, a metadata tag with a specific OneSignal key and then file path value
140-
* must be added to the apps AndroidManifest.xml
141-
* ex. <meta-data android:name="com.onesignal.NotificationServiceExtension" android:value="com.company.ExtensionService" />
138+
* Implement this interface on a class with a default public constructor and provide class with namespace
139+
* as a value to a new `meta-data` tag with the key name of "com.onesignal.NotificationServiceExtension" in
140+
* your AndroidManifest.xml.
141+
* ex. <meta-data android:name="com.onesignal.NotificationServiceExtension" android:value="com.company.MyNotificationExtensionService" />
142142
* <br/><br/>
143-
* Allows for modification of a notifications payload by creating a {@link OSNotificationController.OverrideSettings}
144-
* instance and passing it into {@link OSNotificationReceivedEvent#setModifiedContent(OSNotificationController.OverrideSettings)}
145-
* To display the notification, call {@link OSNotificationReceivedEvent#display()}
146-
* Finally, to notify the SDK that the processing work is done, call {@link OSNotificationReceivedEvent#complete()}
147-
* <br/><br/>
148-
* TODO: Update docs with new OSRemoteNotificationReceivedHandler, this would be replacing the old NotificationExtenderService
143+
* Allows for modification of a notification by calling {@link OSNotification#mutableCopy}
144+
* instance and passing it into {@link OSMutableNotification#setExtender(NotificationCompat.Extender)}
145+
* To display the notification, call {@link OSNotificationReceivedEvent#complete(OSNotification)} with a notification instance.
146+
* To omit displaying a notification call {@link OSNotificationReceivedEvent#complete(OSNotification)} with null.
149147
*/
150148
public interface OSRemoteNotificationReceivedHandler {
151149

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3865,11 +3865,11 @@ public void testOSNotificationToJSONObject() throws Exception {
38653865

38663866
JSONObject testJsonObj = osNotification.toJSONObject();
38673867

3868-
assertEquals("msg_body", testJsonObj.optJSONObject("payload").optString("body"));
3869-
JSONObject firstActionButton = (JSONObject)testJsonObj.optJSONObject("payload").optJSONArray("actionButtons").get(0);
3868+
assertEquals("msg_body", testJsonObj.optString("body"));
3869+
JSONObject firstActionButton = (JSONObject)testJsonObj.optJSONArray("actionButtons").get(0);
38703870
assertEquals("text", firstActionButton.optString("text"));
38713871

3872-
JSONObject additionalData = testJsonObj.optJSONObject("payload").optJSONObject("additionalData");
3872+
JSONObject additionalData = testJsonObj.optJSONObject("additionalData");
38733873
assertEquals("bar", additionalData.optString("foo"));
38743874
}
38753875

@@ -3880,11 +3880,11 @@ public void testOSNotificationOpenResultToJSONObject() throws Exception {
38803880

38813881
JSONObject testJsonObj = osNotificationOpenedResult.toJSONObject();
38823882

3883-
JSONObject additionalData = testJsonObj.optJSONObject("notification").optJSONObject("payload").optJSONObject("additionalData");
3883+
JSONObject additionalData = testJsonObj.optJSONObject("notification").optJSONObject("additionalData");
38843884
assertEquals("bar", additionalData.optString("foo"));
38853885

38863886
JSONObject firstGroupedNotification = (JSONObject)testJsonObj.optJSONObject("notification").optJSONArray("groupedNotifications").get(0);
3887-
assertEquals("collapseId1", firstGroupedNotification.optJSONObject("payload").optString("collapseId"));
3887+
assertEquals("collapseId1", firstGroupedNotification.optString("collapseId"));
38883888
}
38893889

38903890
@Test

0 commit comments

Comments
 (0)