Commit 825cf046 authored by Lily Tsai's avatar Lily Tsai
Browse files

get rid of timestamp

parent b48e97b3
Subproject commit 525420689192984227bf975cb9a61c32276029a5 Subproject commit 9b0f55007d93bbe13e48f2750d0b887c880a8add
...@@ -6,7 +6,6 @@ import android.util.Log; ...@@ -6,7 +6,6 @@ import android.util.Log;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.mpisws.database.DBEncounterInfo; import org.mpisws.database.DBEncounterInfo;
import org.mpisws.database.DBTimestamp;
import org.mpisws.encounters.encounterhistory.bridges.EncounterEntriesBridge; import org.mpisws.encounters.encounterhistory.bridges.EncounterEntriesBridge;
import org.mpisws.encounters.lib.time.TimeInterval; import org.mpisws.encounters.lib.time.TimeInterval;
import org.mpisws.helpers.ThreadPoolManager; import org.mpisws.helpers.ThreadPoolManager;
...@@ -101,9 +100,11 @@ public class SDDRClient implements EncounterBasedCommunication.ISDDRClient { ...@@ -101,9 +100,11 @@ public class SDDRClient implements EncounterBasedCommunication.ISDDRClient {
Log.d(TAG, "Issuing credentials"); Log.d(TAG, "Issuing credentials");
int ret = CloudAgentHelpers.issueSetCredentialsRequest(Preferences.getInstance().getUserHandle(), Preferences.getInstance().getAuthorizationToken()); int ret = CloudAgentHelpers.issueSetCredentialsRequest(Preferences.getInstance().getUserHandle(), Preferences.getInstance().getAuthorizationToken());
Log.d(TAG, "Issued Credentials: " + ret); Log.d(TAG, "Issued Credentials: " + ret);
List<MLocation> 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<MLocation> locations = new LocationBridge(context).getLocationsSinceTime(Preferences.getInstance().getDBTimestamp());
List<MEncounterEntry> encounterEntries = new EncounterEntriesBridge(context).getConfirmedEntriesAfterTime( List<MEncounterEntry> encounterEntries = new EncounterEntriesBridge(context).getConfirmedEntriesAfterTime(
Preferences.getInstance().getDBTimestamp().getSecretsDBTimestamp() Preferences.getInstance().getDBTimestamp()
); );
if (encounterEntries.size() == 0) { if (encounterEntries.size() == 0) {
...@@ -148,19 +149,13 @@ public class SDDRClient implements EncounterBasedCommunication.ISDDRClient { ...@@ -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 // 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 // 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; 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 long newLocTimeStamp = lastLocBatch == 0
? Preferences.getInstance().getDBTimestamp().getLocationsDBTimestamp() ? Preferences.getInstance().getDBTimestamp()
: locations.get( : locations.get(
lastLocBatchIndex > locations.size() ? locations.size()-1 : lastLocBatchIndex-1 lastLocBatchIndex > locations.size() ? locations.size()-1 : lastLocBatchIndex-1
).getTimestamp(); ).getTimestamp();
Preferences.getInstance().setDBTimestamp(new DBTimestamp(newEncounterTimeStamp, newLocTimeStamp)); Preferences.getInstance().setTimestamp(newLocTimeStamp);
}); });
} }
} }
\ No newline at end of file
...@@ -180,11 +180,13 @@ public class EncounterEntriesBridge extends AbstractEncountersBridge<MEncounterE ...@@ -180,11 +180,13 @@ public class EncounterEntriesBridge extends AbstractEncountersBridge<MEncounterE
} }
public List<MEncounterEntry> getConfirmedEntriesAfterTime(long timestamp) { public List<MEncounterEntry> getConfirmedEntriesAfterTime(long timestamp) {
final String[] selectionArgs = new String[] { String.valueOf(timestamp) }; final String[] selectionArgs = new String[] { String.valueOf(timestamp), String.valueOf(timestamp) };
String whereClause = PEncounterEntries.Columns.timestampStart + " > ? AND " String whereClause = "(" + PEncounterEntries.Columns.timestampEnd + " > ? OR "
+ PEncounterEntries.Columns.sharedSecret + " IS NOT NULL"; + PEncounterEntries.Columns.timestampEnd + " = -1)"
+ " AND " + PEncounterEntries.Columns.sharedSecret + " IS NOT NULL";
String sortOrder = PEncounterEntries.Columns.timestampStart + " ASC"; 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<MEncounterEntry> locs = new ArrayList(); List<MEncounterEntry> locs = new ArrayList();
while (cursor.moveToNext()) { while (cursor.moveToNext()) {
locs.add(cursorToItem(cursor)); locs.add(cursorToItem(cursor));
......
...@@ -8,7 +8,6 @@ package org.mpisws.encounters.lib; ...@@ -8,7 +8,6 @@ package org.mpisws.encounters.lib;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import org.mpisws.database.DBTimestamp;
import org.mpisws.helpers.GlobalObjectRegistry; import org.mpisws.helpers.GlobalObjectRegistry;
/** /**
...@@ -59,14 +58,11 @@ public class Preferences { ...@@ -59,14 +58,11 @@ public class Preferences {
} }
public DBTimestamp getDBTimestamp() { public long getDBTimestamp() {
return new DBTimestamp( return sharedPreferences.getLong(encEntryDBTimestamp, -1);
sharedPreferences.getLong(encEntryDBTimestamp, -1),
sharedPreferences.getLong(locationDBTimestamp, -1));
} }
public void setDBTimestamp(DBTimestamp timestamp) { public void setTimestamp(long timestamp) {
editor().putLong(encEntryDBTimestamp, timestamp.getSecretsDBTimestamp()).apply(); editor().putLong(encEntryDBTimestamp, timestamp).apply();
editor().putLong(locationDBTimestamp, timestamp.getLocationsDBTimestamp()).apply();
} }
public void setEbCKey(String ebCKey) { public void setEbCKey(String ebCKey) {
......
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;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment