Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #977 from keiji/suppress_unnecessary_notification
Browse files Browse the repository at this point in the history
Suppress notification if the exposure date time is expired.
  • Loading branch information
cocoa-dev003 authored Apr 28, 2022
2 parents 882a268 + 1c085ec commit 2ce01b1
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Covid19Radar/Covid19Radar/Common/AppConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static readonly DateTime COCOA_FIRST_RELEASE_DATE
/// <summary>
/// Number of days of exposure information to display
/// </summary>
public const int DaysOfExposureInformationToDisplay = -15;
public const int TermOfExposureRecordValidityInDays = -15;

/// <summary>
/// Message when `AppDelagate.OnActivated()` occurs on iOS.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,13 @@ public async Task ExposureDetectedAsync(ExposureConfiguration exposureConfigurat
.GetExposureRiskCalculationConfigurationAsync(preferCache: false);
_loggerService.Info(exposureRiskCalculationConfiguration.ToString());

long expectOldestDateMillisSinceEpoch
= _dateTimeUtility.UtcNow
.AddDays(AppConstants.TermOfExposureRecordValidityInDays)
.ToUnixEpochMillis();

bool isHighRiskExposureDetected = newDailySummaries
.Where(ds => ds.DateMillisSinceEpoch >= expectOldestDateMillisSinceEpoch)
.Select(ds => _exposureRiskCalculationService.CalcRiskLevel(
ds,
newExposureWindows.Where(ew => ew.DateMillisSinceEpoch == ds.DateMillisSinceEpoch).ToList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ var exposureRiskCalculationConfiguration
= await _exposureRiskCalculationConfigurationRepository.GetExposureRiskCalculationConfigurationAsync(preferCache: true);
loggerService.Info(exposureRiskCalculationConfiguration.ToString());

var userExposureInformationList = _exposureDataRepository.GetExposureInformationList(AppConstants.DaysOfExposureInformationToDisplay);
var userExposureInformationList = _exposureDataRepository.GetExposureInformationList(AppConstants.TermOfExposureRecordValidityInDays);

string contactedNotifyPageCountFormat = AppResources.ContactedNotifyPageCountOneText;
if (userExposureInformationList.Count() > 1)
{
contactedNotifyPageCountFormat = AppResources.ContactedNotifyPageCountText;
}

var dailySummaryList = await _exposureDataRepository.GetDailySummariesAsync(AppConstants.DaysOfExposureInformationToDisplay);
var dailySummaryList = await _exposureDataRepository.GetDailySummariesAsync(AppConstants.TermOfExposureRecordValidityInDays);
var dailySummaryMap = dailySummaryList.ToDictionary(ds => ds.GetDateTime());
var exposureWindowList = await _exposureDataRepository.GetExposureWindowsAsync(AppConstants.DaysOfExposureInformationToDisplay);
var exposureWindowList = await _exposureDataRepository.GetExposureWindowsAsync(AppConstants.TermOfExposureRecordValidityInDays);

int dayCount = 0;
long exposureDurationInSec = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public async Task Setup()
_loggerService.StartMethod();

List<DailySummary> dailySummaryList = await _exposureDataRepository
.GetDailySummariesAsync(AppConstants.DaysOfExposureInformationToDisplay);
.GetDailySummariesAsync(AppConstants.TermOfExposureRecordValidityInDays);

if (dailySummaryList.Count() == 0)
{
Expand All @@ -182,7 +182,7 @@ public async Task Setup()
_loggerService.Debug($"dailySummaryMap {dailySummaryMap.Count}");

var exposureWindowList
= await _exposureDataRepository.GetExposureWindowsAsync(AppConstants.DaysOfExposureInformationToDisplay);
= await _exposureDataRepository.GetExposureWindowsAsync(AppConstants.TermOfExposureRecordValidityInDays);

_loggerService.Debug($"exposureWindowList {exposureWindowList.Count}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ var exposureRiskCalculationConfiguration
_loggerService.Info(exposureRiskCalculationConfiguration.ToString());

var dailySummaryList
= await _exposureDataRepository.GetDailySummariesAsync(AppConstants.DaysOfExposureInformationToDisplay);
= await _exposureDataRepository.GetDailySummariesAsync(AppConstants.TermOfExposureRecordValidityInDays);
var dailySummaryMap = dailySummaryList.ToDictionary(ds => ds.GetDateTime());

var exposureWindowList
= await _exposureDataRepository.GetExposureWindowsAsync(AppConstants.DaysOfExposureInformationToDisplay);
= await _exposureDataRepository.GetExposureWindowsAsync(AppConstants.TermOfExposureRecordValidityInDays);

var userExposureInformationList
= _exposureDataRepository.GetExposureInformationList(AppConstants.DaysOfExposureInformationToDisplay);
= _exposureDataRepository.GetExposureInformationList(AppConstants.TermOfExposureRecordValidityInDays);

if (dailySummaryList.Count() > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ private void ExposureDetectionAsync()
.GetExposureRiskCalculationConfigurationAsync(preferCache: true);
loggerService.Info(exposureRiskCalculationConfiguration.ToString());
var dailySummaryList = await _exposureDataRepository.GetDailySummariesAsync(AppConstants.DaysOfExposureInformationToDisplay);
var dailySummaryList = await _exposureDataRepository.GetDailySummariesAsync(AppConstants.TermOfExposureRecordValidityInDays);
var dailySummaryMap = dailySummaryList.ToDictionary(ds => ds.GetDateTime());
var exposureWindowList = await _exposureDataRepository.GetExposureWindowsAsync(AppConstants.DaysOfExposureInformationToDisplay);
var exposureWindowList = await _exposureDataRepository.GetExposureWindowsAsync(AppConstants.TermOfExposureRecordValidityInDays);
var userExposureInformationList = _exposureDataRepository.GetExposureInformationList(AppConstants.DaysOfExposureInformationToDisplay);
var userExposureInformationList = _exposureDataRepository.GetExposureInformationList(AppConstants.TermOfExposureRecordValidityInDays);
var hasExposure = dailySummaryList.Count() > 0 || userExposureInformationList.Count() > 0;
var hasHighRiskExposure = userExposureInformationList.Count() > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public async Task UpdateInfo(string exception = "")

var exposureNotificationStatus = await _exposureNotificationApiService.IsEnabledAsync();

var dailySummaryCount = (await _exposureDataRepository.GetDailySummariesAsync(AppConstants.DaysOfExposureInformationToDisplay)).Count();
var exposureWindowCount = (await _exposureDataRepository.GetExposureWindowsAsync(AppConstants.DaysOfExposureInformationToDisplay)).Count();
var dailySummaryCount = (await _exposureDataRepository.GetDailySummariesAsync(AppConstants.TermOfExposureRecordValidityInDays)).Count();
var exposureWindowCount = (await _exposureDataRepository.GetExposureWindowsAsync(AppConstants.TermOfExposureRecordValidityInDays)).Count();

// ../../settings.json
var settings = new[] {
Expand All @@ -113,7 +113,7 @@ public async Task UpdateInfo(string exception = "")
$"PrivacyPolicyUpdatedDateTimeUtc: {privacyPolicyUpdateDateTimeUtc}",
$"StartDate: {_userDataRepository.GetStartDate().ToLocalTime().ToString("F")}",
$"DaysOfUse: {_userDataRepository.GetDaysOfUse()}",
$"Legacy-V1 ExposureCount: {_exposureDataRepository.GetExposureInformationList(AppConstants.DaysOfExposureInformationToDisplay).Count()}",
$"Legacy-V1 ExposureCount: {_exposureDataRepository.GetExposureInformationList(AppConstants.TermOfExposureRecordValidityInDays).Count()}",
$"DailySummaryCount: {dailySummaryCount}",
$"ExposureWindowCount: {exposureWindowCount}",
$"LastProcessTekTimestamp: {lastProcessTekTimestampsStr}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ public void GetExposureInformationListToDisplayTests_Success(int day, int expect
mockSecureStorageService.Setup(x => x.GetStringValue("ExposureInformation", default)).Returns("[{\"Timestamp\":\"2021-01-01T00:00:00\",\"Duration\":\"00:05:00.000\",\"AttenuationValue\":3,\"TotalRiskScore\":21,\"TransmissionRiskLevel\":4},{\"Timestamp\":\"2021-01-02T00:00:00\",\"Duration\":\"00:05:00.000\",\"AttenuationValue\":3,\"TotalRiskScore\":21,\"TransmissionRiskLevel\":4},{\"Timestamp\":\"2021-01-03T00:00:00\",\"Duration\":\"00:05:00.000\",\"AttenuationValue\":3,\"TotalRiskScore\":21,\"TransmissionRiskLevel\":4},{\"Timestamp\":\"2021-01-04T00:00:00\",\"Duration\":\"00:05:00.000\",\"AttenuationValue\":3,\"TotalRiskScore\":21,\"TransmissionRiskLevel\":4}]");
mockDateTimeUtility.Setup(x => x.UtcNow).Returns(new DateTime(2021, 1, day, 0, 0, 0));

var result = unitUnderTest.GetExposureInformationList(AppConstants.DaysOfExposureInformationToDisplay);
var result = unitUnderTest.GetExposureInformationList(AppConstants.TermOfExposureRecordValidityInDays);

Assert.Equal(expectedCount, result.Count);
for (int idx = 0; idx < expectedCount; idx++)
Expand All @@ -446,7 +446,7 @@ public void GetExposureInformationListToDisplayTests_NoData()
mockSecureStorageService.Setup(x => x.GetStringValue("ExposureInformation", default)).Returns((string)(object)null);
mockDateTimeUtility.Setup(x => x.UtcNow).Returns(new DateTime(2021, 1, 1, 0, 0, 0));

var result = unitUnderTest.GetExposureInformationList(AppConstants.DaysOfExposureInformationToDisplay);
var result = unitUnderTest.GetExposureInformationList(AppConstants.TermOfExposureRecordValidityInDays);

Assert.NotNull(result);
Assert.Empty(result);
Expand All @@ -462,7 +462,7 @@ public void GetExposureInformationListToDisplayTests_Jst(int day, int hour, int
mockSecureStorageService.Setup(x => x.GetStringValue("ExposureInformation", default)).Returns("[{\"Timestamp\":\"2021-01-01T00:00:00\",\"Duration\":\"00:05:00.000\",\"AttenuationValue\":3,\"TotalRiskScore\":21,\"TransmissionRiskLevel\":4},{\"Timestamp\":\"2021-01-02T00:00:00\",\"Duration\":\"00:05:00.000\",\"AttenuationValue\":3,\"TotalRiskScore\":21,\"TransmissionRiskLevel\":4},{\"Timestamp\":\"2021-01-03T00:00:00\",\"Duration\":\"00:05:00.000\",\"AttenuationValue\":3,\"TotalRiskScore\":21,\"TransmissionRiskLevel\":4},{\"Timestamp\":\"2021-01-04T00:00:00\",\"Duration\":\"00:05:00.000\",\"AttenuationValue\":3,\"TotalRiskScore\":21,\"TransmissionRiskLevel\":4}]");
mockDateTimeUtility.Setup(x => x.UtcNow).Returns(new DateTime(2021, 1, day, hour, minute, 0).AddHours(-9));

var result = unitUnderTest.GetExposureInformationList(AppConstants.DaysOfExposureInformationToDisplay);
var result = unitUnderTest.GetExposureInformationList(AppConstants.TermOfExposureRecordValidityInDays);

Assert.Equal(expectedCount, result.Count);
for (int idx = 0; idx < expectedCount; idx++)
Expand All @@ -485,7 +485,7 @@ public void GetV1ExposureCountToDisplayTests_Success(int day, int expectedCount)
mockSecureStorageService.Setup(x => x.GetStringValue("ExposureInformation", default)).Returns("[{\"Timestamp\":\"2021-01-01T00:00:00\",\"Duration\":\"00:05:00.000\",\"AttenuationValue\":3,\"TotalRiskScore\":21,\"TransmissionRiskLevel\":4},{\"Timestamp\":\"2021-01-02T00:00:00\",\"Duration\":\"00:05:00.000\",\"AttenuationValue\":3,\"TotalRiskScore\":21,\"TransmissionRiskLevel\":4},{\"Timestamp\":\"2021-01-03T00:00:00\",\"Duration\":\"00:05:00.000\",\"AttenuationValue\":3,\"TotalRiskScore\":21,\"TransmissionRiskLevel\":4},{\"Timestamp\":\"2021-01-04T00:00:00\",\"Duration\":\"00:05:00.000\",\"AttenuationValue\":3,\"TotalRiskScore\":21,\"TransmissionRiskLevel\":4}]");
mockDateTimeUtility.Setup(x => x.UtcNow).Returns(new DateTime(2021, 1, day, 0, 0, 0));

var result = unitUnderTest.GetExposureInformationList(AppConstants.DaysOfExposureInformationToDisplay).Count();
var result = unitUnderTest.GetExposureInformationList(AppConstants.TermOfExposureRecordValidityInDays).Count();

Assert.Equal(expectedCount, result);
}
Expand All @@ -498,7 +498,7 @@ public void GetV1ExposureCountToDisplayTests_NoData()
mockSecureStorageService.Setup(x => x.GetStringValue("ExposureInformation", default)).Returns((string)(object)null);
mockDateTimeUtility.Setup(x => x.UtcNow).Returns(new DateTime(2021, 1, 1, 0, 0, 0));

var result = unitUnderTest.GetExposureInformationList(AppConstants.DaysOfExposureInformationToDisplay).Count();
var result = unitUnderTest.GetExposureInformationList(AppConstants.TermOfExposureRecordValidityInDays).Count();

Assert.Equal(0, result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,16 @@ public void DiagnosisKeysDataMappingApplied_ConfigurationNotUpdated()
public async void ExposureDetected_HighRiskExposureDetected()
{
// Test Data
var now = new DateTime(2022, 04, 17, 12, 00, 00, DateTimeKind.Utc);
var exposureDateTime = now
.AddDays(AppConstants.TermOfExposureRecordValidityInDays);
var exposureConfiguration = new ExposureConfiguration();
var enVersion = 2;

var dailySummaries = new List<DailySummary>() {
new DailySummary()
{
DateMillisSinceEpoch = 0,
DateMillisSinceEpoch = exposureDateTime.ToUnixEpochMillis(),
DaySummary = new ExposureSummaryData(),
ConfirmedClinicalDiagnosisSummary = new ExposureSummaryData(),
ConfirmedTestSummary = new ExposureSummaryData(),
Expand All @@ -212,14 +215,16 @@ public async void ExposureDetected_HighRiskExposureDetected()
new ExposureWindow()
{
CalibrationConfidence = CalibrationConfidence.High,
DateMillisSinceEpoch = 0,
DateMillisSinceEpoch = exposureDateTime.ToUnixEpochMillis(),
Infectiousness = Infectiousness.High,
ReportType = ReportType.Unknown,
ScanInstances = new List<ScanInstance>()
}
};

// Mock Setup
dateTimeUtility.Setup(x => x.UtcNow)
.Returns(now);
preferencesService
.Setup(x => x.GetBoolValue(It.Is<string>(x => x == "IsDiagnosisKeysDataMappingConfigurationUpdated"), false))
.Returns(true);
Expand Down Expand Up @@ -259,13 +264,16 @@ public async void ExposureDetected_HighRiskExposureDetected()
public async void ExposureDetected_HighRiskExposureNotDetected()
{
// Test Data
var now = new DateTime(2022, 04, 17, 12, 00, 00, DateTimeKind.Utc);
var exposureDateTime = now
.AddDays(AppConstants.TermOfExposureRecordValidityInDays);
var exposureConfiguration = new ExposureConfiguration();
var enVersion = 2;

var dailySummaries = new List<DailySummary>() {
new DailySummary()
{
DateMillisSinceEpoch = 0,
DateMillisSinceEpoch = exposureDateTime.ToUnixEpochMillis(),
DaySummary = new ExposureSummaryData(),
ConfirmedClinicalDiagnosisSummary = new ExposureSummaryData(),
ConfirmedTestSummary = new ExposureSummaryData(),
Expand All @@ -279,14 +287,89 @@ public async void ExposureDetected_HighRiskExposureNotDetected()
new ExposureWindow()
{
CalibrationConfidence = CalibrationConfidence.High,
DateMillisSinceEpoch = 0,
DateMillisSinceEpoch = exposureDateTime.ToUnixEpochMillis(),
Infectiousness = Infectiousness.High,
ReportType = ReportType.Unknown,
ScanInstances = new List<ScanInstance>()
}
};

// Mock Setup
dateTimeUtility.Setup(x => x.UtcNow)
.Returns(now);
preferencesService.
Setup(x => x.GetBoolValue(It.Is<string>(x => x == "IsDiagnosisKeysDataMappingConfigurationUpdated"), false))
.Returns(true);
secureStorageService
.Setup(x => x.GetStringValue(It.Is<string>(x => x == "DailySummaries"), It.IsAny<string>()))
.Returns("[]");
secureStorageService
.Setup(x => x.GetStringValue(It.Is<string>(x => x == "ExposureWindows"), It.IsAny<string>()))
.Returns("[]");
exposureDataCollectServer
.Setup(x => x.UploadExposureDataAsync(
It.IsAny<ExposureConfiguration>(),
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<List<DailySummary>>(),
It.IsAny<List<ExposureWindow>>()));
deviceInfoUtility.Setup(x => x.Model).Returns("UnitTest");

exposureRiskCalculationConfigurationRepository
.Setup(x => x.GetExposureRiskCalculationConfigurationAsync(It.IsAny<bool>()))
.ReturnsAsync(new V1ExposureRiskCalculationConfiguration());

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

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


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

[Fact]
public async void ExposureDetected_HighRiskExposureNotDetected_ExpiredDate()
{
// Test Data
var now = new DateTime(2022, 04, 17, 12, 00, 00, DateTimeKind.Utc);
var exposureDateTime = now
.AddDays(AppConstants.TermOfExposureRecordValidityInDays)
.AddDays(-1);
var exposureConfiguration = new ExposureConfiguration();
var enVersion = 2;

var dailySummaries = new List<DailySummary>() {
new DailySummary()
{
DateMillisSinceEpoch = exposureDateTime.ToUnixEpochMillis(),
DaySummary = new ExposureSummaryData(),
ConfirmedClinicalDiagnosisSummary = new ExposureSummaryData(),
ConfirmedTestSummary = new ExposureSummaryData(),
RecursiveSummary = new ExposureSummaryData(),
SelfReportedSummary = new ExposureSummaryData()
}
};

var exposureWindows = new List<ExposureWindow>()
{
new ExposureWindow()
{
CalibrationConfidence = CalibrationConfidence.High,
DateMillisSinceEpoch = exposureDateTime.ToUnixEpochMillis(),
Infectiousness = Infectiousness.High,
ReportType = ReportType.Unknown,
ScanInstances = new List<ScanInstance>()
}
};

// Mock Setup
dateTimeUtility.Setup(x => x.UtcNow)
.Returns(now);
preferencesService.
Setup(x => x.GetBoolValue(It.Is<string>(x => x == "IsDiagnosisKeysDataMappingConfigurationUpdated"), false))
.Returns(true);
Expand Down
Loading

0 comments on commit 2ce01b1

Please sign in to comment.