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

Fixed to save isMaxPerDayExposureDetectionAPILimitReached in the app #993

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Covid19Radar/Covid19Radar/Common/PreferenceKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static class PreferenceKey
public static string PrivacyPolicyLastUpdateDateTimeEpoch = "PrivacyPolicyLastUpdateDateTimeEpoch";

public static string CanConfirmExposure = "CanConfirmExposure";
public static string IsMaxPerDayExposureDetectionAPILimitReached = "IsMaxPerDayExposureDetectionAPILimitReached";
public static string LastConfirmedDateTimeEpoch = "LastConfirmedDateTimeEpoch";

public static string SendEventLogState = "SendEventLogState";
Expand Down
19 changes: 19 additions & 0 deletions Covid19Radar/Covid19Radar/Repository/UserDataRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public interface IUserDataRepository
void SetCanConfirmExposure(bool canConfirmExposure);
bool IsCanConfirmExposure();

void SetIsMaxPerDayExposureDetectionAPILimitReached(bool isMaxPerDayExposureDetectionAPILimitReached);
bool IsMaxPerDayExposureDetectionAPILimitReached();

void SetLastConfirmedDate(DateTime utcNow);
DateTime? GetLastConfirmedDate();

Expand Down Expand Up @@ -218,6 +221,22 @@ public bool IsCanConfirmExposure()
return canConfirmExposure;
}

public void SetIsMaxPerDayExposureDetectionAPILimitReached(bool isMaxPerDayExposureDetectionAPILimitReached)
{
_loggerService.StartMethod();
_preferencesService.SetBoolValue(PreferenceKey.IsMaxPerDayExposureDetectionAPILimitReached, isMaxPerDayExposureDetectionAPILimitReached);
_loggerService.EndMethod();
}

public bool IsMaxPerDayExposureDetectionAPILimitReached()
{
_loggerService.StartMethod();
var isMaxPerDayExposureDetectionAPILimitReached = _preferencesService.GetBoolValue(PreferenceKey.IsMaxPerDayExposureDetectionAPILimitReached, false);
_loggerService.EndMethod();

return isMaxPerDayExposureDetectionAPILimitReached;
}

