Skip to content

Commit d73bfc6

Browse files
committed
resolve conflicts between main and user-model/main
1 parent d15ee42 commit d73bfc6

33 files changed

+71
-12175
lines changed

OneSignalSDK/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ buildscript {
1515
huaweiHMSLocationVersion = '4.0.0.300'
1616
kotlinVersion = '1.7.10'
1717
kotestVersion = '5.5.0'
18-
ktlintPluginVersion = '11.3.1'
19-
ktlintVersion = '0.48.2'
18+
ktlintPluginVersion = '11.6.1'
19+
ktlintVersion = '1.0.1'
2020
junitVersion = '4.13.2'
2121
}
2222

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/common/JSONObjectExtensions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ fun JSONObject.safeLong(name: String): Long? {
3434
}
3535

3636
/**
37-
* Retrieve an [Double] from the [JSONObject] safely.
37+
* Retrieve a [Double] from the [JSONObject] safely.
3838
*
39-
* @param name The name of the attribute that contains an [Int] value.
39+
* @param name The name of the attribute that contains a [Double] value.
4040
*
4141
* @return The [Double] value if it exists, null otherwise.
4242
*/

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/common/events/EventProducer.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,25 @@ open class EventProducer<THandler> : IEventNotifier<THandler> {
1616
private val subscribers: MutableList<THandler> = Collections.synchronizedList(mutableListOf())
1717

1818
override fun subscribe(handler: THandler) {
19-
subscribers.add(handler)
19+
synchronized(subscribers) {
20+
subscribers.add(handler)
21+
}
2022
}
2123

2224
override fun unsubscribe(handler: THandler) {
23-
subscribers.remove(handler)
25+
synchronized(subscribers) {
26+
subscribers.remove(handler)
27+
}
2428
}
2529

2630
/**
2731
* Subscribe all from an existing producer to this subscriber.
2832
*/
2933
fun subscribeAll(from: EventProducer<THandler>) {
30-
for (s in from.subscribers) {
31-
subscribe(s)
34+
synchronized(subscribers) {
35+
for (s in from.subscribers) {
36+
subscribe(s)
37+
}
3238
}
3339
}
3440

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/common/modeling/ModelStore.kt

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ abstract class ModelStore<TModel>(
4040
model: TModel,
4141
tag: String,
4242
) {
43-
val oldModel = models.firstOrNull { it.id == model.id }
44-
if (oldModel != null) {
45-
removeItem(oldModel, tag)
46-
}
43+
synchronized(models) {
44+
val oldModel = models.firstOrNull { it.id == model.id }
45+
if (oldModel != null) {
46+
removeItem(oldModel, tag)
47+
}
4748

4849
addItem(model, tag)
4950
}
@@ -54,10 +55,11 @@ abstract class ModelStore<TModel>(
5455
model: TModel,
5556
tag: String,
5657
) {
57-
val oldModel = models.firstOrNull { it.id == model.id }
58-
if (oldModel != null) {
59-
removeItem(oldModel, tag)
60-
}
58+
synchronized(models) {
59+
val oldModel = models.firstOrNull { it.id == model.id }
60+
if (oldModel != null) {
61+
removeItem(oldModel, tag)
62+
}
6163

6264
addItem(model, tag, index)
6365
}
@@ -75,8 +77,10 @@ abstract class ModelStore<TModel>(
7577
id: String,
7678
tag: String,
7779
) {
78-
val model = models.firstOrNull { it.id == id } ?: return
79-
removeItem(model, tag)
80+
synchronized(models) {
81+
val model = models.firstOrNull { it.id == id } ?: return
82+
removeItem(model, tag)
83+
}
8084
}
8185

8286
override fun onChanged(
@@ -91,7 +95,8 @@ abstract class ModelStore<TModel>(
9195
models: List<TModel>,
9296
tag: String,
9397
) {
94-
clear(tag)
98+
synchronized(models) {
99+
clear(tag)
95100

96101
for (model in models) {
97102
add(model, tag)
@@ -118,11 +123,12 @@ abstract class ModelStore<TModel>(
118123
tag: String,
119124
index: Int? = null,
120125
) {
121-
if (index != null) {
122-
models.add(index, model)
123-
} else {
124-
models.add(model)
125-
}
126+
synchronized(models) {
127+
if (index != null) {
128+
models.add(index, model)
129+
} else {
130+
models.add(model)
131+
}
126132

127133
// listen for changes to this model
128134
model.subscribe(this)
@@ -136,7 +142,8 @@ abstract class ModelStore<TModel>(
136142
model: TModel,
137143
tag: String,
138144
) {
139-
models.remove(model)
145+
synchronized(models) {
146+
models.remove(model)
140147

141148
// no longer listen for changes to this model
142149
model.unsubscribe(this)
@@ -147,23 +154,29 @@ abstract class ModelStore<TModel>(
147154
}
148155

149156
protected fun load() {
150-
if (name != null && _prefs != null) {
151-
val str = _prefs.getString(PreferenceStores.ONESIGNAL, PreferenceOneSignalKeys.MODEL_STORE_PREFIX + name, "[]")
152-
val jsonArray = JSONArray(str)
153-
for (index in 0 until jsonArray.length()) {
154-
val newModel = create(jsonArray.getJSONObject(index)) ?: continue
155-
models.add(newModel)
156-
// listen for changes to this model
157-
newModel.subscribe(this)
157+
synchronized(models) {
158+
if (name != null && _prefs != null) {
159+
val str = _prefs.getString(PreferenceStores.ONESIGNAL, PreferenceOneSignalKeys.MODEL_STORE_PREFIX + name, "[]")
160+
val jsonArray = JSONArray(str)
161+
for (index in 0 until jsonArray.length()) {
162+
val newModel = create(jsonArray.getJSONObject(index)) ?: continue
163+
models.add(newModel)
164+
// listen for changes to this model
165+
newModel.subscribe(this)
166+
}
158167
}
159168
}
160169
}
161170

162171
fun persist() {
163-
if (name != null && _prefs != null) {
164-
val jsonArray = JSONArray()
165-
for (model in models) {
166-
jsonArray.put(model.toJSON())
172+
synchronized(models) {
173+
if (name != null && _prefs != null) {
174+
val jsonArray = JSONArray()
175+
for (model in models) {
176+
jsonArray.put(model.toJSON())
177+
}
178+
179+
_prefs.saveString(PreferenceStores.ONESIGNAL, PreferenceOneSignalKeys.MODEL_STORE_PREFIX + name, jsonArray.toString())
167180
}
168181
}
169182
}

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/common/modeling/SingletonModelStore.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ open class SingletonModelStore<TModel>(
2020

2121
override val model: TModel
2222
get() {
23-
val model = store.get(singletonId)
24-
if (model != null) {
25-
return model
26-
}
23+
synchronized(this) {
24+
val model = store.get(singletonId)
25+
if (model != null) {
26+
return model
27+
}
2728

28-
val createdModel = store.create() ?: throw Exception("Unable to initialize model from store $store")
29-
createdModel.id = singletonId
30-
store.add(createdModel)
31-
return createdModel
29+
val createdModel = store.create() ?: throw Exception("Unable to initialize model from store $store")
30+
createdModel.id = singletonId
31+
store.add(createdModel)
32+
return createdModel
33+
}
3234
}
3335

3436
override fun replace(

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/internal/OneSignalImp.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import com.onesignal.user.internal.subscriptions.SubscriptionModel
5151
import com.onesignal.user.internal.subscriptions.SubscriptionModelStore
5252
import com.onesignal.user.internal.subscriptions.SubscriptionStatus
5353
import com.onesignal.user.internal.subscriptions.SubscriptionType
54+
import org.json.JSONObject
5455

5556
internal class OneSignalImp : IOneSignal, IServiceProvider {
5657
override val sdkVersion: String = OneSignalUtils.SDK_VERSION

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/operations/impl/executors/LoginUserOperationExecutor.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ internal class LoginUserOperationExecutor(
137137
var identities = mapOf<String, String>()
138138
var subscriptions = mapOf<String, SubscriptionObject>()
139139
val properties = mutableMapOf<String, String>()
140-
properties["timezone_id"] = TimeUtils.getTimeZoneId()
140+
properties["timezone_id"] = TimeUtils.getTimeZoneId()!!
141+
properties["language"] = _languageContext.language
141142

142143
if (createUserOperation.externalId != null) {
143144
val mutableIdentities = identities.toMutableMap()

OneSignalSDK/onesignal/core/src/test/java/com/onesignal/user/internal/operations/RefreshUserOperationExecutorTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class RefreshUserOperationExecutorTests : FunSpec({
4343
CreateUserResponse(
4444
mapOf(IdentityConstants.ONESIGNAL_ID to remoteOneSignalId, "aliasLabel1" to "aliasValue1"),
4545
PropertiesObject(country = "US"),
46-
listOf(SubscriptionObject(remoteSubscriptionId1, SubscriptionObjectType.ANDROID_PUSH, enabled = true, token = "pushToken"), SubscriptionObject(remoteSubscriptionId2, SubscriptionObjectType.EMAIL, token = "name@company.com")),
46+
listOf(SubscriptionObject(existingSubscriptionId1, SubscriptionObjectType.ANDROID_PUSH, enabled = true, token = "pushToken1"), SubscriptionObject(remoteSubscriptionId1, SubscriptionObjectType.ANDROID_PUSH, enabled = true, token = "pushToken2"), SubscriptionObject(remoteSubscriptionId2, SubscriptionObjectType.EMAIL, token = "name@company.com")),
4747
)
4848

4949
// Given

OneSignalSDK/onesignal/notifications/src/main/java/com/onesignal/notifications/internal/permissions/impl/NavigateToAndroidSettingsForNotifications.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ internal object NavigateToAndroidSettingsForNotifications {
3838

3939
// for Android 5-7
4040
intent.putExtra("app_package", context.getPackageName())
41-
val applicationInfo = ApplicationInfoHelper.getInfo(context)
42-
if (applicationInfo != null) {
43-
intent.putExtra("app_uid", applicationInfo.uid)
44-
}
41+
intent.putExtra("app_uid", context.getApplicationInfo().uid)
4542

4643
// for Android 8 and above
4744
intent.putExtra("android.provider.extra.APP_PACKAGE", context.getPackageName())

0 commit comments

Comments
 (0)