Esempio n. 1
0
        /// <summary>
        /// Request privileges asynchronously.
        /// </summary>
        ////<param name="callback">The method to call back once a result is known. It will be called when all privileges are granted or if requesting all privileges fails.</param>
        /// <param name="privileges">An array of privileges to request.</param>
        public static MLResult RequestPrivilegesAsync(Action <MLResult> callback, params MLPrivileges.Id[] privileges)
        {
            #if PLATFORM_LUMIN
            int numPrivilegesToRequest = privileges.Length;

            for (int i = 0; i < privileges.Length; i++)
            {
                MLPrivileges.Id privilege = privileges[i];

                _result = CheckPrivilege(privilege);
                if (_result.Result == MLResult.Code.PrivilegeGranted)
                {
                    numPrivilegesToRequest--;
                    if (numPrivilegesToRequest == 0)
                    {
                        callback?.Invoke(_result);
                    }
                    continue;
                }

                _result = MLPrivileges.RequestPrivilegeAsync(privilege, (MLResult result, MLPrivileges.Id priv) =>
                {
                    numPrivilegesToRequest--;

                    if (result.Result == MLResult.Code.PrivilegeGranted)
                    {
                        if (numPrivilegesToRequest == 0)
                        {
                            callback?.Invoke(result);
                        }
                    }

                    // Privilege was not granted
                    else
                    {
                        numPrivilegesToRequest = 0;
                        if (numPrivilegesToRequest == 0)
                        {
                            callback?.Invoke(result);
                        }
                    }
                });

                if (!_result.IsOk)
                {
                    return(_result);
                }
            }

            // Override result in case privilege was already granted.
            if (_result.Result == MLResult.Code.PrivilegeGranted)
            {
                _result = MLResult.Create(MLResult.Code.Ok);
            }
            #endif

            return(_result);
        }
        /// <summary>
        /// Requests privileges and calls the callback when the privilege request is
        /// complete.
        /// <param name="callback">Callback function to call when the privilege is granted </param>
        /// </summary>
        void RequestPrivilege()
        {
            Debug.Log("Requesting required privileges");
            MLResult result = MLPrivileges.RequestPrivilegeAsync(MLPrivilegeId.PwFoundObjRead, HandlePrivilegeAsyncRequest);

            if (!result.IsOk)
            {
                Debug.LogErrorFormat("{0} Privilege Request Error: {1}", MLPrivilegeId.PwFoundObjRead, result);
                return;
            }
        }
        /// <summary>
        /// Requests privileges and calls the callback when the privilege request is
        /// complete.
        /// <param name="callback">Callback function to call when the privielege is granted.</param>
        /// </summary>
        void RequestPrivilege()
        {
            _state = State.RequestPrivilege;
            SetProgress(TEXT_REQUESTING_REQUIRED_PRIVILEGES);
            MLResult result = MLPrivileges.RequestPrivilegeAsync(MLPrivilegeId.PwFoundObjRead, HandlePrivilegeAsyncRequest);

            if (!result.IsOk)
            {
                _state = State.CritialError;
                string errorMsg = string.Format("MLPrivilegeId.PwFoundObjRead Privilege Request Error: {1}", result);
                SetProgress(errorMsg);
                Debug.LogErrorFormat(errorMsg);
                return;
            }
        }
        /// <summary>
        /// Request each needed privilege.
        /// </summary>
        private void RequestPrivileges()
        {
            foreach (MLPrivilegeId priv in _privilegesNeeded)
            {
                MLResult result = MLPrivileges.RequestPrivilegeAsync(priv, HandlePrivilegeAsyncRequest);
                if (!result.IsOk)
                {
                    Debug.LogErrorFormat("{0} Privilege Request Error: {1}", priv, result);
                    _currentPrivilegeState = PrivilegeState.Denied;
                    return;
                }
            }

            _currentPrivilegeState = PrivilegeState.Requested;
        }
Esempio n. 5
0
    /// <summary>
    /// Request each needed privilege.
    /// </summary>
    private void RequestPrivileges()
    {
        foreach (MLPrivilegeId priv in _privilegesToRequest)
        {
            MLResult result = MLPrivileges.RequestPrivilegeAsync(priv, HandlePrivilegeAsyncRequest);
            if (!result.IsOk)
            {
                Debug.LogErrorFormat("Error: PrivilegeRequester failed requesting {0} privilege. Reason: {1}", priv,
                                     result);
                _state = PrivilegeState.Failed;
                return;
            }
        }

        _state = PrivilegeState.Requested;
    }
Esempio n. 6
0
        public static async UniTask RequestPrivilege(MLPrivilegeId privilege)
        {
            // Don't do privilege if app is running in neither ML device nor ZI mode
            if (!XRDevice.isPresent)
            {
                return;
            }

            MLPrivileges.Start().ThrowIfFail();

            MLResult?result = null;

            MLPrivileges.RequestPrivilegeAsync(privilege, (r, _) =>
            {
                result = r;
            }).ThrowIfFail();

            await UniTask.WaitUntil(() => result.HasValue);

            result?.ThrowIfFail();
        }