Exemplo n.º 1
0
        private void InitiateRequest(AppUpdateRequestImpl request, AppUpdateInfo appUpdateInfo,
                                     AppUpdateOptions appUpdateOptions)
        {
            if (appUpdateInfo.UpdateAvailability == UpdateAvailability.DeveloperTriggeredUpdateInProgress)
            {
                // If an update is already in progress, it would skip user confirmation dialog and
                // the ActivityResult for user confirmation should be set to ResultOk.
                request.SetUpdateActivityResult(ActivityResult.ResultOk);
            }

            if (request.IsDone && appUpdateOptions.AppUpdateType == AppUpdateType.Flexible)
            {
                request.OnUpdateDownloaded();
            }
            else
            {
                var requestFlowTask = _appUpdateManagerPlayCore.StartUpdateFlow(appUpdateInfo, appUpdateOptions);

                requestFlowTask.RegisterOnSuccessCallback(resultCode =>
                {
                    // Set user confirmation dialog result for the update request.
                    request.SetUpdateActivityResult(resultCode);
                    requestFlowTask.Dispose();
                });

                requestFlowTask.RegisterOnFailureCallback((reason, errorCode) =>
                {
                    Debug.LogErrorFormat("Update flow request failed: {0}", errorCode);
                    request.OnErrorOccurred(AppUpdatePlayCoreTranslator.TranslatePlayCoreErrorCode(errorCode));
                    requestFlowTask.Dispose();
                });
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Starts the desired update flow indicated by <param name="appUpdateOptions"> asynchronously.
        /// </summary>
        /// <param name="appUpdateInfo">The on success result of <see cref="GetAppUpdateInfo"/>.</param>
        /// <param name="appUpdateOptions"><see cref="AppUpdateOptions"/> contains update type options.</param>
        /// <returns>
        /// A <see cref="PlayCoreTask<int>"/> which gives an int result
        /// once the dialog has been accepted, denied or closed.
        /// A successful task result contains one of the following values:
        /// <ul>
        ///   <li><see cref="ActivityResult.ResultOk"/> -1 if the user accepted.</li>
        ///   <li><see cref="ActivityResult.ResultCancelled"/> 0 if the user denied or the dialog has been closed in
        ///       any other way (e.g. backpress).</li>
        ///   <li><see cref="ActivityResult.ResultFailed"/> 1 if the activity created to achieve has failed.</li>
        /// </ul>
        /// </returns>
        public PlayCoreTask <int> StartUpdateFlow(AppUpdateInfo appUpdateInfo, AppUpdateOptions appUpdateOptions)
        {
            var javaTask =
                _javaAppUpdateManager.Call <AndroidJavaObject>("startUpdateFlow",
                                                               appUpdateInfo.GetJavaUpdateInfo(), UnityPlayerHelper.GetCurrentActivity(),
                                                               appUpdateOptions.GetJavaAppUpdateOptions());

            return(new PlayCoreTask <int>(javaTask));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates an <see cref="AppUpdateRequest"/> that can be used to monitor the update progress and start the
        /// desired update flow indicated by <see cref="appUpdateOptions"/>.
        /// </summary>
        /// <param name="appUpdateInfo">The on success result of <see cref="GetAppUpdateInfo"/>.</param>
        /// <param name="appUpdateOptions"><see cref="AppUpdateOptions"/> contains update type options.</param>
        /// <returns>
        /// A <see cref="AppUpdateRequest"/> which can be used to monitor the asynchronous request of an update flow.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// Throws if any of the the provided parameters are null.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// Throws if there is already an <see cref="AppUpdateRequest"/> in progress.
        /// </exception>
        public AppUpdateRequest StartUpdateInternal(AppUpdateInfo appUpdateInfo, AppUpdateOptions appUpdateOptions)
        {
            if (appUpdateInfo == null)
            {
                throw new ArgumentNullException("appUpdateInfo");
            }

            if (appUpdateOptions == null)
            {
                throw new ArgumentNullException("appUpdateOptions");
            }

            if (_appUpdateRequest != null)
            {
                throw new InvalidOperationException(
                          "Another update flow is already in progress.");
            }

            _appUpdateRequest = new AppUpdateRequestImpl();

            if (appUpdateInfo.UpdateAvailability == UpdateAvailability.UpdateNotAvailable)
            {
                _appUpdateRequest.OnErrorOccurred(AppUpdateErrorCode.ErrorUpdateUnavailable);
                return(_appUpdateRequest);
            }

            if (!appUpdateInfo.IsUpdateTypeAllowed(appUpdateOptions))
            {
                _appUpdateRequest.OnErrorOccurred(AppUpdateErrorCode.ErrorUpdateNotAllowed);
                return(_appUpdateRequest);
            }

            _appUpdateRequest.Completed += (req) => { _appUpdateRequest = null; };
            InitiateRequest(_appUpdateRequest, appUpdateInfo, appUpdateOptions);
            return(_appUpdateRequest);
        }