Skip to content

Commit 4a597b7

Browse files
committed
Merge pull request #681 from garvankeeley/provider-to-client
Fix issue 663 (I hope). Don't record cellinfo with unknown network type.
2 parents 4649326 + ccdec56 commit 4a597b7

9 files changed

+72
-18
lines changed

src/org/mozilla/mozstumbler/client/LogActivity.java

+33-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,22 @@
55
import android.content.Context;
66
import android.content.Intent;
77
import android.content.IntentFilter;
8+
import android.os.Handler;
9+
import android.os.Message;
810
import android.support.v4.content.LocalBroadcastManager;
911
import android.os.Bundle;
12+
import android.text.Html;
1013
import android.util.AttributeSet;
1114
import android.widget.ScrollView;
1215
import android.widget.TextView;
1316
import org.mozilla.mozstumbler.R;
1417
import org.mozilla.mozstumbler.service.SharedConstants;
18+
19+
import java.util.Date;
1520
import java.util.LinkedList;
21+
import java.util.Timer;
22+
import java.util.TimerTask;
23+
import java.util.concurrent.ConcurrentLinkedQueue;
1624

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

2230
public static class LogMessageReceiver extends BroadcastReceiver {
2331

32+
Timer mFlushMessagesTimer = new Timer();
33+
Handler mMainThreadHandler = new Handler() {
34+
public void handleMessage(Message m) {
35+
String msg = SharedConstants.guiLogMessageBuffer.poll();
36+
addMessageToBuffer(msg);
37+
}
38+
};
39+
2440
public static void createGlobalInstance(Context context) {
2541
sInstance = new LogMessageReceiver(context);
42+
SharedConstants.guiLogMessageBuffer = new ConcurrentLinkedQueue<String>();
2643
}
2744

2845
LogMessageReceiver(Context context) {
2946
LocalBroadcastManager.getInstance(context).registerReceiver(this,
3047
new IntentFilter(SharedConstants.ACTION_GUI_LOG_MESSAGE));
48+
49+
final int kMillis = 1000 * 3;
50+
mFlushMessagesTimer.scheduleAtFixedRate(new TimerTask() {
51+
@Override
52+
public void run() {
53+
mMainThreadHandler.obtainMessage().sendToTarget();
54+
}
55+
}, kMillis, kMillis);
3156
}
3257

33-
@Override
34-
public void onReceive(Context c, Intent intent) {
35-
String s = intent.getStringExtra(SharedConstants.ACTION_GUI_LOG_MESSAGE_EXTRA);
58+
void addMessageToBuffer(String s) {
3659
if (s == null)
3760
return;
3861

@@ -44,6 +67,12 @@ public void onReceive(Context c, Intent intent) {
4467
sConsoleView.println(s);
4568
}
4669
}
70+
71+
@Override
72+
public void onReceive(Context c, Intent intent) {
73+
String s = intent.getStringExtra(SharedConstants.ACTION_GUI_LOG_MESSAGE_EXTRA);
74+
addMessageToBuffer(s);
75+
}
4776
}
4877

4978
ConsoleView mConsoleView;
@@ -103,7 +132,7 @@ public void enableScroll(boolean v) {
103132
}
104133

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

108137
if (enable_scroll) {
109138
scrollTo(0,tv.getBottom());

src/org/mozilla/mozstumbler/service/AbstractCommunicator.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public abstract class AbstractCommunicator {
2424
private static final String USER_AGENT_HEADER = "User-Agent";
2525
private HttpURLConnection httpURLConnection;
2626
private final String mUserAgent;
27+
private static int sBytesSentTotal = 0;
2728

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

9697
public void send(byte[] data) throws IOException {
9798
setHeaders();
99+
String logMsg;
98100
try {
99-
sendData(zipData(data));
101+
byte[] zipped = zipData(data);
102+
sendData(zipped);
103+
sBytesSentTotal += zipped.length;
104+
logMsg = "Send zipped: " + String.format("%.2f", zipped.length / 1024.0) + " kB";
100105
} catch (IOException e) {
101106
Log.e(LOGTAG, "Couldn't compress and send data, falling back to plain-text: ", e);
102107
close();
103108
setHeaders();
104109
sendData(data);
110+
sBytesSentTotal += data.length;
111+
logMsg = "Send plain: " + String.format("%.2f", data.length / 1024.0) + " kB";
105112
}
113+
114+
logMsg += " Session Total:" + String.format("%.2f", sBytesSentTotal / 1024.0) + " kB";
115+
if (SharedConstants.guiLogMessageBuffer != null) {
116+
SharedConstants.guiLogMessageBuffer.add("<font color='#FFFFCC'><b>" + logMsg + "</b></font>");
117+
}
118+
Log.d(LOGTAG, logMsg);
106119
}
107120

108121
public InputStream getInputStream() {

src/org/mozilla/mozstumbler/service/PassiveServiceStarter.java src/org/mozilla/mozstumbler/service/PassiveServiceReceiver.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@
1717
* Using GPS_* event changes during development, switch to using the existing permissions for a
1818
* service on Fennec.
1919
<meta-data name="MOZILLA_API_KEY" value="aValue">
20-
<receiver android:name=".service.PassiveServiceStarter">
20+
<receiver android:name=".service.PassiveServiceReceiver">
2121
<intent-filter>
2222
<action android:name="android.location.GPS_ENABLED_CHANGE" />
2323
<action android:name="android.location.GPS_FIX_CHANGE" />
2424
</intent-filter>
2525
</receiver>
2626
*/
27-
public class PassiveServiceStarter extends BroadcastReceiver {
28-
final static String LOGTAG = PassiveServiceStarter.class.getName();
27+
public class PassiveServiceReceiver extends BroadcastReceiver {
28+
final static String LOGTAG = PassiveServiceReceiver.class.getName();
2929

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

34-
if (SharedConstants.isDebug) Log.d(LOGTAG, "Starting Passively");
34+
if (SharedConstants.isDebug) Log.d(LOGTAG, "Starting Passively");
3535
if (SharedConstants.mozillaApiKey == null) {
3636
try {
3737
ApplicationInfo ai = context.getPackageManager().

src/org/mozilla/mozstumbler/service/SharedConstants.java

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

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

9+
import java.util.concurrent.ConcurrentLinkedQueue;
10+
911
public class SharedConstants {
1012
/** All intent actions start with this string */
1113
public static final String ACTION_NAMESPACE = "org.mozilla.mozstumbler.intent.action";
@@ -37,6 +39,8 @@ public enum ActiveOrPassiveStumbling { ACTIVE_STUMBLING, PASSIVE_STUMBLING }
3739
public static boolean isDebug;
3840
public static String mozillaApiKey;
3941

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

4145
public static ContentResolverInterface stumblerContentResolver;
4246
}

src/org/mozilla/mozstumbler/service/datahandling/StumblerBundleReceiver.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ public void handleBundle(Context context, StumblerBundle bundle) {
4949
values.put(DatabaseContract.Reports.WIFI, wifis.toString());
5050
values.put(DatabaseContract.Reports.WIFI_COUNT, wifis.length());
5151

52-
Intent message = new Intent(SharedConstants.ACTION_GUI_LOG_MESSAGE);
53-
message.putExtra(SharedConstants.ACTION_GUI_LOG_MESSAGE_EXTRA, mlsObj.toString());
54-
LocalBroadcastManager.getInstance(context).sendBroadcast(message);
52+
if (SharedConstants.guiLogMessageBuffer != null)
53+
SharedConstants.guiLogMessageBuffer.add(mlsObj.toString());
5554
} catch (JSONException e) {
5655
Log.w(LOGTAG, "Failed to convert bundle to JSON: " + e);
5756
return;

src/org/mozilla/mozstumbler/service/scanners/GPSScanner.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,8 @@ public boolean isGeofenced() {
139139
}
140140

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

147146
@Override

src/org/mozilla/mozstumbler/service/scanners/cellscanner/CellInfo.java

+4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ private CellInfo(Parcel in) {
7373
mPsc = in.readInt();
7474
}
7575

76+
public boolean isCellRadioValid() {
77+
return mCellRadio != null && (mCellRadio.length() > 0) && !mCellRadio.equals("0");
78+
}
79+
7680
public String getRadio() {
7781
return mRadio;
7882
}

src/org/mozilla/mozstumbler/service/scanners/cellscanner/CellScannerNoWCDMA.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ private List<CellInfo> getNeighboringCells() {
166166
try {
167167
final CellInfo record = new CellInfo(mPhoneType);
168168
record.setNeighboringCellInfo(nci, networkOperator);
169-
records.add(record);
169+
if (record.isCellRadioValid()) {
170+
records.add(record);
171+
}
170172
} catch (IllegalArgumentException iae) {
171173
Log.e(LOGTAG, "Skip invalid or incomplete NeighboringCellInfo: " + nci, iae);
172174
}
@@ -245,7 +247,7 @@ public List<CellInfo> getAllCellInfo(TelephonyManager tm) {
245247
List<CellInfo> cells = new ArrayList<CellInfo>(observed.size());
246248
for (android.telephony.CellInfo observedCell : observed) {
247249
if (!addCellToList(cells, observedCell, tm)) {
248-
Log.i(LOGTAG, "Skipped CellInfo of unknown class: " + observedCell.toString());
250+
//Log.i(LOGTAG, "Skipped CellInfo of unknown class: " + observedCell.toString());
249251
}
250252
}
251253
return cells;

src/org/mozilla/mozstumbler/service/sync/Submitter.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.net.HttpURLConnection;
1010
import org.mozilla.mozstumbler.service.AbstractCommunicator;
1111
import org.mozilla.mozstumbler.service.Prefs;
12+
import org.mozilla.mozstumbler.service.SharedConstants;
1213

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

0 commit comments

Comments
 (0)