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 #1156 from cocoa-mhlw/feature/termination-of-use
Browse files Browse the repository at this point in the history
利用終了時の処理を追加
  • Loading branch information
cocoa-dev004 authored Sep 27, 2022
2 parents cfc9d2b + 14fdc87 commit 076adc2
Show file tree
Hide file tree
Showing 19 changed files with 299 additions and 46 deletions.
36 changes: 21 additions & 15 deletions Covid19Radar/Covid19Radar.Android/MainApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ private Lazy<ILoggerService> _loggerService
private Lazy<IExposureConfigurationRepository> _exposureConfigurationRepository
= new Lazy<IExposureConfigurationRepository>(() => ContainerLocator.Current.Resolve<IExposureConfigurationRepository>());

private Lazy<IUserDataRepository> _userDataRepository
= new Lazy<IUserDataRepository>(() => ContainerLocator.Current.Resolve<IUserDataRepository>());

public MainApplication(IntPtr handle, JniHandleOwnership transfer) : base(handle, transfer)
{
}
Expand Down Expand Up @@ -93,22 +96,25 @@ public override void OnCreate()

private void ScheduleBackgroundTasks()
{
try
{
_exposureDetectionBackgroundService.Value.Schedule();
}
catch (Exception exception)
{
_loggerService.Value.Exception("Failed to schedule ExposureDetectionBackgroundService", exception);
}

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ private PeriodicWorkRequest CreatePeriodicWorkRequest()
return workRequestBuilder.Build();
}

public override void Cancel()
{
WorkManager workManager = WorkManager.GetInstance(Platform.AppContext);
workManager.CancelUniqueWork(CURRENT_WORK_NAME);
}

[Preserve]
public class BackgroundWorker : Worker
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ private PeriodicWorkRequest CreatePeriodicWorkRequest()
return workRequestBuilder.Build();
}

public override void Cancel()
{
WorkManager workManager = WorkManager.GetInstance(Platform.AppContext);
workManager.CancelUniqueWork(CURRENT_WORK_NAME);
}

[Preserve]
public class BackgroundWorker : Worker
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ private static PeriodicWorkRequest CreatePeriodicWorkRequest()
.SetBackoffCriteria(BackoffPolicy.Linear, BACKOFF_DELAY_IN_MINUTES, TimeUnit.Minutes);
return workRequestBuilder.Build();
}

public override void Cancel()
{
WorkManager workManager = WorkManager.GetInstance(Platform.AppContext);
workManager.CancelUniqueWork(CURRENT_WORK_NAME);
}
}

[Preserve]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Android.App;
using Android.Content;
using AndroidX.Work;
using Covid19Radar.Repository;
using Covid19Radar.Services;
using Covid19Radar.Services.Logs;
using Covid19Radar.Services.Migration;
Expand Down Expand Up @@ -75,18 +76,21 @@ public class MigrationProccessService : IMigrationProcessService
private readonly AbsEventLogSubmissionBackgroundService _eventLogSubmissionBackgroundService;

private readonly ILoggerService _loggerService;
private readonly IUserDataRepository _userDataRepository;

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

public async Task SetupAsync()
Expand All @@ -97,7 +101,8 @@ public async Task SetupAsync()
_exposureDetectionBackgroundService,
_dataMaintainanceBackgroundService,
_eventLogSubmissionBackgroundService,
_loggerService
_loggerService,
_userDataRepository
).ExecuteAsync();

_loggerService.EndMethod();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Threading.Tasks;
using AndroidX.Work;
using Covid19Radar.Repository;
using Covid19Radar.Services;
using Covid19Radar.Services.Logs;

Expand All @@ -23,18 +24,21 @@ internal class WorkManagerMigrator
private readonly AbsEventLogSubmissionBackgroundService _eventLogSubmissionBackgroundService;

private readonly ILoggerService _loggerService;
private readonly IUserDataRepository _userDataRepository;

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

internal Task ExecuteAsync()
Expand All @@ -44,8 +48,11 @@ internal Task ExecuteAsync()
var workManager = WorkManager.GetInstance(Xamarin.Essentials.Platform.AppContext);
CancelOldWorks(workManager, OldWorkNames, _loggerService);

_exposureDetectionBackgroundService.Schedule();
_dataMaintainanceBackgroundService.Schedule();
if (_userDataRepository.IsAllAgreed())
{
_exposureDetectionBackgroundService.Schedule();
_dataMaintainanceBackgroundService.Schedule();
}

_loggerService.EndMethod();

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

private Lazy<IUserDataRepository> _userDataRepositiry
= new Lazy<IUserDataRepository>(() => ContainerLocator.Current.Resolve<IUserDataRepository>());

private App? AppInstance
{
get
Expand Down Expand Up @@ -128,22 +131,25 @@ private void ScheduleBackgroundTasks()
{
_loggerService.Value.StartMethod();

try
if (_userDataRepositiry.Value.IsAllAgreed())
{
_exposureDetectionBackgroundService.Value.Schedule();
}
catch (Exception exception)
{
_loggerService.Value.Exception("Failed to schedule ExposureDetectionBackgroundService", exception);
}
try
{
_exposureDetectionBackgroundService.Value.Schedule();
}
catch (Exception exception)
{
_loggerService.Value.Exception("Failed to schedule ExposureDetectionBackgroundService", exception);
}

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

_loggerService.Value.EndMethod();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ private void ScheduleBgTask()
LoggerService.EndMethod();
}
}

public override void Cancel()
{
BGTaskScheduler.Shared.Cancel(BGTASK_IDENTIFIER);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ private void ScheduleBgTask()
_loggerService.EndMethod();
}
}

public override void Cancel()
{
BGTaskScheduler.Shared.Cancel(BGTASK_IDENTIFIER);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,9 @@ private void ScheduleBgTask()
}
}

public override void Cancel()
{
BGTaskScheduler.Shared.Cancel(BGTASK_IDENTIFIER);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ protected AbsDataMaintainanceBackgroundService(
}

public abstract void Schedule();
public abstract void Cancel();

public void Execute()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ namespace Covid19Radar.Services
public abstract class AbsEventLogSubmissionBackgroundService : IBackgroundService
{
public abstract void Schedule();
public abstract void Cancel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ ILocalNotificationService localNotificationService
}

public abstract void Schedule();
public abstract void Cancel();

public virtual async Task ExposureDetectionAsync(CancellationTokenSource cancellationTokenSource = null)
{
Expand Down
1 change: 1 addition & 0 deletions Covid19Radar/Covid19Radar/Services/IBackgroundService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ namespace Covid19Radar.Services
public interface IBackgroundService
{
public abstract void Schedule();
public abstract void Cancel();
}
}
7 changes: 1 addition & 6 deletions Covid19Radar/Covid19Radar/Services/Logs/LogFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,14 @@ public void Rotate()

public bool DeleteLogsDir()
{
loggerService.StartMethod();
try
{
var logsDirPath = logPathService.LogsDirPath;
Directory.Delete(logsDirPath, true);
loggerService.Info("Deleted all log files.");
loggerService.EndMethod();
return true;
}
catch (Exception ex)
catch
{
loggerService.Exception("Failed to Delete all log files.", ex);
loggerService.EndMethod();
return false;
}
}
Expand Down
Loading

0 comments on commit 076adc2

Please sign in to comment.