Beispiel #1
0
        private async Task ProvideDiagnosisKeys()
        {
            var diagnosisKeyPaths = await PrepareDiagnosisKeyFilesAsync();

            if (diagnosisKeyPaths.Count == 0)
            {
                status.Text = "No diagnosisKey file found";
                return;
            }

            try
            {
                await EnClient.ProvideDiagnosisKeysAsync(diagnosisKeyPaths);
            }
            catch (TimeoutException exception)
            {
                Logger.E(exception);
            }
            catch (ENException enException)
            {
                ShowENException(enException);
            }
            catch (ApiException apiException)
            {
                ShowApiException("ProvideDiagnosisKeys", apiException);
            }
        }
Beispiel #2
0
        private async Task RequestPreAuthorizeKeys()
        {
            Logger.D("RequestPreAuthorizeKeys");
            try
            {
                await EnClient.RequestPreAuthorizedTemporaryExposureKeyHistoryAsync();

                Logger.D("RequestPreAuthorizeKeys Success");
            }
            catch (ENException enException)
            {
                ShowENException(enException);
            }
            catch (ApiException apiException)
            {
                if (apiException.StatusCode == CommonStatusCodes.ResolutionRequired)
                {
                    apiException.Status.StartResolutionForResult(this, REQUEST_PREAUTHORIZE_KEYS);
                }
                else
                {
                    ShowApiException("RequestPreAuthorizeKeys", apiException);
                }
            }
        }
Beispiel #3
0
        private void ShowENException(ENException enException)
        {
            Logger.D($"ENException - Code:{enException.Code}, {enException.Message}");

            string message = enException.Code switch
            {
                ENException.Code_iOS.ApiMisuse => "ApiMisuse",
                ENException.Code_iOS.BadFormat => "BadFormat",
                ENException.Code_iOS.BadParameter => "BadParameter",
                ENException.Code_iOS.BluetoothOff => "BluetoothOff",
                ENException.Code_iOS.DataInaccessible => "DataInaccessible",
                ENException.Code_iOS.InsufficientMemory => "InsufficientMemory",
                ENException.Code_iOS.InsufficientStorage => "InsufficientStorage",
                ENException.Code_iOS.Internal => "Internal",
                ENException.Code_iOS.Invalidated => "Invalidated",
                ENException.Code_iOS.NotAuthorized => "NotAuthorized",
                ENException.Code_iOS.NotEnabled => "NotEnabled",
                ENException.Code_iOS.NotEntitled => "NotEntitled",
                ENException.Code_iOS.RateLimited => "RateLimited",
                ENException.Code_iOS.Restricted => "Restricted",
                ENException.Code_iOS.TravelStatusNotAvailable => "TravelStatusNotAvailable",
                ENException.Code_iOS.Unsupported => "Unsupported",
                _ => "Unknown",
            };

            status.Text = $"ENException: {message}";
        }
Beispiel #4
0
        private async Task UploadDiagnosisKeys()
        {
            Logger.D("UploadDiagnosisKeys");
            status.Text = "UploadDiagnosisKeys is clicked.\n";

            try
            {
                IList <TemporaryExposureKey> teks = await EnClient.GetTemporaryExposureKeyHistoryAsync();

                DateTime symptomOnsetDate = DateTime.UtcNow.Date - TimeSpan.FromDays(teks.Count / 2);
                string   idempotencyKey   = Guid.NewGuid().ToString();

                await _diagnosisKeyServer.UploadDiagnosisKeysAsync(symptomOnsetDate, teks, idempotencyKey);

                status.Append($"diagnosisKeyEntryList have been uploaded.\n");
            }
            catch (ENException enException)
            {
                ShowENException(enException);
            }
            catch (ApiException apiException)
            {
                if (apiException.StatusCode == CommonStatusCodes.ResolutionRequired)
                {
                    apiException.Status.StartResolutionForResult(this, REQUEST_GET_TEK_HISTORY);
                }
                else
                {
                    ShowApiException("GetTekHistory", apiException);
                }
            }
        }
Beispiel #5
0
        public async Task ExposureNotDetectedAsync(ExposureConfiguration exposureConfiguration)
        {
            Logger.D($"ExposureNotDetected: {DateTime.UtcNow}");

            var enVersion = (await EnClient.GetVersionAsync()).ToString();

            var exposureResult = new ExposureResult(
                exposureConfiguration,
                DateTime.Now
                )
            {
                Device    = DeviceInfo.Model,
                EnVersion = enVersion
            };
            var filePath = await SaveExposureResult(exposureResult);

            var exposureDataServerConfiguration = await LoadExposureDataServerConfiguration();

            var exposureDataResponse = await new ExposureDataServer(exposureDataServerConfiguration).UploadExposureDataAsync(
                exposureConfiguration,
                DeviceInfo.Model,
                enVersion
                );

            if (exposureDataResponse != null)
            {
                await SaveExposureResult(exposureDataResponse);

                File.Delete(filePath);
            }
        }
