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 #1129 from cocoa-mhlw/release/v2.1.0
Browse files Browse the repository at this point in the history
Release/v2.1.0
  • Loading branch information
cocoa-dev001 authored Sep 6, 2022
2 parents 56b7c04 + c57b9e6 commit 294db91
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 35 deletions.
32 changes: 0 additions & 32 deletions Covid19Radar/Covid19Radar.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,6 @@ public override bool FinishedLaunching(UIApplication app, NSDictionary launchOpt
// https://developer.apple.com/documentation/backgroundtasks/bgtaskscheduler/3180427-register
ScheduleBackgroundTasks();

try
{
LoggingPendingTaskRequests();
}
catch (Exception ex)
{
_loggerService.Value.Exception("Failure get pending task requests", ex);
}

return base.FinishedLaunching(app, launchOptions);
}

Expand Down Expand Up @@ -167,20 +158,6 @@ private void ScheduleBackgroundTasks()
_loggerService.Value.EndMethod();
}

private void LoggingPendingTaskRequests()
{
_loggerService.Value.Info($"Get pending task requests");
BGTaskScheduler.Shared.GetPending(pendingTaskRequests =>
{
_loggerService.Value.Info($"Pending task count: {pendingTaskRequests.Length}");
foreach (var pendingTaskRequest in pendingTaskRequests)
{
string identifier = pendingTaskRequest.Identifier.Split(".")?.Last();
_loggerService.Value.Info($"Identifier: {identifier}, EarliestBeginDate: {pendingTaskRequest.EarliestBeginDate}");
}
});
}

