public async Task <bool> StartExposureNotification()
        {
            loggerService.StartMethod();
            try
            {
                var enabled = await ExposureNotification.IsEnabledAsync();

                if (!enabled)
                {
                    await ExposureNotification.StartAsync();
                }

                loggerService.EndMethod();
                return(true);
            }
            catch (Exception ex)
            {
                loggerService.Exception("Error enabling notifications.", ex);
                loggerService.EndMethod();
                return(false);
            }
            finally
            {
            }
        }
Exemple #2
0
 public async void CheckIfAppIsRestricted(Action action = null)
 {
     try
     {
         if (await IsEnabled())
         {
             if (await IsRunning())
             {
                 await ExposureNotification.StartAsync();
             }
         }
         IsAppRestricted = false;
     }
     catch (Exception)
     {
         IsAppRestricted = true;
     }
     action?.Invoke();
 }
Exemple #3
0
        public async Task <bool> StartENService()
        {
            if (IsAppRestricted)
            {
                return(false);
            }
            try
            {
                await ExposureNotification.StartAsync();
            }
            catch (Exception e)
            {
                if (!e.HandleExposureNotificationException(nameof(InfectionStatusViewModel), nameof(StartENService)))
                {
                    throw e;
                }
            }

            return(await IsRunning());
        }
        /*
         * public async Task TestDownloadBatch()
         * {
         *  long sinceEpochSeconds = new DateTimeOffset(DateTime.UtcNow.AddDays(-14)).ToUnixTimeSeconds();
         *  TemporaryExposureKeysResult tekResult = await httpDataService.GetTemporaryExposureKeys(sinceEpochSeconds);
         *  Console.WriteLine("Fetch Exposure Key");
         *
         *  foreach (var keys in tekResult.Keys)
         *  {
         *      Console.WriteLine(keys.Url);
         *  }
         *
         * }
         *
         * public bool GetOptInStatus()
         * {
         *  return userData.IsOptined;
         * }
         */


        /*
         * public async Task SetOptinStatusAsync(bool flg)
         * {
         *  userData.IsOptined = flg;
         *  await userDataService.SetAsync(userData);
         * }
         * public bool GetOptInStatus()
         * {
         *  return userData.IsOptined;
         * }
         *
         *
         * public async Task SetExposureNotificationStatusAsync(bool flg)
         * {
         *  userData.IsExposureNotificationEnabled = flg;
         *  await userDataService.SetAsync(userData);
         * }
         * public bool GetExposureNotificationStatus()
         * {
         *  return userData.IsExposureNotificationEnabled;
         * }
         *
         * public async Task SetNotificationStatusAsync(bool flg)
         * {
         *  userData.IsNotificationEnabled = flg;
         *  await userDataService.SetAsync(userData);
         * }
         * public bool GetNotificationStatus()
         * {
         *  return userData.IsNotificationEnabled;
         * }
         */
        public async Task <bool> StartExposureNotification()
        {
            if (!userData.IsOptined)
            {
                await UserDialogs.Instance.AlertAsync("利用規約に同意する必要があります。同意ページへ遷移します。");

                await navigationService.NavigateAsync(nameof(PrivacyPolicyPage));
            }

            Status status = await ExposureNotification.GetStatusAsync();

            if (status == Status.BluetoothOff
                //            || status == Status.Restricted
                || status == Status.NotAuthorized)
            {
                await UserDialogs.Instance.AlertAsync(GetStatusMessage(status));

                userData.IsExposureNotificationEnabled = false;
                await userDataService.SetAsync(userData);

                return(false);
            }

            //            bool IsEnabled = await ExposureNotification.IsEnabledAsync();

            if (userData.IsOptined && userData.IsExposureNotificationEnabled && (status == Status.Unknown || status == Status.Active || status == Status.Disabled))
            {
                try
                {
                    await ExposureNotification.StartAsync();
                }
                catch (Exception)
                {
                    userData.IsExposureNotificationEnabled = false;
                    await userDataService.SetAsync(userData);

                    return(false);
                }
            }
            return(true);
        }
