using Chartboost.Core.Consent;
using Chartboost.Core.Initialization;
using System.Collections.Generic;
using UnityEngine.Scripting;
namespace Chartboost.Core.Unmanaged
{
///
///
///
public class UnmanagedConsentAdapter : NativeModuleWrapper, IUnmanagedConsentAdapter
{
#nullable enable
private IUnmanagedConsentAdapter? UnmanagedInstance
{
get
{
var adapter = (IUnmanagedConsentAdapter)Instance;
return adapter;
}
}
#nullable disable
protected override string DefaultModuleId => "unmanaged_consent_adapter";
protected override string DefaultModuleVersion => "1.0.1";
///
/// Holds value in case no instance is found.
///
private bool _shouldCollectConsent;
///
/// Indicates whether the CMP has determined that consent should be collected from the user.
///
public bool ShouldCollectConsent
{
get => UnmanagedInstance?.ShouldCollectConsent ?? _shouldCollectConsent;
set
{
if (UnmanagedInstance == null)
_shouldCollectConsent = value;
else
UnmanagedInstance.ShouldCollectConsent = value;
}
}
///
/// Holds value in case no instance is found.
///
private IReadOnlyDictionary _consents = new Dictionary();
///
///
/// Current user consent info as determined by the CMP.
///
///
///
/// Consent info may include IAB strings, like TCF or GPP, and parsed boolean-like signals like "CCPA Opt In Sale"
/// and partner-specific signals.
///
///
///
/// Predefined consent key constants, such as `ConsentKeys/tcf` and `ConsentKeys/usp`, are provided
/// by Core. Adapters should use them when reporting the status of a common standard.
/// Custom keys should only be used by adapters when a corresponding constant is not provided by the Core.
///
///
///
/// Predefined consent value constants are also provided, but are only applicable to non-IAB string keys, like
/// `ConsentKeys/ccpaOptIn` and `ConsentKeys/gdprConsentGiven`.
///
///
public IReadOnlyDictionary Consents
{
get => UnmanagedInstance?.Consents ?? _consents;
set
{
if (UnmanagedInstance == null)
_consents = value;
else
UnmanagedInstance.Consents = value;
}
}
// ReSharper disable once InconsistentNaming
// ReSharper disable once UnusedAutoPropertyAccessor.Global
///
///
/// A flag that indicates if the adapter observers and fetches standard IAB consent strings from the
/// user defaults. If enabled, this info is merged with the user-provided info to obtain the final
/// map of consents.
///
///
///
/// In some cases setting this flag to true is everything that's needed to receive CMP consent info.
/// If the CMP used provides other consent information besides standard IAB consent strings, that info
/// will need to be explicitly set by the user.
///
///
///
/// This should be set to false if the user does not want to get this automatic behavior, and instead
/// prefers to set all the consent info explicitly themselves.
///
///
public bool UsesIABStringsFromAppPreferences { get; }
// ReSharper disable once InconsistentNaming
[Preserve]
public UnmanagedConsentAdapter(bool usesIABStringsFromAppPreferences) : base(usesIABStringsFromAppPreferences) => UsesIABStringsFromAppPreferences = usesIABStringsFromAppPreferences;
}
}