Skip to content
This repository was archived by the owner on Apr 12, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cdbe128
Migrate from AlarmManager to WorkManager
keiji Dec 27, 2021
6e2acc6
Schedule LogPeriodicDelete to WorkManager on Migrating process.
keiji Dec 27, 2021
7b50be6
Merge branch 'develop' of github.com:cocoa-mhlw/cocoa into cocoa2/log…
keiji Apr 22, 2022
ce749bd
Merge branch 'develop' of github.com:cocoa-mhlw/cocoa into cocoa2/log…
keiji Jun 22, 2022
60b4163
Move LogPeriodicDeleteService scheduling from App to AppDelegate and …
keiji Jun 22, 2022
506123b
Fix the issue that restoring NuGet packages failed on mac-latest image.
keiji Jun 18, 2022
bf67ec4
Update CIserver.yml
keiji Jun 22, 2022
4ba25b4
Migrate BGAppRefreshTaskRequest to BGProcessingTaskRequest
keiji Jun 24, 2022
eddd4b6
Fix build.
keiji Jun 24, 2022
ff3215a
Merge branch 'develop' of github.com:cocoa-mhlw/cocoa into cocoa2/log…
keiji Jun 24, 2022
3e6bce7
Add log.
keiji Jun 24, 2022
5258916
COCOA will not use BGAppRefreshTask.
keiji Jun 25, 2022
961c89e
Rename LogPeriodicDeleteService to DataMaintainanceBackgroundService.
keiji Jun 26, 2022
621cece
Update log.
keiji Jun 26, 2022
12a886c
Rename argument/variable.
keiji Jun 26, 2022
1d546a3
Update log.
keiji Jun 26, 2022
79961b6
Add logs.
keiji Jun 26, 2022
e8c7622
Refactoring.
keiji Jun 28, 2022
6a2d85f
Change ExistingPeriodicWorkPolicy to Keep.
keiji Jun 28, 2022
143c9a6
Change BGAppRefreshTaskRequest to BGProcessingTaskRequest.
keiji Jun 28, 2022
2ac3d64
Add handling AbsEventLogSubmissionBackgroundService to WorkManagerMig…
keiji Jun 28, 2022
cb7607c
Fix build.
keiji Jun 28, 2022
b4734b4
Move Rotate execution from App to SplashPageViewModel.
keiji Jun 28, 2022
28a3cfc
Adjust .SetPeriodStartTime from 24 hours later to 00:00 in UTC.
keiji Jun 28, 2022
034b499
Avoid using SetPeriodStartTime.
keiji Jun 29, 2022
669860b
Run background task immediately at make first scheduling from AppDele…
keiji Jun 29, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Services\CloseApplicationService.cs" />
<Compile Include="Services\DeviceCheckService.cs" />
<Compile Include="Services\Logs\LogPeriodicDeleteService.cs" />
<Compile Include="Renderers\CustomDatePickerRenderer.cs" />
<Compile Include="Services\PreferencesService.cs" />
<Compile Include="Services\SecureStorageService.cs" />
Expand All @@ -192,6 +191,7 @@
<Compile Include="Services\IPlatformService.cs" />
<Compile Include="Services\LocalPathService.cs" />
<Compile Include="Services\EventLogSubmissionBackgroundService.cs" />
<Compile Include="Services\DataMaintainanceBackgroundService.cs" />
</ItemGroup>
<ItemGroup>
<None Include="appcenter-pre-build.sh" />
Expand Down Expand Up @@ -601,7 +601,6 @@
<ItemGroup>
<Folder Include="Renderers\" />
<Folder Include="Resources\xml\" />
<Folder Include="Services\Logs\" />
<Folder Include="Resources\drawable-zh-xxhdpi\" />
<Folder Include="Resources\drawable-zh-xhdpi\" />
<Folder Include="Services\Migration\" />
Expand Down
15 changes: 14 additions & 1 deletion Covid19Radar/Covid19Radar.Android/MainApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ private Lazy<ILoggerService> _loggerService
private Lazy<IExposureConfigurationRepository> _exposureConfigurationRepository
= new Lazy<IExposureConfigurationRepository>(() => ContainerLocator.Current.Resolve<IExposureConfigurationRepository>());

