Skip to content

Commit

Permalink
Merge pull request #1771 from OneSignal/user-model/update_privacy_con…
Browse files Browse the repository at this point in the history
…sent_names

User Model - Update privacy consent property names
  • Loading branch information
emawby authored and jinliu9508 committed Jan 31, 2024
2 parents dd3feaa + f6f48b1 commit 7f73687
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void onBackPressed() {
protected void onResume() {
super.onResume();

boolean hasConsent = OneSignal.getRequiresPrivacyConsent();
boolean hasConsent = OneSignal.getConsentGiven();
if (hasConsent)
viewModel.setupLayout();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ private String getOneSignalAppId() {
}

private void togglePrivacyConsent(boolean hasConsent) {
OneSignal.setPrivacyConsent(hasConsent);
OneSignal.setConsentGiven(hasConsent);
SharedPreferenceUtil.cacheUserPrivacyConsent(context, hasConsent);

shouldScrollTop = hasConsent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void networkDisconnected() {
private void setupOneSignalSDK() {
boolean privacyConsent = true;

OneSignal.setRequiresPrivacyConsent(privacyConsent);
OneSignal.setConsentRequired(privacyConsent);

boolean isLocationShared = SharedPreferenceUtil.getCachedLocationSharedStatus(context);
OneSignal.getLocation().setShared(isLocationShared);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ interface IOneSignal {
* should be set to `true` prior to the invocation of
* [initWithContext] to ensure compliance.
*/
var requiresPrivacyConsent: Boolean
var consentRequired: Boolean

/**
* Indicates whether privacy consent has been granted. This field is only relevant when
* the application has opted into data privacy protections. See [requiresPrivacyConsent].
* the application has opted into data privacy protections. See [consentRequired].
*/
var privacyConsent: Boolean
var consentGiven: Boolean

/**
* Whether to disable the "GMS is missing" prompt to the user.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,18 @@ object OneSignal {
* [initWithContext] to ensure compliance.
*/
@JvmStatic
var requiresPrivacyConsent: Boolean
get() = oneSignal.requiresPrivacyConsent
set(value) { oneSignal.requiresPrivacyConsent = value }
var consentRequired: Boolean
get() = oneSignal.consentRequired
set(value) { oneSignal.consentRequired = value }

/**
* Indicates whether privacy consent has been granted. This field is only relevant when
* the application has opted into data privacy protections. See [requiresPrivacyConsent].
*/
@JvmStatic
var privacyConsent: Boolean
get() = oneSignal.privacyConsent
set(value) { oneSignal.privacyConsent = value }
var consentGiven: Boolean
get() = oneSignal.consentGiven
set(value) { oneSignal.consentGiven = value }

/**
* Whether to disable the "GMS is missing" prompt to the user.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ class ConfigModel : Model() {
/**
* Whether the SDK requires privacy consent to send data to backend.
*/
var requiresPrivacyConsent: Boolean?
get() = getOptBooleanProperty(::requiresPrivacyConsent.name)
set(value) { setOptBooleanProperty(::requiresPrivacyConsent.name, value) }
var consentRequired: Boolean?
get() = getOptBooleanProperty(::consentRequired.name)
set(value) { setOptBooleanProperty(::consentRequired.name, value) }

/**
* Whether the SDK has been given consent to privacy.
*/
var givenPrivacyConsent: Boolean?
get() = getOptBooleanProperty(::givenPrivacyConsent.name)
set(value) { setOptBooleanProperty(::givenPrivacyConsent.name, value) }
var consentGiven: Boolean?
get() = getOptBooleanProperty(::consentGiven.name)
set(value) { setOptBooleanProperty(::consentGiven.name, value) }

/**
* Whether location is shared.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ internal class ConfigModelStoreListener(
params.disableGMSMissingPrompt?.let { config.disableGMSMissingPrompt = it }
params.unsubscribeWhenNotificationsDisabled?.let { config.unsubscribeWhenNotificationsDisabled = it }
params.locationShared?.let { config.locationShared = it }
params.requiresUserPrivacyConsent?.let { config.requiresPrivacyConsent = it }
params.requiresUserPrivacyConsent?.let { config.consentRequired = it }
params.opRepoExecutionInterval?.let { config.opRepoExecutionInterval = it }
params.influenceParams.notificationLimit?.let { config.influenceParams.notificationLimit = it }
params.influenceParams.indirectNotificationAttributionWindow?.let { config.influenceParams.indirectNotificationAttributionWindow = it }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal class HttpClient(
cacheKey: String?,
): HttpResponse {
// If privacy consent is required but not yet given, any non-GET request should be blocked.
if (method != null && _configModelStore.model.requiresPrivacyConsent == true && _configModelStore.model.givenPrivacyConsent != true) {
if (method != null && _configModelStore.model.consentRequired == true && _configModelStore.model.consentGiven != true) {
Logging.warn("$method `$url` was called before the user provided privacy consent. Your application is set to require the user's privacy consent before the OneSignal SDK can be initialized. Please ensure the user has provided consent before calling this method. You can check the latest OneSignal consent status by calling OneSignal.privacyConsent")
return HttpResponse(0, null, null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,18 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
override val sdkVersion: String = OneSignalUtils.sdkVersion
override var isInitialized: Boolean = false

override var requiresPrivacyConsent: Boolean
get() = _configModel?.requiresPrivacyConsent ?: (_requiresPrivacyConsent == true)
override var consentRequired: Boolean
get() = _configModel?.consentRequired ?: (_consentRequired == true)
set(value) {
_requiresPrivacyConsent = value
_configModel?.requiresPrivacyConsent = value
_consentRequired = value
_configModel?.consentRequired = value
}

override var privacyConsent: Boolean
get() = _configModel?.givenPrivacyConsent ?: (_givenPrivacyConsent == true)
override var consentGiven: Boolean
get() = _configModel?.consentGiven ?: (_consentGiven == true)
set(value) {
_givenPrivacyConsent = value
_configModel?.givenPrivacyConsent = value
_consentGiven = value
_configModel?.consentGiven = value
}

override var disableGMSMissingPrompt: Boolean
Expand Down Expand Up @@ -98,8 +98,8 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
private val _services: ServiceProvider
private var _configModel: ConfigModel? = null
private var _sessionModel: SessionModel? = null
private var _requiresPrivacyConsent: Boolean? = null
private var _givenPrivacyConsent: Boolean? = null
private var _consentRequired: Boolean? = null
private var _consentGiven: Boolean? = null
private var _disableGMSMissingPrompt: Boolean? = null
private val _loginLock: Any = Any()

Expand Down Expand Up @@ -173,13 +173,13 @@ internal class OneSignalImp : IOneSignal, IServiceProvider {
}

// if requires privacy consent was set prior to init, set it in the model now
if (_requiresPrivacyConsent != null) {
_configModel!!.requiresPrivacyConsent = _requiresPrivacyConsent!!
if (_consentRequired != null) {
_configModel!!.consentRequired = _consentRequired!!
}

// if privacy consent was set prior to init, set it in the model now
if (_givenPrivacyConsent != null) {
_configModel!!.givenPrivacyConsent = _givenPrivacyConsent!!
if (_consentGiven != null) {
_configModel!!.consentGiven = _consentGiven!!
}

if (_disableGMSMissingPrompt != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ class OutcomeEventsControllerTests : FunSpec({
Logging.logLevel = LogLevel.NONE
}

fun createTestSubscriptionModel(): SubscriptionModel {
val subModel = SubscriptionModel()
subModel.id = "subscriptionId"
subModel.address = "subscriptionAddress"
subModel.optedIn = true
return subModel
}

test("send outcome with disabled influences") {
/* Given */
val now = 111L
Expand Down Expand Up @@ -86,8 +94,7 @@ class OutcomeEventsControllerTests : FunSpec({
val mockInfluenceManager = mockk<IInfluenceManager>()
every { mockInfluenceManager.influences } returns listOf(Influence(InfluenceChannel.NOTIFICATION, InfluenceType.UNATTRIBUTED, null))

val subscriptionModel = SubscriptionModel()
subscriptionModel.id = "subscriptionId"
val subscriptionModel = createTestSubscriptionModel()

val mockSubscriptionManager = mockk<ISubscriptionManager>()
every { mockSubscriptionManager.subscriptions.push } returns PushSubscription(subscriptionModel)
Expand Down Expand Up @@ -132,8 +139,8 @@ class OutcomeEventsControllerTests : FunSpec({
val mockInfluenceManager = mockk<IInfluenceManager>()
every { mockInfluenceManager.influences } returns listOf(Influence(InfluenceChannel.NOTIFICATION, InfluenceType.INDIRECT, JSONArray(notificationIds)))

val subscriptionModel = SubscriptionModel()
subscriptionModel.id = "subscriptionId"
val subscriptionModel = createTestSubscriptionModel()

val mockSubscriptionManager = mockk<ISubscriptionManager>()
every { mockSubscriptionManager.subscriptions.push } returns PushSubscription(subscriptionModel)

Expand Down Expand Up @@ -178,8 +185,8 @@ class OutcomeEventsControllerTests : FunSpec({
val mockInfluenceManager = mockk<IInfluenceManager>()
every { mockInfluenceManager.influences } returns listOf(Influence(InfluenceChannel.NOTIFICATION, InfluenceType.DIRECT, JSONArray(notificationIds)))

val subscriptionModel = SubscriptionModel()
subscriptionModel.id = "subscriptionId"
val subscriptionModel = createTestSubscriptionModel()

val mockSubscriptionManager = mockk<ISubscriptionManager>()
every { mockSubscriptionManager.subscriptions.push } returns PushSubscription(subscriptionModel)

Expand Down Expand Up @@ -224,8 +231,8 @@ class OutcomeEventsControllerTests : FunSpec({
val mockInfluenceManager = mockk<IInfluenceManager>()
every { mockInfluenceManager.influences } returns listOf(Influence(InfluenceChannel.NOTIFICATION, InfluenceType.UNATTRIBUTED, null))

val subscriptionModel = SubscriptionModel()
subscriptionModel.id = "subscriptionId"
val subscriptionModel = createTestSubscriptionModel()

val mockSubscriptionManager = mockk<ISubscriptionManager>()
every { mockSubscriptionManager.subscriptions.push } returns PushSubscription(subscriptionModel)

Expand Down Expand Up @@ -268,8 +275,8 @@ class OutcomeEventsControllerTests : FunSpec({
val mockInfluenceManager = mockk<IInfluenceManager>()
every { mockInfluenceManager.influences } returns listOf(Influence(InfluenceChannel.NOTIFICATION, InfluenceType.UNATTRIBUTED, null))

val subscriptionModel = SubscriptionModel()
subscriptionModel.id = "subscriptionId"
val subscriptionModel = createTestSubscriptionModel()

val mockSubscriptionManager = mockk<ISubscriptionManager>()
every { mockSubscriptionManager.subscriptions.push } returns PushSubscription(subscriptionModel)

Expand Down Expand Up @@ -322,8 +329,8 @@ class OutcomeEventsControllerTests : FunSpec({
coEvery { mockOutcomeEventsRepository.getNotCachedUniqueInfluencesForOutcome("OUTCOME_1", any()) } returns listOf(notificationInfluence) andThen listOf()
coEvery { mockOutcomeEventsRepository.saveUniqueOutcomeEventParams(any()) } answers { waiter.wake() }

val subscriptionModel = SubscriptionModel()
subscriptionModel.id = "subscriptionId"
val subscriptionModel = createTestSubscriptionModel()

val mockSubscriptionManager = mockk<ISubscriptionManager>()
every { mockSubscriptionManager.subscriptions.push } returns PushSubscription(subscriptionModel)

Expand Down Expand Up @@ -376,8 +383,8 @@ class OutcomeEventsControllerTests : FunSpec({
val notificationInfluence2 = Influence(InfluenceChannel.NOTIFICATION, InfluenceType.DIRECT, JSONArray(notificationIds2))
every { mockInfluenceManager.influences } returns listOf(notificationInfluence1) andThen listOf(notificationInfluence2)

val subscriptionModel = SubscriptionModel()
subscriptionModel.id = "subscriptionId"
val subscriptionModel = createTestSubscriptionModel()

val mockSubscriptionManager = mockk<ISubscriptionManager>()
every { mockSubscriptionManager.subscriptions.push } returns PushSubscription(subscriptionModel)

Expand Down Expand Up @@ -438,8 +445,8 @@ class OutcomeEventsControllerTests : FunSpec({
val mockInfluenceManager = mockk<IInfluenceManager>()
every { mockInfluenceManager.influences } returns listOf(Influence(InfluenceChannel.NOTIFICATION, InfluenceType.UNATTRIBUTED, null))

val subscriptionModel = SubscriptionModel()
subscriptionModel.id = "subscriptionId"
val subscriptionModel = createTestSubscriptionModel()

val mockSubscriptionManager = mockk<ISubscriptionManager>()
every { mockSubscriptionManager.subscriptions.push } returns PushSubscription(subscriptionModel)

Expand Down Expand Up @@ -483,8 +490,8 @@ class OutcomeEventsControllerTests : FunSpec({
val mockSessionService = mockk<ISessionService>()
every { mockSessionService.subscribe(any()) } just Runs

val subscriptionModel = SubscriptionModel()
subscriptionModel.id = "subscriptionId"
val subscriptionModel = createTestSubscriptionModel()

val mockSubscriptionManager = mockk<ISubscriptionManager>()
every { mockSubscriptionManager.subscriptions.push } returns PushSubscription(subscriptionModel)

Expand Down Expand Up @@ -571,8 +578,8 @@ class OutcomeEventsControllerTests : FunSpec({
val mockSessionService = mockk<ISessionService>()
every { mockSessionService.subscribe(any()) } just Runs

val subscriptionModel = SubscriptionModel()
subscriptionModel.id = "subscriptionId"
val subscriptionModel = createTestSubscriptionModel()

val mockSubscriptionManager = mockk<ISubscriptionManager>()
every { mockSubscriptionManager.subscriptions.push } returns PushSubscription(subscriptionModel)

Expand Down

0 comments on commit 7f73687

Please sign in to comment.