diff --git a/ebc_enclave_messaging b/ebc_enclave_messaging index 525420689192984227bf975cb9a61c32276029a5..9b0f55007d93bbe13e48f2750d0b887c880a8add 160000 --- a/ebc_enclave_messaging +++ b/ebc_enclave_messaging @@ -1 +1 @@ -Subproject commit 525420689192984227bf975cb9a61c32276029a5 +Subproject commit 9b0f55007d93bbe13e48f2750d0b887c880a8add diff --git a/ebclibrary/src/main/java/org/mpisws/encounters/clients/SDDRClient.java b/ebclibrary/src/main/java/org/mpisws/encounters/clients/SDDRClient.java index 8ac1a409da4a71660906084279a8b599c5e9e4b3..83a409ed03f53eb984f820c4b34bcb15da721c4f 100644 --- a/ebclibrary/src/main/java/org/mpisws/encounters/clients/SDDRClient.java +++ b/ebclibrary/src/main/java/org/mpisws/encounters/clients/SDDRClient.java @@ -6,7 +6,6 @@ import android.util.Log; import org.apache.commons.lang3.tuple.Pair; import org.mpisws.database.DBEncounterInfo; -import org.mpisws.database.DBTimestamp; import org.mpisws.encounters.encounterhistory.bridges.EncounterEntriesBridge; import org.mpisws.encounters.lib.time.TimeInterval; import org.mpisws.helpers.ThreadPoolManager; @@ -101,9 +100,11 @@ public class SDDRClient implements EncounterBasedCommunication.ISDDRClient { Log.d(TAG, "Issuing credentials"); int ret = CloudAgentHelpers.issueSetCredentialsRequest(Preferences.getInstance().getUserHandle(), Preferences.getInstance().getAuthorizationToken()); Log.d(TAG, "Issued Credentials: " + ret); - List locations = new LocationBridge(context).getLocationsSinceTime(Preferences.getInstance().getDBTimestamp().getLocationsDBTimestamp()); + + // get all locations and encounters that have completed past the given time stamp (as well as ongoing encounters) + List locations = new LocationBridge(context).getLocationsSinceTime(Preferences.getInstance().getDBTimestamp()); List encounterEntries = new EncounterEntriesBridge(context).getConfirmedEntriesAfterTime( - Preferences.getInstance().getDBTimestamp().getSecretsDBTimestamp() + Preferences.getInstance().getDBTimestamp() ); if (encounterEntries.size() == 0) { @@ -148,19 +149,13 @@ public class SDDRClient implements EncounterBasedCommunication.ISDDRClient { // update the checkpoints to the most recently added encounter/loc/secret if we successfully posted // make sure that we don't update the timestamps beyond what succeeded - int lastEntryBatchIndex = (lastEntryBatch+1)*Utils.BATCH_SIZE; int lastLocBatchIndex = (lastLocBatch+1)*Utils.BATCH_SIZE; - long newEncounterTimeStamp = lastEntryBatch == 0 - ? Preferences.getInstance().getDBTimestamp().getSecretsDBTimestamp() - : encounterEntries.get( - lastEntryBatchIndex > encounterEntries.size() ? encounterEntries.size()-1 : lastEntryBatchIndex-1 - ).getTimeInterval().getStartL(); long newLocTimeStamp = lastLocBatch == 0 - ? Preferences.getInstance().getDBTimestamp().getLocationsDBTimestamp() + ? Preferences.getInstance().getDBTimestamp() : locations.get( lastLocBatchIndex > locations.size() ? locations.size()-1 : lastLocBatchIndex-1 ).getTimestamp(); - Preferences.getInstance().setDBTimestamp(new DBTimestamp(newEncounterTimeStamp, newLocTimeStamp)); + Preferences.getInstance().setTimestamp(newLocTimeStamp); }); } } \ No newline at end of file diff --git a/ebclibrary/src/main/java/org/mpisws/encounters/encounterhistory/bridges/EncounterEntriesBridge.java b/ebclibrary/src/main/java/org/mpisws/encounters/encounterhistory/bridges/EncounterEntriesBridge.java index 8dcf45c6ba8eb807fcb817ad0736a752fe289837..8e709ef7463fd49b7f06dd7f6c56406ab79df4f6 100644 --- a/ebclibrary/src/main/java/org/mpisws/encounters/encounterhistory/bridges/EncounterEntriesBridge.java +++ b/ebclibrary/src/main/java/org/mpisws/encounters/encounterhistory/bridges/EncounterEntriesBridge.java @@ -180,11 +180,13 @@ public class EncounterEntriesBridge extends AbstractEncountersBridge getConfirmedEntriesAfterTime(long timestamp) { - final String[] selectionArgs = new String[] { String.valueOf(timestamp) }; - String whereClause = PEncounterEntries.Columns.timestampStart + " > ? AND " - + PEncounterEntries.Columns.sharedSecret + " IS NOT NULL"; + final String[] selectionArgs = new String[] { String.valueOf(timestamp), String.valueOf(timestamp) }; + String whereClause = "(" + PEncounterEntries.Columns.timestampEnd + " > ? OR " + + PEncounterEntries.Columns.timestampEnd + " = -1)" + + " AND " + PEncounterEntries.Columns.sharedSecret + " IS NOT NULL"; String sortOrder = PEncounterEntries.Columns.timestampStart + " ASC"; - final Cursor cursor = context.getContentResolver().query(EncounterHistoryAPM.getContentURI(EncounterHistoryAPM.encounterEntries), null, whereClause, selectionArgs, sortOrder); + final Cursor cursor = context.getContentResolver().query(EncounterHistoryAPM.getContentURI(EncounterHistoryAPM.encounterEntries), + null, whereClause, selectionArgs, sortOrder); List locs = new ArrayList(); while (cursor.moveToNext()) { locs.add(cursorToItem(cursor)); diff --git a/ebclibrary/src/main/java/org/mpisws/encounters/lib/Preferences.java b/ebclibrary/src/main/java/org/mpisws/encounters/lib/Preferences.java index c6d162c8ddc4fe741a3b8f7b8bc8d7183125be6c..42f61a9beb3bb29502cf89ce3d6c727bfe3ef2c7 100644 --- a/ebclibrary/src/main/java/org/mpisws/encounters/lib/Preferences.java +++ b/ebclibrary/src/main/java/org/mpisws/encounters/lib/Preferences.java @@ -8,7 +8,6 @@ package org.mpisws.encounters.lib; import android.content.Context; import android.content.SharedPreferences; -import org.mpisws.database.DBTimestamp; import org.mpisws.helpers.GlobalObjectRegistry; /** @@ -59,14 +58,11 @@ public class Preferences { } - public DBTimestamp getDBTimestamp() { - return new DBTimestamp( - sharedPreferences.getLong(encEntryDBTimestamp, -1), - sharedPreferences.getLong(locationDBTimestamp, -1)); + public long getDBTimestamp() { + return sharedPreferences.getLong(encEntryDBTimestamp, -1); } - public void setDBTimestamp(DBTimestamp timestamp) { - editor().putLong(encEntryDBTimestamp, timestamp.getSecretsDBTimestamp()).apply(); - editor().putLong(locationDBTimestamp, timestamp.getLocationsDBTimestamp()).apply(); + public void setTimestamp(long timestamp) { + editor().putLong(encEntryDBTimestamp, timestamp).apply(); } public void setEbCKey(String ebCKey) { diff --git a/ebcutils/src/main/java/org/mpisws/database/DBTimestamp.java b/ebcutils/src/main/java/org/mpisws/database/DBTimestamp.java deleted file mode 100644 index b7553fdf7178a322f7fc58f8c3e056e8136ddbc2..0000000000000000000000000000000000000000 --- a/ebcutils/src/main/java/org/mpisws/database/DBTimestamp.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.mpisws.database; - -/** - * Created by tslilyai on 2/18/18. - */ - -public class DBTimestamp { - long encEntriesDBTimestamp; - long locationsDBTimestamp; - - public long getSecretsDBTimestamp() { - return encEntriesDBTimestamp; - } - - public long getLocationsDBTimestamp() { - return locationsDBTimestamp; - } - - public DBTimestamp(long encEntriesDBTimestamp, long locationsDBTimestamp) { - this.encEntriesDBTimestamp = encEntriesDBTimestamp; - this.locationsDBTimestamp = locationsDBTimestamp; - } -}