Skip to content

Commit 0e1ca74

Browse files
committed
[User Model] ADM Fixes
* Update example app `AndroidManifest.xml` to point to new ADM bridges. * Update PushRegistratorADM to not launch a new task and run in calling thread.
1 parent 3ad1b97 commit 0e1ca74

File tree

2 files changed

+31
-35
lines changed

2 files changed

+31
-35
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@
4646
</service>
4747

4848
<service
49-
android:name="com.onesignal.ADMMessageHandlerJob"
49+
android:name="com.onesignal.notifications.services.ADMMessageHandlerJob"
5050
android:permission="android.permission.BIND_JOB_SERVICE"
5151
android:exported="false" />
5252

5353
<!-- This is needed for devices with older ADM versions -->
5454
<service
55-
android:name="com.onesignal.ADMMessageHandler"
55+
android:name="com.onesignal.notifications.services.ADMMessageHandler"
5656
android:exported="false" />
5757

5858
<receiver
59-
android:name="com.onesignal.ADMMessageHandler$Receiver"
59+
android:name="com.onesignal.notifications.receivers.ADMMessageReceiver"
6060
android:permission="com.amazon.device.messaging.permission.SEND"
6161
android:exported="true">
6262

OneSignalSDK/onesignal/notifications/src/main/java/com/onesignal/notifications/internal/registration/impl/PushRegistratorADM.kt

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import com.onesignal.core.internal.application.IApplicationService
66
import com.onesignal.debug.internal.logging.Logging
77
import com.onesignal.notifications.internal.registration.IPushRegistrator
88
import com.onesignal.user.internal.subscriptions.SubscriptionStatus
9-
import kotlinx.coroutines.Dispatchers
10-
import kotlinx.coroutines.coroutineScope
11-
import kotlinx.coroutines.launch
129
import kotlinx.coroutines.withTimeout
1310

1411
internal class PushRegistratorADM(
@@ -17,45 +14,44 @@ internal class PushRegistratorADM(
1714

1815
private var _waiter: WaiterWithValue<String?>? = null
1916

20-
override suspend fun registerForPush(): IPushRegistrator.RegisterResult = coroutineScope {
17+
override suspend fun registerForPush(): IPushRegistrator.RegisterResult {
2118
var result: IPushRegistrator.RegisterResult? = null
2219

2320
_waiter = WaiterWithValue()
24-
launch(Dispatchers.Default) {
25-
val adm = ADM(_applicationService.appContext)
26-
var registrationId = adm.registrationId
27-
if (registrationId != null) {
28-
Logging.debug("ADM Already registered with ID:$registrationId")
29-
result = IPushRegistrator.RegisterResult(
21+
22+
val adm = ADM(_applicationService.appContext)
23+
var registrationId = adm.registrationId
24+
if (registrationId != null) {
25+
Logging.debug("ADM Already registered with ID:$registrationId")
26+
result = IPushRegistrator.RegisterResult(
27+
registrationId,
28+
SubscriptionStatus.SUBSCRIBED
29+
)
30+
} else {
31+
adm.startRegister()
32+
33+
// wait up to 30 seconds for someone to call `fireCallback` with the registration id.
34+
// if it comes before we will continue immediately.
35+
withTimeout(30000) {
36+
registrationId = _waiter?.waitForWake()
37+
}
38+
39+
result = if (registrationId != null) {
40+
Logging.error("ADM registered with ID:$registrationId")
41+
IPushRegistrator.RegisterResult(
3042
registrationId,
3143
SubscriptionStatus.SUBSCRIBED
3244
)
3345
} else {
34-
adm.startRegister()
35-
36-
// wait up to 30 seconds for someone to call `fireCallback` with the registration id.
37-
// if it comes before we will continue immediately.
38-
withTimeout(30000) {
39-
registrationId = _waiter?.waitForWake()
40-
}
41-
42-
result = if (registrationId != null) {
43-
Logging.error("ADM registered with ID:$registrationId")
44-
IPushRegistrator.RegisterResult(
45-
registrationId,
46-
SubscriptionStatus.SUBSCRIBED
47-
)
48-
} else {
49-
Logging.error("com.onesignal.ADMMessageHandler timed out, please check that your have the receiver, service, and your package name matches(NOTE: Case Sensitive) per the OneSignal instructions.")
50-
IPushRegistrator.RegisterResult(
51-
null,
52-
SubscriptionStatus.ERROR
53-
)
54-
}
46+
Logging.error("com.onesignal.ADMMessageHandler timed out, please check that your have the receiver, service, and your package name matches(NOTE: Case Sensitive) per the OneSignal instructions.")
47+
IPushRegistrator.RegisterResult(
48+
null,
49+
SubscriptionStatus.ERROR
50+
)
5551
}
5652
}
5753

58-
return@coroutineScope result!!
54+
return result!!
5955
}
6056

6157
override suspend fun fireCallback(id: String?) {

0 commit comments

Comments
 (0)