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 #602 from keiji/cocoa2/fix_background_schedule
Browse files Browse the repository at this point in the history
Fix the WorkManager scheduling issue.
  • Loading branch information
kazuhiro4949 authored Dec 19, 2021
2 parents 6d8d84a + d600997 commit 86b9799
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Covid19Radar/Covid19Radar.Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Covid19Radar.Common;
using Covid19Radar.Services.Logs;
using Prism.Ioc;
using AndroidX.AppCompat.App;

namespace Covid19Radar.Droid
{
Expand Down Expand Up @@ -83,6 +84,8 @@ protected override async void OnCreate(Bundle savedInstanceState)
base.SetTheme(Resource.Style.MainTheme);
base.OnCreate(savedInstanceState);

AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightNo;

Xamarin.Forms.Forms.SetFlags("RadioButton_Experimental");
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
Xamarin.Forms.Forms.Init(this, savedInstanceState);
Expand Down
19 changes: 15 additions & 4 deletions Covid19Radar/Covid19Radar.Android/MainApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using Chino;
using Chino.Android.Google;
using System.Collections.Generic;
using AndroidX.AppCompat.App;
using Prism.Ioc;

namespace Covid19Radar.Droid
Expand All @@ -35,13 +34,18 @@ private readonly JobSetting _exposureDetectedV2JobSetting
= new JobSetting(INITIAL_BACKOFF_MILLIS, Android.App.Job.BackoffPolicy.Linear, true);
private readonly JobSetting _exposureNotDetectedJobSetting = null;


private Lazy<AbsExposureNotificationApiService> _exposureNotificationApiService
= new Lazy<AbsExposureNotificationApiService>(() => ContainerLocator.Current.Resolve<AbsExposureNotificationApiService>());

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

private Lazy<AbsExposureDetectionBackgroundService> _exposureDetectionBackgroundService
= new Lazy<AbsExposureDetectionBackgroundService>(() => ContainerLocator.Current.Resolve<AbsExposureDetectionBackgroundService>());

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

public MainApplication(IntPtr handle, JniHandleOwnership transfer) : base(handle, transfer)
{
}
Expand All @@ -62,15 +66,22 @@ public override void OnCreate()
{
base.OnCreate();

AppCompatDelegate.DefaultNightMode = AppCompatDelegate.ModeNightNo;

App.InitializeServiceLocator(RegisterPlatformTypes);

AbsExposureNotificationClient.Handler = this;
if (_exposureNotificationApiService.Value is ExposureNotificationApiService exposureNotificationApiService)
{
SetupENClient(exposureNotificationApiService.Client);
}

try
{
_exposureDetectionBackgroundService.Value.Schedule();
}
catch (Exception exception)
{
_loggerService.Value.Exception("failed to Scheduling", exception);
}
}

private void SetupENClient(ExposureNotificationClient client)
Expand Down

0 comments on commit 86b9799

Please sign in to comment.