Skip to content

Commit

Permalink
Merge branch 'develop' into DIA-2811-remove-code-signing-iOS
Browse files Browse the repository at this point in the history
* develop: (26 commits)
  Update `unitypackage`
  Update `package.json`
  Update `CHANGELOG.md`
  fix race conditions by dispatching JSON parsing to the UnityMain thread
  make BroadcastReceivers class thread-safe
  BroadcastEventDispatcher.actions is a ConcurrentQueue now
  fix race conditions by dispatching JSON parsing to the UnityMain thread
  make BroadcastReceivers class thread-safe
  BroadcastEventDispatcher.actions is a ConcurrentQueue now
  [DIA-2584] Change `throw` to `logError`
  Update `unitypackage`
  Update `CHANGELOG.md`
  Update `package.json`
  Update `CHANGELOG.md`
  remove code signing for IOS
  [DIA] remove unused folder
  [DIA-2584] rename
  [DIA-2584] remove old script
  [DIA-2584] Remove redefinition
  [DIA-2584] Add set and delete methods for `customConsent`
  ...
  • Loading branch information
Nevazhnovu committed Jan 24, 2024
2 parents 0107da6 + f20dc1c commit 82e662d
Show file tree
Hide file tree
Showing 22 changed files with 922 additions and 338 deletions.
8 changes: 0 additions & 8 deletions Assets/ConsentManagementProvider/Plugins/Android.meta

This file was deleted.

8 changes: 0 additions & 8 deletions Assets/ConsentManagementProvider/Plugins/Android/cmp.meta

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ import UIKit
let language: SPMessageLanguage
let gdprPmId, ccpaPmId: String?

let myVendorId: String = ""
let myPurposesId: [String] = []
var vendors: [String] = []
var categories: [String] = []
var legIntCategories: [String] = []
}

var idfaStatus: SPIDFAStatus { SPIDFAStatus.current() }
Expand Down Expand Up @@ -85,6 +86,7 @@ import UIKit
var callbackOnErrorCallback: СallbackCharMessage? = nil
var callbackOnSPFinished: СallbackCharMessage? = nil
var callbackOnSPUIFinished: СallbackCharMessage? = nil
var callbackOnCustomConsent: СallbackCharMessage? = nil

// MARK: - Bridge config
@objc public func addTargetingParam(campaignType: Int, key: String, value: String){
Expand Down Expand Up @@ -122,6 +124,24 @@ import UIKit
)}()
}

@objc public func addCustomVendor(vendor: String) {
config.vendors.append(vendor)
}

@objc public func addCustomCategory(category: String) {
config.categories.append(category)
}

@objc public func addCustomLegIntCategory(legIntCategory: String) {
config.legIntCategories.append(legIntCategory)
}

@objc public func clearCustomArrays() {
config.vendors = []
config.categories = []
config.legIntCategories = []
}

