This repository has been archived by the owner on Apr 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1038 from cocoa-mhlw/feature/send-exposure-notify
接触通知の発生イベントを収集する処理の実装
- Loading branch information
Showing
31 changed files
with
1,664 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
Covid19Radar/Covid19Radar.Android/Services/EventLogSubmissionBackgroundService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// 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.Common; | ||
using Covid19Radar.Services; | ||
using Covid19Radar.Services.Logs; | ||
using Java.Util.Concurrent; | ||
using Prism.Ioc; | ||
using Xamarin.Essentials; | ||
|
||
namespace Covid19Radar.Droid.Services | ||
{ | ||
public class EventLogSubmissionBackgroundService : AbsEventLogSubmissionBackgroundService | ||
{ | ||
private const string CURRENT_WORK_NAME = "eventlog_submission_worker_20220112"; | ||
|
||
private const long INTERVAL_IN_HOURS = 24; | ||
private const long BACKOFF_DELAY_IN_MINUTES = 60; | ||
|
||
private readonly ILoggerService _loggerService; | ||
|
||
public EventLogSubmissionBackgroundService( | ||
ILoggerService loggerService | ||
) : base() | ||
{ | ||
_loggerService = loggerService; | ||
} | ||
|
||
public override void Schedule() | ||
{ | ||
_loggerService.StartMethod(); | ||
|
||
WorkManager workManager = WorkManager.GetInstance(Platform.AppContext); | ||
|
||
PeriodicWorkRequest periodicWorkRequest = CreatePeriodicWorkRequest(); | ||
workManager.EnqueueUniquePeriodicWork( | ||
CURRENT_WORK_NAME, | ||
ExistingPeriodicWorkPolicy.Replace, | ||
periodicWorkRequest | ||
); | ||
|
||
_loggerService.EndMethod(); | ||
} | ||
|
||
private static PeriodicWorkRequest CreatePeriodicWorkRequest() | ||
{ | ||
var workRequestBuilder = new PeriodicWorkRequest.Builder( | ||
typeof(BackgroundWorker), | ||
INTERVAL_IN_HOURS, TimeUnit.Hours | ||
) | ||
.SetConstraints(new Constraints.Builder() | ||
.SetRequiresBatteryNotLow(true) | ||
.SetRequiredNetworkType(NetworkType.Connected) | ||
.Build()) | ||
.SetBackoffCriteria(BackoffPolicy.Linear, BACKOFF_DELAY_IN_MINUTES, TimeUnit.Minutes); | ||
return workRequestBuilder.Build(); | ||
} | ||
|
||
[Preserve] | ||
public class BackgroundWorker : Worker | ||
{ | ||
private Lazy<ILoggerService> _loggerService => new Lazy<ILoggerService>(() => ContainerLocator.Current.Resolve<ILoggerService>()); | ||
private Lazy<IEventLogService> _eventLogService => new Lazy<IEventLogService>(() => ContainerLocator.Current.Resolve<IEventLogService>()); | ||
|
||
public BackgroundWorker(Context context, WorkerParameters workerParams) : base(context, workerParams) | ||
{ | ||
// do nothing | ||
} | ||
|
||
public override Result DoWork() | ||
{ | ||
var loggerService = _loggerService.Value; | ||
var eventLogService = _eventLogService.Value; | ||
|
||
loggerService.StartMethod(); | ||
|
||
try | ||
{ | ||
eventLogService.SendAllAsync( | ||
AppConstants.EventLogMaxRequestSizeInBytes, | ||
AppConstants.EventLogMaxRetry); | ||
return Result.InvokeSuccess(); | ||
} | ||
catch (Exception exception) | ||
{ | ||
loggerService.Exception("Exception occurred, SendAllAsync", exception); | ||
return Result.InvokeFailure(); | ||
} | ||
finally | ||
{ | ||
loggerService.EndMethod(); | ||
} | ||
} | ||
|
||
public override void OnStopped() | ||
{ | ||
base.OnStopped(); | ||
|
||
_loggerService.Value.Warning("OnStopped"); | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.