/// <summary> /// Permission check /// </summary> public void PrivilegeCheck() { try { /// Check location permission CheckResult result = PrivacyPrivilegeManager.CheckPermission("http://tizen.org/privilege/location"); switch (result) { case CheckResult.Allow: break; case CheckResult.Deny: break; case CheckResult.Ask: /// Request to privacy popup PrivacyPrivilegeManager.RequestPermission("http://tizen.org/privilege/location"); break; } } catch (Exception ex) { /// Exception handling positionLabel.Text = ex.Message; positionLabel.IsVisible = true; Tizen.Log.Error("CircularUI", $"[Pravacy]Exception {ex.Message}"); } }
internal static async Task <bool> RequestAsync(string privilege) { EnsureDeclared(privilege); var checkResult = PrivacyPrivilegeManager.CheckPermission(privilege); if (checkResult == CheckResult.Ask) { var completionSource = new TaskCompletionSource <bool>(); if (PrivacyPrivilegeManager.GetResponseContext(privilege).TryGetTarget(out var context)) { void OnResponseFetched(object sender, RequestResponseEventArgs e) { completionSource.TrySetResult(e.result == RequestResult.AllowForever); } context.ResponseFetched += OnResponseFetched; PrivacyPrivilegeManager.RequestPermission(privilege); var result = await completionSource.Task; context.ResponseFetched -= OnResponseFetched; return(result); } return(false); } else if (checkResult == CheckResult.Deny) { return(false); } return(true); }
/// <summary> /// Returns true if all required privileges are granted, false otherwise. /// </summary> /// <returns>Task with check result.</returns> public async Task <bool> CheckPrivileges() { CheckResult result = PrivacyPrivilegeManager.CheckPermission(HEALTHINFO_PRIVILEGE); switch (result) { case CheckResult.Allow: return(true); case CheckResult.Deny: return(false); case CheckResult.Ask: PrivacyPrivilegeManager.ResponseContext context = null; PrivacyPrivilegeManager.GetResponseContext(HEALTHINFO_PRIVILEGE) .TryGetTarget(out context); if (context == null) { Log.Error("STT", "Unable to get privilege response context"); return(false); } _checkPrivilegesTask = new TaskCompletionSource <bool>(); context.ResponseFetched += PrivilegeManagerOnResponseFetched; PrivacyPrivilegeManager.RequestPermission(HEALTHINFO_PRIVILEGE); return(await _checkPrivilegesTask.Task); default: return(false); } }
/// <summary> /// Permission check /// </summary> public void PrivilegeCheck() { try { /// Check location permission CheckResult result = PrivacyPrivilegeManager.CheckPermission("http://tizen.org/privilege/location"); switch (result) { case CheckResult.Allow: break; case CheckResult.Deny: break; case CheckResult.Ask: /// Request to privacy popup PrivacyPrivilegeManager.RequestPermission("http://tizen.org/privilege/location"); break; } } catch (Exception ex) { /// Exception handling textMessage.Text = "[Pravacy] Exception \n" + ex.Message; } }
protected async override void OnResume() { Tizen.Log.Info(LOG_TAG, " <<< Program :OnResume "); base.OnResume(); bool locationGranted = true /*, healthInfoGranted = true*/; Tizen.Log.Info(LOG_TAG, " <<< LocationPrivilege : " + PrivacyPrivilegeManager.CheckPermission(LocationPrivilege).ToString()); //Tizen.Log.Info(LOG_TAG, " <<< HealthInfoPrivilege : " + PrivacyPrivilegeManager.CheckPermission(HealthInfoPrivilege).ToString()); if (PrivacyPrivilegeManager.CheckPermission(LocationPrivilege) != CheckResult.Allow) { locationGranted = await RequestPermission(LocationPrivilege); Tizen.Log.Info(LOG_TAG, " >>> locationGranted : " + locationGranted); } //if (PrivacyPrivilegeManager.CheckPermission(HealthInfoPrivilege) != CheckResult.Allow) //{ // healthInfoGranted = await RequestPermission(HealthInfoPrivilege); // Tizen.Log.Info(LOG_TAG, " >>> healthInfoGranted : " + healthInfoGranted); //} if (!locationGranted) { Tizen.Log.Error(LOG_TAG, "Failed to obtain user consent."); // Terminate this application. Application.Current.Exit(); return; } Tizen.Log.Info(LOG_TAG, " >>> Program :OnResume "); app.PageModel.Mylabel = ">>> Program :OnResume " + DateTime.Now.ToString("h:mm:ss tt") + "\n" + app.PageModel.Mylabel; }
/// <summary> /// Handle when your app resumes. /// </summary> protected override void OnResume() { /// Set the value to label InfoLabelList[0].Text = "new GeofenceManager and VirtualPerimeter"; try { if (geofence == null) { // Create the GeofenceManager object geofence = new GeofenceManager(); // Create the VirtualPerimeter object perimeter = new VirtualPerimeter(geofence); } // Set the value to label InfoLabelList[1].Text = "Success"; // Check the permission for location privilege if (PrivacyPrivilegeManager.CheckPermission("http://tizen.org/privilege/location") == CheckResult.Allow) { // Add a handle for GeofenceEventChanged geofence.GeofenceEventChanged += GeofenceEventChanged; // Add a handle for StateChanged geofence.StateChanged += StateChanged; // Add a handle for ProximityChanged geofence.ProximityChanged += ProximityChanged; } } catch (Exception e) { // Set the value to label about occured exception InfoLabelList[1].Text = e.Message; } }
public static void CheckAndRequestPermission(String permission) { SetupPPMHandler(permission); try { CheckResult result = PrivacyPrivilegeManager.CheckPermission(permission); switch (result) { case CheckResult.Allow: /// Update UI and start accessing protected functionality break; case CheckResult.Deny: PrivacyPrivilegeManager.RequestPermission(permission); break; case CheckResult.Ask: PrivacyPrivilegeManager.RequestPermission(permission); break; } } catch (Exception) { /// Handle exception } }
/// <summary> /// Permission check /// </summary> private void PrivilegeCheck() { try { /// Check location permission CheckResult result = PrivacyPrivilegeManager.CheckPermission("http://tizen.org/privilege/location"); switch (result) { case CheckResult.Allow: break; case CheckResult.Deny: break; case CheckResult.Ask: /// Request to privacy popup PrivacyPrivilegeManager.RequestPermission("http://tizen.org/privilege/location"); break; } } catch (Exception ex) { /// Exception handling InfoLabelList[1].Text = "[Status] Privilege : " + ex.Message; } }
/// <summary> /// Handle when your app sleeps. /// </summary> protected override void OnSleep() { // Check the permission for location privilege if (PrivacyPrivilegeManager.CheckPermission("http://tizen.org/privilege/location") == CheckResult.Allow) { // Remove the handle for GeofenceEventChanged geofence.GeofenceEventChanged -= GeofenceEventChanged; // Remove the handle for StateChanged geofence.StateChanged -= StateChanged; // Remove the handle for ProximityChanged geofence.ProximityChanged -= ProximityChanged; } // Dispose the GeofenceManager object if (geofence != null) { geofence.Dispose(); } perimeter = null; geofence = null; // Set the value to the labels InfoLabelList[0].Text = "GeofenceManager.Dispose"; InfoLabelList[1].Text = "Success"; }
private void CheckPrivileges() { // Check permission status (allow, deny, ask) to determinate action which has to be taken string privilege = "http://tizen.org.privilege/healthinfo"; CheckResult result = PrivacyPrivilegeManager.CheckPermission(privilege); if (result == CheckResult.Allow) { OnPrivilegesGranted(); } else if (result == CheckResult.Deny) { OnPrivilegesDenied(); } else // the user must be asked about granting the privilege { PrivacyPrivilegeManager.GetResponseContext(privilege).TryGetTarget(out var context); if (context != null) { context.ResponseFetched += (sender, e) => { if (e.cause == CallCause.Answer && e.result == RequestResult.AllowForever) { OnPrivilegesGranted(); } else { OnPrivilegesDenied(); } }; } } }
/// <summary> /// Used to check calendar.read privilege. /// </summary> public void CheckCalendarReadPrivileges() { CheckResult result = PrivacyPrivilegeManager.CheckPermission("http://tizen.org/privilege/calendar.read"); switch (result) { case CheckResult.Allow: // Privilege can be used pEvent.AllowCalendarReadPrivilege(); break; case CheckResult.Deny: // Privilege can't be used break; case CheckResult.Ask: // User permission request required AskPrivacyPrivilege("http://tizen.org/privilege/calendar.read"); PrivacyPrivilegeManager.RequestPermission("http://tizen.org/privilege/contact.read"); break; default: break; } }
/// <summary> /// Checks location privilege. Request location privilege if not set. /// Starts application when privilege check is complete. /// </summary> private void LocationPrivilegeCheck() { CheckResult result = PrivacyPrivilegeManager.CheckPermission(Config.LocationPrivilege); switch (result) { case CheckResult.Allow: ViewModels.ViewModelLocator.ViewModel.IsGPSAvailable = true; StartApplication(); break; case CheckResult.Deny: ViewModels.ViewModelLocator.ViewModel.IsGPSAvailable = false; StartApplication(); break; case CheckResult.Ask: PrivacyPrivilegeManager.GetResponseContext(Config.LocationPrivilege) .TryGetTarget(out PrivacyPrivilegeManager.ResponseContext context); if (context != null) { context.ResponseFetched += PPM_RequestResponse; } PrivacyPrivilegeManager.RequestPermission(Config.LocationPrivilege); break; } }
/// <summary> /// Check whether the application has the specific permission or not. /// </summary> /// <param name="privilege">Privilege</param> public static void CheckPermission(string privilege) { try { CheckResult result = PrivacyPrivilegeManager.CheckPermission(privilege); switch (result) { case CheckResult.Allow: break; case CheckResult.Deny: break; case CheckResult.Ask: // Request permission to user PrivacyPrivilegeManager.RequestPermission(privilege); break; } } catch (Exception e) { global::Tizen.Log.Error(Log.LogTag, e.Message); } }
public HRMPage() { Model = new HRMModel { IsSupported = HeartRateMonitor.IsSupported, SensorCount = HeartRateMonitor.Count }; InitializeComponent(); SetupPrivilegeHandler(); CheckResult result = PrivacyPrivilegeManager.CheckPermission(hrmPrivilege); switch (result) { case CheckResult.Allow: CreateHRM(); break; case CheckResult.Deny: break; case CheckResult.Ask: PrivacyPrivilegeManager.RequestPermission(hrmPrivilege); break; } }
public bool Dial(string number) { _number = number; try { CheckResult result = PrivacyPrivilegeManager.CheckPermission(_callPrivilege); switch (result) { case CheckResult.Allow: Call(); return(true); case CheckResult.Deny: return(false); case CheckResult.Ask: PrivacyPrivilegeManager.RequestPermission(_callPrivilege); // Dial() method is synchronous, return true return(true); default: return(false); } } catch (Exception exc) { Tizen.Log.Error(Tag, "Dialing failed: " + exc.Message); return(false); } }
/// <summary> /// Checks a selected privilege. Requests a privilege if not set. /// </summary> /// <param name="privilege">The privilege to check.</param> private static void CheckPrivilege(string privilege) { switch (PrivacyPrivilegeManager.CheckPermission(privilege)) { case CheckResult.Allow: SetPermission(privilege, true); break; case CheckResult.Deny: SetPermission(privilege, false); break; case CheckResult.Ask: PrivacyPrivilegeManager.RequestPermission(privilege); PrivacyPrivilegeManager.GetResponseContext(privilege) .TryGetTarget(out PrivacyPrivilegeManager.ResponseContext context); if (context != null) { context.ResponseFetched += PrivilegeRequestResponse; } break; } AllPrivilegesChecked(); }
private static void SetupPPMHandler(string privilege) { PrivacyPrivilegeManager.ResponseContext context = null; if (PrivacyPrivilegeManager.GetResponseContext(privilege).TryGetTarget(out context)) { context.ResponseFetched += PPMResponseHandler; } }
private void SetupPrivilegeHandler() { PrivacyPrivilegeManager.ResponseContext context = null; if (PrivacyPrivilegeManager.GetResponseContext(hrmPrivilege).TryGetTarget(out context)) { context.ResponseFetched += PrivilegeResponseHandler; } }
/// <summary> /// Triggers required permission requests. /// </summary> private void AskForPermissions() { var result = PrivacyPrivilegeManager.CheckPermission(MEDIASTORAGE_PRIVILEGE); if (result != CheckResult.Allow) { RequestPermission(); } }
/// <summary> /// Constructor of InsertInfoPage class. /// </summary> /// <param name="sender">Specifies the sender of this event</param> public InsertInfoPage(object sender) { if (PrivacyPrivilegeManager.CheckPermission("http://tizen.org/privilege/location") != CheckResult.Allow) { ShowNoPermissionAlert(); return; } CreatePage(-1, FenceType.GeoPoint, sender); }
/// <summary> /// Used to set privilege event listener and request the privilege. /// </summary> void AskPrivacyPrivilege(string privilege) { // Set event listener for privilege PrivacyPrivilegeManager.GetResponseContext(privilege).TryGetTarget(out context); if (context != null) { context.ResponseFetched += PPM_RequestResponse; } // Request pop-up message for privileges PrivacyPrivilegeManager.RequestPermission(privilege); }
/// <summary> /// Checks if the specified privilege has been granted /// </summary> /// <param name="privilege">The privilege name to check for</param> /// <returns>A status that indicates whether the permission has been granted or not</returns> public static PrivacyPermissionStatus Check(string privilege) { switch (PrivacyPrivilegeManager.CheckPermission(privilege)) { case CheckResult.Allow: return(PrivacyPermissionStatus.Granted); case CheckResult.Deny: case CheckResult.Ask: default: return(PrivacyPermissionStatus.Denied); } }
public static async Task <AccessState> RequestAccess(string permission) { var priv = "http://tizen.org/privilege/" + permission; var result = PrivacyPrivilegeManager .CheckPermission(priv) .ToAccessState(); if (result == AccessState.Unknown) { result = await RequestPermission(priv); } return(result); }
/// <summary> /// Request user permission for privacy privileges /// </summary> /// <param name="service">privacy privilege</param> /// <returns>true if user consent is gained</returns> public async Task <bool> GetPermission(string service) { try { GrantedPermission = -1; // Gets the status of a privacy privilege permission. CheckResult result = PrivacyPrivilegeManager.CheckPermission(service); switch (result) { case CheckResult.Allow: // user consent for privacy privilege is already gained Console.WriteLine("\n\n\nuser consent for privacy privilege is already gained\n\n"); return(true); case CheckResult.Deny: case CheckResult.Ask: // User permission request should be required tcs = new TaskCompletionSource <bool>(); // Gets the response context for a given privilege. var reponseContext = PrivacyPrivilegeManager.GetResponseContext(service); PrivacyPrivilegeManager.ResponseContext context = null; if (reponseContext.TryGetTarget(out context)) { if (context != null) { context.ResponseFetched += Context_ResponseFetched; } } // Try to get the permission for service from a user. PrivacyPrivilegeManager.RequestPermission(service); // Check if permission is granted or not every second Device.BeginInvokeOnMainThread(() => { Device.StartTimer(new TimeSpan(0, 0, 0, 1, 0), CheckPermission); }); return(await tcs.Task); default: return(false); } } catch (Exception e) { Console.WriteLine("[UserPermission] (" + service + ") Error :" + e.Message + ", " + e.StackTrace + ", " + e.InnerException); return(false); } }
public static void PrivilegeCheck(string permission) { var result = PrivacyPrivilegeManager.CheckPermission(permission); switch (result) { case CheckResult.Allow: break; case CheckResult.Deny: case CheckResult.Ask: PrivacyPrivilegeManager.RequestPermission(permission); break; } }
protected override void OnCreate() { base.OnCreate(); var result = PrivacyPrivilegeManager.CheckPermission("http://tizen.org/privilege/camera"); switch (result) { case CheckResult.Allow: LoadApplication(new App()); break; default: break; } }
private Task RequestPermission() { TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>(); var response = PrivacyPrivilegeManager.GetResponseContext(MEDIASTORAGE_PRIVILEGE); PrivacyPrivilegeManager.ResponseContext target; response.TryGetTarget(out target); target.ResponseFetched += (s, e) => { tcs.SetResult(true); _mainPage.RestartScan(); }; PrivacyPrivilegeManager.RequestPermission(MEDIASTORAGE_PRIVILEGE); return(tcs.Task); }
/// <summary> /// Check privacy privilege and if need to ask for user, send request for PPM. /// </summary> public bool CheckPrivilege() { // Make array list for requesting privacy privilege // Contacts need 2 privilege, contact read and account write. ArrayList PrivilegeList = new ArrayList(); PrivilegeList.Add("http://tizen.org/privilege/contact.read"); PrivilegeList.Add("http://tizen.org/privilege/contact.write"); int privilageAcceptedCount = 0; // Check and request privacy privilege if app is needed foreach (string list in PrivilegeList) { PrivacyPrivilegeManager.GetResponseContext(list).TryGetTarget(out context); if (context != null) { ++CBCount; context.ResponseFetched += PPM_RequestResponse; } CheckResult result = PrivacyPrivilegeManager.CheckPermission(list); switch (result) { case CheckResult.Allow: /// Privilege can be used privilageAcceptedCount++; break; case CheckResult.Deny: /// Privilege can't be used break; case CheckResult.Ask: /// Request permission to user PrivacyPrivilegeManager.RequestPermission(list); break; } } if (privilageAcceptedCount == PrivilegeList.Count) { return(true); } else { return(false); } }
/// <summary> /// Check if a permission is granted and request a permission if it's not granted /// </summary> /// <param name="privilege">privilege name</param> /// <returns>bool</returns> public async Task <bool> CheckAndRequestPermission(string privilege) { try { // Gets the status of a privacy privilege permission. CheckResult result = PrivacyPrivilegeManager.CheckPermission(privilege); Log.Debug(Utility.LOG_TAG, "State: " + result.ToString()); switch (result) { case CheckResult.Allow: // Permission has already been granted // Privilege can be used return(true); case CheckResult.Deny: // Privilege can't be used Log.Debug(Utility.LOG_TAG, "In this case, " + privilege + " privilege is not available until the user changes the permission state from the Settings application."); return(false); case CheckResult.Ask: // Permission is not granted so we need to request the permission PrivacyPrivilegeManager.ResponseContext context; PrivacyPrivilegeManager.GetResponseContext(privilege).TryGetTarget(out context); if (context == null) { return(false); } tcs = new TaskCompletionSource <bool>(); context.ResponseFetched += PPMResponseHandler; // Request a permission // Calling it brings up a system dialog that an app user can decide to approve or deny it. PrivacyPrivilegeManager.RequestPermission(privilege); return(await tcs.Task); default: return(false); } } catch (Exception e) { // Handle exception Log.Error(Utility.LOG_TAG, "An error occurred. : " + e.Message); return(false); } }
async Task <PermissionStatus> CheckPrivilegeAsync(bool ask) { if (RequiredPrivileges == null || !RequiredPrivileges.Any()) { return(PermissionStatus.Granted); } EnsureDeclared(); var tizenPrivileges = RequiredPrivileges.Where(p => p.isRuntime); foreach (var(tizenPrivilege, isRuntime) in tizenPrivileges) { var checkResult = PrivacyPrivilegeManager.CheckPermission(tizenPrivilege); if (checkResult == CheckResult.Ask) { if (ask) { var tcs = new TaskCompletionSource <bool>(); PrivacyPrivilegeManager.GetResponseContext(tizenPrivilege) .TryGetTarget(out var context); void OnResponseFetched(object sender, RequestResponseEventArgs e) { tcs.TrySetResult(e.result == RequestResult.AllowForever); } context.ResponseFetched += OnResponseFetched; PrivacyPrivilegeManager.RequestPermission(tizenPrivilege); var result = await tcs.Task; context.ResponseFetched -= OnResponseFetched; if (result) { continue; } } return(PermissionStatus.Denied); } else if (checkResult == CheckResult.Deny) { return(PermissionStatus.Denied); } } return(PermissionStatus.Granted); }