Beispiel #6
0
        private async Task <List <TemporaryExposureKey> > GetTekHistory()
        {
            Logger.D("GetTekHistory");
            try
            {
                return(await EnClient.GetTemporaryExposureKeyHistoryAsync());
            }
            catch (ENException enException)
            {
                ShowENException(enException);
            }
            catch (ApiException apiException)
            {
                if (apiException.StatusCode == CommonStatusCodes.ResolutionRequired)
                {
                    apiException.Status.StartResolutionForResult(this, REQUEST_GET_TEK_HISTORY);
                }
                else
                {
                    ShowApiException("GetTekHistory", apiException);
                }
            }

            return(new List <TemporaryExposureKey>());
        }
Beispiel #7
0
        private async Task EnableEnAsync()
        {
            Logger.D("EnableEnAsync");
            try
            {
                await EnClient.StartAsync();

                long version = await EnClient.GetVersionAsync();

                Logger.D($"Version: {version}");
            }
            catch (ENException enException)
            {
                ShowENException(enException);
            }
            catch (ApiException apiException)
            {
                if (apiException.StatusCode == CommonStatusCodes.ResolutionRequired)
                {
                    apiException.Status.StartResolutionForResult(this, REQUEST_EN_START);
                }
                else
                {
                    ShowApiException("EnableEnAsync", apiException);
                }
            }
        }
Beispiel #8
0
        public async Task ExposureDetectedAsync(ExposureSummary exposureSummary, IList <ExposureInformation> exposureInformations, ExposureConfiguration exposureConfiguration)
        {
            Logger.D($"ExposureDetected V1: {DateTime.UtcNow}");

            var enVersion = (await ExposureNotificationClientManager.Shared.GetVersionAsync()).ToString();

            var exposureResult = new ExposureResult(
                exposureConfiguration,
                DateTime.Now,
                exposureSummary, exposureInformations
                )
            {
                Device    = DeviceInfo.Model,
                EnVersion = enVersion
            };
            var filePath = await SaveExposureResult(exposureResult);

            var exposureDataServerConfiguration = await LoadExposureDataServerConfiguration();

            var exposureDataResponse = await new ExposureDataServer(exposureDataServerConfiguration).UploadExposureDataAsync(
                exposureConfiguration,
                DeviceInfo.Model,
                enVersion,
                exposureSummary, exposureInformations
                );

            if (exposureDataResponse != null)
            {
                await SaveExposureResult(exposureDataResponse);

                File.Delete(filePath);
            }
        }
Beispiel #9
0
        public Task TemporaryExposureKeyReleasedAsync(IList <TemporaryExposureKey> temporaryExposureKeys)
        {
            Logger.D("TemporaryExposureKeyReleased");

            var serializedJson = JsonConvert.SerializeObject(temporaryExposureKeys, Formatting.Indented);

            Logger.D(serializedJson);

            return(Task.CompletedTask);
        }
Beispiel #10
0
        public Task TemporaryExposureKeyReleasedAsync(IList <TemporaryExposureKey> temporaryExposureKeys)
        {
            Logger.D("TemporaryExposureKeyReleased");

            foreach (TemporaryExposureKey tek in temporaryExposureKeys)
            {
                Logger.D(Convert.ToBase64String(tek.KeyData));
            }

            return(Task.CompletedTask);
        }
Beispiel #11
0
        public bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            Logger.D("FinishedLaunching");

            InitializeDirs();

            AbsExposureNotificationClient.Handler = this;
            ExposureNotificationClientManager.Shared.UserExplanation = USER_EXPLANATION;

            return(true);
        }
Beispiel #12
0
        private async Task DownloadDiagnosisKeys()
        {
            Logger.D("DownloadDiagnosisKeys");
            status.Text = "DownloadDiagnosisKeys is clicked.\n";

            var diagnosisKeyEntryList = await _diagnosisKeyServer.GetDiagnosisKeysListAsync();

            foreach (var diagnosisKeyEntry in diagnosisKeyEntryList)
            {
                await _diagnosisKeyServer.DownloadDiagnosisKeysAsync(diagnosisKeyEntry, _exposureDetectionDir);

                status.Text += $"{diagnosisKeyEntry.Url} has been downloaded.\n";
            }
        }
