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 #1154 from cocoa-mhlw/feature/endofservice-notify
Browse files Browse the repository at this point in the history
サービス終了の通知
  • Loading branch information
cocoa-dev004 authored Sep 22, 2022
2 parents b230af6 + 423190c commit 8eab266
Show file tree
Hide file tree
Showing 18 changed files with 184 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public ExposureDetectionBackgroundService(
IUserDataRepository userDataRepository,
IServerConfigurationRepository serverConfigurationRepository,
ILocalPathService localPathService,
IDateTimeUtility dateTimeUtility
IDateTimeUtility dateTimeUtility,
ILocalNotificationService localNotificationService
) : base(
diagnosisKeyRepository,
exposureNotificationApiService,
Expand All @@ -46,7 +47,8 @@ IDateTimeUtility dateTimeUtility
userDataRepository,
serverConfigurationRepository,
localPathService,
dateTimeUtility
dateTimeUtility,
localNotificationService
)
{
_loggerService = loggerService;
Expand Down Expand Up @@ -105,7 +107,7 @@ public override Result DoWork()

try
{

_ = backgroundService.ShowEndOfServiceNotificationAync();
return Result.InvokeSuccess();
}
catch (IOException exception)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,36 @@ public async Task PrepareAsync()

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
public async Task ShowExposureNotificationAsync()
{
}
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
public async Task DismissExposureNotificationAsync()
{
_loggerService.StartMethod();

var nm = NotificationManagerCompat.From(Platform.AppContext);
nm.Cancel(NOTIFICATION_ID_EXPOSURE);

_loggerService.EndMethod();
}
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
public async Task<bool> IsWarnedLocalNotificationOffAsync()
{
_loggerService.StartMethod();
_loggerService.EndMethod();
return false;
}
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously

public async Task ShowEndOfServiceNoticationAsync()
{
_loggerService.StartMethod();

Intent intent = MainActivity.NewIntent(Platform.AppContext, Destination.ContactedNotifyPage);
Intent intent = MainActivity.NewIntent(Platform.AppContext, Destination.EndOfServiceNotice);
intent.AddFlags(ActivityFlags.ClearTask);

PendingIntent pendingIntent = PendingIntent.GetActivity(
Expand All @@ -74,8 +100,8 @@ public async Task ShowExposureNotificationAsync()
.Builder(Platform.AppContext, NOTIFICATION_CHANNEL_ID)
.SetStyle(new NotificationCompat.BigTextStyle())
.SetSmallIcon(Resource.Drawable.ic_notification)
.SetContentTitle(AppResources.LocalExposureNotificationTitle)
.SetContentText(AppResources.LocalExposureNotificationContent)
.SetContentTitle(AppResources.EndOfServiceNotificationTitle)
.SetContentText(AppResources.EndOfServiceNotificationContent)
.SetVisibility(NotificationCompat.VisibilitySecret)
.SetContentIntent(pendingIntent)
.SetLocalOnly(true)
Expand All @@ -85,30 +111,10 @@ public async Task ShowExposureNotificationAsync()
var nm = NotificationManagerCompat.From(Platform.AppContext);
nm.Notify(NOTIFICATION_ID_EXPOSURE, notification);

_loggerService.Info("Local exposure notification shown.");
_loggerService.EndMethod();
}
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
public async Task DismissExposureNotificationAsync()
{
_loggerService.StartMethod();

var nm = NotificationManagerCompat.From(Platform.AppContext);
nm.Cancel(NOTIFICATION_ID_EXPOSURE);
await Task.CompletedTask;

_loggerService.Info("End-of-service notification shown.");
_loggerService.EndMethod();
}
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
public async Task<bool> IsWarnedLocalNotificationOffAsync()
{
_loggerService.StartMethod();
_loggerService.EndMethod();
return false;
}
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
}
}
2 changes: 1 addition & 1 deletion Covid19Radar/Covid19Radar.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public override bool FinishedLaunching(UIApplication app, NSDictionary launchOpt
_notificationCenterDelegate.OnRecieved += async (UserNotificationCenterDelegate sender, UNNotificationResponse response) =>
{
var navigationParameters = new NavigationParameters();
await AppInstance?.NavigateToSplashAsync(Destination.ContactedNotifyPage, navigationParameters);
await AppInstance?.NavigateToSplashAsync(Destination.EndOfServiceNotice, navigationParameters);
};
UNUserNotificationCenter.Current.Delegate = _notificationCenterDelegate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public ExposureDetectionBackgroundService(
IUserDataRepository userDataRepository,
IServerConfigurationRepository serverConfigurationRepository,
ILocalPathService localPathService,
IDateTimeUtility dateTimeUtility
IDateTimeUtility dateTimeUtility,
ILocalNotificationService localNotificationService
) : base(
diagnosisKeyRepository,
exposureNotificationApiService,
Expand All @@ -45,7 +46,8 @@ IDateTimeUtility dateTimeUtility
userDataRepository,
serverConfigurationRepository,
localPathService,
dateTimeUtility
dateTimeUtility,
localNotificationService
)
{
_loggerService = loggerService;
Expand All @@ -68,7 +70,7 @@ public override void Schedule()
{
try
{
await ShowEndOfServiceNotificationAync();
task.SetTaskCompleted(true);
}
catch (OperationCanceledException exception)
Expand Down
74 changes: 40 additions & 34 deletions Covid19Radar/Covid19Radar.iOS/Services/LocalNotificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ public async Task PrepareAsync()

_loggerService.EndMethod();
}


#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously

public async Task ShowExposureNotificationAsync()
{
_loggerService.StartMethod();

await ScheduleLocalNotificationAsync();

_loggerService.EndMethod();
await Task.CompletedTask;
}

private void AskPermissionForUserNotification()
Expand All @@ -55,35 +53,6 @@ private void AskPermissionForUserNotification()
_loggerService.EndMethod();
}

private async Task ScheduleLocalNotificationAsync()
{
_loggerService.StartMethod();

try
{
var settings = await UNUserNotificationCenter.Current.GetNotificationSettingsAsync();
if (settings.AuthorizationStatus != UNAuthorizationStatus.Authorized)
{
throw new Exception($"UserNotification is not authorized: {settings.AuthorizationStatus}");
}

var content = new UNMutableNotificationContent();

content.Title = AppResources.LocalExposureNotificationTitle;
content.Body = AppResources.LocalExposureNotificationContent;

var request = UNNotificationRequest.FromIdentifier(NOTIFICATION_ID, content, null);
var notificationCenter = UNUserNotificationCenter.Current;
await notificationCenter.AddNotificationRequestAsync(request);
}
catch (Exception e)
{
_loggerService.Exception("Exception occurred", e);
}

_loggerService.EndMethod();
}

public async Task DismissExposureNotificationAsync()
{
_loggerService.StartMethod();
Expand Down Expand Up @@ -112,5 +81,42 @@ public async Task<bool> IsWarnedLocalNotificationOffAsync()

return settings.AuthorizationStatus == UNAuthorizationStatus.Denied;
}

public async Task ShowEndOfServiceNoticationAsync()
{
_loggerService.StartMethod();
await ScheduleEndOfServiceNoticationAsync();
_loggerService.EndMethod();
}

private async Task ScheduleEndOfServiceNoticationAsync()
{
_loggerService.StartMethod();

try
{
var settings = await UNUserNotificationCenter.Current.GetNotificationSettingsAsync();
if (settings.AuthorizationStatus != UNAuthorizationStatus.Authorized)
{
throw new Exception($"UserNotification is not authorized: {settings.AuthorizationStatus}");
}

var content = new UNMutableNotificationContent();

content.Title = AppResources.EndOfServiceNotificationTitle;
content.Body = AppResources.EndOfServiceNotificationContent;

var request = UNNotificationRequest.FromIdentifier(NOTIFICATION_ID, content, null);
var notificationCenter = UNUserNotificationCenter.Current;
await notificationCenter.AddNotificationRequestAsync(request);
}
catch (Exception e)
{
_loggerService.Exception("Exception occurred", e);
}

_loggerService.EndMethod();
}

}
}
1 change: 0 additions & 1 deletion Covid19Radar/Covid19Radar/Destination.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace Covid19Radar
public enum Destination : int
{
SplashPage,
ContactedNotifyPage,
EndOfServiceNotice,
EndOfService,
}
Expand Down
18 changes: 18 additions & 0 deletions Covid19Radar/Covid19Radar/Resources/AppResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Covid19Radar/Covid19Radar/Resources/AppResources.ja.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,14 @@
<value>新型コロナウイルス感染症の陽性登録者と接触した可能性があります。タップして詳細を確認してください。</value>
<comment>新型コロナウイルス感染症の陽性登録者と接触した可能性があります。タップして詳細を確認してください。</comment>
</data>
<data name="EndOfServiceNotificationTitle" xml:space="preserve">
<value>サービス終了のお知らせ</value>
<comment>サービス終了のお知らせ</comment>
</data>
<data name="EndOfServiceNotificationContent" xml:space="preserve">
<value>接触確認アプリ「COCOA」は2022年◯月◯日をもってサービスを終了します。</value>
<comment>接触確認アプリ「COCOA」は2022年◯月◯日をもってサービスを終了します。</comment>
</data>
<data name="WebAccessibilityPolicyPageTitle" xml:space="preserve">
<value>ウェブアクセシビリティ方針</value>
<comment>ウェブアクセシビリティ方針</comment>
Expand Down
8 changes: 8 additions & 0 deletions Covid19Radar/Covid19Radar/Resources/AppResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,14 @@ You do not have to request it yourself.</value>
<value>It is possible you have been in close proximity to a user who tested positive for COVID-19. Tap for more details.</value>
<comment>新型コロナウイルス感染症の陽性登録者と接触した可能性があります。タップして詳細を確認してください。</comment>
</data>
<data name="EndOfServiceNotificationTitle" xml:space="preserve">
<value>TODO</value>
<comment>サービス終了のお知らせ</comment>
</data>
<data name="EndOfServiceNotificationContent" xml:space="preserve">
<value>TODO</value>
<comment>接触確認アプリ「COCOA」は2022年◯月◯日をもってサービスを終了します。</comment>
</data>
<data name="WebAccessibilityPolicyPageTitle" xml:space="preserve">
<value>Web accessibility policy</value>
<comment>ウェブアクセシビリティ方針</comment>
Expand Down
8 changes: 8 additions & 0 deletions Covid19Radar/Covid19Radar/Resources/AppResources.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,14 @@
<value>您可能接触过感染新型冠状病毒的阳性登记者。点击查看详细信息。</value>
<comment>新型コロナウイルス感染症の陽性登録者と接触した可能性があります。タップして詳細を確認してください。</comment>
</data>
<data name="EndOfServiceNotificationTitle" xml:space="preserve">
<value>TODO</value>
<comment>サービス終了のお知らせ</comment>
</data>
<data name="EndOfServiceNotificationContent" xml:space="preserve">
<value>TODO</value>
<comment>接触確認アプリ「COCOA」は2022年◯月◯日をもってサービスを終了します。</comment>
</data>
<data name="WebAccessibilityPolicyPageTitle" xml:space="preserve">
<value>网页无障碍访问政策</value>
<comment>ウェブアクセシビリティ方針</comment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public abstract class AbsExposureDetectionBackgroundService : IBackgroundService
private readonly IServerConfigurationRepository _serverConfigurationRepository;
private readonly ILocalPathService _localPathService;
private readonly IDateTimeUtility _dateTimeUtility;
private readonly ILocalNotificationService _localNotificationService;

