Skip to content

Commit 026f748

Browse files
authored
Merge pull request #1716 from OneSignal/user-model/alpha-final-touches
[User Model] Final touches
2 parents 2038f7a + a3d839f commit 026f748

File tree

10 files changed

+357
-18
lines changed

10 files changed

+357
-18
lines changed

Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/model/MainActivityViewModel.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858

5959
import java.util.ArrayList;
6060
import java.util.HashMap;
61-
import java.util.List;
6261
import java.util.Map;
6362

6463
@RequiresApi(api = Build.VERSION_CODES.N)
@@ -632,7 +631,7 @@ private void setupEmailRecyclerView() {
632631
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
633632
emailsRecyclerView.setLayoutManager(linearLayoutManager);
634633
emailsRecyclerViewAdapter = new SubscriptionRecyclerViewAdapter(context, emailArrayList, value -> {
635-
String email = ((IEmailSubscription)value).getEmail();
634+
String email = ((DummySubscription)value).getId();
636635
OneSignal.getUser().removeEmailSubscription(email);
637636
emailArrayList.remove(value);
638637
refreshEmailRecyclerView();
@@ -658,7 +657,7 @@ private void setupSMSRecyclerView() {
658657
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
659658
smssRecyclerView.setLayoutManager(linearLayoutManager);
660659
smssRecyclerViewAdapter = new SubscriptionRecyclerViewAdapter(context, smsArrayList, value -> {
661-
String number = ((ISmsSubscription)value).getNumber();
660+
String number = ((DummySubscription)value).getId();
662661
OneSignal.getUser().removeSmsSubscription(number);
663662
smsArrayList.remove(value);
664663
refreshSMSRecyclerView();

MIGRATION_GUIDE.md

Lines changed: 320 additions & 0 deletions
Large diffs are not rendered by default.

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/IOneSignal.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interface IOneSignal {
2323
* The user manager for accessing user-scoped
2424
* management.
2525
*/
26-
val user: IUserManager
26+
val User: IUserManager
2727

2828
/**
2929
* The session manager for accessing session-scoped management.
@@ -85,7 +85,7 @@ interface IOneSignal {
8585

8686
/**
8787
* Login to OneSignal under the user identified by the [externalId] provided. The act of
88-
* logging a user into the OneSignal SDK will switch the [user] context to that specific user.
88+
* logging a user into the OneSignal SDK will switch the [User] context to that specific user.
8989
*
9090
* * If the [externalId] exists the user will be retrieved and the context set from that
9191
* user information. If operations have already been performed under a guest user, they
@@ -108,7 +108,7 @@ interface IOneSignal {
108108
suspend fun login(externalId: String) = login(externalId, null)
109109

110110
/**
111-
* Logout the user previously logged in via [login]. The [user] property now references
111+
* Logout the user previously logged in via [login]. The [User] property now references
112112
* a new device-scoped user. A device-scoped user has no user identity that can later
113113
* be retrieved, except through this device as long as the app remains installed and the app
114114
* data is not cleared.

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/OneSignal.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ object OneSignal {
4242
* called.
4343
*/
4444
@JvmStatic
45-
val user: IUserManager
46-
get() = oneSignal.user
45+
val User: IUserManager
46+
get() = oneSignal.User
4747

4848
/**
4949
* The session manager for accessing session-scoped management. Initialized only after [initWithContext]
@@ -128,7 +128,7 @@ object OneSignal {
128128

129129
/**
130130
* Login to OneSignal under the user identified by the [externalId] provided. The act of
131-
* logging a user into the OneSignal SDK will switch the [user] context to that specific user.
131+
* logging a user into the OneSignal SDK will switch the [User] context to that specific user.
132132
*
133133
* * If the [externalId] exists the user will be retrieved and the context set from that
134134
* user information. If operations have already been performed under a guest user, they
@@ -149,7 +149,7 @@ object OneSignal {
149149

150150
/**
151151
* Login to OneSignal under the user identified by the [externalId] provided. The act of
152-
* logging a user into the OneSignal SDK will switch the [user] context to that specific user.
152+
* logging a user into the OneSignal SDK will switch the [User] context to that specific user.
153153
*
154154
* * If the [externalId] exists the user will be retrieved and the context set from that
155155
* user information. If operations have already been performed under a guest user, they
@@ -172,7 +172,7 @@ object OneSignal {
172172
suspend fun login(externalId: String, jwtBearerToken: String? = null) = oneSignal.login(externalId, jwtBearerToken)
173173

174174
/**
175-
* Logout the user previously logged in via [login]. The [user] property now references
175+
* Logout the user previously logged in via [login]. The [User] property now references
176176
* a new device-scoped user. A device-scoped user has no user identity that can later
177177
* be retrieved, except through this device as long as the app remains installed and the app
178178
* data is not cleared.

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ object AndroidUtils {
6060
return hasFlag
6161
}
6262

63+
fun getAppVersion(context: Context): String? {
64+
val appVersion: Int? =
65+
try {
66+
context.packageManager.getPackageInfo(context.packageName, 0).versionCode
67+
} catch (e: PackageManager.NameNotFoundException) {
68+
null
69+
}
70+
71+
return appVersion?.toString()
72+
}
73+
6374
fun getManifestMeta(context: Context, metaName: String?): String? {
6475
val bundle = getManifestMetaBundle(context)
6576
return bundle?.getString(metaName)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
7575
override val notifications: INotificationsManager get() = if (isInitialized) _notifications!! else throw Exception("Must call 'initWithContext' before use")
7676
override val location: ILocationManager get() = if (isInitialized) _location!! else throw Exception("Must call 'initWithContext' before use")
7777
override val inAppMessages: IInAppMessagesManager get() = if (isInitialized) _iam!! else throw Exception("Must call 'initWithContext' before use")
78-
override val user: IUserManager get() = if (isInitialized) _user!! else throw Exception("Must call 'initWithContext' before use")
78+
override val User: IUserManager get() = if (isInitialized) _user!! else throw Exception("Must call 'initWithContext' before use")
7979

8080
// Services required by this class
8181
private var _user: IUserManager? = null

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/backend/SubscriptionObject.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ class SubscriptionObject(
1111
val deviceOS: String? = null,
1212
val rooted: Boolean? = null,
1313
val netType: Int? = null,
14-
val carrier: String? = null
14+
val carrier: String? = null,
15+
val appVersion: String? = null
1516
)

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/backend/impl/JSONConverter.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ object JSONConverter {
4545
it.safeString("device_model"),
4646
it.safeString("device_os"),
4747
it.safeBool("rooted"),
48-
it.safeInt("test_type"),
48+
it.safeInt("net_type"),
49+
it.safeString("carrier"),
4950
it.safeString("app_version")
5051
)
5152
}
@@ -100,5 +101,6 @@ object JSONConverter {
100101
.putSafe("rooted", subscription.rooted)
101102
.putSafe("net_type", subscription.netType)
102103
.putSafe("carrier", subscription.carrier)
104+
.putSafe("app_version", subscription.appVersion)
103105
}
104106
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.onesignal.user.internal.operations.impl.executors
22

33
import android.os.Build
4+
import com.onesignal.common.AndroidUtils
45
import com.onesignal.common.DeviceUtils
56
import com.onesignal.common.NetworkUtils
67
import com.onesignal.common.OneSignalUtils
@@ -209,7 +210,8 @@ internal class LoginUserOperationExecutor(
209210
Build.VERSION.RELEASE,
210211
RootToolsInternalMethods.isRooted,
211212
DeviceUtils.getNetType(_application.appContext),
212-
DeviceUtils.getCarrierName(_application.appContext)
213+
DeviceUtils.getCarrierName(_application.appContext),
214+
AndroidUtils.getAppVersion(_application.appContext)
213215
)
214216

215217
return mutableSubscriptions
@@ -229,7 +231,8 @@ internal class LoginUserOperationExecutor(
229231
subscriptions[operation.subscriptionId]!!.deviceOS,
230232
subscriptions[operation.subscriptionId]!!.rooted,
231233
subscriptions[operation.subscriptionId]!!.netType,
232-
subscriptions[operation.subscriptionId]!!.carrier
234+
subscriptions[operation.subscriptionId]!!.carrier,
235+
subscriptions[operation.subscriptionId]!!.appVersion
233236
)
234237
}
235238
// TODO: Is it possible for the Create to be after the Update?

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.onesignal.user.internal.operations.impl.executors
22

33
import android.os.Build
4+
import com.onesignal.common.AndroidUtils
45
import com.onesignal.common.DeviceUtils
56
import com.onesignal.common.NetworkUtils
67
import com.onesignal.common.OneSignalUtils
@@ -82,7 +83,8 @@ internal class SubscriptionOperationExecutor(
8283
Build.VERSION.RELEASE,
8384
RootToolsInternalMethods.isRooted,
8485
DeviceUtils.getNetType(_applicationService.appContext),
85-
DeviceUtils.getCarrierName(_applicationService.appContext)
86+
DeviceUtils.getCarrierName(_applicationService.appContext),
87+
AndroidUtils.getAppVersion(_applicationService.appContext)
8688
)
8789

8890
val backendSubscriptionId = _subscriptionBackend.createSubscription(
@@ -134,7 +136,8 @@ internal class SubscriptionOperationExecutor(
134136
Build.VERSION.RELEASE,
135137
RootToolsInternalMethods.isRooted,
136138
DeviceUtils.getNetType(_applicationService.appContext),
137-
DeviceUtils.getCarrierName(_applicationService.appContext)
139+
DeviceUtils.getCarrierName(_applicationService.appContext),
140+
AndroidUtils.getAppVersion(_applicationService.appContext)
138141
)
139142

140143
_subscriptionBackend.updateSubscription(lastOperation.appId, lastOperation.subscriptionId, subscription)

0 commit comments

Comments
 (0)