Skip to content

Commit

Permalink
Merge pull request #681 from garvankeeley/provider-to-client
Browse files Browse the repository at this point in the history
Fix issue 663 (I hope). Don't record cellinfo with unknown network type.
  • Loading branch information
garvankeeley committed Jul 4, 2014
2 parents 4649326 + ccdec56 commit 4a597b7
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 18 deletions.
37 changes: 33 additions & 4 deletions src/org/mozilla/mozstumbler/client/LogActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.os.Message;
import android.support.v4.content.LocalBroadcastManager;
import android.os.Bundle;
import android.text.Html;
import android.util.AttributeSet;
import android.widget.ScrollView;
import android.widget.TextView;
import org.mozilla.mozstumbler.R;
import org.mozilla.mozstumbler.service.SharedConstants;

import java.util.Date;
import java.util.LinkedList;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentLinkedQueue;

public class LogActivity extends Activity {
static LinkedList<String> buffer = new LinkedList<String>();
Expand All @@ -21,18 +29,33 @@ public class LogActivity extends Activity {

public static class LogMessageReceiver extends BroadcastReceiver {

Timer mFlushMessagesTimer = new Timer();
Handler mMainThreadHandler = new Handler() {
public void handleMessage(Message m) {
String msg = SharedConstants.guiLogMessageBuffer.poll();
addMessageToBuffer(msg);
}
};

public static void createGlobalInstance(Context context) {
sInstance = new LogMessageReceiver(context);
SharedConstants.guiLogMessageBuffer = new ConcurrentLinkedQueue<String>();
}

LogMessageReceiver(Context context) {
LocalBroadcastManager.getInstance(context).registerReceiver(this,
new IntentFilter(SharedConstants.ACTION_GUI_LOG_MESSAGE));

final int kMillis = 1000 * 3;
mFlushMessagesTimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
mMainThreadHandler.obtainMessage().sendToTarget();
}
}, kMillis, kMillis);
}

@Override
public void onReceive(Context c, Intent intent) {
String s = intent.getStringExtra(SharedConstants.ACTION_GUI_LOG_MESSAGE_EXTRA);
void addMessageToBuffer(String s) {
if (s == null)
return;

Expand All @@ -44,6 +67,12 @@ public void onReceive(Context c, Intent intent) {
sConsoleView.println(s);
}
}

@Override
public void onReceive(Context c, Intent intent) {
String s = intent.getStringExtra(SharedConstants.ACTION_GUI_LOG_MESSAGE_EXTRA);
addMessageToBuffer(s);
}
}

ConsoleView mConsoleView;
Expand Down Expand Up @@ -103,7 +132,7 @@ public void enableScroll(boolean v) {
}