@objc public func dispose() {
callbackDefault = nil
callbackOnConsentReady = nil
Expand Down Expand Up @@ -152,24 +172,25 @@ import UIKit
@objc public func onCCPAPrivacyManagerTap() {
consentManager.loadCCPAPrivacyManager(withId: config.ccpaPmId!)
}
//TO-DO
func onAcceptMyVendorTap(_ sender: Any) {


@objc public func customConsentToGDPR() {
consentManager.customConsentGDPR(
vendors: [config.myVendorId],
categories: config.myPurposesId,
legIntCategories: []) { consents in
self.myVendorAccepted = VendorStatus(fromBool: consents.vendorGrants[self.config.myVendorId]?.granted)
vendors: config.vendors,
categories: config.categories,
legIntCategories: config.legIntCategories){contents in
self.print(contents)
self.runCallback(callback: self.callbackOnCustomConsent, arg: contents.toJSON())
}
}

//TO-DO
func onDeleteMyVendorTap(_ sender: Any) {

@objc public func deleteCustomConsentGDPR() {
consentManager.deleteCustomConsentGDPR(
vendors: [config.myVendorId],
categories: config.myPurposesId,
legIntCategories: []) { consents in
self.myVendorAccepted = VendorStatus(fromBool: consents.vendorGrants[self.config.myVendorId]?.granted)
vendors: config.vendors,
categories: config.categories,
legIntCategories: config.legIntCategories){contents in
self.print(contents)
self.runCallback(callback: self.callbackOnCustomConsent, arg: contents.toJSON())
}
}
}
Expand Down Expand Up @@ -207,9 +228,6 @@ extension SwiftBridge: SPDelegate {

public func onConsentReady(userData: SPUserData) {
print("onConsentReady:", userData)
myVendorAccepted = VendorStatus(
fromBool: userData.gdpr?.consents?.vendorGrants[config.myVendorId]?.granted
)
logger.log("PURE SWIFT onConsentReady")
runCallback(callback: callbackOnConsentReady, arg: userData.toJSON())
}
Expand Down Expand Up @@ -264,11 +282,16 @@ extension SwiftBridge {
callbackOnSPFinished = callback
}

@objc public func setCallbackOnCustomConsent(callback: @escaping СallbackCharMessage) -> Void{
print("setCallbackOnSPFinished")
callbackOnCustomConsent = callback
}

func runCallback(callback: СallbackCharMessage?, arg: String?) {
if callback != nil {
callback!(arg)
}else{
(callbackDefault ?? callbackSystem)("onError not set")
(callbackDefault ?? callbackSystem)("onError not set:"+(arg ?? ""))
}
}

Expand Down
37 changes: 34 additions & 3 deletions Assets/ConsentManagementProvider/Plugins/iOS/Source/Unity.mm
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ void _setCallbackOnSPFinished (СallbackCharMessage callback){
[swiftBridge setCallbackOnSPFinishedWithCallback:callback];
}

void _setCallbackOnCustomConsent (СallbackCharMessage callback){
if (swiftBridge == nil)
swiftBridge = [[SwiftBridge alloc] init];
[swiftBridge setCallbackOnCustomConsentWithCallback:callback];
}

void _initLib()
{
if (swiftBridge == nil)
Expand Down Expand Up @@ -89,10 +95,35 @@ void _cleanConsent()
{
[swiftBridge onClearConsentTap];
}

void _customConsentGDPRWithVendors()

void _customConsentGDPR()
{
[swiftBridge customConsentToGDPR];
}

void _deleteCustomConsentGDPR()
{
[swiftBridge deleteCustomConsentGDPR];
}

void _addVendor(char* vendor)
{
[swiftBridge addCustomVendorWithVendor:[NSString stringWithFormat:@"%s", vendor]];
}

void _addCategory(char* category)
{
[swiftBridge addCustomCategoryWithCategory:[NSString stringWithFormat:@"%s", category]];
}

void _addLegIntCategory(char* legIntCategory)
{
[swiftBridge addCustomLegIntCategoryWithLegIntCategory:[NSString stringWithFormat:@"%s", legIntCategory]];
}

void _clearCustomArrays()
{
//TO-DO
[swiftBridge clearCustomArrays];
}

void _dispose()
Expand Down
125 changes: 71 additions & 54 deletions Assets/ConsentManagementProvider/Scripts/json/JsonUnwrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public static SpConsents UnwrapSpConsentsAndroid(string json)
{
using StringReader stringReader = new StringReader(json);
using NewtonsoftJson.JsonTextReader reader = new NewtonsoftJson.JsonTextReader(stringReader);

NewtonsoftJson.JsonSerializer serializer = new NewtonsoftJson.JsonSerializer();
SpConsentsWrapperAndroid wrapped = serializer.Deserialize<SpConsentsWrapperAndroid>(reader);

Expand Down Expand Up @@ -60,10 +59,10 @@ private static SpCcpaConsent UnwrapSpCcpaConsentAndroid(CcpaConsentWrapper wrapp
public static SpGdprConsent UnwrapSpGdprConsentAndroid(SpGdprConsentWrapperAndroid wrappedGdpr)
{
if (wrappedGdpr == null)
throw new ArgumentNullException(nameof(wrappedGdpr), "The GDPR consent wrapper cannot be null.");

if (wrappedGdpr.grants == null)
throw new InvalidOperationException("The grants dictionary is null.");
{
CmpDebugUtil.LogError("The GDPR consent wrapper cannot be null.");
return null;
}

GdprConsent unwrapped = new GdprConsent
{
Expand All @@ -73,30 +72,36 @@ public static SpGdprConsent UnwrapSpGdprConsentAndroid(SpGdprConsentWrapperAndro
grants = new Dictionary<string, SpVendorGrant>()
};

foreach (var vendorGrantWrapper in wrappedGdpr.grants)
if (wrappedGdpr.grants == null)
{
var purposeGrants = new Dictionary<string, bool>();
bool isGranted = false;
CmpDebugUtil.LogError("The grants dictionary is null.");
}
else
{
foreach (var vendorGrantWrapper in wrappedGdpr.grants)
{
var purposeGrants = new Dictionary<string, bool>();
bool isGranted = false;

var vendorGrantValue = JToken.FromObject(vendorGrantWrapper.Value);
var vendorGrantValue = JToken.FromObject(vendorGrantWrapper.Value);

if (vendorGrantValue["granted"] != null)
isGranted = vendorGrantValue["granted"].ToObject<bool>();

if (vendorGrantValue["purposeGrants"] != null)
{
var purposeGrantsElement = (JObject)vendorGrantValue["purposeGrants"];

foreach (var purposeGrant in purposeGrantsElement)
purposeGrants.Add(purposeGrant.Key, purposeGrant.Value.ToObject<bool>());
}
if (vendorGrantValue["granted"] != null)
isGranted = vendorGrantValue["granted"].ToObject<bool>();

unwrapped.grants[vendorGrantWrapper.Key] = new SpVendorGrant(isGranted, purposeGrants);
if (vendorGrantValue["purposeGrants"] != null)
{
var purposeGrantsElement = (JObject)vendorGrantValue["purposeGrants"];

foreach (var purposeGrant in purposeGrantsElement)
purposeGrants.Add(purposeGrant.Key, purposeGrant.Value.ToObject<bool>());
}
unwrapped.grants[vendorGrantWrapper.Key] = new SpVendorGrant(isGranted, purposeGrants);
}
}

return new SpGdprConsent(unwrapped);
}

public static SpCustomConsentAndroid UnwrapSpCustomConsentAndroid(string spConsentsJson)
{
try
Expand Down Expand Up @@ -147,7 +152,7 @@ public static SpConsents UnwrapSpConsents(string json)
{
using StringReader stringReader = new StringReader(json);
using NewtonsoftJson.JsonTextReader reader = new NewtonsoftJson.JsonTextReader(stringReader);

NewtonsoftJson.JsonSerializer serializer = new NewtonsoftJson.JsonSerializer();
SpConsentsWrapper wrapped = serializer.Deserialize<SpConsentsWrapper>(reader);

Expand All @@ -168,17 +173,20 @@ public static SpConsents UnwrapSpConsents(string json)
throw new ApplicationException("An error occurred during JSON unwrapping.", ex);
}
}

private static SpGdprConsent UnwrapSpGdprConsent(SpGdprConsentWrapper wrappedGdpr)
{
if (wrappedGdpr == null)
throw new ArgumentNullException(nameof(wrappedGdpr), "The GDPR consent wrapper cannot be null.");

{
CmpDebugUtil.LogError("The GDPR consent wrapper cannot be null.");
return null;
}

bool applies = wrappedGdpr.applies;
GdprConsent consent = UnwrapGdprConsent(wrappedGdpr.consents);
return new SpGdprConsent(applies, consent);
}

private static GdprConsent UnwrapGdprConsent(GdprConsentWrapper wrapped)
{
GdprConsent unwrapped = new GdprConsent
Expand All @@ -192,40 +200,46 @@ private static GdprConsent UnwrapGdprConsent(GdprConsentWrapper wrapped)
};

if (wrapped.grants == null)
throw new InvalidOperationException("The grants dictionary is null.");

foreach (var vendorGrantWrapper in wrapped.grants)
{
var purposeGrants = new Dictionary<string, bool>();
bool isGranted = false;
CmpDebugUtil.LogError("The grants dictionary is null.");
}
else
{
foreach (var vendorGrantWrapper in wrapped.grants)
{
var purposeGrants = new Dictionary<string, bool>();
bool isGranted = false;

var vendorGrantValue = JToken.FromObject(vendorGrantWrapper.Value);
var vendorGrantValue = JToken.FromObject(vendorGrantWrapper.Value);

if (vendorGrantValue["granted"] != null)
isGranted = vendorGrantValue["granted"].ToObject<bool>();

if (vendorGrantValue["purposeGrants"] != null)
{
var purposeGrantsElement = (JObject)vendorGrantValue["purposeGrants"];

foreach (var purposeGrant in purposeGrantsElement)
purposeGrants.Add(purposeGrant.Key, purposeGrant.Value.ToObject<bool>());
}
if (vendorGrantValue["granted"] != null)
isGranted = vendorGrantValue["granted"].ToObject<bool>();

unwrapped.grants[vendorGrantWrapper.Key] = new SpVendorGrant(isGranted, purposeGrants);
if (vendorGrantValue["purposeGrants"] != null)
{
var purposeGrantsElement = (JObject)vendorGrantValue["purposeGrants"];

foreach (var purposeGrant in purposeGrantsElement)
purposeGrants.Add(purposeGrant.Key, purposeGrant.Value.ToObject<bool>());
}

unwrapped.grants[vendorGrantWrapper.Key] = new SpVendorGrant(isGranted, purposeGrants);
}
}

if (wrapped.consentStatus != null){
if (wrapped.consentStatus != null)
{
unwrapped.consentStatus = UnwrapConsentStatus(wrapped.consentStatus);
}

return unwrapped;
}

private static ConsentStatus UnwrapConsentStatus(ConsentStatusWrapper wrappedconsentStatus)
{
GranularStatus granularStatus = null;
if (wrappedconsentStatus.granularStatus != null){
if (wrappedconsentStatus.granularStatus != null)
{
granularStatus = new GranularStatus(
wrappedconsentStatus.granularStatus.vendorConsent,
wrappedconsentStatus.granularStatus.vendorLegInt,
Expand Down Expand Up @@ -253,7 +267,10 @@ private static ConsentStatus UnwrapConsentStatus(ConsentStatusWrapper wrappedcon
private static SpCcpaConsent UnwrapSpCcpaConsent(SpCcpaConsentWrapper wrappedCcpa)
{
if (wrappedCcpa == null)
throw new ArgumentNullException(nameof(wrappedCcpa), "The CCPA consent wrapper cannot be null.");
{
CmpDebugUtil.LogError("The CCPA consent wrapper cannot be null.");
return null;
}

bool applies = wrappedCcpa.applies;
CcpaConsent consent = UnwrapCcpaConsent(wrappedCcpa.consents);
Expand All @@ -263,15 +280,15 @@ private static SpCcpaConsent UnwrapSpCcpaConsent(SpCcpaConsentWrapper wrappedCcp
private static CcpaConsent UnwrapCcpaConsent(CcpaConsentWrapper wrapped)
{
ConsentStatus _consentStatus = UnwrapConsentStatus(wrapped.consentStatus);
return new CcpaConsent(uuid: wrapped.uuid,

return new CcpaConsent(uuid: wrapped.uuid,
status: wrapped.status,
uspstring: wrapped.uspstring,
rejectedVendors: wrapped.rejectedVendors,
uspstring: wrapped.uspstring,
rejectedVendors: wrapped.rejectedVendors,
rejectedCategories: wrapped.rejectedCategories,
childPmId:"",
applies: wrapped.applies,
signedLspa: null,
childPmId: "",
applies: wrapped.applies,
signedLspa: null,
webConsentPayload: wrapped.webConsentPayload,
consentStatus: _consentStatus);
}
Expand Down
Loading

0 comments on commit 82e662d

Please sign in to comment.