53
53
</service>
54
54
*/
55
55
56
- // TODO: This class can no longer extend IntentService. Nor can we change it to JobService.
57
- // It will be called from the respective server / job instead.
58
- public abstract class NotificationExtenderService {
56
+ public abstract class NotificationExtenderService extends IntentService {
59
57
60
58
public static class OverrideSettings {
61
59
public NotificationCompat .Extender extender ;
@@ -75,6 +73,11 @@ void override(OverrideSettings overrideSettings) {
75
73
}
76
74
}
77
75
76
+ public NotificationExtenderService () {
77
+ super ("NotificationExtenderService" );
78
+ setIntentRedelivery (true );
79
+ }
80
+
78
81
private OSNotificationDisplayedResult osNotificationDisplayedResult ;
79
82
private JSONObject currentJsonPayload ;
80
83
private boolean currentlyRestoring ;
@@ -90,19 +93,20 @@ protected final OSNotificationDisplayedResult displayNotification(OverrideSettin
90
93
91
94
overrideSettings .override (currentBaseOverrideSettings );
92
95
osNotificationDisplayedResult = new OSNotificationDisplayedResult ();
93
-
96
+
94
97
NotificationGenerationJob notifJob = createNotifJobFromCurrent ();
95
98
notifJob .overrideSettings = overrideSettings ;
96
-
99
+
97
100
osNotificationDisplayedResult .androidNotificationId = NotificationBundleProcessor .Process (notifJob );
98
101
return osNotificationDisplayedResult ;
99
102
}
100
103
101
104
// App developer must implement
102
105
// - Return true to count it as processed which will prevent the default OneSignal SDK notification from displaying.
103
106
protected abstract boolean onNotificationProcessing (OSNotificationReceivedResult notification );
104
-
105
- final void onHandleIntent (Intent intent ) {
107
+
108
+ @ Override
109
+ protected final void onHandleIntent (Intent intent ) {
106
110
processIntent (intent );
107
111
GcmBroadcastReceiver .completeWakefulIntent (intent );
108
112
}
@@ -119,7 +123,7 @@ private void processIntent(Intent intent) {
119
123
120
124
String jsonStrPayload = bundle .getString ("json_payload" );
121
125
if (jsonStrPayload == null ) {
122
- OneSignal .Log (OneSignal .LOG_LEVEL .ERROR , "json_payload key is nonexistent from mBundle passed to NotificationExtenderService: " + bundle );
126
+ OneSignal .Log (OneSignal .LOG_LEVEL .ERROR , "json_payload key is nonexistent from bundle passed to NotificationExtenderService: " + bundle );
123
127
return ;
124
128
}
125
129
@@ -165,15 +169,15 @@ void processJsonObject(JSONObject currentJsonPayload, boolean restoring) {
165
169
// Save as processed to prevent possible duplicate calls from canonical ids.
166
170
167
171
boolean display = !developerProcessed &&
168
- NotificationBundleProcessor .shouldDisplay (!"" .equals (currentJsonPayload .optString ("alert" )));
172
+ NotificationBundleProcessor .shouldDisplay (!"" .equals (currentJsonPayload .optString ("alert" )));
169
173
170
174
if (!display ) {
171
175
if (!restoring ) {
172
176
NotificationGenerationJob notifJob = new NotificationGenerationJob (this );
173
177
notifJob .jsonPayload = currentJsonPayload ;
174
178
notifJob .overrideSettings = new OverrideSettings ();
175
179
notifJob .overrideSettings .androidNotificationId = -1 ;
176
-
180
+
177
181
NotificationBundleProcessor .saveNotification (notifJob , true );
178
182
OneSignal .handleNotificationReceived (NotificationBundleProcessor .newJsonArray (currentJsonPayload ), false , false );
179
183
}
@@ -182,31 +186,24 @@ void processJsonObject(JSONObject currentJsonPayload, boolean restoring) {
182
186
NotificationBundleProcessor .Process (createNotifJobFromCurrent ());
183
187
}
184
188
}
185
-
186
- private static Intent getIntentBase (Context context ) {
187
- return new Intent ().setAction ("com.onesignal.NotificationExtender" ).setPackage (context .getPackageName ());
188
- }
189
-
190
- static List <ResolveInfo > getIntentResolveInfoList (Context context ) {
191
- PackageManager packageManager = context .getPackageManager ();
192
- return packageManager .queryIntentServices (getIntentBase (context ), PackageManager .GET_META_DATA );
193
- }
194
189
195
190
static Intent getIntent (Context context ) {
196
- List <ResolveInfo > resolveInfo = getIntentResolveInfoList (context );
191
+ PackageManager packageManager = context .getPackageManager ();
192
+ Intent intent = new Intent ().setAction ("com.onesignal.NotificationExtender" ).setPackage (context .getPackageName ());
193
+ List <ResolveInfo > resolveInfo = packageManager .queryIntentServices (intent , PackageManager .GET_META_DATA );
197
194
if (resolveInfo .size () < 1 )
198
195
return null ;
199
196
200
- return getIntentBase ( context ) ;
197
+ return intent ;
201
198
}
202
-
199
+
203
200
private NotificationGenerationJob createNotifJobFromCurrent () {
204
201
NotificationGenerationJob notifJob = new NotificationGenerationJob (this );
205
202
notifJob .restoring = currentlyRestoring ;
206
203
notifJob .jsonPayload = currentJsonPayload ;
207
204
notifJob .shownTimeStamp = restoreTimestamp ;
208
205
notifJob .overrideSettings = currentBaseOverrideSettings ;
209
-
206
+
210
207
return notifJob ;
211
208
}
212
209
}
0 commit comments