private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);

Expand All @@ -39,7 +40,8 @@ public AbsExposureDetectionBackgroundService(
IUserDataRepository userDataRepository,
IServerConfigurationRepository serverConfigurationRepository,
ILocalPathService localPathService,
IDateTimeUtility dateTimeUtility
IDateTimeUtility dateTimeUtility,
ILocalNotificationService localNotificationService
)
{
_diagnosisKeyRepository = diagnosisKeyRepository;
Expand All @@ -50,6 +52,7 @@ IDateTimeUtility dateTimeUtility
_serverConfigurationRepository = serverConfigurationRepository;
_localPathService = localPathService;
_dateTimeUtility = dateTimeUtility;
_localNotificationService = localNotificationService;
}

public abstract void Schedule();
Expand Down Expand Up @@ -237,5 +240,15 @@ private bool CheckMaxPerDayExposureDetectionAPILimitReached(ENException ex)
{
return ex.Code == ENException.Code_iOS.RateLimited || ex.Code == ENException.Code_Android.FAILED_RATE_LIMITED;
}

public virtual async Task ShowEndOfServiceNotificationAync(CancellationTokenSource cancellationTokenSource = null)
{
_loggerService.StartMethod();
if (_userDataRepository.IsAllAgreed())
{
await _localNotificationService.ShowEndOfServiceNoticationAsync();
}
_loggerService.EndMethod();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public interface ILocalNotificationService
public Task DismissExposureNotificationAsync();

public Task<bool> IsWarnedLocalNotificationOffAsync();

public Task ShowEndOfServiceNoticationAsync();
}
}
Loading

0 comments on commit 8eab266

Please sign in to comment.