Exemple #5
0
        public async Task <bool> StartExposureNotification()
        {
            /*
             * if (!userData.IsOptined)
             * {
             *  await UserDialogs.Instance.AlertAsync("利用規約に同意する必要があります。同意ページへ遷移します。");
             *  await navigationService.NavigateAsync(nameof(PrivacyPolicyPage));
             * }
             */

            try
            {
                await ExposureNotification.StartAsync();

                var count = 0;
                while (true)
                {
                    Thread.Sleep(1000);
                    await ExposureNotification.StartAsync();

                    Status status = await ExposureNotification.GetStatusAsync();

                    if (status == Status.Active)
                    {
                        return(true);
                    }
                    else if (status == Status.BluetoothOff)
                    {
                        await UserDialogs.Instance.AlertAsync(GetStatusMessage());

                        return(true);
                    }
                    else
                    {
                        if (count > 2)
                        {
                            throw new Exception();
                        }
                        count++;
                    }
                }
            }
            catch (Exception)
            {
                userData.IsExposureNotificationEnabled = false;
                await userDataService.SetAsync(userData);

                return(false);
            }

            /*
             * ExposureNotificationStatus = await ExposureNotification.GetStatusAsync();
             * if (ExposureNotificationStatus == Status.BluetoothOff
             * //            || ExposureNotificationStatus == Status.Restricted
             || ExposureNotificationStatus == Status.NotAuthorized)
             ||{
             || await UserDialogs.Instance.AlertAsync(GetStatusMessage());
             || userData.IsExposureNotificationEnabled = false;
             || await userDataService.SetAsync(userData);
             || return false;
             ||}
             ||
             ||if (userData.IsOptined && userData.IsExposureNotificationEnabled && (ExposureNotificationStatus == Status.Unknown || ExposureNotificationStatus == Status.Active || ExposureNotificationStatus == Status.Disabled))
             ||{
             || try
             || {
             ||     await ExposureNotification.StartAsync();
             ||
             || }
             || catch (Exception)
             || {
             ||     userData.IsExposureNotificationEnabled = false;
             ||     await userDataService.SetAsync(userData);
             ||     return false;
             || }
             ||}
             ||return true;
             */
        }
Exemple #6
0
        public async Task UploadSelfExposureKeysToServerAsync(IEnumerable <TemporaryExposureKey> tempKeys)
        {
            // Convert to ExposureKeyModel list as it is extended with DaysSinceOnsetOfSymptoms value
            IEnumerable <ExposureKeyModel> temporaryExposureKeys = tempKeys?.Select(key => new ExposureKeyModel(key)) ?? new List <ExposureKeyModel>();

            // There is a better behaviour of uploading keys when scanning is Stoped/Started (UIAlert for permission is always shown then),
            // The IF-check just toggles the scanning status on/off or off/on to keep the scanning status
            // the same as it was before method is called

            try
            {
                if (ServiceLocator.Current.GetInstance <IDeviceInfo>().Platform == DevicePlatform.iOS)
                {
                    if (await ExposureNotification.IsEnabledAsync())
                    {
                        await ExposureNotification.StopAsync();

                        await ExposureNotification.StartAsync();
                    }
                    else
                    {
                        await ExposureNotification.StartAsync();

                        await ExposureNotification.StopAsync();
                    }
                }
            }
            catch (Exception e)
            {
                if (!e.HandleExposureNotificationException(nameof(ExposureNotificationHandler), nameof(UploadSelfExposureKeysToServerAsync)))
                {
                    throw e;
                }
            }

            if (FakeGatewayUtils.IsFakeGatewayTest)
            {
                FakeGatewayUtils.LastPulledExposureKeys = temporaryExposureKeys;
                return;
            }

            if (AuthenticationState.PersonalData?.Access_token == null)
            {
                throw new AccessTokenMissingFromIDPortenException("The token from ID Porten is not set");
            }

            if (AuthenticationState.PersonalData?.VisitedCountries == null)
            {
                throw new VisitedCountriesMissingException(
                          "The visited countries list is missing. Possibly garbage collection removed it.");
            }

            if (!MiBaDate.HasValue)
            {
                throw new MiBaDateMissingException("The symptom onset date is not set from the calling view model");
            }

            DateTime MiBaDateAsUniversalTime = MiBaDate.Value.ToUniversalTime();

            List <ExposureKeyModel> validKeys = UploadDiagnosisKeysHelper.CreateAValidListOfTemporaryExposureKeys(temporaryExposureKeys);

            // Here all keys are extended with DaysSinceOnsetOfSymptoms value
            validKeys = UploadDiagnosisKeysHelper.SetTransmissionRiskLevel(validKeys, MiBaDateAsUniversalTime);

            bool success = await exposureNotificationWebService.PostSelfExposureKeys(validKeys);

            if (!success)
            {
                throw new FailedToPushToServerException("Failed to push keys to the server");
            }
        }