Ejemplo n.º 1
0
        public async Task ExposureDetectedAsync(ExposureSummary exposureSummary, IList <ExposureInformation> exposureInformations, ExposureConfiguration exposureConfiguration)
        {
            Logger.D($"ExposureDetected Legacy-v1: {DateTime.UtcNow}");

            var enVersion = (await EnClient.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);
            }
        }
Ejemplo n.º 2
0
        private (ExposureSummary, IEnumerable <ExposureInformation>) CreateDummyV1ExposureData()
        {
            var exposureSummary = new ExposureSummary()
            {
            };

            IEnumerable <ExposureInformation> CreateInformations()
            {
                var exposureInformations = new List <ExposureInformation>
                {
                    new ExposureInformation()
                    {
                        DateMillisSinceEpoch         = DateTime.UtcNow.AddDays(-10).ToUnixEpoch(),
                        DurationInMillis             = TimeSpan.FromMinutes(5).Ticks,
                        AttenuationDurationsInMillis = new int[] { 1440000, 0, 0 },
                        AttenuationValue             = 65,
                        TotalRiskScore        = 5,
                        TransmissionRiskLevel = RiskLevel.Medium,
                    },
                    new ExposureInformation()
                    {
                        DateMillisSinceEpoch         = DateTime.UtcNow.AddDays(-11).ToUnixEpoch(),
                        DurationInMillis             = TimeSpan.FromMinutes(5).Ticks,
                        AttenuationDurationsInMillis = new int[] { 1440000, 0, 0 },
                        AttenuationValue             = 40,
                        TotalRiskScore        = 3,
                        TransmissionRiskLevel = RiskLevel.Low,
                    },
                };

                return(exposureInformations);
            }

            return(exposureSummary, CreateInformations());
        }
Ejemplo n.º 3
0
 public Task UploadExposureDataAsync(
     ExposureConfiguration exposureConfiguration,
     string deviceModel,
     string enVersion,
     ExposureSummary exposureSummary,
     IList <ExposureInformation> exposureInformation
     )
 => Task.CompletedTask;
        public async void ExposureDetected_ExposureInformationHighRiskExposureDetected()
        {
            // Test Data
            var exposureConfiguration = new ExposureConfiguration()
            {
                GoogleExposureConfig = new ExposureConfiguration.GoogleExposureConfiguration()
                {
                    MinimumRiskScore = 0
                }
            };
            var exposureSummary = new ExposureSummary()
            {
                MaximumRiskScore = 1
            };
            var exposureInformantion = new ExposureInformation()
            {
                AttenuationDurationsInMillis = new int[] { 0 },
                AttenuationValue             = 0,
                DateMillisSinceEpoch         = 0,
                DurationInMillis             = 0,
                TotalRiskScore        = 2,
                TransmissionRiskLevel = RiskLevel.High
            };
            var exposureInformationList = new List <ExposureInformation>()
            {
                exposureInformantion
            };
            var enVersion = 2;

            // Mock Setup
            exposureDataCollectServer
            .Setup(x => x.UploadExposureDataAsync(
                       It.IsAny <ExposureConfiguration>(),
                       It.IsAny <string>(),
                       It.IsAny <string>(),
                       It.IsAny <ExposureSummary>(),
                       It.IsAny <List <ExposureInformation> >()));
            deviceInfoUtility.Setup(x => x.Model).Returns("UnitTest");

            exposureRiskCalculationService
            .Setup(x => x.CalcRiskLevel(It.IsAny <DailySummary>(), It.IsAny <List <ExposureWindow> >(), It.IsAny <V1ExposureRiskCalculationConfiguration>()))
            .Returns(RiskLevel.High);


            // Test Case
            var unitUnderTest = CreateService();
            await unitUnderTest.ExposureDetectedAsync(exposureConfiguration, enVersion, exposureSummary, exposureInformationList);


            // Assert
            localNotificationService
            .Verify(x => x.ShowExposureNotificationAsync(), Times.Once);

            var expectedSerializedData = JsonConvert.SerializeObject(exposureInformationList.Select(x => new UserExposureInfo(x)));

            secureStorageService
            .Verify(x => x.SetValue <string>("ExposureInformation", It.Is <string>(x => x == expectedSerializedData)), Times.Once);
        }
