Skip to content

Commit 133314d

Browse files
authored
Merge pull request #2259 from OneSignal/notification_click_not_foregrounded
Fix: Notification click not foreground the app in the first click if app is closed and no clickListener is added
2 parents 1cb2953 + f5cde9a commit 133314d

File tree

5 files changed

+39
-16
lines changed

5 files changed

+39
-16
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.onesignal.core.internal.startup
2+
3+
import com.onesignal.OneSignal
4+
import com.onesignal.core.internal.application.IApplicationService
5+
import com.onesignal.core.internal.config.ConfigModel
6+
import com.onesignal.core.internal.config.ConfigModelStore
7+
8+
/**
9+
* Implement and provide this interface as part of service registration to indicate the service
10+
* wants to be instantiated and its [bootstrap] function called during the initialization process.
11+
*
12+
* When [IBootstrapService.bootstrap] is called, only [OneSignal.setAppId] have been called during
13+
* [OneSignal.initWithContext].
14+
*
15+
* This means the following is true:
16+
*
17+
* 1) An appContext is available in [IApplicationService.appContext].
18+
* 2) An appId is available in [ConfigModel.appId] via [ConfigModelStore.get]
19+
* 3) None of the [IStartableService.start] is called
20+
*
21+
* When bootstrap there is no guarantee that any other data is available. Typically a bootstrap service
22+
* must be instantiated immediately and will add their appropriate hooks to then respond to changes
23+
* in the system.
24+
*/
25+
interface IBootstrapService {
26+
/**
27+
* Called when the service is to be bootstrap. The appId and appContext have already been established.
28+
*/
29+
30+
fun bootstrap()
31+
}

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/internal/startup/IStartableService.kt

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ import com.onesignal.core.internal.config.ConfigModelStore
1515
* 1) An appContext is available in [IApplicationService.appContext].
1616
* 2) An appId is available in [ConfigModel.appId] via [ConfigModelStore.get]
1717
*
18-
* When started there is no guarantee that any other data is available. Typically a startable service
19-
* must be instantiated immediately and will add their appropriate hooks to then respond to changes
20-
* in the system.
18+
* When started there is no guarantee that any other data is available. Typically a startable service
19+
* can asynchronously start some lengthy process that doesn't require immediate use.
2120
*/
2221
interface IStartableService {
2322
/**
@@ -26,11 +25,3 @@ interface IStartableService {
2625
*/
2726
fun start()
2827
}
29-
30-
internal interface IBootstrapService {
31-
/**
32-
* Called when the service is to be started. The appId and appContext have already been
33-
* established.
34-
*/
35-
fun bootstrap()
36-
}

OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/InAppMessagesModule.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.onesignal.inAppMessages
33
import android.os.Build
44
import com.onesignal.common.modules.IModule
55
import com.onesignal.common.services.ServiceBuilder
6+
import com.onesignal.core.internal.startup.IBootstrapService
67
import com.onesignal.core.internal.startup.IStartableService
78
import com.onesignal.inAppMessages.internal.DummyInAppMessagesManager
89
import com.onesignal.inAppMessages.internal.InAppMessagesManager
@@ -50,7 +51,7 @@ internal class InAppMessagesModule : IModule {
5051
builder.register<InAppDisplayer>().provides<IInAppDisplayer>()
5152

5253
// Previews
53-
builder.register<InAppMessagePreviewHandler>().provides<IStartableService>()
54+
builder.register<InAppMessagePreviewHandler>().provides<IBootstrapService>()
5455

5556
// Prompts
5657
builder.register<InAppMessagePromptFactory>().provides<IInAppMessagePromptFactory>()

OneSignalSDK/onesignal/in-app-messages/src/main/java/com/onesignal/inAppMessages/internal/preview/InAppMessagePreviewHandler.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.onesignal.inAppMessages.internal.preview
22

33
import android.app.Activity
44
import com.onesignal.core.internal.application.IApplicationService
5-
import com.onesignal.core.internal.startup.IStartableService
5+
import com.onesignal.core.internal.startup.IBootstrapService
66
import com.onesignal.core.internal.time.ITime
77
import com.onesignal.inAppMessages.internal.display.IInAppDisplayer
88
import com.onesignal.inAppMessages.internal.state.InAppStateService
@@ -25,8 +25,8 @@ internal class InAppMessagePreviewHandler(
2525
private val _notificationLifeCycle: INotificationLifecycleService,
2626
private val _state: InAppStateService,
2727
private val _time: ITime,
28-
) : IStartableService, INotificationLifecycleCallback {
29-
override fun start() {
28+
) : IBootstrapService, INotificationLifecycleCallback {
29+
override fun bootstrap() {
3030
_notificationLifeCycle.setInternalNotificationLifecycleCallback(this)
3131
}
3232

OneSignalSDK/onesignal/notifications/src/main/java/com/onesignal/notifications/internal/lifecycle/impl/NotificationLifecycleService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ internal class NotificationLifecycleService(
8787
activity: Activity,
8888
data: JSONObject,
8989
): Boolean {
90-
var canOpen = extOpenedCallback.hasSubscribers
90+
var canOpen = true
9191
intLifecycleCallback.suspendingFire { canOpen = it.canOpenNotification(activity, data) }
9292
return canOpen
9393
}

0 commit comments

Comments
 (0)