Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make sure google api calls do not block our thread forever if neither… #226

Merged
merged 4 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog for DP3T-SDK Android


## version 2.0.2 (22.01.2021)

- make sure GoogleExposureClient does not block thread forever, but times out after 5min. This to prevent Workers to be stuck, if an EN method does not call the success or error callback, due to an error or missconfiguration in the EN framework.

## version 2.0.1 (22.12.2020)

- updated all dependencies
Expand Down
4 changes: 2 additions & 2 deletions dp3t-sdk/sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ android {
defaultConfig {
minSdkVersion 23
targetSdkVersion 30
versionCode 201
versionName "2.0.1"
versionCode 202
versionName "2.0.2"
testInstrumentationRunnerArgument 'androidx.benchmark.suppressErrors', 'EMULATOR,LOW-BATTERY,ACTIVITY-MISSING,DEBUGGABLE,UNLOCKED,UNSUSTAINED-ACTIVITY-MISSING'
testInstrumentationRunner "androidx.benchmark.junit4.AndroidBenchmarkRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.File;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.nearby.Nearby;
Expand All @@ -33,6 +34,8 @@ public class GoogleExposureClient {

private static final String EITHER_EXCEPTION_OR_RESULT_MUST_BE_SET = "either exception or result must be set";

private static final long TIMEOUT_EXPOSURE_CLIENT_CALL_MS = 5 * 60 * 1000L;//5min

private static GoogleExposureClient instance;

private final ExposureNotificationClient exposureNotificationClient;
Expand Down Expand Up @@ -131,7 +134,10 @@ public List<TemporaryExposureKey> getTemporaryExposureKeyHistorySynchronous() th
countDownLatch.countDown();
});

countDownLatch.await();
boolean noTimeout = countDownLatch.await(TIMEOUT_EXPOSURE_CLIENT_CALL_MS, TimeUnit.MILLISECONDS);
if (!noTimeout) {
throw new IllegalStateException("getTemporaryExposureKeyHistory() did not result in success or failure in time.");
}

if (results[0] instanceof Exception) {
throw (Exception) results[0];
Expand Down Expand Up @@ -159,7 +165,12 @@ public void provideDiagnosisKeys(List<File> keys) throws Exception {
exceptions[0] = e;
countDownLatch.countDown();
});
countDownLatch.await();

boolean noTimeout = countDownLatch.await(TIMEOUT_EXPOSURE_CLIENT_CALL_MS, TimeUnit.MILLISECONDS);
if (!noTimeout) {
throw new IllegalStateException("provideDiagnosisKeys() did not result in success or failure in time.");
}

if (exceptions[0] != null) {
throw exceptions[0];
}
Expand Down Expand Up @@ -189,7 +200,11 @@ public void provideDiagnosisKeys(List<File> keys, ExposureConfiguration exposure
exceptions[0] = e;
countDownLatch.countDown();
});
countDownLatch.await();

boolean noTimeout = countDownLatch.await(TIMEOUT_EXPOSURE_CLIENT_CALL_MS, TimeUnit.MILLISECONDS);
if (!noTimeout) {
throw new IllegalStateException("provideDiagnosisKeys() did not result in success or failure in time.");
}

if (exceptions[0] != null) {
throw exceptions[0];
Expand All @@ -214,7 +229,10 @@ public ExposureSummary getExposureSummary(String token) throws Exception {
countDownLatch.countDown();
});

countDownLatch.await();
boolean noTimeout = countDownLatch.await(TIMEOUT_EXPOSURE_CLIENT_CALL_MS, TimeUnit.MILLISECONDS);
if (!noTimeout) {
throw new IllegalStateException("getExposureSummary() did not result in success or failure in time.");
}

if (results[0] instanceof Exception) {
throw (Exception) results[0];
Expand All @@ -238,7 +256,12 @@ public List<ExposureWindow> getExposureWindows() throws Exception {
results[0] = e;
countDownLatch.countDown();
});
countDownLatch.await();

boolean noTimeout = countDownLatch.await(TIMEOUT_EXPOSURE_CLIENT_CALL_MS, TimeUnit.MILLISECONDS);
if (!noTimeout) {
throw new IllegalStateException("getExposureWindows() did not result in success or failure in time.");
}

if (results[0] instanceof Exception) {
throw (Exception) results[0];
} else if (results[0] instanceof List) {
Expand Down Expand Up @@ -268,7 +291,12 @@ public Integer getCalibrationConfidence() throws Exception {
results[0] = e;
countDownLatch.countDown();
});
countDownLatch.await();

boolean noTimeout = countDownLatch.await(TIMEOUT_EXPOSURE_CLIENT_CALL_MS, TimeUnit.MILLISECONDS);
if (!noTimeout) {
throw new IllegalStateException("getCalibrationConfidence() did not result in success or failure in time.");
}

if (results[0] instanceof Exception) {
throw (Exception) results[0];
} else if (results[0] instanceof Integer) {
Expand Down