Ejemplo n.º 5
0
 public UserExposureSummary(ExposureSummary exposureSummary)
 {
     DaysSinceLastExposure = exposureSummary.DaysSinceLastExposure;
     MatchedKeyCount       = exposureSummary.MatchedKeyCount;
     HighestRiskScore      = exposureSummary.MaximumRiskScore;
     AttenuationDurations  = exposureSummary.AttenuationDurationsInMillis
                             .Select(attenuationDuration => TimeSpan.FromMilliseconds(attenuationDuration))
                             .ToArray();
     SummationRiskScore = exposureSummary.SummationRiskScore;
 }
Ejemplo n.º 6
0
 public Task SendExposureDataAsync(
     string idempotencyKey,
     ExposureConfiguration exposureConfiguration,
     string deviceModel, string enVersion,
     ExposureSummary exposureSummary,
     IList <ExposureInformation> exposureInformation
     )
 {
     // do nothing
     return(Task.CompletedTask);
 }
        public async void ExposureDetected_ExposureInformationHighRiskExposureNotDetected()
        {
            // Test Data
            var exposureConfiguration = new ExposureConfiguration()
            {
                GoogleExposureConfig = new ExposureConfiguration.GoogleExposureConfiguration()
                {
                    MinimumRiskScore = 3
                }
            };
            var exposureSummary = new ExposureSummary()
            {
                MaximumRiskScore = 1
            };
            var exposureInformantion = new ExposureInformation()
            {
                AttenuationDurationsInMillis = new int[] { 0 },
                AttenuationValue             = 0,
                DateMillisSinceEpoch         = 0,
                DurationInMillis             = 0,
                TotalRiskScore        = 2,
                TransmissionRiskLevel = RiskLevel.High
            };
            var exposureInformationList = new List <ExposureInformation>()
            {
                exposureInformantion
            };
            var enVersion = 2;

            // Mock Setup
            exposureDataCollectServer
            .Setup(x => x.UploadExposureDataAsync(
                       It.IsAny <ExposureConfiguration>(),
                       It.IsAny <string>(),
                       It.IsAny <string>(),
                       It.IsAny <ExposureSummary>(),
                       It.IsAny <List <ExposureInformation> >()));
            deviceInfoUtility.Setup(x => x.Model).Returns("UnitTest");


            // Test Case
            var unitUnderTest = CreateService();
            await unitUnderTest.ExposureDetectedAsync(exposureConfiguration, enVersion, exposureSummary, exposureInformationList);


            // Assert
            localNotificationService
            .Verify(x => x.ShowExposureNotificationAsync(), Times.Never);
            secureStorageService
            .Verify(x => x.SetStringValue("ExposureInformation", It.IsAny <string>()), Times.Never);
        }
Ejemplo n.º 8
0
        public ExposureResult(ExposureConfiguration exposureConfiguration,
                              DateTime generatedAt,
                              ExposureSummary exposureSummary, IList <ExposureInformation> exposureInformations,
                              IList <DailySummary> dailySummaries, IList <ExposureWindow> exposureWindows)
        {
            this.exposureConfiguration = exposureConfiguration;

            // to ISO 8601
            this.generatedAt = generatedAt.ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz");

            this.exposureSummary      = exposureSummary;
            this.exposureInformations = exposureInformations;
            this.dailySummaries       = dailySummaries;
            this.exposureWindows      = exposureWindows;
        }
Ejemplo n.º 9
0
        public async Task UploadExposureDataAsync(
            ExposureConfiguration exposureConfiguration,
            string deviceModel,
            string enVersion,
            ExposureSummary exposureSummary,
            IList <ExposureInformation> exposureInformation
            )
        {
            var exposureResult = new ExposureRequest(exposureConfiguration,
                                                     exposureSummary, exposureInformation
                                                     )
            {
                Device    = deviceModel,
                EnVersion = enVersion,
            };

            await UploadExposureDataAsync(exposureResult);
        }
