using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using AppLovinMax.ThirdParty.MiniJson;
using AppLovinMax.Internal;
using UnityEngine;
#if UNITY_IOS && !UNITY_EDITOR
using System.Runtime.InteropServices;
#endif
public abstract class MaxSdkBase
{
// Shared Properties
protected static readonly MaxUserSegment SharedUserSegment = new MaxUserSegment();
protected static readonly MaxTargetingData SharedTargetingData = new MaxTargetingData();
///
/// This enum represents the user's geography used to determine the type of consent flow shown to the user.
///
public enum ConsentFlowUserGeography
{
///
/// User's geography is unknown.
///
Unknown,
///
/// The user is in GDPR region.
///
Gdpr,
///
/// The user is in a non-GDPR region.
///
Other
}
#if UNITY_EDITOR || UNITY_IPHONE || UNITY_IOS
///
/// App tracking status values. Primarily used in conjunction with iOS14's AppTrackingTransparency.framework.
///
public enum AppTrackingStatus
{
///
/// Device is on < iOS14, AppTrackingTransparency.framework is not available.
///
Unavailable,
///
/// The value returned if a user has not yet received an authorization request to authorize access to app-related data that can be used for tracking the user or the device.
///
NotDetermined,
///
/// The value returned if authorization to access app-related data that can be used for tracking the user or the device is restricted.
///
Restricted,
///
/// The value returned if the user denies authorization to access app-related data that can be used for tracking the user or the device.
///
Denied,
///
/// The value returned if the user authorizes access to app-related data that can be used for tracking the user or the device.
///
Authorized,
}
#endif
public enum AdViewPosition
{
TopLeft,
TopCenter,
TopRight,
Centered,
CenterLeft,
CenterRight,
BottomLeft,
BottomCenter,
BottomRight
}
public enum BannerPosition
{
TopLeft,
TopCenter,
TopRight,
Centered,
CenterLeft,
CenterRight,
BottomLeft,
BottomCenter,
BottomRight
}
public class SdkConfiguration
{
///
/// Whether or not the SDK has been initialized successfully.
///
public bool IsSuccessfullyInitialized { get; private set; }
///
/// Get the country code for this user.
///
public string CountryCode { get; private set; }
#if UNITY_EDITOR || UNITY_IPHONE || UNITY_IOS
///
/// App tracking status values. Primarily used in conjunction with iOS14's AppTrackingTransparency.framework.
///
public AppTrackingStatus AppTrackingStatus { get; private set; }
#endif
public bool IsTestModeEnabled { get; private set; }
///
/// Get the user's geography used to determine the type of consent flow shown to the user.
/// If no such determination could be made, will be returned.
///
public ConsentFlowUserGeography ConsentFlowUserGeography { get; private set; }
[Obsolete("This API has been deprecated and will be removed in a future release.")]
public ConsentDialogState ConsentDialogState { get; private set; }
#if UNITY_EDITOR || !(UNITY_ANDROID || UNITY_IPHONE || UNITY_IOS)
public static SdkConfiguration CreateEmpty()
{
var sdkConfiguration = new SdkConfiguration();
sdkConfiguration.IsSuccessfullyInitialized = true;
#pragma warning disable 0618
sdkConfiguration.ConsentDialogState = ConsentDialogState.Unknown;
#pragma warning restore 0618
#if UNITY_EDITOR
sdkConfiguration.AppTrackingStatus = AppTrackingStatus.Authorized;
#endif
var currentRegion = RegionInfo.CurrentRegion;
sdkConfiguration.CountryCode = currentRegion != null ? currentRegion.TwoLetterISORegionName : "US";
sdkConfiguration.IsTestModeEnabled = false;
return sdkConfiguration;
}
#endif
public static SdkConfiguration Create(IDictionary eventProps)
{
var sdkConfiguration = new SdkConfiguration();
sdkConfiguration.IsSuccessfullyInitialized = MaxSdkUtils.GetBoolFromDictionary(eventProps, "isSuccessfullyInitialized");
sdkConfiguration.CountryCode = MaxSdkUtils.GetStringFromDictionary(eventProps, "countryCode", "");
sdkConfiguration.IsTestModeEnabled = MaxSdkUtils.GetBoolFromDictionary(eventProps, "isTestModeEnabled");
var consentFlowUserGeographyStr = MaxSdkUtils.GetStringFromDictionary(eventProps, "consentFlowUserGeography", "");
if ("1".Equals(consentFlowUserGeographyStr))
{
sdkConfiguration.ConsentFlowUserGeography = ConsentFlowUserGeography.Gdpr;
}
else if ("2".Equals(consentFlowUserGeographyStr))
{
sdkConfiguration.ConsentFlowUserGeography = ConsentFlowUserGeography.Other;
}
else
{
sdkConfiguration.ConsentFlowUserGeography = ConsentFlowUserGeography.Unknown;
}
#pragma warning disable 0618
var consentDialogStateStr = MaxSdkUtils.GetStringFromDictionary(eventProps, "consentDialogState", "");
if ("1".Equals(consentDialogStateStr))
{
sdkConfiguration.ConsentDialogState = ConsentDialogState.Applies;
}
else if ("2".Equals(consentDialogStateStr))
{
sdkConfiguration.ConsentDialogState = ConsentDialogState.DoesNotApply;
}
else
{
sdkConfiguration.ConsentDialogState = ConsentDialogState.Unknown;
}
#pragma warning restore 0618
#if UNITY_IPHONE || UNITY_IOS
var appTrackingStatusStr = MaxSdkUtils.GetStringFromDictionary(eventProps, "appTrackingStatus", "-1");
if ("-1".Equals(appTrackingStatusStr))
{
sdkConfiguration.AppTrackingStatus = AppTrackingStatus.Unavailable;
}
else if ("0".Equals(appTrackingStatusStr))
{
sdkConfiguration.AppTrackingStatus = AppTrackingStatus.NotDetermined;
}
else if ("1".Equals(appTrackingStatusStr))
{
sdkConfiguration.AppTrackingStatus = AppTrackingStatus.Restricted;
}
else if ("2".Equals(appTrackingStatusStr))
{
sdkConfiguration.AppTrackingStatus = AppTrackingStatus.Denied;
}
else // "3" is authorized
{
sdkConfiguration.AppTrackingStatus = AppTrackingStatus.Authorized;
}
#endif
return sdkConfiguration;
}
}
public struct Reward
{
public string Label;
public int Amount;
public override string ToString()
{
return "Reward: " + Amount + " " + Label;
}
public bool IsValid()
{
return !string.IsNullOrEmpty(Label) && Amount > 0;
}
}
/**
* This enum contains various error codes that the SDK can return when a MAX ad fails to load or display.
*/
public enum ErrorCode
{
///
/// This error code represents an error that could not be categorized into one of the other defined errors. See the message field in the error object for more details.
///
Unspecified = -1,
///
/// This error code indicates that MAX returned no eligible ads from any mediated networks for this app/device.
///
NoFill = 204,
///
/// This error code indicates that MAX returned eligible ads from mediated networks, but all ads failed to load. See the adLoadFailureInfo field in the error object for more details.
///
AdLoadFailed = -5001,
///
/// This error code represents an error that was encountered when showing an ad.
///
AdDisplayFailed = -4205,
///
/// This error code indicates that the ad request failed due to a generic network error. See the message field in the error object for more details.
///
NetworkError = -1000,
///
/// This error code indicates that the ad request timed out due to a slow internet connection.
///
NetworkTimeout = -1001,
///
/// This error code indicates that the ad request failed because the device is not connected to the internet.
///
NoNetwork = -1009,
///
/// This error code indicates that you attempted to show a fullscreen ad while another fullscreen ad is still showing.
///
FullscreenAdAlreadyShowing = -23,
///
/// This error code indicates you are attempting to show a fullscreen ad before the one has been loaded.
///
FullscreenAdNotReady = -24,
#if UNITY_ANDROID
///
/// This error code indicates that the SDK failed to load an ad because it could not find the top Activity.
///
NoActivity = -5601,
///
/// This error code indicates that the SDK failed to display an ad because the user has the "Don't Keep Activities" developer setting enabled.
///
DontKeepActivitiesEnabled = -5602,
#endif
}
/**
* This enum contains possible states of an ad in the waterfall the adapter response info could represent.
*/
public enum MaxAdLoadState
{
///
/// The AppLovin Max SDK did not attempt to load an ad from this network in the waterfall because an ad higher
/// in the waterfall loaded successfully.
///
AdLoadNotAttempted,
///
/// An ad successfully loaded from this network.
///
AdLoaded,
///
/// An ad failed to load from this network.
///
FailedToLoad
}
public class AdInfo
{
public string AdUnitIdentifier { get; private set; }
public string AdFormat { get; private set; }
public string NetworkName { get; private set; }
public string NetworkPlacement { get; private set; }
public string Placement { get; private set; }
public string CreativeIdentifier { get; private set; }
public double Revenue { get; private set; }
public string RevenuePrecision { get; private set; }
public WaterfallInfo WaterfallInfo { get; private set; }
public long LatencyMillis { get; private set; }
public string DspName { get; private set; }
public AdInfo(IDictionary adInfoDictionary)
{
AdUnitIdentifier = MaxSdkUtils.GetStringFromDictionary(adInfoDictionary, "adUnitId");
AdFormat = MaxSdkUtils.GetStringFromDictionary(adInfoDictionary, "adFormat");
NetworkName = MaxSdkUtils.GetStringFromDictionary(adInfoDictionary, "networkName");
NetworkPlacement = MaxSdkUtils.GetStringFromDictionary(adInfoDictionary, "networkPlacement");
CreativeIdentifier = MaxSdkUtils.GetStringFromDictionary(adInfoDictionary, "creativeId");
Placement = MaxSdkUtils.GetStringFromDictionary(adInfoDictionary, "placement");
Revenue = MaxSdkUtils.GetDoubleFromDictionary(adInfoDictionary, "revenue", -1);
RevenuePrecision = MaxSdkUtils.GetStringFromDictionary(adInfoDictionary, "revenuePrecision");
WaterfallInfo = new WaterfallInfo(MaxSdkUtils.GetDictionaryFromDictionary(adInfoDictionary, "waterfallInfo", new Dictionary()));
LatencyMillis = MaxSdkUtils.GetLongFromDictionary(adInfoDictionary, "latencyMillis");
DspName = MaxSdkUtils.GetStringFromDictionary(adInfoDictionary, "dspName");
}
public override string ToString()
{
return "[AdInfo adUnitIdentifier: " + AdUnitIdentifier +
", adFormat: " + AdFormat +
", networkName: " + NetworkName +
", networkPlacement: " + NetworkPlacement +
", creativeIdentifier: " + CreativeIdentifier +
", placement: " + Placement +
", revenue: " + Revenue +
", revenuePrecision: " + RevenuePrecision +
", latency: " + LatencyMillis +
", dspName: " + DspName + "]";
}
}
///
/// Returns information about the ad response in a waterfall.
///
public class WaterfallInfo
{
public String Name { get; private set; }
public String TestName { get; private set; }
public List NetworkResponses { get; private set; }
public long LatencyMillis { get; private set; }
public WaterfallInfo(IDictionary waterfallInfoDict)
{
Name = MaxSdkUtils.GetStringFromDictionary(waterfallInfoDict, "name");
TestName = MaxSdkUtils.GetStringFromDictionary(waterfallInfoDict, "testName");
var networkResponsesList = MaxSdkUtils.GetListFromDictionary(waterfallInfoDict, "networkResponses", new List