public void SetLastConfirmedDate(DateTime dateTime)
{
_loggerService.StartMethod();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ private async Task InternalExposureDetectionAsync(CancellationTokenSource cancel
await _serverConfigurationRepository.LoadAsync();

bool canConfirmExposure = true;
bool isMaxPerDayExposureDetectionAPILimitReached = false;

foreach (var region in _serverConfigurationRepository.Regions)
{
Expand Down Expand Up @@ -161,10 +162,12 @@ await _exposureNotificationApiService.ProvideDiagnosisKeysAsync(

_userDataRepository.SetLastConfirmedDate(_dateTimeUtility.UtcNow);
_userDataRepository.SetCanConfirmExposure(true);
_userDataRepository.SetIsMaxPerDayExposureDetectionAPILimitReached(isMaxPerDayExposureDetectionAPILimitReached);
}
catch (ENException exception)
{
canConfirmExposure = false;
isMaxPerDayExposureDetectionAPILimitReached = CheckMaxPerDayExposureDetectionAPILimitReached(exception);
_loggerService.Exception($"ENExcepiton occurred, Code:{exception.Code}, Message:{exception.Message}", exception);
throw;
}
Expand All @@ -178,6 +181,7 @@ await _exposureNotificationApiService.ProvideDiagnosisKeysAsync(
{
RemoveFiles(downloadedFileNameList);
_userDataRepository.SetCanConfirmExposure(canConfirmExposure);
_userDataRepository.SetIsMaxPerDayExposureDetectionAPILimitReached(isMaxPerDayExposureDetectionAPILimitReached);
}
}
}
Expand Down Expand Up @@ -236,5 +240,10 @@ private void RemoveFiles(List<string> fileList)

_loggerService.EndMethod();
}

private bool CheckMaxPerDayExposureDetectionAPILimitReached(ENException ex)
{
return ex.Code == ENException.Code_iOS.RateLimited || ex.Code == ENException.Code_Android.FAILED_RATE_LIMITED;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ public bool IsVisibleLocalNotificationOffWarningLayout

private bool _isShowTroubleshootingPage = false;

private bool _isMaxPerDayExposureDetectionAPILimitReached = false;

private string _enStatusUnconfirmedDescription1;
public string EnStatusUnconfirmedDescription1
{
Expand Down Expand Up @@ -220,8 +218,6 @@ private void ExposureDetectionAsync()
catch (ENException ex)
{
loggerService.Exception("Failed to exposure detection.", ex);
// Check if the exposure detection API limit has been reached
_isMaxPerDayExposureDetectionAPILimitReached = ex.Code == ENException.Code_iOS.RateLimited || ex.Code == ENException.Code_Android.FAILED_RATE_LIMITED;
}
catch (Exception ex)
{
Expand Down Expand Up @@ -431,11 +427,12 @@ private async Task UpdateView()
IsVisibleENStatusUnconfirmedLayout = true;
IsVisibleENStatusStoppedLayout = false;

EnStatusUnconfirmedDescription1 = _isMaxPerDayExposureDetectionAPILimitReached
var isMaxPerDayExposureDetectionAPILimitReached = _userDataRepository.IsMaxPerDayExposureDetectionAPILimitReached();
EnStatusUnconfirmedDescription1 = isMaxPerDayExposureDetectionAPILimitReached
? AppResources.HomePageExposureDetectionAPILimitReachedDescription1 : AppResources.HomePageENStatusUnconfirmedDescription1;
EnStatusUnconfirmedDescription2 = _isMaxPerDayExposureDetectionAPILimitReached
EnStatusUnconfirmedDescription2 = isMaxPerDayExposureDetectionAPILimitReached
? AppResources.HomePageExposureDetectionAPILimitReachedDescription2 : AppResources.HomePageENStatusUnconfirmedDescription2;
IsVisibleUnconfirmedTroubleshootingButton = !_isMaxPerDayExposureDetectionAPILimitReached;
IsVisibleUnconfirmedTroubleshootingButton = !isMaxPerDayExposureDetectionAPILimitReached;
}
else
{
Expand Down
5 changes: 3 additions & 2 deletions Covid19Radar/Covid19Radar/Views/HomePage/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
BackgroundColor="#EEEEEE"
Spacing="15">
<xct:SemanticOrderView
x:Name="activeLayoutOrderView">
<StackLayout IsVisible="{Binding IsVisibleENStatusActiveLayout}">
cocoa-dev003 marked this conversation as resolved.
Show resolved Hide resolved
x:Name="activeLayoutOrderView"
IsVisible="{Binding IsVisibleENStatusActiveLayout}">
<StackLayout>
<StackLayout
Orientation="Horizontal"
HorizontalOptions="Center"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ public async Task ExposureDetectionAsync_ListFileNotFound()
// Assert
mockDiagnosisKeyRepository.Verify(x => x.GetDiagnosisKeysListAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()), Times.Once);
mockDiagnosisKeyRepository.Verify(x => x.DownloadDiagnosisKeysAsync(It.IsAny<DiagnosisKeyEntry>(), It.IsAny<string>(), It.IsAny<CancellationToken>()), Times.Never);
mockUserDataRepository.Verify(x => x.SetCanConfirmExposure(false), Times.Once);
mockUserDataRepository.Verify(x => x.SetCanConfirmExposure(false), Times.Once());
mockUserDataRepository.Verify(x => x.SetIsMaxPerDayExposureDetectionAPILimitReached(false), Times.Once());
}

[Fact(Skip = "[Occurs on Windows] System.IO.IOException : The process cannot access the file '1.zip' because it is being used by another process.")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ public void UpdateView_ENStatus_Unconfirmed()
mockPreferenceService
.Setup(x => x.GetBoolValue("CanConfirmExposure", true))
.Returns(false);
mockPreferenceService
.Setup(x => x.GetBoolValue("IsMaxPerDayExposureDetectionAPILimitReached", false))
.Returns(false);

homePageViewModel.OnAppearing();

Expand All @@ -230,6 +233,32 @@ public void UpdateView_ENStatus_Unconfirmed()
Assert.True(homePageViewModel.IsVisibleUnconfirmedTroubleshootingButton);
}

[Fact]
public void UpdateView_ENStatus_Unconfirmed_Exposure_Detection_API_Limit_Reached()
{
var homePageViewModel = CreateViewModel();

mockExposureNotificationApiService
.Setup(x => x.GetStatusCodesAsync())
.Returns(Task.FromResult(new List<int>() { ExposureNotificationStatus.Code_Android.ACTIVATED } as IList<int>));

mockPreferenceService
.Setup(x => x.GetBoolValue("CanConfirmExposure", true))
.Returns(false);
mockPreferenceService
.Setup(x => x.GetBoolValue("IsMaxPerDayExposureDetectionAPILimitReached", false))
.Returns(true);

homePageViewModel.OnAppearing();

Assert.False(homePageViewModel.IsVisibleENStatusActiveLayout);
Assert.True(homePageViewModel.IsVisibleENStatusUnconfirmedLayout);
Assert.False(homePageViewModel.IsVisibleENStatusStoppedLayout);
Assert.Equal(AppResources.HomePageExposureDetectionAPILimitReachedDescription1, homePageViewModel.EnStatusUnconfirmedDescription1);
Assert.Equal(AppResources.HomePageExposureDetectionAPILimitReachedDescription2, homePageViewModel.EnStatusUnconfirmedDescription2);
Assert.False(homePageViewModel.IsVisibleUnconfirmedTroubleshootingButton);
}

[Fact]
public void UpdateView_ENStatus_Stopped()
{
Expand Down