Skip to content

Commit

Permalink
Merge pull request #191 from DP-3T/develop
Browse files Browse the repository at this point in the history
Version 1.0.3
  • Loading branch information
simonroesch authored Jul 24, 2020
2 parents ad3150c + 586d252 commit 739bf16
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 46 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog for DP3T-SDK Android

## version 1.0.3 (24.7.2020)

- upgraded to play-services-nearby-18.0.3-eap (adds a service for Google to restart our application after force stop starting v1.5)
- add success and error callback to senFakeInfectedRequest
- add response body to StatusCodeException

## version 1.0.2 (17.7.2020)

- fix logic for when a sync is considered successfull in HistoryDatabase (only if no errors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ private void updateSdkStatus() {
Button buttonReportFake = view.findViewById(R.id.home_button_report_fake);
buttonReportFake.setOnClickListener(
v -> {
DP3T.sendFakeInfectedRequest(getContext(), null);
DP3T.sendFakeInfectedRequest(getContext(), null, null, null);
});

EditText deanonymizationDeviceId = view.findViewById(R.id.deanonymization_device_id);
Expand Down Expand Up @@ -427,4 +427,5 @@ private void setUploadDbLoadingViewVisible(boolean visible) {
view.findViewById(R.id.home_button_upload_db).setVisibility(visible ? View.INVISIBLE : View.VISIBLE);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
package org.dpppt.android.calibration.handshakes;

import android.content.Context;
import androidx.annotation.NonNull;

import org.dpppt.android.calibration.MainApplication;
import org.dpppt.android.sdk.backend.ResponseCallback;
import org.dpppt.android.sdk.internal.backend.Repository;
import org.dpppt.android.sdk.internal.backend.StatusCodeException;
import org.dpppt.android.sdk.internal.backend.models.GaenRequest;

import androidx.annotation.NonNull;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
Expand Down Expand Up @@ -46,7 +46,7 @@ public void onResponse(@NonNull Call<Void> call, @NonNull Response<Void> respons
if (response.isSuccessful()) {
responseCallback.onSuccess(null);
} else {
onFailure(call, new StatusCodeException(response.raw()));
onFailure(call, new StatusCodeException(response.raw(), response.errorBody()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
package org.dpppt.android.calibration.handshakes;

import android.content.Context;
import androidx.annotation.NonNull;

import java.io.IOException;

import org.dpppt.android.calibration.MainApplication;
import org.dpppt.android.sdk.backend.SignatureException;
import org.dpppt.android.sdk.internal.backend.Repository;
import org.dpppt.android.sdk.internal.backend.ServerTimeOffsetException;
import org.dpppt.android.sdk.internal.backend.StatusCodeException;

import java.io.IOException;

import androidx.annotation.NonNull;
import okhttp3.ResponseBody;
import retrofit2.Response;
import retrofit2.Retrofit;
Expand Down Expand Up @@ -47,7 +47,7 @@ public ResponseBody getGaenExposees(long batchReleaseTime)
if (response.isSuccessful() && response.body() != null) {
return response.body();
} else {
throw new StatusCodeException(response.raw());
throw new StatusCodeException(response.raw(), response.errorBody());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
attenuationBucket1Seeekbar = view.findViewById(R.id.parameter_seekbar_attenuation_bucket1);
attenuationBucket1Text = view.findViewById(R.id.parameter_seekbar_attenuation_bucket1_value);

attenuationBucket1Seeekbar.setMax(255);
attenuationBucket1Seeekbar.setMax(254);
attenuationBucket1Seeekbar.setProgress(appConfigManager.getAttenuationThresholdLow());
attenuationBucket1Seeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
Expand Down Expand Up @@ -99,6 +99,8 @@ public void onStopTrackingTouch(SeekBar seekBar) { }
attenuationBucket2Seeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int min = 1;
if (progress < min) progress = min;
setBucket2Value(progress);
}

Expand Down Expand Up @@ -133,16 +135,18 @@ public void onStopTrackingTouch(SeekBar seekBar) { }
BuildConfig.BUILD_TYPE);
}

private void setBucket1Value(int value) {
appConfigManager.setAttenuationThresholdLow(value);
attenuationBucket1Text.setText(Integer.toString(value));
attenuationBucket2Seeekbar.setProgress(Math.max(attenuationBucket2Seeekbar.getProgress(), value + 1));
private void setBucket1Value(int thresholdLow) {
int thresholdMedium = Math.max(attenuationBucket2Seeekbar.getProgress(), thresholdLow + 1);
appConfigManager.setAttenuationThresholds(thresholdLow, thresholdMedium);
attenuationBucket1Text.setText(Integer.toString(thresholdLow));
attenuationBucket2Seeekbar.setProgress(thresholdMedium);
}

private void setBucket2Value(int value) {
appConfigManager.setAttenuationThresholdMedium(value);
attenuationBucket2Text.setText(Integer.toString(value));
attenuationBucket1Seeekbar.setProgress(Math.min(attenuationBucket1Seeekbar.getProgress(), value - 1));
private void setBucket2Value(int thresholdMedium) {
int thresholdLow = Math.min(attenuationBucket1Seeekbar.getProgress(), thresholdMedium - 1);
appConfigManager.setAttenuationThresholds(thresholdLow, thresholdMedium);
attenuationBucket2Text.setText(Integer.toString(thresholdMedium));
attenuationBucket1Seeekbar.setProgress(thresholdLow);
}


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 29
versionCode 102
versionName "1.0.2"
versionCode 103
versionName "1.0.3"
testInstrumentationRunnerArgument 'androidx.benchmark.suppressErrors', 'EMULATOR,LOW-BATTERY,ACTIVITY-MISSING,DEBUGGABLE,UNLOCKED,UNSUSTAINED-ACTIVITY-MISSING'
testInstrumentationRunner "androidx.benchmark.junit4.AndroidBenchmarkRunner"

Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@

import com.google.android.gms.common.api.Api;
import com.google.android.gms.common.api.internal.ApiKey;
import com.google.android.gms.nearby.exposurenotification.ExposureConfiguration;
import com.google.android.gms.nearby.exposurenotification.ExposureInformation;
import com.google.android.gms.nearby.exposurenotification.ExposureNotificationClient;
import com.google.android.gms.nearby.exposurenotification.ExposureSummary;
import com.google.android.gms.nearby.exposurenotification.TemporaryExposureKey;
import com.google.android.gms.nearby.exposurenotification.*;
import com.google.android.gms.tasks.Task;

import org.dpppt.android.sdk.internal.util.Json;
Expand Down Expand Up @@ -85,6 +81,11 @@ public Task<Void> provideDiagnosisKeys(List<File> list, ExposureConfiguration ex
return new DummyTask<>(null);
}

@Override
public Task<List<ExposureWindow>> getExposureWindows(String s) {
return new DummyTask<>(new ArrayList<>());
}

@Override
public Task<ExposureSummary> getExposureSummary(String s) {
return new DummyTask<>(new ExposureSummary.ExposureSummaryBuilder().build());
Expand Down
20 changes: 14 additions & 6 deletions dp3t-sdk/sdk/src/main/java/org/dpppt/android/sdk/DP3T.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
import org.dpppt.android.sdk.internal.nearby.GoogleExposureClient;
import org.dpppt.android.sdk.internal.storage.ErrorNotificationStorage;
import org.dpppt.android.sdk.internal.storage.ExposureDayStorage;
import org.dpppt.android.sdk.internal.storage.models.PendingKey;
import org.dpppt.android.sdk.internal.storage.PendingKeyUploadStorage;
import org.dpppt.android.sdk.internal.storage.models.PendingKey;
import org.dpppt.android.sdk.models.ApplicationInfo;
import org.dpppt.android.sdk.models.DayDate;
import org.dpppt.android.sdk.models.ExposeeAuthMethod;
Expand Down Expand Up @@ -85,12 +85,12 @@ public static void init(Context context, ApplicationInfo applicationInfo, Public
googleExposureClient
.setParams(appConfigManager.getAttenuationThresholdLow(), appConfigManager.getAttenuationThresholdMedium());

executeInit(context.getApplicationContext());
executeInit(context.getApplicationContext(), appConfigManager);

initialized = true;
}

private static void executeInit(Context context) {
private static void executeInit(Context context, AppConfigManager appConfigManager) {
if (initialized) {
return;
}
Expand All @@ -114,6 +114,11 @@ private static void executeInit(Context context) {

GaenStateHelper.invalidateGaenAvailability(context);
GaenStateHelper.invalidateGaenEnabled(context);

if (appConfigManager.isTracingEnabled()) {
SyncWorker.startSyncWorker(context);
BroadcastHelper.sendUpdateAndErrorBroadcast(context);
}
}

public static boolean isInitialized() {
Expand Down Expand Up @@ -288,7 +293,8 @@ private static void reportFailedIAmInfected(Throwable e) {
pendingIAmInfectedRequest = null;
}

public static void sendFakeInfectedRequest(Context context, ExposeeAuthMethod exposeeAuthMethod) {
public static void sendFakeInfectedRequest(Context context, ExposeeAuthMethod exposeeAuthMethod, Runnable successCallback,
Runnable errorCallback) {
checkInit();

int delayedKeyDate = DateUtil.getCurrentRollingStartNumber();
Expand All @@ -311,6 +317,7 @@ public void onSuccess(String authToken) {
historyDatabase.addEntry(new HistoryEntry(HistoryEntryType.FAKE_REQUEST, null, true,
System.currentTimeMillis()));
}
if (successCallback != null) successCallback.run();
}

@Override
Expand All @@ -323,6 +330,7 @@ public void onError(Throwable throwable) {
historyDatabase.addEntry(new HistoryEntry(HistoryEntryType.FAKE_REQUEST, status, false,
System.currentTimeMillis()));
}
if (errorCallback != null) errorCallback.run();
}
});
} catch (IllegalStateException e) {
Expand All @@ -332,6 +340,7 @@ public void onError(Throwable throwable) {
historyDatabase.addEntry(new HistoryEntry(HistoryEntryType.FAKE_REQUEST, "SYST", false,
System.currentTimeMillis()));
}
if (errorCallback != null) errorCallback.run();
}
}

Expand Down Expand Up @@ -398,8 +407,7 @@ public static void setMatchingParameters(Context context, int attenuationThresho
checkInit();

AppConfigManager appConfigManager = AppConfigManager.getInstance(context);
appConfigManager.setAttenuationThresholdLow(attenuationThresholdLow);
appConfigManager.setAttenuationThresholdMedium(attenuationThresholdMedium);
appConfigManager.setAttenuationThresholds(attenuationThresholdLow, attenuationThresholdMedium);
appConfigManager.setAttenuationFactorLow(attenuationFactorLow);
appConfigManager.setAttenuationFactorMedium(attenuationFactorMedium);
appConfigManager.setMinDurationForExposure(minDurationForExposure);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;
import java.lang.IllegalArgumentException;

import org.dpppt.android.sdk.internal.backend.BackendReportRepository;
import org.dpppt.android.sdk.internal.nearby.GoogleExposureClient;
Expand Down Expand Up @@ -148,18 +149,17 @@ public int getAttenuationThresholdLow() {
return sharedPrefs.getInt(PREF_ATTENUATION_THRESHOLD_LOW, DEFAULT_ATTENUATION_THRESHOLD_LOW);
}

public void setAttenuationThresholdLow(int threshold) {
sharedPrefs.edit().putInt(PREF_ATTENUATION_THRESHOLD_LOW, threshold).apply();
googleExposureClient.setParams(threshold, getAttenuationThresholdMedium());
}

public int getAttenuationThresholdMedium() {
return sharedPrefs.getInt(PREF_ATTENUATION_THRESHOLD_MEDIUM, DEFAULT_ATTENUATION_THRESHOLD_MEDIUM);
}

public void setAttenuationThresholdMedium(int threshold) {
sharedPrefs.edit().putInt(PREF_ATTENUATION_THRESHOLD_MEDIUM, threshold).apply();
googleExposureClient.setParams(getAttenuationThresholdLow(), threshold);
public void setAttenuationThresholds(int thresholdLow, int thresholdMedium) {
if (thresholdLow >= thresholdMedium) {
throw new IllegalArgumentException("Illegal Arguments: thresholdLow must be smaller than thresholdMedium");
}
sharedPrefs.edit().putInt(PREF_ATTENUATION_THRESHOLD_LOW, thresholdLow).apply();
sharedPrefs.edit().putInt(PREF_ATTENUATION_THRESHOLD_MEDIUM, thresholdMedium).apply();
googleExposureClient.setParams(thresholdLow, thresholdMedium);
}

public float getAttenuationFactorLow() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
package org.dpppt.android.sdk.internal.backend;

import android.content.Context;
import androidx.annotation.NonNull;

import java.io.IOException;
import java.security.PublicKey;

import org.dpppt.android.sdk.backend.SignatureException;
import org.dpppt.android.sdk.backend.SignatureVerificationInterceptor;
import org.dpppt.android.sdk.models.DayDate;

import java.io.IOException;
import java.security.PublicKey;

import androidx.annotation.NonNull;
import okhttp3.OkHttpClient;
import okhttp3.ResponseBody;
import retrofit2.Response;
Expand Down Expand Up @@ -51,7 +51,7 @@ public Response<ResponseBody> getGaenExposees(DayDate keyDate, Long lastLoadedTi
if (response.isSuccessful()) {
return response;
} else {
throw new StatusCodeException(response.raw());
throw new StatusCodeException(response.raw(), response.errorBody());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void onResponse(@NonNull Call<Void> call, @NonNull Response<Void> respons
if (response.isSuccessful()) {
responseCallback.onSuccess(response.headers().get("Authorization"));
} else {
onFailure(call, new StatusCodeException(response.raw()));
onFailure(call, new StatusCodeException(response.raw(), response.errorBody()));
}
}

Expand All @@ -66,7 +66,7 @@ public void onFailure(@NonNull Call<Void> call, @NonNull Throwable throwable) {
public void addPendingGaenKey(GaenKey gaenKey, String token) throws IOException, StatusCodeException {
Response<Void> response = reportService.addPendingGaenKey(new GaenSecondDay(gaenKey), token).execute();
if (!response.isSuccessful()) {
throw new StatusCodeException(response.raw());
throw new StatusCodeException(response.raw(), response.errorBody());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,52 @@
*/
package org.dpppt.android.sdk.internal.backend;

import java.io.IOException;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import okhttp3.Response;
import okhttp3.ResponseBody;

public class StatusCodeException extends Exception {

private Response response;
private String body;

public StatusCodeException(@NonNull Response response) {
public StatusCodeException(@NonNull Response response, @Nullable ResponseBody errorBody) {
this.response = response;
this.body = readBody(errorBody);
}

@Nullable
@Override
public String getMessage() {
return "Code: " + response.code() + " Message: " + response.message();
StringBuilder sb = new StringBuilder()
.append("Code: ")
.append(response.code())
.append(" Message: ")
.append(response.message());
if (body != null) {
sb.append(" Body: ").append(body);
}
return sb.toString();
}

@Nullable
public String getBody() {
return body;
}

public int getCode() {
return response.code();
}

private static String readBody(ResponseBody body) {
try {
return body == null ? null : body.string();
} catch (IOException error) {
return null;
}
}
}

0 comments on commit 739bf16

Please sign in to comment.