Skip to content

Commit

Permalink
Merge pull request #138 from keiji/add_exposure_configuration_to_call…
Browse files Browse the repository at this point in the history
…back

Pass ExposureConfiguration to Callback.
  • Loading branch information
keiji authored Dec 21, 2021
2 parents 8ddf184 + 998761a commit 94317ba
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 39 deletions.
17 changes: 12 additions & 5 deletions Chino.Android/ExposureStateBroadcastReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ public override bool OnStartJob(JobParameters @params)
{
try
{
handler.PreExposureDetected();
handler.PreExposureDetected(enClient.ExposureConfiguration);
var (exposureSummary, exposureInformations) = await GetExposureV1Async(enClient, token);
handler.ExposureDetected(exposureSummary, exposureInformations);
handler.ExposureDetected(exposureSummary, exposureInformations, enClient.ExposureConfiguration);
}
catch (ApiException exception)
{
Expand Down Expand Up @@ -290,11 +290,11 @@ public override bool OnStartJob(JobParameters @params)
{
try
{
handler.PreExposureDetected();
handler.PreExposureDetected(enClient.ExposureConfiguration);
var (dailySummaries, exposureWindows) = await GetExposureV2Async(enClient);
handler.ExposureDetected(dailySummaries, exposureWindows);
handler.ExposureDetected(dailySummaries, exposureWindows, enClient.ExposureConfiguration);
}
catch (ApiException exception)
{
Expand Down Expand Up @@ -381,11 +381,18 @@ JobSetting jobSetting
public override bool OnStartJob(JobParameters @params)
{
IExposureNotificationHandler? handler = null;
ExposureNotificationClient? enClient = null;
if (ApplicationContext is IExposureNotificationHandler exposureNotificationHandler)
{
handler = exposureNotificationHandler;
enClient = (ExposureNotificationClient)exposureNotificationHandler.GetEnClient();
}

if (enClient is null)
{
Logger.E("ExposureDetectedV2Job: enClient is null.");
return false;
}
if (handler is null)
{
Logger.E("ExposureDetectedV2Job: handler is null.");
Expand All @@ -396,7 +403,7 @@ public override bool OnStartJob(JobParameters @params)
{
try
{
handler.ExposureNotDetected();
handler.ExposureNotDetected(enClient.ExposureConfiguration);
}
finally
{
Expand Down
28 changes: 23 additions & 5 deletions Chino.Common/IExposureNotificationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public void DiagnosisKeysDataMappingApplied()
/// <summary>
/// A pre-event of Exposure is detected, before retrieving Exposure infomations.
/// </summary>
public void PreExposureDetected()
/// <param name="exposureConfiguration">Exposure configuration parameters that can be provided when detecting exposure.</param>
public void PreExposureDetected(ExposureConfiguration exposureConfiguration)
{
// do nothing
}
Expand All @@ -40,7 +41,12 @@ public void PreExposureDetected()
/// </summary>
/// <param name="dailySummaries">Daily exposure summary to pass to client side.</param>
/// <param name="exposureWindows">List of duration of up to 30 minutes during which beacons from a TEK were observed.</param>
public void ExposureDetected(IList<DailySummary> dailySummaries, IList<ExposureWindow> exposureWindows)
/// <param name="exposureConfiguration">Exposure configuration parameters that can be provided when detecting exposure.</param>
public void ExposureDetected(
IList<DailySummary> dailySummaries,
IList<ExposureWindow> exposureWindows,
ExposureConfiguration exposureConfiguration
)
{
// do nothing
}
Expand All @@ -51,7 +57,13 @@ public void ExposureDetected(IList<DailySummary> dailySummaries, IList<ExposureW
/// <param name="exposureSummary">Summary information about recent exposures.</param>
/// <param name="dailySummaries">Daily exposure summary to pass to client side.</param>
/// <param name="exposureWindows">List of duration of up to 30 minutes during which beacons from a TEK were observed.</param>
public void ExposureDetected(ExposureSummary exposureSummary, IList<DailySummary> dailySummaries, IList<ExposureWindow> exposureWindows)
/// <param name="exposureConfiguration">Exposure configuration parameters that can be provided when detecting exposure.</param>
public void ExposureDetected(
ExposureSummary exposureSummary,
IList<DailySummary> dailySummaries,
IList<ExposureWindow> exposureWindows,
ExposureConfiguration exposureConfiguration
)
{
// do nothing
}
Expand All @@ -61,15 +73,21 @@ public void ExposureDetected(ExposureSummary exposureSummary, IList<DailySummary
/// </summary>
/// <param name="exposureSummary">Summary information about recent exposures.</param>
/// <param name="exposureInformations">List of information about an exposure.</param>
public void ExposureDetected(ExposureSummary exposureSummary, IList<ExposureInformation> exposureInformations)
/// <param name="exposureConfiguration">Exposure configuration parameters that can be provided when detecting exposure.</param>
public void ExposureDetected(
ExposureSummary exposureSummary,
IList<ExposureInformation> exposureInformations,
ExposureConfiguration exposureConfiguration
)
{
// do nothing
}

/// <summary>
/// An event of Exposure is not detected.
/// </summary>
public void ExposureNotDetected()
/// <param name="exposureConfiguration">Exposure configuration parameters that can be provided when detecting exposure.</param>
public void ExposureNotDetected(ExposureConfiguration exposureConfiguration)
{
// do nothing
}
Expand Down
28 changes: 14 additions & 14 deletions Chino.iOS/ExposureNotificationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ public async override Task<ProvideDiagnosisKeysResult> ProvideDiagnosisKeysAsync

ENExposureConfiguration exposureConfiguration = enAPiVersion switch
{
2 => ExposureConfiguration.AppleExposureConfigV2.ToENExposureConfiguration(),
_ => ExposureConfiguration.AppleExposureConfigV1.ToENExposureConfiguration(),
2 => configuration.AppleExposureConfigV2.ToENExposureConfiguration(),
_ => configuration.AppleExposureConfigV1.ToENExposureConfiguration(),

};
Logger.D(exposureConfiguration.ToString());
Expand All @@ -329,15 +329,15 @@ out NSProgress result

if (enAPiVersion == 2 && UIDevice.CurrentDevice.CheckSystemVersion(13, 7))
{
await GetExposureV2(summary, Handler);
await GetExposureV2(summary, configuration, Handler);
}
else if (UIDevice.CurrentDevice.CheckSystemVersion(13, 5))
{
await GetExposureV1(summary, Handler);
await GetExposureV1(summary, configuration, Handler);
}
else if (Class.GetHandle("ENManager") != null)
{
await GetExposureV2(summary, Handler);
await GetExposureV2(summary, configuration, Handler);
}
else
{
Expand Down Expand Up @@ -391,44 +391,44 @@ public override async Task<ProvideDiagnosisKeysResult> ProvideDiagnosisKeysAsync
=> await ProvideDiagnosisKeysAsync(keyFiles, configuration, cancellationTokenSource);
#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member

private async Task GetExposureV2(ENExposureDetectionSummary summary, IExposureNotificationHandler handler)
private async Task GetExposureV2(ENExposureDetectionSummary summary, ExposureConfiguration exposureConfiguration, IExposureNotificationHandler handler)
{
Logger.D($"GetExposureV2");

List<DailySummary> dailySummaries = summary.DaySummaries.Select(ds => (DailySummary)new PlatformDailySummary(ds)).ToList();

if (dailySummaries.Count > 0)
{
handler.PreExposureDetected();
handler.PreExposureDetected(exposureConfiguration);

ENExposureWindow[] ews = await EnManager.Value.GetExposureWindowsAsync(summary);
List<ExposureWindow> exposureWindows = ews.Select(ew => (ExposureWindow)new PlatformExposureWindow(ew)).ToList();

handler.ExposureDetected(dailySummaries, exposureWindows);
handler.ExposureDetected(new PlatformExposureSummary(summary), dailySummaries, exposureWindows);
handler.ExposureDetected(dailySummaries, exposureWindows, exposureConfiguration);
handler.ExposureDetected(new PlatformExposureSummary(summary), dailySummaries, exposureWindows, exposureConfiguration);
}
else
{
handler.ExposureNotDetected();
handler.ExposureNotDetected(exposureConfiguration);
}
}

private async Task GetExposureV1(ENExposureDetectionSummary summary, IExposureNotificationHandler handler)
private async Task GetExposureV1(ENExposureDetectionSummary summary, ExposureConfiguration exposureConfiguration, IExposureNotificationHandler handler)
{
Logger.D($"GetExposureV1");

if (summary.MatchedKeyCount > 0)
{
handler.PreExposureDetected();
handler.PreExposureDetected(exposureConfiguration);

ENExposureInfo[] eis = await EnManager.Value.GetExposureInfoAsync(summary, UserExplanation);
List<ExposureInformation> exposureInformations = eis.Select(ei => (ExposureInformation)new PlatformExposureInformation(ei)).ToList();

handler.ExposureDetected(new PlatformExposureSummary(summary), exposureInformations);
handler.ExposureDetected(new PlatformExposureSummary(summary), exposureInformations, exposureConfiguration);
}
else
{
handler.ExposureNotDetected();
handler.ExposureNotDetected(exposureConfiguration);
}
}

Expand Down
16 changes: 8 additions & 8 deletions Sample.Android/MainApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ public void TemporaryExposureKeyReleased(IList<TemporaryExposureKey> temporaryEx
Logger.D(serializedJson);
}

public void PreExposureDetected()
public void PreExposureDetected(ExposureConfiguration exposureConfiguration)
{
Logger.D($"PreExposureDetected: {DateTime.UtcNow}");
}

public void ExposureDetected(IList<DailySummary> dailySummaries, IList<ExposureWindow> exposureWindows)
public void ExposureDetected(IList<DailySummary> dailySummaries, IList<ExposureWindow> exposureWindows, ExposureConfiguration exposureConfiguration)
{
Logger.D($"ExposureDetected ExposureWindows: {DateTime.UtcNow}");

Expand All @@ -121,7 +121,7 @@ public void ExposureDetected(IList<DailySummary> dailySummaries, IList<ExposureW
var enVersion = (await EnClient.GetVersionAsync()).ToString();
var exposureResult = new ExposureResult(
EnClient.ExposureConfiguration,
exposureConfiguration,
DateTime.Now,
dailySummaries, exposureWindows
)
Expand All @@ -134,7 +134,7 @@ public void ExposureDetected(IList<DailySummary> dailySummaries, IList<ExposureW
var exposureDataServerConfiguration = await LoadExposureDataServerConfiguration();
var exposureDataResponse = await new ExposureDataServer(exposureDataServerConfiguration).UploadExposureDataAsync(
EnClient.ExposureConfiguration,
exposureConfiguration,
DeviceInfo.Model,
enVersion,
dailySummaries, exposureWindows
Expand All @@ -148,7 +148,7 @@ public void ExposureDetected(IList<DailySummary> dailySummaries, IList<ExposureW
});
}

public void ExposureDetected(ExposureSummary exposureSummary, IList<ExposureInformation> exposureInformations)
public void ExposureDetected(ExposureSummary exposureSummary, IList<ExposureInformation> exposureInformations, ExposureConfiguration exposureConfiguration)
{
Logger.D($"ExposureDetected Legacy-v1: {DateTime.UtcNow}");

Expand All @@ -157,7 +157,7 @@ public void ExposureDetected(ExposureSummary exposureSummary, IList<ExposureInfo
var enVersion = (await EnClient.GetVersionAsync()).ToString();
var exposureResult = new ExposureResult(
EnClient.ExposureConfiguration,
exposureConfiguration,
DateTime.Now,
exposureSummary, exposureInformations
)
Expand All @@ -184,7 +184,7 @@ public void ExposureDetected(ExposureSummary exposureSummary, IList<ExposureInfo
});
}

public void ExposureNotDetected()
public void ExposureNotDetected(ExposureConfiguration exposureConfiguration)
{
Logger.D($"ExposureNotDetected: {DateTime.UtcNow}");

Expand All @@ -193,7 +193,7 @@ public void ExposureNotDetected()
var enVersion = (await EnClient.GetVersionAsync()).ToString();
var exposureResult = new ExposureResult(
EnClient.ExposureConfiguration,
exposureConfiguration,
DateTime.Now
)
{
Expand Down
14 changes: 7 additions & 7 deletions Sample.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ public void TemporaryExposureKeyReleased(IList<TemporaryExposureKey> temporaryEx
}
}

public void PreExposureDetected()
public void PreExposureDetected(ExposureConfiguration exposureConfiguration)
{
Logger.D($"PreExposureDetected: {DateTime.UtcNow}");
}

public void ExposureDetected(ExposureSummary exposureSummary, IList<DailySummary> dailySummaries, IList<ExposureWindow> exposureWindows)
public void ExposureDetected(ExposureSummary exposureSummary, IList<DailySummary> dailySummaries, IList<ExposureWindow> exposureWindows, ExposureConfiguration exposureConfiguration)
{
Logger.D($"ExposureDetected V2: {DateTime.UtcNow}");

Expand All @@ -119,7 +119,7 @@ public void ExposureDetected(ExposureSummary exposureSummary, IList<DailySummary
var enVersion = (await ExposureNotificationClientManager.Shared.GetVersionAsync()).ToString();
var exposureResult = new ExposureResult(
ExposureNotificationClientManager.Shared.ExposureConfiguration,
exposureConfiguration,
DateTime.Now,
exposureSummary,
null,
Expand Down Expand Up @@ -149,7 +149,7 @@ public void ExposureDetected(ExposureSummary exposureSummary, IList<DailySummary
});
}

public void ExposureDetected(ExposureSummary exposureSummary, IList<ExposureInformation> exposureInformations)
public void ExposureDetected(ExposureSummary exposureSummary, IList<ExposureInformation> exposureInformations, ExposureConfiguration exposureConfiguration)
{
Logger.D($"ExposureDetected V1: {DateTime.UtcNow}");

Expand All @@ -158,7 +158,7 @@ public void ExposureDetected(ExposureSummary exposureSummary, IList<ExposureInfo
var enVersion = (await ExposureNotificationClientManager.Shared.GetVersionAsync()).ToString();
var exposureResult = new ExposureResult(
ExposureNotificationClientManager.Shared.ExposureConfiguration,
exposureConfiguration,
DateTime.Now,
exposureSummary, exposureInformations
)
Expand All @@ -185,7 +185,7 @@ public void ExposureDetected(ExposureSummary exposureSummary, IList<ExposureInfo
});
}

public void ExposureNotDetected()
public void ExposureNotDetected(ExposureConfiguration exposureConfiguration)
{
Logger.D($"ExposureNotDetected: {DateTime.UtcNow}");

Expand All @@ -194,7 +194,7 @@ public void ExposureNotDetected()
var enVersion = (await ExposureNotificationClientManager.Shared.GetVersionAsync()).ToString();
var exposureResult = new ExposureResult(
ExposureNotificationClientManager.Shared.ExposureConfiguration,
exposureConfiguration,
DateTime.Now
)
{
Expand Down

0 comments on commit 94317ba

Please sign in to comment.