Skip to content

Commit

Permalink
Merge pull request #246 from DP-3T/develop
Browse files Browse the repository at this point in the history
Version 1.2.0
  • Loading branch information
simonroesch committed Oct 28, 2020
2 parents 5d8fc53 + a4c04c6 commit 293e126
Show file tree
Hide file tree
Showing 37 changed files with 1,168 additions and 431 deletions.
7 changes: 3 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ android {
applicationId "ch.admin.bag.dp3t"
minSdkVersion 23
targetSdkVersion 30
versionCode 11200
versionName "1.1.2"
versionCode 12000
versionName "1.2.0"
resConfigs "en", "fr", "de", "it", "pt", "es", "sq", "bs", "hr", "sr", "rm", "tr", "ti"

buildConfigField "long", "BUILD_TIME", readPropertyWithDefault('buildTimestamp', System.currentTimeMillis()) + 'L'
Expand Down Expand Up @@ -152,7 +152,7 @@ sonarqube {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])

def dp3t_sdk_version = '1.0.5'
def dp3t_sdk_version = '2.0.0'
devImplementation "org.dpppt:dp3t-sdk-android:$dp3t_sdk_version-calibration"
teschtImplementation "org.dpppt:dp3t-sdk-android:$dp3t_sdk_version"
abnahmeImplementation "org.dpppt:dp3t-sdk-android:$dp3t_sdk_version"
Expand Down Expand Up @@ -183,6 +183,5 @@ dependencies {
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.work:work-testing:2.3.4'
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:3.14.7'
androidTestImplementation "androidx.work:work-testing:2.3.4"

}
Binary file removed app/libs/play-services-nearby-18.0.3-eap.aar
Binary file not shown.
Binary file not shown.
14 changes: 8 additions & 6 deletions app/src/androidTest/java/ch/admin/bag/dp3t/FakeWorkerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import android.util.Log;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.work.*;
import androidx.work.Configuration;
import androidx.work.WorkInfo;
import androidx.work.WorkManager;
import androidx.work.testing.SynchronousExecutor;
import androidx.work.testing.TestDriver;
import androidx.work.testing.WorkManagerTestInitHelper;
Expand Down Expand Up @@ -60,11 +62,11 @@ public void setup() throws IOException {
server.start();

AppConfigManager appConfigManager = AppConfigManager.getInstance(context);
DP3T.init(context, new ApplicationInfo("test", server.url("/bucket/").toString(), server.url("/report/").toString()),
DP3T.init(context, new ApplicationInfo(server.url("/bucket/").toString(), server.url("/report/").toString()),
null);
appConfigManager.setTracingEnabled(false);
DP3T.clearData(context);
DP3T.init(context, new ApplicationInfo("test", server.url("/bucket/").toString(), server.url("/report/").toString()),
DP3T.init(context, new ApplicationInfo(server.url("/bucket/").toString(), server.url("/report/").toString()),
null);
appConfigManager.setTracingEnabled(true);

Expand All @@ -78,7 +80,7 @@ public void testInitialTDummy() throws Exception {

FakeWorker.safeStartFakeWorker(context);
// TDummy is initialized to a time in the future.
assertTrue (SecureStorage.getInstance(context).getTDummy() > System.currentTimeMillis());
assertTrue(SecureStorage.getInstance(context).getTDummy() > System.currentTimeMillis());
}

@Test
Expand Down Expand Up @@ -199,8 +201,8 @@ public void testSyncInterval() {
double max = 1.1 / FakeWorker.SAMPLING_RATE;
double min = 0.9 / FakeWorker.SAMPLING_RATE;

assertTrue (averageIntervalDays < max);
assertTrue (averageIntervalDays > min);
assertTrue(averageIntervalDays < max);
assertTrue(averageIntervalDays > min);
}

@Test
Expand Down
32 changes: 26 additions & 6 deletions app/src/dev/java/ch/admin/bag/dp3t/debug/DebugFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@

import android.content.res.ColorStateList;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.ViewModelProvider;

import java.util.Arrays;

import org.dpppt.android.sdk.DP3T;
import org.dpppt.android.sdk.internal.storage.ExposureDayStorage;
import org.dpppt.android.sdk.models.DayDate;
Expand Down Expand Up @@ -117,18 +122,33 @@ private void setupStateOptions(View view) {
updateRadioGroup(optionsGroup);

view.findViewById(R.id.debug_button_testmeldung).setOnClickListener(v -> {
exposeMyself();
getActivity().finish();
showExposureDaysInputDialog();
});
}

private void exposeMyself() {
private void showExposureDaysInputDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(getString(R.string.number_of_exposure_days));
final EditText input = new EditText(getContext());
input.setText("2");
input.setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_CLASS_NUMBER);
builder.setView(input);
builder.setPositiveButton(R.string.android_button_ok,
(a, b) -> exposeMyself(Integer.parseInt(input.getText().toString())));
builder.show();
}

private void exposeMyself(int numberOfDays) {

ExposureDayStorage eds = ExposureDayStorage.getInstance(requireContext());
eds.clear();

DayDate dayOfExposure = new DayDate();
ExposureDay exposureDay = new ExposureDay(-1, dayOfExposure, System.currentTimeMillis());
eds.addExposureDay(requireContext(), exposureDay);
for (int i = 0; i < numberOfDays; i++) {
DayDate dayOfExposure = new DayDate().subtractDays(i);
ExposureDay exposureDay = new ExposureDay(i, dayOfExposure, System.currentTimeMillis());
eds.addExposureDays(requireContext(), Arrays.asList(exposureDay));
}
getActivity().finish();
}

private void updateRadioGroup(RadioGroup optionsGroup) {
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/ch/admin/bag/dp3t/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,13 @@ public void onActivityDestroyed(Activity activity) {

public static void initDP3T(Context context) {
PublicKey signaturePublicKey = SignatureUtil.getPublicKeyFromBase64OrThrow(BuildConfig.BUCKET_PUBLIC_KEY);
DP3T.init(context, new ApplicationInfo("dp3t-app", BuildConfig.REPORT_URL, BuildConfig.BUCKET_URL), signaturePublicKey,
DP3T.init(context, new ApplicationInfo(BuildConfig.REPORT_URL, BuildConfig.BUCKET_URL), signaturePublicKey,
BuildConfig.DEV_HISTORY);

DP3T.setCertificatePinner(CertificatePinning.getCertificatePinner());
DP3T.setUserAgent(context.getPackageName() + ";" + BuildConfig.VERSION_NAME + ";" + BuildConfig.BUILD_TIME + ";Android;" +
Build.VERSION.SDK_INT);
DP3T.setUserAgent(
() -> context.getPackageName() + ";" + BuildConfig.VERSION_NAME + ";" + BuildConfig.BUILD_TIME + ";Android;" +
Build.VERSION.SDK_INT + ";" + DP3T.getENModuleVersion(context));
}

private BroadcastReceiver contactUpdateReceiver = new BroadcastReceiver() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ public ConfigRepository(@NonNull Context context) {
secureStorage = SecureStorage.getInstance(context);
}

public ConfigResponseModel getConfig() throws IOException, ResponseError {
public ConfigResponseModel getConfig(Context context) throws IOException, ResponseError {
String appVersion = APP_VERSION_PREFIX_ANDROID + BuildConfig.VERSION_NAME;
String osVersion = OS_VERSION_PREFIX_ANDROID + Build.VERSION.SDK_INT;
String buildNumber = String.valueOf(BuildConfig.BUILD_TIME);
String enModuleVersion = String.valueOf(DP3T.getENModuleVersion(context));

Response<ConfigResponseModel> configResponse = configService.getConfig(appVersion, osVersion, buildNumber).execute();
Response<ConfigResponseModel> configResponse = configService.getConfig(appVersion, osVersion, buildNumber, enModuleVersion).execute();
if (configResponse.isSuccessful()) {
secureStorage.setLastConfigLoadSuccess(System.currentTimeMillis());
secureStorage.setLastConfigLoadSuccessAppVersion(BuildConfig.VERSION_CODE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
package ch.admin.bag.dp3t.networking;

import ch.admin.bag.dp3t.networking.models.ConfigResponseModel;

import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Headers;
Expand All @@ -23,7 +22,8 @@ public interface ConfigService {
Call<ConfigResponseModel> getConfig(
@Query("appversion") String appVersion,
@Query("osversion") String osVersion,
@Query("buildnr") String buildNumber
@Query("buildnr") String buildNumber,
@Query("enModuleVersion") String enModuleVersion
);

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Result doWork() {

private static void loadConfig(Context context) throws IOException, ResponseError, SignatureException {
ConfigRepository configRepository = new ConfigRepository(context);
ConfigResponseModel config = configRepository.getConfig();
ConfigResponseModel config = configRepository.getConfig(context);

DP3T.setMatchingParameters(context,
config.getSdkConfig().getLowerThreshold(), config.getSdkConfig().getHigherThreshold(),
Expand Down
Loading

0 comments on commit 293e126

Please sign in to comment.