Пример #1
0
 async Task DoAsyncWork()
 {
     if (await ExposureNotification.IsEnabledAsync())
     {
         await ExposureNotification.UpdateKeysFromServer();
     }
 }
		protected override async void OnHandleWork(Intent workIntent)
		{
			var token = workIntent.GetStringExtra(ExposureNotificationClient.ExtraToken);

			var summary = await ExposureNotification.PlatformGetExposureSummaryAsync(token);

			// Invoke the custom implementation handler code with the summary info
			if (summary?.MatchedKeyCount > 0)
			{
				var info = await ExposureNotification.PlatformGetExposureInformationAsync(token);

				await ExposureNotification.Handler.ExposureDetectedAsync(summary, info);
			}
		}
        static Task PlatformScheduleFetch()
        {
            // This is a special ID suffix which iOS treats a certain way
            // we can basically request infinite background tasks
            // and iOS will throttle it sensibly for us.
            var id = AppInfo.PackageName + ".exposure-notification";

            void scheduleBgTask()
            {
                var newBgTask = new BGProcessingTaskRequest(id);

                newBgTask.RequiresNetworkConnectivity = true;
                BGTaskScheduler.Shared.Submit(newBgTask, out _);
            }

            BGTaskScheduler.Shared.Register(id, null, async t =>
            {
                if (await PlatformIsEnabled())
                {
                    var cancelSrc       = new CancellationTokenSource();
                    t.ExpirationHandler = cancelSrc.Cancel;

                    Exception ex = null;
                    try
                    {
                        await ExposureNotification.UpdateKeysFromServer();
                    }
                    catch (Exception e)
                    {
                        ex = e;
                    }

                    t.SetTaskCompleted(ex != null);
                }

                scheduleBgTask();
            });

            scheduleBgTask();

            return(Task.CompletedTask);
        }
        protected override async void OnHandleWork(Intent workIntent)
        {
            Console.WriteLine($"C19R {nameof(ExposureNotificationCallbackService)}");
            var token = workIntent.GetStringExtra(ExposureNotificationClient.ExtraToken);

            var summary = await ExposureNotification.PlatformGetExposureSummaryAsync(token);

            Task <IEnumerable <ExposureInfo> > GetInfo()
            {
                return(ExposureNotification.PlatformGetExposureInformationAsync(token));
            }

            // Invoke the custom implementation handler code with the summary info
            Console.WriteLine($"C19R {nameof(ExposureNotificationCallbackService)}{summary?.MatchedKeyCount} Matched Key Count");

            if (summary?.MatchedKeyCount > 0)
            {
                await ExposureNotification.Handler.ExposureDetectedAsync(summary, GetInfo);
            }
        }
Пример #5
0
        protected override async void OnHandleWork(Intent workIntent)
        {
            if (workIntent.Action == ExposureNotificationCallbackBroadcastReceiver.ActionExposureStateUpdated)
            {
                var summary = await ExposureNotification.AndroidGetExposureSummary();

                if (summary != null && summary.MatchedKeyCount > 0)
                {
                    // Invoke the custom implementation handler code with the summary info
                    await ExposureNotification.Handler.ExposureDetected(
                        summary,
                        () => ExposureNotification.GetExposureInformationAsync());
                }
            }
            else if (workIntent.Action == ExposureNotificationCallbackBroadcastReceiver.ActionRequestDiagnosisKeys)
            {
                // Go fetch latest keys from server
                await ExposureNotification.UpdateKeysFromServer();
            }
        }