Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

Migrate IDeviceVerifier from DependencyService to ServiceLocator #189

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions Covid19Radar/Covid19Radar.Android/MainApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ private void RegisterPlatformTypes(IContainer container)
container.Register<ISecureStorageDependencyService, SecureStorageServiceAndroid>(Reuse.Singleton);
container.Register<IPreferencesService, PreferencesService>(Reuse.Singleton);
container.Register<IApplicationPropertyService, ApplicationPropertyService>(Reuse.Singleton);

#if USE_MOCK
container.Register<IDeviceVerifier, DeviceVerifierMock>(Reuse.Singleton);
#else
container.Register<IDeviceVerifier, DeviceCheckService>(Reuse.Singleton);
#endif
}
}
}
14 changes: 0 additions & 14 deletions Covid19Radar/Covid19Radar.Android/Services/DeviceCheckService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,11 @@
* 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 System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Covid19Radar.Services;
using Covid19Radar.Droid.Services;
using Xamarin.Forms;
using Covid19Radar.Model;
using Covid19Radar.Common;
using Android.Gms.SafetyNet;

[assembly: Dependency(typeof(DeviceCheckService))]
namespace Covid19Radar.Droid.Services
{
public class DeviceCheckService : IDeviceVerifier
Expand Down
6 changes: 6 additions & 0 deletions Covid19Radar/Covid19Radar.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ private void RegisterPlatformTypes(IContainer container)
container.Register<ISecureStorageDependencyService, SecureStorageServiceIos>(Reuse.Singleton);
container.Register<IPreferencesService, PreferencesService>(Reuse.Singleton);
container.Register<IApplicationPropertyService, ApplicationPropertyService>(Reuse.Singleton);

#if USE_MOCK
container.Register<IDeviceVerifier, DeviceVerifierMock>(Reuse.Singleton);
#else
container.Register<IDeviceVerifier, DeviceCheckService>(Reuse.Singleton);
#endif
}
}
}
3 changes: 0 additions & 3 deletions Covid19Radar/Covid19Radar.iOS/Services/DeviceCheckService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
using System;
using System.Threading.Tasks;
using Covid19Radar.Services;
using Covid19Radar.iOS.Services;
using Xamarin.Forms;
using Covid19Radar.Model;

[assembly: Dependency(typeof(DeviceCheckService))]
namespace Covid19Radar.iOS.Services
{
public class DeviceCheckService : IDeviceVerifier
Expand Down
15 changes: 15 additions & 0 deletions Covid19Radar/Covid19Radar/Services/DeviceVerifierMock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* 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 Covid19Radar.Model;

namespace Covid19Radar.Services
{
public class DeviceVerifierMock : IDeviceVerifier
{
public Task<string> VerifyAsync(DiagnosisSubmissionParameter submission)
=> Task.Run(() => "DUMMY RESPONSE");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
using Covid19Radar.Services.Logs;
using Xamarin.Essentials;
using Xamarin.ExposureNotifications;
using Xamarin.Forms;

namespace Covid19Radar.Services
{
Expand All @@ -29,6 +28,7 @@ public class ExposureNotificationHandler : IExposureNotificationHandler
private IHttpDataService HttpDataService => ServiceLocator.Current.GetInstance<IHttpDataService>();
private IExposureNotificationService ExposureNotificationService => ServiceLocator.Current.GetInstance<IExposureNotificationService>();
private IUserDataService UserDataService => ServiceLocator.Current.GetInstance<IUserDataService>();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この辺にもreadonly付けたかったけど、今回の変更に関係ないのでぐっと我慢

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この辺はフィールド変数ではなく読み取り専用のプロパティになっているので readonly を付ける必要はありません。

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ほんとだ! よく見たら => ですね!

private readonly IDeviceVerifier DeviceVerifier = ServiceLocator.Current.GetInstance<IDeviceVerifier>();

public ExposureNotificationHandler()
{
Expand Down Expand Up @@ -386,11 +386,7 @@ private async Task<DiagnosisSubmissionParameter> CreateSubmissionAsync(IEnumerab
Padding = padding
};

// See if we can add the device verification
if (DependencyService.Get<IDeviceVerifier>() is IDeviceVerifier verifier)
{
submission.DeviceVerificationPayload = await verifier?.VerifyAsync(submission);
}
submission.DeviceVerificationPayload = await DeviceVerifier.VerifyAsync(submission);

loggerService.Info($"DeviceVerificationPayload is {(string.IsNullOrEmpty(submission.DeviceVerificationPayload) ? "null or empty" : "set")}.");
loggerService.Info($"VerificationPayload is {(string.IsNullOrEmpty(submission.VerificationPayload) ? "null or empty" : "set")}.");
Expand Down