public void SetTagForUnderAgeOfConsent(bool underAgeOfConsent)
        {
            ConsentData consentData = LoadConsentData();

            consentData.UnderAgeOfConsent = underAgeOfConsent;
            SaveConsentData(consentData);
        }
        private void SaveConsentData(ConsentData consentData)
        {
            ISharedPreferences sharedPref =
                context.GetSharedPreferences(PREFERENCES_FILE_KEY, FileCreationMode.Private);
            ISharedPreferencesEditor editor = sharedPref.Edit();
            String consentDataString        = JsonConvert.SerializeObject(consentData);

            editor.PutString(CONSENT_DATA_KEY, consentDataString);
            editor.Apply();
        }
        internal void SetConsentStatus(ConsentStatus consentStatus, String source)
        {
            ConsentData consentData = LoadConsentData();

            if (consentStatus == ConsentStatus.UNKNOWN)
            {
                consentData.AdProviders = new HashSet <AdProvider>();
            }
            else
            {
                consentData.ConsentedAdProviders = consentData.AdProviders;
            }

            consentData.ConsentSource = source;
            consentData.ConsentStatus = consentStatus;
            SaveConsentData(consentData);
        }
Пример #4
0
        private void UpdateDialogContent(WebView webView)
        {
            var formInfo = new Dictionary <String, Object>();

            formInfo.Add("app_name", GetApplicationName(context));
            formInfo.Add("app_icon", GetAppIconURIString(context));
            formInfo.Add("offer_personalized", this.personalizedAdsOption);
            formInfo.Add("offer_non_personalized", this.nonPersonalizedAdsOption);
            formInfo.Add("offer_ad_free", this.adFreeOption);
            formInfo.Add("is_request_in_eea_or_unknown",
                         ConsentInformation.GetInstance(context).IsRequestLocationInEeaOrUnknown());
            formInfo.Add("app_privacy_url", this.appPrivacyPolicyURL);
            ConsentData consentData = ConsentInformation.GetInstance(context).LoadConsentData();

            formInfo.Add("plat", consentData.SdkPlatformString);
            formInfo.Add("consent_info", consentData);

            String argumentsJSON     = JsonConvert.SerializeObject(formInfo);
            String javascriptCommand = CreateJavascriptCommand("setUpConsentDialog",
                                                               argumentsJSON);

            webView.LoadUrl(javascriptCommand);
        }
        protected async Task RequestConsentInfoUpdate(String[] publisherIds, String url,
                                                      Action <ConsentStatus> OnConsentInfoUpdated,
                                                      Action <String> OnFailedToUpdateConsentInfo)
        {
            if (IsTestDevice())
            {
                Log.Info(TAG, "This request is sent from a test device.");
            }
            else
            {
                Log.Info(TAG, "Use ConsentInformation.getInstance(context).addTestDevice(\""
                         + HashedDeviceId
                         + "\") to get test ads on this device.");
            }

            String publisherIdsString = String.Join(',', publisherIds);


            ConsentData consentData = LoadConsentData();

            Android.Net.Uri.Builder uriBuilder =
                Android.Net.Uri.Parse(url)
                .BuildUpon()
                .AppendQueryParameter("pubs", publisherIdsString)
                .AppendQueryParameter("es", "2")
                .AppendQueryParameter("plat", consentData.SdkPlatformString)
                .AppendQueryParameter("v", consentData.SdkVersionString);
            if (IsTestDevice() && DebugGeography != DebugGeography.DEBUG_GEOGRAPHY_DISABLED)
            {
                uriBuilder =
                    uriBuilder.AppendQueryParameter(
                        "debug_geo",
                        ((int)DebugGeography).ToString());
            }
            await MakeConsentLookupRequest(uriBuilder.Build().ToString(), publisherIds,
                                           OnConsentInfoUpdated, OnFailedToUpdateConsentInfo);
        }
        public ConsentStatus GetConsentStatus()
        {
            ConsentData consentData = LoadConsentData();

            return(consentData.ConsentStatus);
        }
        public bool IsRequestLocationInEeaOrUnknown()
        {
            ConsentData consentData = LoadConsentData();

            return(consentData.IsRequestLocationInEeaOrUnknown);
        }
        public List <AdProvider> GetAdProviders()
        {
            ConsentData consentData = LoadConsentData();

            return(consentData.AdProviders.ToList());
        }
        private void UpdateConsentData(String responseString,
                                       List <String> publisherIds)
        {
            ServerResponse response = JsonConvert.DeserializeObject <ServerResponse>(responseString);

            ValidatePublisherIds(response);

            bool hasNonPersonalizedPublisherId = false;
            var  nonPersonalizedAdProvidersIds = new HashSet <String>();

            if (response.AdNetworkLookupResponses != null)
            {
                foreach (AdNetworkLookupResponse adNetworkLookupResponse in
                         response.AdNetworkLookupResponses)
                {
                    if (!adNetworkLookupResponse.IsNPA)
                    {
                        continue;
                    }

                    hasNonPersonalizedPublisherId = true;
                    List <String> companyIds = adNetworkLookupResponse.CompanyIds;
                    if (companyIds != null)
                    {
                        nonPersonalizedAdProvidersIds.UnionWith(companyIds);
                    }
                }
            }

            HashSet <AdProvider> newAdProviderSet;

            if (response.Companies == null)
            {
                newAdProviderSet = new HashSet <AdProvider>();
            }
            else if (hasNonPersonalizedPublisherId)
            {
                newAdProviderSet =
                    GetNonPersonalizedAdProviders(response.Companies, nonPersonalizedAdProvidersIds);
            }
            else
            {
                newAdProviderSet = new HashSet <AdProvider>(response.Companies);
            }

            ConsentData consentData = LoadConsentData();

            bool hasNonPersonalizedPublisherIdChanged =
                consentData.HasNonPersonalizedPublisherId != hasNonPersonalizedPublisherId;

            consentData.HasNonPersonalizedPublisherId = hasNonPersonalizedPublisherId;
            consentData.RawResponse  = responseString;
            consentData.PublisherIds = new HashSet <String>(publisherIds);
            consentData.AdProviders  = newAdProviderSet;
            consentData.IsRequestLocationInEeaOrUnknown = response.IsRequestLocationInEeaOrUnknown.HasValue &&
                                                          response.IsRequestLocationInEeaOrUnknown.Value;

            if (!response.IsRequestLocationInEeaOrUnknown.Value)
            {
                SaveConsentData(consentData);
                return;
            }

            if (!consentData.ConsentedAdProviders.SequenceEqual(consentData.AdProviders) ||
                hasNonPersonalizedPublisherIdChanged)
            {
                consentData.ConsentSource        = "sdk";
                consentData.ConsentStatus        = ConsentStatus.UNKNOWN;
                consentData.ConsentedAdProviders = new HashSet <AdProvider>();
            }
            SaveConsentData(consentData);
        }