Ejemplo n.º 1
0
 async Task DoAsyncWork()
 {
     if (await ExposureNotification.IsEnabledAsync())
     {
         await ExposureNotification.UpdateKeysFromServer();
     }
 }
        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);
        }
Ejemplo n.º 3
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();
            }
        }