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 #1038 from cocoa-mhlw/feature/send-exposure-notify
Browse files Browse the repository at this point in the history
接触通知の発生イベントを収集する処理の実装
  • Loading branch information
cocoa-dev004 authored Jun 20, 2022
2 parents 149cd38 + 642f67e commit 091b5d0
Show file tree
Hide file tree
Showing 31 changed files with 1,664 additions and 363 deletions.
33 changes: 33 additions & 0 deletions COPYRIGHT_THIRD_PARTY_SOFTWARE_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,39 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

---
## Polly
---

<pre>
New BSD License
=
Copyright (c) 2015-2020, App vNext
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of App vNext nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</pre>

---
## (Sample Code) Exposure Notifications API: Android Reference Design
---
Expand Down
32 changes: 32 additions & 0 deletions Covid19Radar/Covid19Radar.Android/Assets/license.html
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,38 @@ <h2>System.IdentityModel.Tokens.Jwt</h2>
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.</p>
<hr />
<h2>Polly</h2>
<hr />
<pre>
New BSD License
=
Copyright (c) 2015-2020, App vNext
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of App vNext nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</pre>

<hr />
<h2>(Sample Code) Exposure Notifications API: Android Reference Design</h2>
<hr />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
<Compile Include="Services\PlatformService.cs" />
<Compile Include="Services\IPlatformService.cs" />
<Compile Include="Services\LocalPathService.cs" />
<Compile Include="Services\EventLogSubmissionBackgroundService.cs" />
</ItemGroup>
<ItemGroup>
<None Include="appcenter-pre-build.sh" />
Expand Down
19 changes: 18 additions & 1 deletion Covid19Radar/Covid19Radar.Android/MainApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ private Lazy<IExposureDetectionService> _exposureDetectionService
private Lazy<AbsExposureDetectionBackgroundService> _exposureDetectionBackgroundService
= new Lazy<AbsExposureDetectionBackgroundService>(() => ContainerLocator.Current.Resolve<AbsExposureDetectionBackgroundService>());

private readonly Lazy<AbsEventLogSubmissionBackgroundService> _eventLogSubmissionBackgroundService
= new Lazy<AbsEventLogSubmissionBackgroundService>(() => ContainerLocator.Current.Resolve<AbsEventLogSubmissionBackgroundService>());

private Lazy<ILoggerService> _loggerService
= new Lazy<ILoggerService>(() => ContainerLocator.Current.Resolve<ILoggerService>());

Expand Down Expand Up @@ -79,13 +82,26 @@ public override void OnCreate()
SetupENClient(exposureNotificationApiService.Client);
}

ScheduleBackgroundTasks();
}

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

Expand Down Expand Up @@ -121,6 +137,7 @@ private void RegisterPlatformTypes(IContainer container)

container.Register<IExternalNavigationService, ExternalNavigationService>(Reuse.Singleton);
container.Register<IPlatformService, PlatformService>(Reuse.Singleton);
container.Register<AbsEventLogSubmissionBackgroundService, EventLogSubmissionBackgroundService>(Reuse.Singleton);
}

public Task<ExposureConfiguration> GetExposureConfigurationAsync()
Expand Down
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");
}
}
}
}

23 changes: 20 additions & 3 deletions Covid19Radar/Covid19Radar.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ private Lazy<AbsExposureNotificationApiService> _exposureNotificationClient
private Lazy<AbsExposureDetectionBackgroundService> _exposureDetectionBackgroundService
= new Lazy<AbsExposureDetectionBackgroundService>(() => ContainerLocator.Current.Resolve<AbsExposureDetectionBackgroundService>());

private readonly Lazy<AbsEventLogSubmissionBackgroundService> _eventLogSubmissionBackgroundService
= new Lazy<AbsEventLogSubmissionBackgroundService>(() => ContainerLocator.Current.Resolve<AbsEventLogSubmissionBackgroundService>());

private Lazy<IExposureDetectionService> _exposureDetectionService
= new Lazy<IExposureDetectionService>(() => ContainerLocator.Current.Resolve<IExposureDetectionService>());

Expand Down Expand Up @@ -109,16 +112,29 @@ public override bool FinishedLaunching(UIApplication app, NSDictionary launchOpt

UIApplication.SharedApplication.SetMinimumBackgroundFetchInterval(UIApplication.BackgroundFetchIntervalMinimum);

ScheduleBackgroundTask();

return base.FinishedLaunching(app, launchOptions);
}

private void ScheduleBackgroundTask()
{
try
{
_exposureDetectionBackgroundService.Value.Schedule();
}
catch (Exception exception)
{
_loggerService.Value.Exception("failed to Scheduling", exception);
_loggerService.Value.Exception("Failed to schedule ExposureDetectionBackgroundService", exception);
}
try
{
_eventLogSubmissionBackgroundService.Value.Schedule();
}
catch (Exception exception)
{
_loggerService.Value.Exception("Failed to schedule EventLogSubmissionBackgroundService", exception);
}

return base.FinishedLaunching(app, launchOptions);
}

private bool IsUniversalLinks(NSDictionary launchOptions)
Expand Down Expand Up @@ -257,6 +273,7 @@ private void RegisterPlatformTypes(IContainer container)
container.Register<AbsExposureNotificationApiService, ExposureNotificationApiService>(Reuse.Singleton);
#endif
container.Register<IExternalNavigationService, ExternalNavigationService>(Reuse.Singleton);
container.Register<AbsEventLogSubmissionBackgroundService, EventLogSubmissionBackgroundService>(Reuse.Singleton);
}

public Task<ExposureConfiguration> GetExposureConfigurationAsync()
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 @@ -270,6 +270,7 @@
<Compile Include="Services\ExternalNavigationService.cs" />
<None Include="EntitlementsDebug.plist" />
<Compile Include="Services\LocalPathService.cs" />
<Compile Include="Services\EventLogSubmissionBackgroundService.cs" />
</ItemGroup>
<ItemGroup>
<ImageAsset Include="Assets.xcassets\Contents.json">
Expand Down
1 change: 1 addition & 0 deletions Covid19Radar/Covid19Radar.iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<array>
<string>APP_PACKAGE_NAME.exposure-notification</string>
<string>APP_PACKAGE_NAME.delete-old-logs</string>
<string>APP_PACKAGE_NAME.eventlog-submission</string>
</array>
<key>UIAppFonts</key>
<array>
Expand Down
32 changes: 32 additions & 0 deletions Covid19Radar/Covid19Radar.iOS/Resources/license.html
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,38 @@ <h2>System.IdentityModel.Tokens.Jwt</h2>
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.</p>
<hr />
<h2>Polly</h2>
<hr />
<pre>
New BSD License
=
Copyright (c) 2015-2020, App vNext
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of App vNext nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</pre>

<hr />
<h2>(Sample Code) Exposure Notifications API: Android Reference Design</h2>
<hr />
Expand Down
Loading

0 comments on commit 091b5d0

Please sign in to comment.