Beispiel #13
0
        private async Task UploadDiagnosisKeys()
        {
            Logger.D("UploadDiagnosisKeys");
            status.Text = "UploadDiagnosisKeys is clicked.\n";

            List <TemporaryExposureKey> teks = await ExposureNotificationClientManager.Shared.GetTemporaryExposureKeyHistoryAsync();

            DateTime symptomOnsetDate = DateTime.UtcNow.Date - TimeSpan.FromDays(teks.Count / 2);
            string   idempotencyKey   = Guid.NewGuid().ToString();

            await _diagnosisKeyServer.UploadDiagnosisKeysAsync(symptomOnsetDate, teks, idempotencyKey);

            status.Text += $"diagnosisKeyEntryList have been uploaded.\n";
        }
Beispiel #14
0
        private async Task DetectExposure()
        {
            status.Text = "DetectExposure is clicked.\n";

            List <string> diagnosisKeyPaths = Directory.GetFiles(_exposureDetectionDir).ToList()
                                              .FindAll(path => !Directory.Exists(path))
                                              .FindAll(path => path.EndsWith(".zip"));

            foreach (string path in diagnosisKeyPaths)
            {
                Logger.D($"path {path}");
            }

            await ExposureNotificationClientManager.Shared.ProvideDiagnosisKeysAsync(diagnosisKeyPaths);
        }
Beispiel #15
0
        private async Task SaveTeksAsync(IList <TemporaryExposureKey> temporaryExposureKeys)
        {
            TemporaryExposureKeys teks = new TemporaryExposureKeys(temporaryExposureKeys, DateTime.Now)
            {
                Device = DeviceInfo.Model
            };

            string fileName = $"{teks.Id}.json";
            string json     = teks.ToJsonString();

            Logger.D(json);

            var filePath = Path.Combine(_teksDir, fileName);
            await File.WriteAllTextAsync(filePath, json);
        }
Beispiel #16
0
        private async Task SaveTekHistoryAsync(List <TemporaryExposureKey> temporaryExposureKeys)
        {
            TemporaryExposureKeys teks = new TemporaryExposureKeys(temporaryExposureKeys, DateTime.Now)
            {
                Device = DeviceInfo.Model
            };

            string fileName = $"{teks.Id}.json";
            string json     = teks.ToJsonString();

            Logger.D(json);

            AndroidFile filePath = new AndroidFile(_teksDir, fileName);
            await File.WriteAllTextAsync(filePath.AbsolutePath, json);
        }
Beispiel #17
0
 private async Task RequestReleaseKeys()
 {
     Logger.D("RequestReleaseKeys");
     try
     {
         await EnClient.RequestPreAuthorizedTemporaryExposureKeyReleaseAsync();
     }
     catch (ENException enException)
     {
         ShowENException(enException);
     }
     catch (ApiException apiException)
     {
         ShowApiException("RequestReleaseKeys", apiException);
     }
 }
Beispiel #18
0
        public Task ExceptionOccurredAsync(Exception exception)
        {
            Logger.E(exception);

            return(Task.CompletedTask);
        }
Beispiel #19
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Platform.Init(this, savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);

            PrepareDirs();

            EnClient = ((MainApplication)ApplicationContext).GetEnClient();

            buttonEn        = FindViewById <Button>(Resource.Id.btn_enable_en);
            buttonEn.Click += async delegate
            {
                Logger.D("EnableEnAsync clicked");

                await EnableEnAsync();
            };

            buttonGetTekHistory        = FindViewById <Button>(Resource.Id.btn_get_teks);
            buttonGetTekHistory.Click += async delegate
            {
                Logger.D("buttonGetTekHistory clicked");

                List <TemporaryExposureKey> teks = await GetTekHistory();

                ShowTekHistory(teks);
                await SaveTekHistoryAsync(teks);
            };

            buttonProvideDiagnosisKeys        = FindViewById <Button>(Resource.Id.btn_provide_diagnosis_keys);
            buttonProvideDiagnosisKeys.Click += async delegate
            {
                Logger.D("buttonProvideDiagnosisKeys clicked");

                await ProvideDiagnosisKeys();
            };

            buttonProvideDiagnosisKeysV1        = FindViewById <Button>(Resource.Id.btn_provide_diagnosis_keys_legacy_v1);
            buttonProvideDiagnosisKeysV1.Click += async delegate
            {
                Logger.D("buttonProvideDiagnosisKeysV1 clicked");

                await ProvideDiagnosisKeysV1();
            };

            buttonRequestPreauthorizedKeys        = FindViewById <Button>(Resource.Id.btn_request_preauthorize_keys);
            buttonRequestPreauthorizedKeys.Click += async delegate
            {
                Logger.D("buttonRequestPreauthorizedKeys clicked");

                await RequestPreAuthorizeKeys();
            };

            buttonRequestReleaseKeys        = FindViewById <Button>(Resource.Id.btn_request_release_keys);
            buttonRequestReleaseKeys.Click += async delegate
            {
                Logger.D("buttonRequestReleaseKeys clicked");

                await RequestReleaseKeys();
            };

            buttonUploadDiagnosisKeys        = FindViewById <Button>(Resource.Id.btn_upload_diagnosis_keys);
            buttonUploadDiagnosisKeys.Click += async delegate
            {
                Logger.D("buttonUploadDiagnosisKeys clicked");

                await UploadDiagnosisKeys();
            };

            buttonDownloadDiagnosisKeys        = FindViewById <Button>(Resource.Id.btn_download_diagnosis_keys);
            buttonDownloadDiagnosisKeys.Click += async delegate
            {
                Logger.D("buttonDownloadDiagnosisKeys clicked");

                await DownloadDiagnosisKeys();
            };

            status = FindViewById <TextView>(Resource.Id.tv_status);

            serverInfo = FindViewById <TextView>(Resource.Id.tv_server_info);
        }
