Skip to content

Commit 90c491a

Browse files
Implement cross-platform push completion handling for background tasks (opt-in).
Added Display.notifyPushCompletion() to manually signal the completion of a background push task. This mechanism is OPT-IN via the `delayPushCompletion` (or `android.delayPushCompletion`/`ios.delayPushCompletion`) build hint. If the hint is present and true: - Android: Acquires a `PARTIAL_WAKE_LOCK` upon receiving a push, preventing the device from sleeping until `notifyPushCompletion()` is called (or timeout). - iOS: Ensures the `remote-notification` background mode is enabled and delays firing the system completion handler until `notifyPushCompletion()` is called. If the hint is NOT present (default behavior): - Android: No wake lock is acquired. - iOS: The completion handler is fired immediately after the push callback. Updated `IOSImplementation`, `AndroidImplementation`, `PushNotificationService`, `AndroidGradleBuilder`, and `IPhoneBuilder`.
1 parent 79a6d12 commit 90c491a

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Ports/Android/src/com/codename1/impl/android/PushNotificationService.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,17 @@ public void onDestroy() {
109109
public void push(final String value) {
110110
final PushCallback callback = getPushCallbackInstance();
111111
if(callback != null) {
112-
AndroidImplementation.acquirePushWakeLock(30000);
112+
final boolean delayPushCompletion = "true".equals(Display.getInstance().getProperty("delayPushCompletion", "false")) ||
113+
"true".equals(Display.getInstance().getProperty("android.delayPushCompletion", "false"));
114+
if (delayPushCompletion) {
115+
AndroidImplementation.acquirePushWakeLock(30000);
116+
}
113117
Display.getInstance().callSerially(new Runnable() {
114118
public void run() {
115119
try {
116120
callback.push(value);
117121
} finally {
118-
if (!"true".equals(Display.getInstance().getProperty("delayPushCompletion", "false")) &&
119-
!"true".equals(Display.getInstance().getProperty("android.delayPushCompletion", "false"))) {
122+
if (!delayPushCompletion) {
120123
Display.getInstance().notifyPushCompletion();
121124
}
122125
}

maven/codenameone-maven-plugin/src/main/java/com/codename1/builders/AndroidGradleBuilder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,10 @@ public boolean build(File sourceZip, final BuildRequest request) throws BuildExc
11631163
playFlag = "true";
11641164

11651165
gpsPermission = request.getArg("android.gpsPermission", "false").equals("true");
1166+
if (request.getArg("android.delayPushCompletion", "false").equals("true") ||
1167+
request.getArg("delayPushCompletion", "false").equals("true")) {
1168+
wakeLock = true;
1169+
}
11661170
mediaPlaybackPermission = false;
11671171
try {
11681172
scanClassesForPermissions(dummyClassesDir, new Executor.ClassScanner() {

maven/codenameone-maven-plugin/src/main/java/com/codename1/builders/IPhoneBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2380,7 +2380,8 @@ public boolean accept(File file, String string) {
23802380
}
23812381
}
23822382
String backgroundModesStr = request.getArg("ios.background_modes", null);
2383-
if (includePush) {
2383+
if (includePush || "true".equals(request.getArg("ios.delayPushCompletion", "false")) ||
2384+
"true".equals(request.getArg("delayPushCompletion", "false"))) {
23842385
if (backgroundModesStr == null || !backgroundModesStr.contains("remote-notification")) {
23852386
if (backgroundModesStr == null) {
23862387
backgroundModesStr = "";

0 commit comments

Comments
 (0)