Ejemplo n.º 10
0
        public async Task SendExposureDataAsync(
            string idempotencyKey,
            ExposureConfiguration exposureConfiguration,
            string deviceModel,
            string enVersion,
            ExposureSummary exposureSummary,
            IList <ExposureInformation> exposureInformation
            )
        {
            var data = new ExposureData(exposureConfiguration,
                                        exposureSummary, exposureInformation
                                        )
            {
                Device    = deviceModel,
                EnVersion = enVersion,
            };

            await SendExposureDataAsync(idempotencyKey, data);
        }
Ejemplo n.º 11
0
        public async Task <ExposureDataResponse?> UploadExposureDataAsync(
            ExposureConfiguration exposureConfiguration,
            string deviceModel,
            string enVersion,
            ExposureSummary exposureSummary,
            IList <DailySummary> dailySummaries,
            IList <ExposureWindow> exposureWindows
            )
        {
            var exposureResult = new ExposureRequest(exposureConfiguration,
                                                     dailySummaries, exposureWindows
                                                     )
            {
                Device    = deviceModel,
                EnVersion = enVersion,
            };

            return(await UploadExposureDataAsync(exposureResult));
        }
Ejemplo n.º 12
0
        public bool AppendExposureData(
            ExposureSummary exposureSummary,
            List <ExposureInformation> exposureInformationList,
            int minimumRiskScore
            )
        {
            var  existExposureInformationList = GetExposureInformationList() ?? new List <UserExposureInfo>();
            bool isNewExposureDetected        = false;

            if (exposureSummary.MaximumRiskScore >= minimumRiskScore)
            {
                foreach (var exposureInfo in exposureInformationList)
                {
                    _loggerService.Info($"Exposure.Timestamp: {exposureInfo.DateMillisSinceEpoch}");
                    _loggerService.Info($"Exposure.Duration: {exposureInfo.DurationInMillis}");
                    _loggerService.Info($"Exposure.AttenuationValue: {exposureInfo.AttenuationValue}");
                    _loggerService.Info($"Exposure.TotalRiskScore: {exposureInfo.TotalRiskScore}");
                    _loggerService.Info($"Exposure.TransmissionRiskLevel: {exposureInfo.TransmissionRiskLevel}");

                    if (exposureInfo.TotalRiskScore >= minimumRiskScore)
                    {
                        existExposureInformationList.Add(new UserExposureInfo(exposureInfo));
                        isNewExposureDetected = true;
                    }
                }

                _loggerService.Info($"Save ExposureSummary. MatchedKeyCount: {exposureSummary.MatchedKeyCount}");
                _loggerService.Info($"Save ExposureInformation. Count: {existExposureInformationList.Count}");

                existExposureInformationList.Sort((a, b) => a.Timestamp.CompareTo(b.Timestamp));

                SetExposureInformation(existExposureInformationList);
            }

            return(isNewExposureDetected);
        }
Ejemplo n.º 13
0
        public async Task ExposureDetectedAsync(ExposureSummary exposureSummary, IList <DailySummary> dailySummaries, IList <ExposureWindow> exposureWindows, ExposureConfiguration exposureConfiguration)
        {
            Logger.D($"ExposureDetected V2: {DateTime.UtcNow}");

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

            var exposureResult = new ExposureResult(
                exposureConfiguration,
                DateTime.Now,
                exposureSummary,
                null,
                dailySummaries, exposureWindows
                )
            {
                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,
                dailySummaries, exposureWindows
                );

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

                File.Delete(filePath);
            }
        }
Ejemplo n.º 14
0
 public ExposureData(ExposureConfiguration exposureConfiguration,
                     ExposureSummary exposureSummary, IList <ExposureInformation> exposureInformations)
     : this(exposureConfiguration, exposureSummary, exposureInformations, null, null)
 {
 }