Beispiel #20
0
        public Task PreExposureDetectedAsync(ExposureConfiguration exposureConfiguration)
        {
            Logger.D($"PreExposureDetected: {DateTime.UtcNow}");

            return(Task.CompletedTask);
        }
Beispiel #21
0
        public override async void ViewDidLoad()
        {
            base.ViewDidLoad();

            Logger.D("ViewDidLoad");

            PrepareDirs();

            IList <ExposureNotificationStatus> statuses = await ExposureNotificationClientManager.Shared.GetStatusesAsync();

            long version = await ExposureNotificationClientManager.Shared.GetVersionAsync();

            ShowStatus(statuses, version);

            buttonEnableEn.TouchUpInside += async(sender, e) =>
            {
                status.Text = "Enable Exposure Notification is clicked.\n";

                try
                {
                    await ExposureNotificationClientManager.Shared.StartAsync();

                    IList <ExposureNotificationStatus> statuses = await ExposureNotificationClientManager.Shared.GetStatusesAsync();

                    long version = await ExposureNotificationClientManager.Shared.GetVersionAsync();

                    ShowStatus(statuses, version);
                }
                catch (ENException enException)
                {
                    ShowENException(enException);
                }
                catch (NSErrorException exception)
                {
                    exception.LogD();
                }
            };
            buttonShowTeksHistory.TouchUpInside += async(sender, e) =>
            {
                status.Text = "Show TEKs History is clicked.\n";
                try
                {
                    List <TemporaryExposureKey> teks = await ExposureNotificationClientManager.Shared.GetTemporaryExposureKeyHistoryAsync();

                    ShowTeks(teks);
                    await SaveTeksAsync(teks);
                }
                catch (ENException enException)
                {
                    ShowENException(enException);
                }
                catch (NSErrorException exception)
                {
                    exception.LogD();
                }
            };
            buttonDetectExposure.TouchUpInside += async(sender, e) =>
            {
                try
                {
                    await DetectExposure();
                }
                catch (TaskCanceledException exception)
                {
                    Logger.E(exception);
                }
                catch (ENException enException)
                {
                    ShowENException(enException);
                }
                catch (NSErrorException exception)
                {
                    exception.LogD();
                }
            };
            buttonRequestPreauthorizedKeys.TouchUpInside += async(sender, e) =>
            {
                try
                {
                    await RequestPreauthorizedKeys();
                }
                catch (ENException enException)
                {
                    ShowENException(enException);
                }
                catch (NSErrorException exception)
                {
                    exception.LogD();
                }
            };
            buttonRequestReleaseKeys.TouchUpInside += async(sender, e) =>
            {
                try
                {
                    await RequestReleaseKeys();
                }
                catch (ENException enException)
                {
                    ShowENException(enException);
                }
                catch (NSErrorException exception)
                {
                    exception.LogD();
                }
            };
            buttonUploadDiagnosisKeys.TouchUpInside += async(sender, e) =>
            {
                try
                {
                    await UploadDiagnosisKeys();
                }
                catch (ENException enException)
                {
                    ShowENException(enException);
                }
                catch (NSErrorException exception)
                {
                    exception.LogD();
                }
            };
            buttonDownloadDiagnosisKeys.TouchUpInside += async(sender, e) =>
            {
                try
                {
                    await DownloadDiagnosisKeys();
                }
                catch (ENException enException)
                {
                    ShowENException(enException);
                }
                catch (NSErrorException exception)
                {
                    exception.LogD();
                }
            };

            _diagnosisKeyServerConfiguration = await LoadDiagnosisKeyServerConfiguration();

            _diagnosisKeyServer = new DiagnosisKeyServer(_diagnosisKeyServerConfiguration);
            ShowServerConfiguration(_diagnosisKeyServerConfiguration);
        }