示例#1
0
 public async Task <bool> StopExposureNotification()
 {
     if (await Xamarin.ExposureNotifications.ExposureNotification.IsEnabledAsync())
     {
         await ExposureNotification.StopAsync();
     }
     return(true);
 }
示例#2
0
 public async Task <bool> StopENService()
 {
     if (IsAppRestricted)
     {
         return(false);
     }
     try
     {
         await ExposureNotification.StopAsync();
     }
     catch (Exception e)
     {
         if (!e.HandleExposureNotificationException(nameof(InfectionStatusViewModel), nameof(StopENService)))
         {
             throw e;
         }
     }
     return(await IsRunning());
 }
示例#3
0
        public async Task <bool> StopExposureNotification()
        {
            loggerService.StartMethod();
            try
            {
                var enabled = await ExposureNotification.IsEnabledAsync();

                if (enabled)
                {
                    await ExposureNotification.StopAsync();
                }

                loggerService.EndMethod();
                return(true);
            }
            catch (Exception ex)
            {
                loggerService.Exception("Error disabling notifications.", ex);
                loggerService.EndMethod();
                return(false);
            }
        }
示例#4
0
 public async void CheckIfAppIsRestricted(Action action = null)
 {
     try
     {
         if (await IsEnabled())
         {
             if (await IsRunning())
             {
                 await ExposureNotification.StartAsync();
             }
             else
             {
                 await ExposureNotification.StopAsync();
             }
         }
         IsAppRestricted = false;
     }
     catch (Exception)
     {
         IsAppRestricted = true;
     }
     action?.Invoke();
 }
        public async Task <bool> StopExposureNotification()
        {
            await ExposureNotification.StopAsync();

            return(true);
        }
示例#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");
            }
        }