private static void DemoDialog_Completed(ConsentDialog dialog, ConsentDialog.CompletedResults results) { Debug.Log("Demo consent dialog completed with button ID: " + results.buttonId); // Construct the new consent. DemoAppConsent newConsent = new DemoAppConsent(); if (results.toggleValues != null) { Debug.Log("Consent toggles:"); foreach (KeyValuePair <string, bool> t in results.toggleValues) { string toggleId = t.Key; bool toggleValue = t.Value; Debug.Log("Toggle ID: " + toggleId + "; Value: " + toggleValue); if (toggleId == AdsToggleId) { // Whether the Advertising module is given consent. newConsent.advertisingConsent = toggleValue ? ConsentStatus.Granted : ConsentStatus.Revoked; } else if (toggleId == NotifsToggleId) { // Whether the Notifications module is given consent. newConsent.notificationConsent = toggleValue ? ConsentStatus.Granted : ConsentStatus.Revoked; } else if (toggleId == UnityAnalyticsToggleId) { // We don't store the UnityAnalytics consent ourselves as it is managed // by the Unity Data Privacy plugin. } else { // Unrecognized toggle ID. } } } Debug.Log("Now forwarding new consent to relevant modules and then store it..."); // Forward the consent to relevant modules. DemoAppConsent.ApplyDemoAppConsent(newConsent); // Store the new consent. DemoAppConsent.SaveDemoAppConsent(newConsent); // So now we have applied the consent, we can initialize EM runtime // (as well as other 3rd-party SDKs in a real-world app). if (!RuntimeManager.IsInitialized()) { RuntimeManager.Init(); } else { // The initialization has already been done. Inform the user // that the changes will take effect during next initialization (next app launch). NativeUI.Alert("Consent Updated", "You've updated your data privacy consent. " + "Since the initialization process has already completed, all changes will take effect in the next app launch."); } }
/// <summary> /// If a user has not set consent, the consent dialog box is displayed. /// </summary> /// <param name="adProviders"></param> private void ShowConsentDialog(IList <AdProvider> adProviders) { Log.Info(TAG, "Show consent dialog."); ConsentDialog dialog = new ConsentDialog(this, adProviders); dialog.SetCanceledOnTouchOutside(false); dialog.Show(); }
internal ConsentDialogContentSerializer(ConsentDialog consentDialog) { if (consentDialog == null) { throw new ArgumentNullException("Tried to pass a null consent dialog into ConsentDialogNativeAdapter's constructor."); } SerializedContent = GenerateSplitedContents(consentDialog); }
/// <summary> /// Display the consent dialog box. /// </summary> private void ShowConsentDialog() { // Start to process the consent dialog box. ConsentDialog consentDialog = new ConsentDialog(this, mAdProviders); consentDialog.SetCallback(this); consentDialog.SetCanceledOnTouchOutside(false); consentDialog.Show(); }
public void PreviewDefaultConsentDialog(bool dismissible = true) { if (mPreviewConsentDialog == null) { // Grab the default consent dialog. mPreviewConsentDialog = Privacy.GetDefaultConsentDialog(); SubscribePreviewConsentDialogEvents(); } mPreviewConsentDialog.Show(dismissible); }
private static void SubscribeConsentDialogEvents(ConsentDialog dialog) { if (dialog == null) { return; } dialog.Dismissed += DemoDialog_Dismissed; dialog.Completed += DemoDialog_Completed; dialog.ToggleStateUpdated += DemoDialog_ToggleStateUpdated; }
private string GenerateSplitedContents(ConsentDialog consentDialog) { List <SplitContent> result = new List <SplitContent>(); List <string> splittedContents = consentDialog.GetSplittedContents(); foreach (var content in splittedContents) { if (string.IsNullOrEmpty(content)) { continue; } /// If this content is a button. if (ConsentDialog.IsButtonPattern(content)) { string id = ConsentDialog.SearchForIdInButtonPattern(content); var button = consentDialog.FindButtonWithId(id); /// This mean the id is not defined, so we just skip it. if (button == null) { continue; } result.Add(new SplitContent(SplitContent.ButtonType, button.ToString())); continue; } /// If this content is a toggle. if (ConsentDialog.IsTogglePattern(content)) { string id = ConsentDialog.SearchForIdInTogglePattern(content); var toggle = consentDialog.FindToggleWithId(id); /// This mean the id is not defined, so we just skip it. if (toggle == null) { continue; } result.Add(new SplitContent(SplitContent.ToggleType, toggle.ToString())); continue; } /// Otherwise this content should be plain text. result.Add(new SplitContent(SplitContent.PlainTextType, content)); } return(Json.Serialize(result.ToArray())); }
private async void RecentFilesWidget_RecentFileInvoked(object sender, UserControls.PathNavigationEventArgs e) { try { var directoryName = Path.GetDirectoryName(e.ItemPath); await AppInstance.InteractionOperations.InvokeWin32ComponentAsync(e.ItemPath, workingDir : directoryName); } catch (UnauthorizedAccessException) { var consentDialog = new ConsentDialog(); await consentDialog.ShowAsync(); } catch (ArgumentException) { if (new DirectoryInfo(e.ItemPath).Root.ToString().Contains(@"C:\")) { AppInstance.ContentFrame.Navigate(FolderSettings.GetLayoutType(e.ItemPath), new NavigationArguments() { AssociatedTabInstance = AppInstance, NavPathParam = e.ItemPath }); } else { foreach (DriveItem drive in Enumerable.Concat(App.DrivesManager.Drives, AppSettings.CloudDrivesManager.Drives)) { if (drive.Path.ToString() == new DirectoryInfo(e.ItemPath).Root.ToString()) { AppInstance.ContentFrame.Navigate(FolderSettings.GetLayoutType(e.ItemPath), new NavigationArguments() { AssociatedTabInstance = AppInstance, NavPathParam = e.ItemPath }); return; } } } } catch (COMException) { await DialogDisplayHelper.ShowDialogAsync( "DriveUnpluggedDialog/Title".GetLocalized(), "DriveUnpluggedDialog/Text".GetLocalized()); } }
public static void TestConsent() { ConsentDialog cd = new ConsentDialog(); // Define dummy app data ApplicationInfo meta = new ApplicationInfo(); meta.ApplicationName = "Foxlet's Big Adventure"; meta.Manifest = "manifest"; meta.ProviderName = "FurCode"; meta.Version = new Version(4, 0, 2, 0); // Five score risks exist, NoRisk, LowRisk, MediumRisk, HighRisk, MaxRisk ScoreResultCollection scores = new ScoreResultCollection(); scores.Add(new ScoreResult(ScoreRiskBucket.MediumRisk, "This application does not attempt to be functional and is a literal security hole.")); cd.GetConsent(null, meta, scores); }
private static void PreviewDialog_Completed(ConsentDialog dialog, ConsentDialog.CompletedResults results) { var sb = new StringBuilder(); sb.AppendLine("The preview consent dialog completed with button ID: " + results.buttonId); if (results.toggleValues != null) { sb.AppendLine("Consent toggles:"); foreach (KeyValuePair <string, bool> t in results.toggleValues) { string toggleId = t.Key; bool toggleValue = t.Value; sb.AppendLine("Toggle ID: " + toggleId + "; Value: " + toggleValue); } } NativeUI.Alert("Consent Dialog Completed", sb.ToString()); }
public static void ShowDemoConsentDialog(bool localize, bool dismissible) { if (localize) { if (mDemoConsentDialogLocalized == null) { mDemoConsentDialogLocalized = ConstructConsentDialog(localize); SubscribeConsentDialogEvents(mDemoConsentDialogLocalized); } mDemoConsentDialogLocalized.Show(dismissible); } else { if (mDemoConsentDialog == null) { mDemoConsentDialog = ConstructConsentDialog(localize); SubscribeConsentDialogEvents(mDemoConsentDialog); } mDemoConsentDialog.Show(dismissible); } }
private async void RecentsView_ItemClick(object sender, ItemClickEventArgs e) { var path = (e.ClickedItem as RecentItem).RecentPath; try { var directoryName = Path.GetDirectoryName(path); await Interaction.InvokeWin32Component(path, workingDir : directoryName); } catch (UnauthorizedAccessException) { var consentDialog = new ConsentDialog(); await consentDialog.ShowAsync(); } catch (ArgumentException) { if (new DirectoryInfo(path).Root.ToString().Contains(@"C:\")) { App.CurrentInstance.ContentFrame.Navigate(AppSettings.GetLayoutType(), path); } else { foreach (DriveItem drive in AppSettings.DrivesManager.Drives) { if (drive.Path.ToString() == new DirectoryInfo(path).Root.ToString()) { App.CurrentInstance.ContentFrame.Navigate(AppSettings.GetLayoutType(), path); return; } } } } catch (COMException) { await DialogDisplayHelper.ShowDialog( "DriveUnpluggedDialog/Title".GetLocalized(), "DriveUnpluggedDialog/Text".GetLocalized()); } }
void Dialog_Completed(ConsentDialog dialog, ConsentDialog.CompletedResults results) { buttonId.Value = results.buttonId; if (results.toggleValues != null) { toggleCount.Value = results.toggleValues.Count; toggleIDs.stringValues = new string[toggleCount.Value]; toggleValues.boolValues = new bool[toggleCount.Value]; int i = 0; foreach (KeyValuePair <string, bool> pair in results.toggleValues) { toggleIDs.stringValues[i] = pair.Key; toggleValues.boolValues[i] = pair.Value; i++; } } Fsm.Event(eventTarget, completedEvent); Finish(); }
private static void PreviewDialog_ToggleStateUpdated(ConsentDialog dialog, string toggleId, bool isOn) { }
private static void DemoDialog_Dismissed(ConsentDialog dialog) { }
private static void PreviewDialog_ToggleStateUpdated(ConsentDialog dialog, string toggleId, bool isOn) { Debug.Log("ToggleStateUpdated. ID: " + toggleId + "; new value: " + isOn); }
private static void PreviewDialog_Dismissed(ConsentDialog dialog) { Debug.Log("The preview consent dialog was dismissed."); }
private static void PreviewDialog_Dismissed(ConsentDialog dialog) { }
private static void DemoDialog_Dismissed(ConsentDialog dialog) { Debug.Log("Demo consent dialog was dismissed."); }
/// <summary> /// Constructs the consent dialog. Set localize to true to use the /// localized content. /// </summary> /// <returns>The consent dialog.</returns> /// <param name="localize">If set to <c>true</c> localize.</param> private static ConsentDialog ConstructConsentDialog(bool localize) { /// /// Here we create a consent dialog completely from coding. /// The alternative is to use our consent dialog editor in /// the Privacy module settings UI to compose the dialog content. /// Here we manually pick the correct translation based on the /// localization requirement. In a real-world app, you may use /// a professional localization tool to do that. /// If you're showing the default consent dialog (constructed /// with the consent dialog editor), you can insert placeholder /// texts into the dialog content and then replace them /// with translated texts in script before showing /// the dialog for localization purpose. /// // First check if there's any consent saved previously. // If there is, we will set the 'isOn' state of our toggles // according to the saved consent to reflect the current consent // status on the consent dialog. DemoAppConsent consent = DemoAppConsent.LoadDemoAppConsent(); // First create a new consent dialog. ConsentDialog dialog = new ConsentDialog(); // Title. dialog.Title = localize ? FrTitle : EnTitle; // Put our disclaimer on top. dialog.AppendText(Disclaimer); // Add the first paragraph. dialog.AppendText(localize ? FrFirstParagraph : EnFirstParagraph); // Build and append the Advertising toggle. ConsentDialog.Toggle adsToggle = new ConsentDialog.Toggle(AdsToggleId); adsToggle.Title = localize ? FrAdsToggleTitle : EnAdsToggleTitle; adsToggle.OnDescription = localize ? FrAdsToggleOnDesc : EnAdsToggleOnDesc; adsToggle.OffDescription = localize ? FrAdsToggleOffDesc : EnAdsToggleOffDesc; adsToggle.ShouldToggleDescription = true; // make the description change with the toggle state. adsToggle.IsOn = consent != null ? consent.advertisingConsent == ConsentStatus.Granted : false; // reflect previous ads consent if any dialog.AppendToggle(adsToggle); // Build and append the Notifications toggle. ConsentDialog.Toggle notifsToggle = new ConsentDialog.Toggle(NotifsToggleId); notifsToggle.Title = localize ? FrNotifsToggleTitle : EnNotifsToggleTitle; notifsToggle.OnDescription = localize ? FrNotifsToggleDesc : EnNotifsToggleDesc; notifsToggle.ShouldToggleDescription = false; // use same description for both on & off states. notifsToggle.IsOn = consent != null ? consent.notificationConsent == ConsentStatus.Granted : false; // reflect previous notifs consent if any dialog.AppendToggle(notifsToggle); // Build and append the Unity Analytics toggle. // If the opt-out URL for Unity Analytics is available, we'll insert it // to the toggle description. Otherwise we'll use the "URL unavailable" description. // Note that this toggle is ON by default and is not interactable because we can't opt-out // Unity Analytics locally, instead the user must visit the fetched URL to opt-out. ConsentDialog.Toggle uaToggle = new ConsentDialog.Toggle(UnityAnalyticsToggleId); uaToggle.Title = localize ? FrAnalyticsToggleTitle : EnAnalyticsToggleTitle; uaToggle.ShouldToggleDescription = false; // the description won't change when the toggle switches between on & off states. uaToggle.IsInteractable = false; // not interactable uaToggle.IsOn = true; // consent for UnityAnalytics is ON by default, can opt-out via Unity URL if (!string.IsNullOrEmpty(UnityAnalyticsOptOutURL)) { // Unity Analytics opt-out URL is available. var description = localize ? FrAnalyticsToogleDesc : EnAnalyticsToogleDesc; description = description.Replace(UnityAnalyticsOptOutURLPlaceholder, UnityAnalyticsOptOutURL); // replace placeholder with actual URL uaToggle.OnDescription = description; } else { // Unity Analytics opt-out URL is not available. uaToggle.OnDescription = localize ? FrAnalyticsToggleUnavailDesc : EnAnalyticsToggleUnavailDesc; } dialog.AppendToggle(uaToggle); // Append the second paragraph. dialog.AppendText(localize ? FrSecondParagraph : EnSecondParagraph); // Build and append the accept button. // A consent dialog should always have at least one button! ConsentDialog.Button okButton = new ConsentDialog.Button(AcceptButtonId); okButton.Title = localize ? FrButtonTitle : EnButtonTitle; okButton.TitleColor = Color.white; okButton.BodyColor = new Color(66 / 255f, 179 / 255f, 1); dialog.AppendButton(okButton); return(dialog); }
private static void SubscribeConsentDialogEvents(ConsentDialog dialog) { }
void Dialog_Dismissed(ConsentDialog obj) { Fsm.Event(eventTarget, dismissedEvent); Finish(); }
private static void PreviewDialog_Completed(ConsentDialog dialog, ConsentDialog.CompletedResults results) { }