Ejemplo n.º 15
0
        public async Task ExposureDetectedAsync(ExposureSummary exposureSummary, IList <ExposureInformation> exposureInformations, ExposureConfiguration exposureConfiguration)
        {
            long enVersion = await GetEnClient().GetVersionAsync();

            await _exposureDetectionService.Value.ExposureDetectedAsync(exposureConfiguration, enVersion, exposureSummary, exposureInformations);
        }
Ejemplo n.º 16
0
        public async Task ExposureDetectedAsync(ExposureConfiguration exposureConfiguration, long enVersion, ExposureSummary exposureSummary, IList <ExposureInformation> exposureInformations)
        {
            _loggerService.Info("ExposureDetected: Legacy-V1");

            var enVersionStr = enVersion.ToString();

            ExposureConfiguration.GoogleExposureConfiguration configurationV1 = exposureConfiguration.GoogleExposureConfig;

            bool isNewExposureDetected = _exposureDataRepository.AppendExposureData(
                exposureSummary,
                exposureInformations.ToList(),
                configurationV1.MinimumRiskScore
                );

            if (isNewExposureDetected)
            {
                _ = _localNotificationService.ShowExposureNotificationAsync();
            }
            else
            {
                _loggerService.Info($"MatchedKeyCount: {exposureSummary.MatchedKeyCount}, but no new exposure detected");
            }

            try
            {
                await _exposureDataCollectServer.UploadExposureDataAsync(
                    exposureConfiguration,
                    _deviceInfoUtility.Model,
                    enVersionStr,
                    exposureSummary, exposureInformations
                    );
            }
            catch (Exception e)
            {
                _loggerService.Exception("UploadExposureDataAsync", e);
            }

            string idempotencyKey = Guid.NewGuid().ToString();

            try
            {
                await _eventLogService.SendExposureDataAsync(
                    idempotencyKey,
                    exposureConfiguration,
                    _deviceInfoUtility.Model,
                    enVersionStr,
                    exposureSummary, exposureInformations
                    );
            }
            catch (Exception e)
            {
                _loggerService.Exception("SendExposureDataAsync", e);
            }
        }
Ejemplo n.º 17
0
        public async Task ExposureDetectedAsync(ExposureConfiguration exposureConfiguration, long enVersion, ExposureSummary exposureSummary, IList <ExposureInformation> exposureInformations)
        {
            _loggerService.Info("ExposureDetected: Legacy-V1");

            ExposureConfiguration.GoogleExposureConfiguration configurationV1 = exposureConfiguration.GoogleExposureConfig;

            bool isNewExposureDetected = _exposureDataRepository.AppendExposureData(
                exposureSummary,
                exposureInformations.ToList(),
                configurationV1.MinimumRiskScore
                );

            if (isNewExposureDetected)
            {
                _ = _localNotificationService.ShowExposureNotificationAsync();

                bool enableSendEventExposureNotificationNotified = _sendEventLogStateRepository
                                                                   .GetSendEventLogState(EventType.ExposureNotified) == SendEventLogState.Enable;

                if (enableSendEventExposureNotificationNotified)
                {
                    await _eventLogRepository.AddEventNotifiedAsync();
                }
            }
            else
            {
                _loggerService.Info($"MatchedKeyCount: {exposureSummary.MatchedKeyCount}, but no new exposure detected");
            }
        }
Ejemplo n.º 18
0
 public ExposureResult(ExposureConfiguration exposureConfiguration,
                       DateTime generatedAt,
                       ExposureSummary exposureSummary, IList <ExposureInformation> exposureInformations)
     : this(exposureConfiguration, generatedAt, exposureSummary, exposureInformations, null, null)
 {
 }
Ejemplo n.º 19
0
 public bool AppendExposureData(ExposureSummary exposureSummary, List <ExposureInformation> exposureInformationList, int minimumRiskScore)
 {
     // Do nothing
     return(true);
 }