Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DIA-3630 introduce USNat campaign for android #48

Merged
merged 10 commits into from
Mar 22, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace ConsentMessagePlugin.Android
{
internal static class CONFIG_OPTION_FULL_KEY
{
internal const string
TRANSITION_CCPA_AUTH = "TRANSITION_CCPA_AUTH",
SUPPORT_LEGACY_USPSTRING = "SUPPORT_LEGACY_USPSTRING";
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 17 additions & 12 deletions Assets/ConsentManagementProvider/Scripts/facade/CMP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ public static void Initialize(
List<SpCampaign> spCampaigns,
int accountId,
int propertyId,
string propertyName,
bool gdpr,
bool ccpa,
bool usnat,
string propertyName,
MESSAGE_LANGUAGE language,
string gdprPmId,
string ccpaPmId,
Expand All @@ -40,9 +37,16 @@ public static void Initialize(
{
return;
}
useGDPR = gdpr;
useCCPA = ccpa;
useUSNAT = usnat;

foreach (SpCampaign sp in spCampaigns)
{
switch (sp.CampaignType)
{
case CAMPAIGN_TYPE.GDPR: useGDPR = true; break;
case CAMPAIGN_TYPE.CCPA: useCCPA = true; break;
case CAMPAIGN_TYPE.USNAT: useUSNAT = true; break;
}
}
#if UNITY_ANDROID
CreateBroadcastExecutorGO();
//excluding ios14 campaign if any
Expand All @@ -51,25 +55,26 @@ public static void Initialize(
{
return;
}
//TO-DO add usnat
ConsentWrapperAndroid.Instance.InitializeLib(
spCampaigns: spCampaigns,
accountId: accountId,
propertyId: propertyId,
propertyName: propertyName,
language: language,
campaignsEnvironment: campaignsEnvironment,
messageTimeoutMilliSeconds: messageTimeoutInSeconds * 1000);
messageTimeoutMilliSeconds: messageTimeoutInSeconds * 1000,
transitionCCPAAuth: transitionCCPAAuth,
supportLegacyUSPString: supportLegacyUSPString);

#elif UNITY_IOS && !UNITY_EDITOR_OSX
CreateBroadcastExecutorGO();
ConsentWrapperIOS.Instance.InitializeLib(
accountId,
propertyId,
propertyName,
gdpr,
ccpa,
usnat,
useGDPR,
useCCPA,
useUSNAT,
language,
gdprPmId,
ccpaPmId,
Expand Down
44 changes: 43 additions & 1 deletion Assets/ConsentManagementProvider/Scripts/json/JsonUnwrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ public static SpConsents UnwrapSpConsentsAndroid(string json)

SpGdprConsent unwrappedGdpr = CMP.useGDPR ? UnwrapSpGdprConsentAndroid(wrapped.gdpr) : null;
SpCcpaConsent unwrappedCcpa = CMP.useCCPA ? UnwrapSpCcpaConsentAndroid(wrapped.ccpa) : null;
SpUsnatConsent unwrappedUsnat = CMP.useUSNAT ? null : null; //TODO parse
SpUsnatConsent unwrappedUsnat = CMP.useUSNAT ? UnwrapSpUsnatConsentAndroid(wrapped.usnat) : null;

return new SpConsents(unwrappedGdpr, unwrappedCcpa, unwrappedUsnat);
}
catch (NewtonsoftJson.JsonException ex)
{
CmpDebugUtil.LogError(ex.Message);
throw new ApplicationException("Error deserializing JSON.", ex);
}
catch (Exception ex)
Expand All @@ -39,6 +40,47 @@ public static SpConsents UnwrapSpConsentsAndroid(string json)
}
}

private static SpUsnatConsent UnwrapSpUsnatConsentAndroid(SpUsnatConsentWrapperAndroid wrapped)
{
StatusesUsnat _statuses = new StatusesUsnat
{
hasConsentData = wrapped.statuses.hasConsentData,
rejectedAny = wrapped.statuses.rejectedAny,
consentedToAll = wrapped.statuses.consentedToAll,
consentedToAny = wrapped.statuses.consentedToAny,
sellStatus = wrapped.statuses.sellStatus,
shareStatus = wrapped.statuses.shareStatus,
sensitiveDataStatus = wrapped.statuses.sensitiveDataStatus,
gpcStatus = wrapped.statuses.gpcStatus
};
List<ConsentString> _consentStrings = new List<ConsentString>();
List<ConsentStringWrapper> _consentStringsWrapped = NewtonsoftJson.JsonConvert.DeserializeObject<List<ConsentStringWrapper>>(wrapped.consentStrings);
foreach (ConsentStringWrapper _string in _consentStringsWrapped)
{
_consentStrings.Add(new ConsentString(_string.consentString, _string.sectionId, _string.sectionName));
}

List<Consentable> _vendors = new List<Consentable>();
List<ConsentableWrapper> _vendorsWrapped = NewtonsoftJson.JsonConvert.DeserializeObject<List<ConsentableWrapper>>(wrapped.vendors);
foreach (ConsentableWrapper _consentable in _vendorsWrapped)
{
_vendors.Add(new Consentable { id = _consentable.id, consented = _consentable.consented });
}

List<Consentable> _categories = new List<Consentable>();
List<ConsentableWrapper> _categoriesWrapped = NewtonsoftJson.JsonConvert.DeserializeObject<List<ConsentableWrapper>>(wrapped.categories);
foreach (ConsentableWrapper _consentable in _categoriesWrapped)
{
_categories.Add(new Consentable { id = _consentable.id, consented = _consentable.consented });
}
return new SpUsnatConsent(new UsnatConsent(uuid: wrapped.uuid,
applies: wrapped.applies,
consentStrings: _consentStrings,
vendors: _vendors,
categories: _categories,
statuses: _statuses));
}

private static SpCcpaConsent UnwrapSpCcpaConsentAndroid(CcpaConsentWrapper wrappedCcpa)
{
if (wrappedCcpa == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ internal class SpConsentsWrapperAndroid
#nullable enable
public CcpaConsentWrapper? ccpa;
public SpGdprConsentWrapperAndroid? gdpr;
public SpUsnatConsentWrapperAndroid? usnat;
#nullable disable
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Newtonsoft.Json;
using System.Collections.Generic;

namespace ConsentManagementProviderLib.Json
{
internal class SpUsnatConsentWrapperAndroid
{
#nullable enable
public string? uuid;
#nullable disable
public StatusWrapperAndroid statuses;
public bool applies;
public string consentStrings;
public string vendors;
public string categories;
}

internal class StatusWrapperAndroid
{
#nullable enable
public bool? hasConsentData;
public bool? rejectedAny;
public bool? consentedToAll;
public bool? consentedToAny;
public bool? sellStatus;
public bool? shareStatus;
public bool? sensitiveDataStatus;
public bool? gpcStatus;
#nullable disable
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ internal class UserConsentsWrapper

internal class ConsentableWrapper
{
#if UNITY_IOS && !UNITY_EDITOR_OSX
[JsonProperty("_id")]
#endif
public string id;
public bool consented;
}

internal class ConsentStringWrapper
{
public string consentString;
public string sectionId;
public int sectionId;
public string sectionName;
public string consentString;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,26 @@ ConsentStatus consentStatus
this.categories = categories;
this.statuses = StatusesUsnat.collectData(consentStatus);
}


public UsnatConsent(
#nullable enable
string? uuid,
bool applies,
List<ConsentString> consentStrings,
List<Consentable> vendors,
List<Consentable> categories,
StatusesUsnat statuses
#nullable disable
)
{
this.uuid = uuid;
this.applies = applies;
this.consentStrings = consentStrings;
this.vendors = vendors;
this.categories = categories;
this.statuses = statuses;
}

public string ToFullString()
{
StringBuilder sb = new StringBuilder();
Expand Down Expand Up @@ -113,10 +132,10 @@ public class Consentable
public class ConsentString
{
public string consentString;
public string sectionId;
public int sectionId;
public string sectionName;

public ConsentString(string consentString, string sectionId, string sectionName)
public ConsentString(string consentString, int sectionId, string sectionName)
{
this.consentString = consentString;
this.sectionId = sectionId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using ConsentManagementProviderLib.Enum;
using ConsentMessagePlugin.Android;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace ConsentManagementProviderLib.Android
Expand Down Expand Up @@ -55,6 +57,26 @@ internal AndroidJavaObject ConstructCampaign(AndroidJavaObject campaignType, And
return campaign;
}

internal AndroidJavaObject ConstructCampaign(AndroidJavaObject campaignType, AndroidJavaObject targetingParams, CAMPAIGN_TYPE campaignTypeForLog, bool? transitionCCPAAuth = null, bool? supportLegacyUSPString = null)
{
AndroidJavaObject[] configOptions = new AndroidJavaObject[2];
AndroidJavaClass enumConfigOption = new AndroidJavaClass("com.sourcepoint.cmplibrary.creation.ConfigOption");
if (transitionCCPAAuth.HasValue && transitionCCPAAuth==true)
{
AndroidJavaObject option = enumConfigOption.GetStatic<AndroidJavaObject>(CONFIG_OPTION_FULL_KEY.TRANSITION_CCPA_AUTH);
configOptions.Append(option);
}
if (supportLegacyUSPString.HasValue && supportLegacyUSPString==true)
{
AndroidJavaObject option = enumConfigOption.GetStatic<AndroidJavaObject>(CONFIG_OPTION_FULL_KEY.SUPPORT_LEGACY_USPSTRING);
configOptions.Append(option);
}
AndroidJavaObject configSet = CmpJavaToUnityUtils.ConvertArrayToSet(configOptions);
AndroidJavaObject campaign = new AndroidJavaObject("com.sourcepoint.cmplibrary.model.exposed.SpCampaign", campaignType, targetingParams, configSet);
CmpDebugUtil.Log($"Campaign {campaignTypeForLog} with configOptions is OK");
return campaign;
}

internal AndroidJavaObject ConstructCampaignType(CAMPAIGN_TYPE campaignType)
{
AndroidJavaObject type = null;
Expand All @@ -67,6 +89,9 @@ internal AndroidJavaObject ConstructCampaignType(CAMPAIGN_TYPE campaignType)
case CAMPAIGN_TYPE.CCPA:
type = enumClass.GetStatic<AndroidJavaObject>("CCPA");
break;
case CAMPAIGN_TYPE.USNAT:
type = enumClass.GetStatic<AndroidJavaObject>("USNAT");
break;
default:
CmpDebugUtil.LogError("CampaignType is NULL. How did you get there?");
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ internal static AndroidJavaObject ConvertArrayToList(AndroidJavaObject[] array)
}
}

internal static AndroidJavaObject ConvertArrayToSet(AndroidJavaObject[] array)
{
using (AndroidJavaClass UnityUtils = new AndroidJavaClass(UnityUtilsPackageName))
{
CmpDebugUtil.Log("C# : passing Array to Set conversion to Android's UnityUtils...");
AndroidJavaObject set = UnityUtils.CallStatic<AndroidJavaObject>("arrayToSet", new AndroidJavaObject[][] { array });
return set;
}
}

internal static Exception ConvertThrowableToError(AndroidJavaObject rawErr)
{
using (AndroidJavaClass UnityUtils = new AndroidJavaClass(UnityUtilsPackageName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private set
#endif
}

public void InitializeLib(List<SpCampaign> spCampaigns, int accountId, int propertyId, string propertyName, MESSAGE_LANGUAGE language, CAMPAIGN_ENV campaignsEnvironment, long messageTimeoutMilliSeconds = 3000)
public void InitializeLib(List<SpCampaign> spCampaigns, int accountId, int propertyId, string propertyName, MESSAGE_LANGUAGE language, CAMPAIGN_ENV campaignsEnvironment, long messageTimeoutMilliSeconds = 3000, bool? transitionCCPAAuth = null, bool? supportLegacyUSPString = null)
{
#if UNITY_ANDROID
if (Application.platform == RuntimePlatform.Android)
Expand All @@ -64,7 +64,11 @@ public void InitializeLib(List<SpCampaign> spCampaigns, int accountId, int prope
paramsArray[sp.TargetingParams.IndexOf(tp)] = param;
}
AndroidJavaObject paramsList = CmpJavaToUnityUtils.ConvertArrayToList(paramsArray);
AndroidJavaObject campaign = constructor.ConstructCampaign(typeAJO, paramsList, sp.CampaignType);
AndroidJavaObject campaign;
if (sp.CampaignType == CAMPAIGN_TYPE.USNAT && (transitionCCPAAuth.HasValue || supportLegacyUSPString.HasValue))
campaign = constructor.ConstructCampaign(typeAJO, paramsList, sp.CampaignType, transitionCCPAAuth, supportLegacyUSPString);
else
campaign = constructor.ConstructCampaign(typeAJO, paramsList, sp.CampaignType);
campaigns[spCampaigns.IndexOf(sp)] = campaign;
}
AndroidJavaObject spConfig = constructor.ConstructSpConfig(accountId: accountId,
Expand Down
2 changes: 1 addition & 1 deletion Assets/ExampleApp/Scenes/SourcepointSampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ MonoBehaviour:
propertyId: 16893
propertyName: mobile.multicampaign.demo
useGDPR: 1
useCCPA: 0
useCCPA: 1
useUSNAT: 1
gdprPmId: 488393
ccpaPmId: 509688
Expand Down
Loading