Skip to content

Commit

Permalink
Fixes proposed by @cpeterso
Browse files Browse the repository at this point in the history
CELLS_COUNT_WATERMARK=50
s/keySet().size()/.size()/
Report unknown accuracy/altitude as 0 until the server side has not been fixed
remove mIsGpsPositionKnown
PSC - is part of a cell identifier
  • Loading branch information
illarionov committed Jan 11, 2014
1 parent e1b1c02 commit 8c08696
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/org/mozilla/mozstumbler/Reporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final class Reporter extends BroadcastReceiver {
private static final int RECORD_BATCH_SIZE = 100;
private static final int REPORTER_WINDOW = 60000; //ms
private static final int WIFI_COUNT_WATERMARK = 500;
private static final int CELLS_COUNT_WATERMARK = 500;
private static final int CELLS_COUNT_WATERMARK = 50;

private static String MOZSTUMBLER_USER_AGENT_STRING;

Expand All @@ -53,7 +53,6 @@ final class Reporter extends BroadcastReceiver {
private URL mURL;
private ReentrantLock mReportsLock;

private boolean mIsGpsPositionKnown = false;
private final Location mGpsPosition = new Location("");
private long mGpsPositionTime;

Expand Down Expand Up @@ -87,11 +86,15 @@ final class Reporter extends BroadcastReceiver {
mContext.registerReceiver(this, new IntentFilter(ScannerService.MESSAGE_TOPIC));
}

private boolean isGpsPositionKnown() {
return (mGpsPositionTime > 0);
}

private void resetData() {
mWifiData.clear();
mCellData.clear();
mGpsPosition.reset();
mIsGpsPositionKnown = false;
mGpsPositionTime = 0;
}

void shutdown() {
Expand All @@ -115,10 +118,10 @@ public void onReceive(Context context, Intent intent) {
return;
}

long time = intent.getLongExtra("time", 0);
long time = intent.getLongExtra("time", System.currentTimeMillis());
String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT);

if (mIsGpsPositionKnown && Math.abs(time - mGpsPositionTime) > REPORTER_WINDOW) {
if (isGpsPositionKnown() && Math.abs(time - mGpsPositionTime) > REPORTER_WINDOW) {
reportCollectedLocation();
}

Expand All @@ -132,19 +135,18 @@ public void onReceive(Context context, Intent intent) {
reportCollectedLocation();
Location l = intent.getParcelableExtra(GPSScanner.GPS_SCANNER_ARG_LOCATION);
if (l == null) {
mIsGpsPositionKnown = false;
mGpsPositionTime = 0;
} else {
mGpsPosition.set(l);
mIsGpsPositionKnown = true;
mGpsPositionTime = time;
}
} else {
Log.d(LOGTAG, "Intent ignored with Subject: " + subject);
return; // Intent not aimed at the Reporter (it is possibly for UI instead)
}

if (mIsGpsPositionKnown && ((mWifiData.keySet().size() > WIFI_COUNT_WATERMARK)
|| (mCellData.keySet().size() > CELLS_COUNT_WATERMARK))) {
if (isGpsPositionKnown() && ((mWifiData.size() > WIFI_COUNT_WATERMARK)
|| (mCellData.size() > CELLS_COUNT_WATERMARK))) {
reportCollectedLocation();
}
}
Expand Down Expand Up @@ -253,7 +255,7 @@ public void run() {
}

private void putWifiResults(List<ScanResult> results) {
if (!mIsGpsPositionKnown) {
if (!isGpsPositionKnown()) {
return;
}
for (ScanResult result : results) {
Expand All @@ -265,7 +267,7 @@ private void putWifiResults(List<ScanResult> results) {
}

private void putCellResults(List<CellInfo> cells) {
if (!mIsGpsPositionKnown) {
if (!isGpsPositionKnown()) {
return;
}
for (CellInfo result : cells) {
Expand All @@ -274,7 +276,8 @@ private void putCellResults(List<CellInfo> cells) {
+ " " + result.getMcc()
+ " " + result.getMnc()
+ " " + result.getLac()
+ " " + result.getCid();
+ " " + result.getCid()
+ " " + result.getPsc();

if (!mCellData.containsKey(key)) {
mCellData.put(key, result);
Expand All @@ -283,7 +286,7 @@ private void putCellResults(List<CellInfo> cells) {
}

private void reportCollectedLocation() {
if (!mIsGpsPositionKnown) {
if (!isGpsPositionKnown()) {
return;
}

Expand Down Expand Up @@ -337,8 +340,8 @@ void reportLocation(Location gpsPosition, Collection<ScanResult> wifiInfo, Strin
locInfo.put("lat", gpsPosition.getLatitude());
locInfo.put("lon", gpsPosition.getLongitude());
locInfo.put("time", DateTimeUtils.formatTime(time));
if (gpsPosition.hasAccuracy()) locInfo.put("accuracy", (int)gpsPosition.getAccuracy());
if (gpsPosition.hasAltitude()) locInfo.put("altitude", (int)gpsPosition.getAltitude());
locInfo.put("accuracy", (int)gpsPosition.getAccuracy());
locInfo.put("altitude", (int)gpsPosition.getAltitude());

if (!cellInfo.isEmpty()) {
JSONArray cellJSON=new JSONArray();
Expand Down
4 changes: 4 additions & 0 deletions src/org/mozilla/mozstumbler/cellscanner/CellInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public int getLac() {
return mLac;
}

public int getPsc() {
return mPsc;
}

public JSONObject toJSONObject() {
final JSONObject obj = new JSONObject();

Expand Down

0 comments on commit 8c08696

Please sign in to comment.