private Lazy<AbsDataMaintainanceBackgroundService> _dataMaintainanceService
= new Lazy<AbsDataMaintainanceBackgroundService>(() => ContainerLocator.Current.Resolve<AbsDataMaintainanceBackgroundService>());

public MainApplication(IntPtr handle, JniHandleOwnership transfer) : base(handle, transfer)
{
}
Expand Down Expand Up @@ -95,6 +98,7 @@ private void ScheduleBackgroundTasks()
{
_loggerService.Value.Exception("Failed to schedule ExposureDetectionBackgroundService", exception);
}

try
{
_eventLogSubmissionBackgroundService.Value.Schedule();
Expand All @@ -103,6 +107,15 @@ private void ScheduleBackgroundTasks()
{
_loggerService.Value.Exception("Failed to schedule EventLogSubmissionBackgroundService", exception);
}

try
{
_dataMaintainanceService.Value.Schedule();
}
catch (Exception exception)
{
_loggerService.Value.Exception("Failed to schedule DataMaintainanceBackgroundService", exception);
}
}

private void SetupENClient(ExposureNotificationClient client)
Expand All @@ -118,7 +131,7 @@ private void RegisterPlatformTypes(IContainer container)
// Services
container.Register<IBackupAttributeService, BackupAttributeService>(Reuse.Singleton);
container.Register<ILocalPathService, LocalPathService>(Reuse.Singleton);
container.Register<ILogPeriodicDeleteService, LogPeriodicDeleteService>(Reuse.Singleton);
container.Register<AbsDataMaintainanceBackgroundService, DataMaintainanceBackgroundService>(Reuse.Singleton);
container.Register<ISecureStorageDependencyService, Services.SecureStorageService>(Reuse.Singleton);
container.Register<IPreferencesService, PreferencesService>(Reuse.Singleton);
container.Register<IApplicationPropertyService, ApplicationPropertyService>(Reuse.Singleton);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/* 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;
using Android.Content;
using Android.Runtime;
using AndroidX.Work;
using Covid19Radar.Services;
using Covid19Radar.Services.Logs;
using Java.Util.Concurrent;
using Prism.Ioc;
using Xamarin.Essentials;

namespace Covid19Radar.Droid.Services.Logs
{
public class DataMaintainanceBackgroundService : AbsDataMaintainanceBackgroundService
{
private const string CURRENT_WORK_NAME = "data_maintainance_worker_20220628";

private static readonly long INTERVAL_IN_HOURS = 24;
private static readonly long BACKOFF_DELAY_IN_MINUTES = 60;

public DataMaintainanceBackgroundService(
ILogFileService logFileService,
ILoggerService loggerService
) : base(logFileService, loggerService)
{
// do nothing
}

public override void Schedule()
{
loggerService.StartMethod();

WorkManager workManager = WorkManager.GetInstance(Platform.AppContext);

PeriodicWorkRequest periodicWorkRequest = CreatePeriodicWorkRequest();
workManager.EnqueueUniquePeriodicWork(
CURRENT_WORK_NAME,
ExistingPeriodicWorkPolicy.Keep,
periodicWorkRequest
);

loggerService.EndMethod();
}

private PeriodicWorkRequest CreatePeriodicWorkRequest()
{
var workRequestBuilder = new PeriodicWorkRequest.Builder(
typeof(BackgroundWorker),
INTERVAL_IN_HOURS, TimeUnit.Hours
)
.SetConstraints(new Constraints.Builder()
.SetRequiresBatteryNotLow(true)
.Build())
.SetBackoffCriteria(BackoffPolicy.Linear, BACKOFF_DELAY_IN_MINUTES, TimeUnit.Minutes);
return workRequestBuilder.Build();
}
}

[Preserve]
public class BackgroundWorker : Worker
{
private Lazy<AbsDataMaintainanceBackgroundService> _dataMaintainanceBackgroundService
=> new Lazy<AbsDataMaintainanceBackgroundService>(() => ContainerLocator.Current.Resolve<AbsDataMaintainanceBackgroundService>());
private Lazy<ILoggerService> _loggerService => new Lazy<ILoggerService>(() => ContainerLocator.Current.Resolve<ILoggerService>());

public BackgroundWorker(Context context, WorkerParameters workerParameters)
: base(context, workerParameters)
{
// do nothing
}

public override Result DoWork()
{
var dataMaintainanceBackgroundService = _dataMaintainanceBackgroundService.Value;
var loggerService = _loggerService.Value;

loggerService.StartMethod();

try
{
dataMaintainanceBackgroundService.ExecuteAsync().GetAwaiter().GetResult();
return Result.InvokeSuccess();
}
catch (Exception exception)
{
loggerService.Exception("Exception", exception);
return Result.InvokeFailure();
}
finally
{
loggerService.EndMethod();
}
}

public override void OnStopped()
{
base.OnStopped();

_loggerService.Value.Warning("OnStopped");
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Covid19Radar.Droid.Services
{
public class EventLogSubmissionBackgroundService : AbsEventLogSubmissionBackgroundService
{
private const string CURRENT_WORK_NAME = "eventlog_submission_worker_20220112";
private const string CURRENT_WORK_NAME = "eventlog_submission_worker_20220628";

private const long INTERVAL_IN_HOURS = 24;
private const long BACKOFF_DELAY_IN_MINUTES = 60;
Expand All @@ -40,14 +40,14 @@ public override void Schedule()
PeriodicWorkRequest periodicWorkRequest = CreatePeriodicWorkRequest();
workManager.EnqueueUniquePeriodicWork(
CURRENT_WORK_NAME,
ExistingPeriodicWorkPolicy.Replace,
ExistingPeriodicWorkPolicy.Keep,
periodicWorkRequest
);

_loggerService.EndMethod();
}

private static PeriodicWorkRequest CreatePeriodicWorkRequest()
private PeriodicWorkRequest CreatePeriodicWorkRequest()
{
var workRequestBuilder = new PeriodicWorkRequest.Builder(
typeof(BackgroundWorker),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,20 @@ public override Result DoWork()
public class MigrationProccessService : IMigrationProcessService
{
private readonly AbsExposureDetectionBackgroundService _exposureDetectionBackgroundService;
private readonly AbsDataMaintainanceBackgroundService _dataMaintainanceBackgroundService;
private readonly AbsEventLogSubmissionBackgroundService _eventLogSubmissionBackgroundService;
private readonly ILoggerService _loggerService;

public MigrationProccessService(
AbsExposureDetectionBackgroundService exposureDetectionBackgroundService,
AbsDataMaintainanceBackgroundService dataMaintainanceBackgroundService,
AbsEventLogSubmissionBackgroundService eventLogSubmissionBackgroundService,
ILoggerService loggerService
)
{
_exposureDetectionBackgroundService = exposureDetectionBackgroundService;
_dataMaintainanceBackgroundService = dataMaintainanceBackgroundService;
_eventLogSubmissionBackgroundService = eventLogSubmissionBackgroundService;
_loggerService = loggerService;
}

Expand All @@ -86,6 +92,8 @@ public async Task SetupAsync()

await new WorkManagerMigrator(
_exposureDetectionBackgroundService,
_dataMaintainanceBackgroundService,
_eventLogSubmissionBackgroundService,
_loggerService
).ExecuteAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,21 @@ internal class WorkManagerMigrator
};

private readonly AbsExposureDetectionBackgroundService _exposureDetectionBackgroundService;
private readonly AbsDataMaintainanceBackgroundService _dataMaintainanceBackgroundService;
private readonly AbsEventLogSubmissionBackgroundService _eventLogSubmissionBackgroundService;

private readonly ILoggerService _loggerService;

public WorkManagerMigrator(
AbsExposureDetectionBackgroundService exposureDetectionBackgroundService,
AbsDataMaintainanceBackgroundService dataMaintainanceBackgroundService,
AbsEventLogSubmissionBackgroundService eventLogSubmissionBackgroundService,
ILoggerService loggerService
)
{
_exposureDetectionBackgroundService = exposureDetectionBackgroundService;
_dataMaintainanceBackgroundService = dataMaintainanceBackgroundService;
_eventLogSubmissionBackgroundService = eventLogSubmissionBackgroundService;
_loggerService = loggerService;
}

Expand All @@ -38,6 +45,8 @@ internal Task ExecuteAsync()
CancelOldWorks(workManager, OldWorkNames, _loggerService);

_exposureDetectionBackgroundService.Schedule();
_dataMaintainanceBackgroundService.Schedule();
_eventLogSubmissionBackgroundService.Schedule();

_loggerService.EndMethod();

Expand Down
19 changes: 16 additions & 3 deletions Covid19Radar/Covid19Radar.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ private Lazy<ILoggerService> _loggerService
private Lazy<IExposureConfigurationRepository> _exposureConfigurationRepository
= new Lazy<IExposureConfigurationRepository>(() => ContainerLocator.Current.Resolve<IExposureConfigurationRepository>());

private Lazy<AbsDataMaintainanceBackgroundService> _dataMaintainanceBackgroundService
= new Lazy<AbsDataMaintainanceBackgroundService>(() => ContainerLocator.Current.Resolve<AbsDataMaintainanceBackgroundService>());

private App? AppInstance
{
get
Expand Down Expand Up @@ -112,12 +115,12 @@ public override bool FinishedLaunching(UIApplication app, NSDictionary launchOpt

UIApplication.SharedApplication.SetMinimumBackgroundFetchInterval(UIApplication.BackgroundFetchIntervalMinimum);

ScheduleBackgroundTask();
ScheduleBackgroundTasks();

return base.FinishedLaunching(app, launchOptions);
}

private void ScheduleBackgroundTask()
private void ScheduleBackgroundTasks()
{
try
{
Expand All @@ -127,6 +130,7 @@ private void ScheduleBackgroundTask()
{
_loggerService.Value.Exception("Failed to schedule ExposureDetectionBackgroundService", exception);
}

try
{
_eventLogSubmissionBackgroundService.Value.Schedule();
Expand All @@ -135,6 +139,15 @@ private void ScheduleBackgroundTask()
{
_loggerService.Value.Exception("Failed to schedule EventLogSubmissionBackgroundService", exception);
}

try
{
_dataMaintainanceBackgroundService.Value.Schedule();
}
catch (Exception exception)
{
_loggerService.Value.Exception("Failed to schedule DataMaintainanceBackgroundService", exception);
}
}

private bool IsUniversalLinks(NSDictionary launchOptions)
Expand Down Expand Up @@ -256,7 +269,7 @@ private void RegisterPlatformTypes(IContainer container)
// Services
container.Register<IBackupAttributeService, BackupAttributeService>(Reuse.Singleton);
container.Register<ILocalPathService, LocalPathService>(Reuse.Singleton);
container.Register<ILogPeriodicDeleteService, LogPeriodicDeleteService>(Reuse.Singleton);
container.Register<AbsDataMaintainanceBackgroundService, DataMaintainanceBackgroundService>(Reuse.Singleton);
container.Register<ISecureStorageDependencyService, Services.SecureStorageService>(Reuse.Singleton);
container.Register<IPreferencesService, PreferencesService>(Reuse.Singleton);
container.Register<IApplicationPropertyService, ApplicationPropertyService>(Reuse.Singleton);
Expand Down
Loading