public void print(String str){
tv.append(str);
tv.append(Html.fromHtml(str + "<br />"));

if (enable_scroll) {
scrollTo(0,tv.getBottom());
Expand Down
15 changes: 14 additions & 1 deletion src/org/mozilla/mozstumbler/service/AbstractCommunicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public abstract class AbstractCommunicator {
private static final String USER_AGENT_HEADER = "User-Agent";
private HttpURLConnection httpURLConnection;
private final String mUserAgent;
private static int sBytesSentTotal = 0;

public abstract String getUrlString();
public abstract int getCorrectResponse();
Expand Down Expand Up @@ -95,14 +96,26 @@ private void sendData(byte[] data) throws IOException{

public void send(byte[] data) throws IOException {
setHeaders();
String logMsg;
try {
sendData(zipData(data));
byte[] zipped = zipData(data);
sendData(zipped);
sBytesSentTotal += zipped.length;
logMsg = "Send zipped: " + String.format("%.2f", zipped.length / 1024.0) + " kB";
} catch (IOException e) {
Log.e(LOGTAG, "Couldn't compress and send data, falling back to plain-text: ", e);
close();
setHeaders();
sendData(data);
sBytesSentTotal += data.length;
logMsg = "Send plain: " + String.format("%.2f", data.length / 1024.0) + " kB";
}

logMsg += " Session Total:" + String.format("%.2f", sBytesSentTotal / 1024.0) + " kB";
if (SharedConstants.guiLogMessageBuffer != null) {
SharedConstants.guiLogMessageBuffer.add("<font color='#FFFFCC'><b>" + logMsg + "</b></font>");
}
Log.d(LOGTAG, logMsg);
}

public InputStream getInputStream() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
* Using GPS_* event changes during development, switch to using the existing permissions for a
* service on Fennec.
<meta-data name="MOZILLA_API_KEY" value="aValue">
<receiver android:name=".service.PassiveServiceStarter">
<receiver android:name=".service.PassiveServiceReceiver">
<intent-filter>
<action android:name="android.location.GPS_ENABLED_CHANGE" />
<action android:name="android.location.GPS_FIX_CHANGE" />
</intent-filter>
</receiver>
*/
public class PassiveServiceStarter extends BroadcastReceiver {
final static String LOGTAG = PassiveServiceStarter.class.getName();
public class PassiveServiceReceiver extends BroadcastReceiver {
final static String LOGTAG = PassiveServiceReceiver.class.getName();

@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();

if (SharedConstants.isDebug) Log.d(LOGTAG, "Starting Passively");
if (SharedConstants.isDebug) Log.d(LOGTAG, "Starting Passively");
if (SharedConstants.mozillaApiKey == null) {
try {
ApplicationInfo ai = context.getPackageManager().
Expand Down
4 changes: 4 additions & 0 deletions src/org/mozilla/mozstumbler/service/SharedConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import org.mozilla.mozstumbler.service.datahandling.ContentResolverInterface;

import java.util.concurrent.ConcurrentLinkedQueue;

public class SharedConstants {
/** All intent actions start with this string */
public static final String ACTION_NAMESPACE = "org.mozilla.mozstumbler.intent.action";
Expand Down Expand Up @@ -37,6 +39,8 @@ public enum ActiveOrPassiveStumbling { ACTIVE_STUMBLING, PASSIVE_STUMBLING }
public static boolean isDebug;
public static String mozillaApiKey;

/* The log activity will clear this periodically, and display the messages */
public static ConcurrentLinkedQueue<String> guiLogMessageBuffer;

public static ContentResolverInterface stumblerContentResolver;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ public void handleBundle(Context context, StumblerBundle bundle) {
values.put(DatabaseContract.Reports.WIFI, wifis.toString());
values.put(DatabaseContract.Reports.WIFI_COUNT, wifis.length());

Intent message = new Intent(SharedConstants.ACTION_GUI_LOG_MESSAGE);
message.putExtra(SharedConstants.ACTION_GUI_LOG_MESSAGE_EXTRA, mlsObj.toString());
LocalBroadcastManager.getInstance(context).sendBroadcast(message);
if (SharedConstants.guiLogMessageBuffer != null)
SharedConstants.guiLogMessageBuffer.add(mlsObj.toString());
} catch (JSONException e) {
Log.w(LOGTAG, "Failed to convert bundle to JSON: " + e);
return;
Expand Down
5 changes: 2 additions & 3 deletions src/org/mozilla/mozstumbler/service/scanners/GPSScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ public boolean isGeofenced() {
}

private void sendToLogActivity(String msg) {
Intent message = new Intent(SharedConstants.ACTION_GUI_LOG_MESSAGE);
message.putExtra(SharedConstants.ACTION_GUI_LOG_MESSAGE_EXTRA,msg);
LocalBroadcastManager.getInstance(mContext).sendBroadcast(message);
if (SharedConstants.guiLogMessageBuffer != null)
SharedConstants.guiLogMessageBuffer.add("<font color='#33ccff'>" + msg + "</font>");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ private CellInfo(Parcel in) {
mPsc = in.readInt();
}

public boolean isCellRadioValid() {
return mCellRadio != null && (mCellRadio.length() > 0) && !mCellRadio.equals("0");
}

public String getRadio() {
return mRadio;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ private List<CellInfo> getNeighboringCells() {
try {
final CellInfo record = new CellInfo(mPhoneType);
record.setNeighboringCellInfo(nci, networkOperator);
records.add(record);
if (record.isCellRadioValid()) {
records.add(record);
}
} catch (IllegalArgumentException iae) {
Log.e(LOGTAG, "Skip invalid or incomplete NeighboringCellInfo: " + nci, iae);
}
Expand Down Expand Up @@ -245,7 +247,7 @@ public List<CellInfo> getAllCellInfo(TelephonyManager tm) {
List<CellInfo> cells = new ArrayList<CellInfo>(observed.size());
for (android.telephony.CellInfo observedCell : observed) {
if (!addCellToList(cells, observedCell, tm)) {
Log.i(LOGTAG, "Skipped CellInfo of unknown class: " + observedCell.toString());
//Log.i(LOGTAG, "Skipped CellInfo of unknown class: " + observedCell.toString());
}
}
return cells;
Expand Down
6 changes: 5 additions & 1 deletion src/org/mozilla/mozstumbler/service/sync/Submitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.net.HttpURLConnection;
import org.mozilla.mozstumbler.service.AbstractCommunicator;
import org.mozilla.mozstumbler.service.Prefs;
import org.mozilla.mozstumbler.service.SharedConstants;

public class Submitter extends AbstractCommunicator {
private static final String SUBMIT_URL = "https://location.services.mozilla.com/v1/submit";
Expand Down Expand Up @@ -43,7 +44,10 @@ public boolean cleanSend(byte[] data) {
this.send(data);
result = true;
} catch (IOException ex) {
Log.e(LOGTAG,"Error submitting: ", ex);
String msg = "Error submitting: " + ex;
Log.e(LOGTAG, msg);
if (SharedConstants.guiLogMessageBuffer != null)
SharedConstants.guiLogMessageBuffer.add("<font color='red'><b>" + msg + "</b></font>");
}
return result;
}
Expand Down

0 comments on commit 4a597b7

Please sign in to comment.