internal bool IsConsentGiven(ConsentFeatures feature) { Debug.Assert(givenConsent != null); //if consent is not required, all is fine if (!consentRequired) { return(true); } ; //if it's required //check if it's given if (givenConsent == null) { return(false); } //nothing set for a feature, pressume that it's denied if (!givenConsent.ContainsKey(feature)) { return(false); } //if a feature's consent is set, return it return(givenConsent[feature]); }
public async Task SetConsent(Dictionary <ConsentFeatures, bool> consentChanges) { Debug.Assert(consentChanges != null); if (consentChanges == null) { throw new ArgumentException("'consentChanges' cannot be null"); } //if we don't need consent, no need to track it if (!consentRequired) { return; } Dictionary <ConsentFeatures, bool> valuesToUpdate = new Dictionary <ConsentFeatures, bool>(); //filter out those values that are changed foreach (KeyValuePair <ConsentFeatures, bool> entry in consentChanges) { bool oldV = IsConsentGiven(entry.Key); bool containsOld = givenConsent.ContainsKey(entry.Key); bool newV = entry.Value; if (!containsOld || oldV != newV) { //if there is no entry about this feature, of the consent has changed, update the value valuesToUpdate[entry.Key] = newV; } } if (valuesToUpdate.Count > 0) { //send request of the consent changes await SendConsentChanges(valuesToUpdate); //react to consent changes locally foreach (KeyValuePair <ConsentFeatures, bool> entryChanges in valuesToUpdate) { bool isGiven = entryChanges.Value; ConsentFeatures feature = entryChanges.Key; //mark changes locally givenConsent[feature] = isGiven; //do special actions switch (feature) { case ConsentFeatures.Crashes: break; case ConsentFeatures.Events: break; case ConsentFeatures.Location: if (!isGiven) { await DisableLocation(); } break; case ConsentFeatures.Sessions: if (isGiven) { if (!startTime.Equals(DateTime.MinValue)) { //if it's not null then we had already tried tracking a session await SessionBegin(); } } else { await SessionEnd(); } break; case ConsentFeatures.Users: break; } } } }