private bool IsUniversalLinks(NSDictionary launchOptions)
{
if (launchOptions == null)
Expand Down Expand Up @@ -293,15 +270,6 @@ public override void OnActivated(UIApplication uiApplication)
{
base.OnActivated(uiApplication);
MessagingCenter.Send((object)this, AppConstants.IosOnActivatedMessage);

try
{
LoggingPendingTaskRequests();
}
catch (Exception ex)
{
_loggerService.Value.Exception("Failure get pending task requests", ex);
}
}

private void RegisterPlatformTypes(IContainer container)
Expand Down
1 change: 1 addition & 0 deletions Covid19Radar/Covid19Radar.iOS/Covid19Radar.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@
<Compile Include="Services\LocalPathService.cs" />
<Compile Include="Services\EventLogSubmissionBackgroundService.cs" />
<Compile Include="Services\DataMaintainanceBackgroundService.cs" />
<Compile Include="Services\Migration\BGTaskMigrator.cs" />
</ItemGroup>
<ItemGroup>
<ImageAsset Include="Assets.xcassets\Contents.json">
Expand Down
43 changes: 43 additions & 0 deletions Covid19Radar/Covid19Radar.iOS/Services/Migration/BGTaskMigrator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

using System.Threading.Tasks;
using BackgroundTasks;
using Covid19Radar.Services.Logs;
using Xamarin.Essentials;

namespace Covid19Radar.iOS.Services.Migration
{
internal class BGTaskMigrator
{
// Array of old identifier.
private static readonly string[] OLD_IDENTIFIER_ARRAY = {
AppInfo.PackageName + ".delete-old-logs",
};

private readonly ILoggerService _loggerService;

public BGTaskMigrator(
ILoggerService loggerService
)
{
_loggerService = loggerService;
}

internal Task ExecuteAsync()
{
_loggerService.StartMethod();

foreach (var identifier in OLD_IDENTIFIER_ARRAY)
{
BGTaskScheduler.Shared.Cancel(identifier);
_loggerService.Info($"BGTask {identifier} has been canceled.");
}

_loggerService.EndMethod();

return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,32 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

using Covid19Radar.Services.Logs;
using System.Threading.Tasks;
using Covid19Radar.Services.Migration;

namespace Covid19Radar.iOS.Services.Migration
{
public class MigrationProcessService : IMigrationProcessService
{
// Currently, It is not needed that iOS platform specific migration process.
private readonly ILoggerService _loggerService;

public MigrationProcessService(
ILoggerService loggerService
)
{
_loggerService = loggerService;
}

public async Task SetupAsync()
{
_loggerService.StartMethod();

await new BGTaskMigrator(
_loggerService
).ExecuteAsync();

_loggerService.EndMethod();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ContactedNotifyPageViewModel : ViewModelBase
private readonly ILoggerService loggerService;
private readonly IExposureDataRepository _exposureDataRepository;
private readonly IExposureRiskCalculationService _exposureRiskCalculationService;
private readonly IExposureRiskCalculationConfigurationRepository _exposureRiskCalculationConfigurationRepository;

private V1ExposureRiskCalculationConfiguration _exposureRiskCalculationConfiguration;

Expand All @@ -45,12 +46,14 @@ public ContactedNotifyPageViewModel(
INavigationService navigationService,
ILoggerService loggerService,
IExposureDataRepository exposureDataRepository,
IExposureRiskCalculationService exposureRiskCalculationService
IExposureRiskCalculationService exposureRiskCalculationService,
IExposureRiskCalculationConfigurationRepository exposureRiskCalculationConfigurationRepository
) : base(navigationService)
{
this.loggerService = loggerService;
_exposureDataRepository = exposureDataRepository;
_exposureRiskCalculationService = exposureRiskCalculationService;
_exposureRiskCalculationConfigurationRepository = exposureRiskCalculationConfigurationRepository;

Title = AppResources.TitileUserStatusSettings;
}
Expand All @@ -65,6 +68,12 @@ public override async void Initialize(INavigationParameters parameters)

_exposureRiskCalculationConfiguration =
parameters.GetValue<V1ExposureRiskCalculationConfiguration>(ContactedNotifyPage.ExposureRiskCalculationConfigurationKey);
if (_exposureRiskCalculationConfiguration is null)
{
// When transitioned from a exposure notification, it is not passed as a parameter, so it is retrieved.
_exposureRiskCalculationConfiguration =
await _exposureRiskCalculationConfigurationRepository.GetExposureRiskCalculationConfigurationAsync(preferCache: true);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class ContactedNotifyPageViewModelTests : IDisposable
private readonly Mock<ILoggerService> mockLoggerService;
private readonly Mock<IExposureRiskCalculationService> mockExposureRiskCalculationService;
private readonly Mock<IExposureDataRepository> mockExposureDataRepository;
private readonly Mock<IExposureRiskCalculationConfigurationRepository> mockExposureRiskCalculationConfigurationRepository;
private readonly CultureInfo originalAppResourceCalture;
private readonly CultureInfo originalThreadCalture;
private readonly CultureInfo originalThreadUICalture;
Expand All @@ -47,6 +48,7 @@ public ContactedNotifyPageViewModelTests()
mockLoggerService = mockRepository.Create<ILoggerService>();
mockExposureRiskCalculationService = mockRepository.Create<IExposureRiskCalculationService>();
mockExposureDataRepository = mockRepository.Create<IExposureDataRepository>();
mockExposureRiskCalculationConfigurationRepository = mockRepository.Create<IExposureRiskCalculationConfigurationRepository>();
}

public void Dispose()
Expand All @@ -63,7 +65,8 @@ private ContactedNotifyPageViewModel CreateViewModel()
mockNavigationService.Object,
mockLoggerService.Object,
mockExposureDataRepository.Object,
mockExposureRiskCalculationService.Object
mockExposureRiskCalculationService.Object,
mockExposureRiskCalculationConfigurationRepository.Object
);
}

Expand Down Expand Up @@ -195,6 +198,51 @@ public void OnClickExposuresTest_Initialize_NoExposureInformation_NoHighRisk()
Assert.Equal("2 件", contactedNotifyViewModel.ExposureCount);
}

[Fact]
public void OnClickExposuresTest_Initialize_NavigationParameter_NotSet()
{
mockExposureDataRepository
.Setup(x => x.GetExposureInformationList(AppConstants.TermOfExposureRecordValidityInDays))
.Returns(new List<UserExposureInfo>()
{
new UserExposureInfo(),
new UserExposureInfo()
});
mockExposureDataRepository
.Setup(x => x.GetDailySummariesAsync(AppConstants.TermOfExposureRecordValidityInDays))
.Returns(Task.FromResult(new List<DailySummary>()
{
new DailySummary()
{
DateMillisSinceEpoch = 1000L * 60 * 60 * 24 * 365
}
}));
mockExposureDataRepository
.Setup(x => x.GetExposureWindowsAsync(AppConstants.TermOfExposureRecordValidityInDays))
.Returns(Task.FromResult(new List<ExposureWindow>()
{
new ExposureWindow()
{
DateMillisSinceEpoch = 1000L * 60 * 60 * 24 * 365,
ScanInstances = new List<ScanInstance>() {
new ScanInstance()
{
SecondsSinceLastScan = 60
}
}
}
}));

mockExposureRiskCalculationConfigurationRepository
.Setup(x => x.GetExposureRiskCalculationConfigurationAsync(true))
.ReturnsAsync(new V1ExposureRiskCalculationConfiguration());

var contactedNotifyViewModel = CreateViewModel();
contactedNotifyViewModel.Initialize(new NavigationParameters());

mockExposureRiskCalculationConfigurationRepository.Verify(x => x.GetExposureRiskCalculationConfigurationAsync(true), Times.Once());
}

[Fact]
public async Task OnExposureListTest()
{
Expand Down

0 comments on commit 294db91

Please sign in to comment.