Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

Commit

Permalink
fixed server upload / changed LOGTag to include ITO
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwo committed May 6, 2020
1 parent 11e523b commit 07105c0
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 36 deletions.
2 changes: 1 addition & 1 deletion android/src/main/java/org/itoapp/strict/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class Helper {

private static final String LOG_TAG = "Helper";
private static final String LOG_TAG = "ITOHelper";
private static MessageDigest sha256MessageDigest;

private Helper() {
Expand Down
2 changes: 1 addition & 1 deletion android/src/main/java/org/itoapp/strict/Preconditions.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


public class Preconditions {
private static final String LOG_TAG = "Preconditions";
private static final String LOG_TAG = "ITOPreconditions";

public static boolean isLocationServiceEnabled(Context context) {
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class ItoDBHelper {


private static final String LOG_TAG = "ItoDBHelper";
private static final String LOG_TAG = "ITODBHelper";

private void checkHashedUUID(byte[] hashedUUID) {

Expand Down
46 changes: 24 additions & 22 deletions android/src/main/java/org/itoapp/strict/network/NetworkHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

public class NetworkHelper {

private static final String LOG_TAG = "InfectedUUIDRepository";
public static final String BASE_URL = "http://loon:8080/tcnreport";
private static final String LOG_TAG = "ITOInfectedUUIDRepository";
public static final String BASE_URL = "https://tcn.ito-app.org/tcnreport";

private static final int SIGNATURELENGTH = 64;
private static final int BASELENGTH = 70;
Expand Down Expand Up @@ -84,33 +84,35 @@ public static List<byte[]> refreshInfectedUUIDs() {

lastReportHashForServer.lastcheck = new Date();

lastReportHashForServer.lastReportHash = byte2Hex(Arrays.copyOfRange(lastreport,0,lastreport.length -SIGNATURELENGTH));
lastReportHashForServer.lastReportHash = byte2Hex(Arrays.copyOfRange(lastreport, 0, lastreport.length - SIGNATURELENGTH));
RoomDB.db.lastReportDao().saveOrUpdate(lastReportHashForServer);
}
return reports;
}


public static void publishReport(byte[] report) throws IOException {
public static void publishReports(List<byte[]> reports) throws IOException {

HttpURLConnection urlConnection = null;
try {
URL url = new URL(BASE_URL);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.addRequestProperty("Content-Type", "application/octet-stream");
OutputStream outputStream = new BufferedOutputStream(urlConnection.getOutputStream());
outputStream.write(report);
outputStream.close();
for (byte[] report : reports) // FIXME: validate return code
try {
URL url = new URL(BASE_URL);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);
urlConnection.addRequestProperty("Content-Type", "application/octet-stream");
OutputStream outputStream = new BufferedOutputStream(urlConnection.getOutputStream());
outputStream.write(report);
outputStream.close();

InputStream inputStream = urlConnection.getInputStream();
inputStream.read();
inputStream.close();
} catch (MalformedURLException e) {
Log.wtf(LOG_TAG, "Malformed URL?!", e);
throw new RuntimeException(e);
} finally {
if (urlConnection != null)
urlConnection.disconnect();
}
InputStream inputStream = urlConnection.getInputStream();
inputStream.read();
inputStream.close();
} catch (MalformedURLException e) {
Log.wtf(LOG_TAG, "Malformed URL?!", e);
throw new RuntimeException(e);
} finally {
if (urlConnection != null)
urlConnection.disconnect();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import static org.itoapp.strict.Constants.BLUETOOTH_COMPANY_ID;

public class BleAdvertiser {
private static final String LOG_TAG = "BleAdvertiser";
private static final String LOG_TAG = "ITOBleAdvertiser";
private final Handler serviceHandler;

private byte[] broadcastData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import static org.itoapp.strict.Constants.HASH_LENGTH;

public class BleScanner {
private static final String LOG_TAG = "BleScanner";
private static final String LOG_TAG = "ITOBleScanner";

private BluetoothLeScanner bluetoothLeScanner;
private ScanCallback bluetoothScanCallback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import static org.itoapp.strict.Helper.byte2Hex;

public class CheckServerTask extends AsyncTask<Void, Void, Void> {
private static final String LOG_TAG = "CheckServerTask";
private static final String LOG_TAG = "ITOCheckServerTask";
private ItoDBHelper dbHelper;

public CheckServerTask(ItoDBHelper itoDBHelper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,30 @@
import android.util.Log;

import org.itoapp.PublishUUIDsCallback;
import org.itoapp.strict.database.RoomDB;
import org.itoapp.strict.network.NetworkHelper;

import java.io.IOException;
import java.util.List;

class PublishBeaconsTask extends AsyncTask<Void, Void, Void> {
private static final String LOG_TAG = "PublishBeaconsTask";
private byte[] report;
private List<byte[]> report;
private long from;
private long to;
private PublishUUIDsCallback callback;

public PublishBeaconsTask(byte[] report, PublishUUIDsCallback callback) {
public PublishBeaconsTask(List<byte[]> report, PublishUUIDsCallback callback) {
this.report = report;
this.callback = callback;
}

@Override
protected Void doInBackground(Void... voids) {
try {
NetworkHelper.publishReport(report);
NetworkHelper.publishReports(report);
try {
RoomDB.db.localKeyDao().deleteAll(); // remove all Keys that we have sent
callback.onSuccess();
} catch (RemoteException e) {
Log.e(LOG_TAG, "._.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public static void generateAllTCNsFromReport(byte[] report, INextTCNCallback cal
byte[] bstartTCK = Arrays.copyOfRange(report, 32, 64);
TCNProtoGen ratchet = new TCNProtoGen(report[68], getRvkfromReport(report), bstartTCK, from - 1);
int to = readUShort(report, 66);
//System.out.println("reading from " + from + " to " + to);
callback.next(ratchet.getCurrentTCN());
for (int i = from; i < to; i++) {
callback.next(ratchet.getNewTCN());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.content.IntentFilter;
import android.graphics.Color;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
Expand All @@ -30,14 +31,16 @@
import org.itoapp.strict.database.RoomDB;

import java.security.SecureRandom;
import java.util.List;
import java.util.stream.Collectors;

import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;

import static org.itoapp.strict.Constants.RATCHET_EXCHANGE_INTERVAL;

public class TracingService extends Service {
private static final String LOG_TAG = "TracingService";
private static final String LOG_TAG = "ITOTracingService";
private static final String DEFAULT_NOTIFICATION_CHANNEL = "ContactTracing";
private static final int NOTIFICATION_ID = 1;
private TCNProtoGen tcnProto;
Expand Down Expand Up @@ -72,8 +75,9 @@ public void setDistanceCallback(DistanceCallback distanceCallback) {
@Override
public void publishBeaconUUIDs(long from, long to, PublishUUIDsCallback callback) {
// todo use from & to ?
TCNProtoUtil.loadAllRatchets().forEach(ratchet ->
new PublishBeaconsTask(ratchet.generateReport(ratchet.getRatchetTickCount()), callback).execute());
List<byte[]> reports = TCNProtoUtil.loadAllRatchets().stream().map(ratchet -> ratchet.generateReport(ratchet.getRatchetTickCount())).collect(Collectors.toList());

new PublishBeaconsTask(reports, callback).execute();
}

@RequiresApi(api = 24)
Expand Down Expand Up @@ -119,7 +123,15 @@ public int getLatestFetchTime() {
tcnProto = new TCNProtoGen();
}
bleAdvertiser.setBroadcastData(tcnProto.getNewTCN());
TCNProtoUtil.persistRatchet(tcnProto);


AsyncTask.execute(new Runnable() { // FIXME make everything async and get aligned with sendReport etc.
@Override
public void run() {
TCNProtoUtil.persistRatchet(tcnProto);
}
});

serviceHandler.postDelayed(this.regenerateUUID, Constants.TCN_VALID_INTERVAL);
};
//TODO move this to some alarmManager governed section.
Expand Down

0 comments on commit 07105c0

Please sign in to comment.