Skip to content

Commit

Permalink
Merge pull request #105 from cpeterso/cpeterso/update-time-after-upload
Browse files Browse the repository at this point in the history
Only update mLastUploadTime after upload completes without error
  • Loading branch information
cpeterso committed Sep 6, 2013
2 parents fd8b928 + 611a8d3 commit f2b507c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/org/mozilla/mozstumbler/Reporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Reporter {
private final Set<String> mAPs = new HashSet<String>();
private int mLocationCount;
private JSONArray mReports;
private long mLastUploadTime;
private volatile long mLastUploadTime;

Reporter(Context context, Prefs prefs) {
mContext = context;
Expand Down Expand Up @@ -90,7 +90,6 @@ void sendReports(boolean force) {

String nickname = mPrefs.getNickname();
spawnReporterThread(reports, nickname);
mLastUploadTime = System.currentTimeMillis();
}

private void spawnReporterThread(final JSONArray reports, final String nickname) {
Expand Down Expand Up @@ -127,6 +126,9 @@ public void run() {
}
r.close();

mLastUploadTime = System.currentTimeMillis();
sendUpdateIntent();

Log.d(LOGTAG, "response was: \n" + total + "\n");
Log.d(LOGTAG, "uploaded data: " + data + " to " + LOCATION_URL);
} catch (JSONException jsonex) {
Expand Down Expand Up @@ -186,11 +188,9 @@ void reportLocation(Location location, Collection<ScanResult> scanResults, int r

mReports.put(locInfo);
sendReports(false);
mLocationCount++;

Intent i = new Intent(ScannerService.MESSAGE_TOPIC);
i.putExtra(Intent.EXTRA_SUBJECT, "Reporter");
mContext.sendBroadcast(i);
mLocationCount++;
sendUpdateIntent();
}

private static boolean shouldLog(ScanResult scanResult) {
Expand Down Expand Up @@ -259,4 +259,10 @@ private String getUserAgentString() {
// "MozStumbler/X.Y.Z"
return appName + '/' + versionName;
}

private void sendUpdateIntent() {
Intent i = new Intent(ScannerService.MESSAGE_TOPIC);
i.putExtra(Intent.EXTRA_SUBJECT, "Reporter");
mContext.sendBroadcast(i);
}
}

0 comments on commit f2b507c

Please sign in to comment.