Skip to content

Commit 49ab325

Browse files
committed
Merge pull request #683 from garvankeeley/provider-to-client
Log activity ease-of-use improvements
2 parents 4a597b7 + d524785 commit 49ab325

File tree

7 files changed

+127
-6
lines changed

7 files changed

+127
-6
lines changed

res/menu/log_menu.xml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
4+
<item
5+
android:id="@+id/scroll_to_start"
6+
android:icon="@android:drawable/arrow_up_float"
7+
android:showAsAction="always"
8+
android:title="@string/scroll_to_start"/>
9+
<item
10+
android:id="@+id/scroll_to_end"
11+
android:icon="@android:drawable/arrow_down_float"
12+
android:showAsAction="always"
13+
android:title="@string/scroll_to_end"/>
14+
</menu>

res/values/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,7 @@
8888
<string name="hello_world">Hello world!</string>
8989
<string name="action_settings">Settings</string>
9090
<string name="action_view_log">View Log</string>
91+
<string name="scroll_to_start">Scroll to Top</string>
92+
<string name="scroll_to_end">Scroll to End</string>
9193

9294
</resources>

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected boolean addCellToList(List<CellInfo> cells,
4040
added = true;
4141
}
4242
else {
43-
if (SharedConstants.isDebug) Log.d(LOGTAG, String.format("Invalid-> mnc:%d mcc:%d", ident.getMnc(), ident.getMcc()));
43+
//if (SharedConstants.isDebug) Log.d(LOGTAG, String.format("Invalid-> mnc:%d mcc:%d", ident.getMnc(), ident.getMcc()));
4444
}
4545
}
4646
return added || super.addCellToList(cells, observedCell, tm);

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

+34-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import android.os.Bundle;
1212
import android.text.Html;
1313
import android.util.AttributeSet;
14+
import android.view.Menu;
15+
import android.view.MenuItem;
16+
import android.view.View;
1417
import android.widget.ScrollView;
1518
import android.widget.TextView;
1619
import org.mozilla.mozstumbler.R;
@@ -32,8 +35,11 @@ public static class LogMessageReceiver extends BroadcastReceiver {
3235
Timer mFlushMessagesTimer = new Timer();
3336
Handler mMainThreadHandler = new Handler() {
3437
public void handleMessage(Message m) {
35-
String msg = SharedConstants.guiLogMessageBuffer.poll();
36-
addMessageToBuffer(msg);
38+
String msg = null;
39+
do {
40+
msg = SharedConstants.guiLogMessageBuffer.poll();
41+
addMessageToBuffer(msg);
42+
} while (msg != null);
3743
}
3844
};
3945

@@ -62,6 +68,11 @@ void addMessageToBuffer(String s) {
6268
if (buffer.size() > MAX_SIZE) {
6369
buffer.removeFirst();
6470
}
71+
72+
if (s.length() > 100) {
73+
s = s.substring(0, 100) + " ...";
74+
}
75+
6576
buffer.add(s);
6677
if (sConsoleView != null) {
6778
sConsoleView.println(s);
@@ -148,4 +159,25 @@ public void clear() {
148159
this.scrollTo(0, 0);
149160
}
150161
}
162+
163+
@Override
164+
public boolean onCreateOptionsMenu(Menu menu) {
165+
// Inflate the menu; this adds items to the action bar if it is present.
166+
getMenuInflater().inflate(R.menu.log_menu, menu);
167+
return true;
168+
}
169+
170+
@Override
171+
public boolean onOptionsItemSelected(MenuItem item) {
172+
switch (item.getItemId()) {
173+
case R.id.scroll_to_start:
174+
this.mConsoleView.fullScroll(View.FOCUS_UP);
175+
return true;
176+
case R.id.scroll_to_end:
177+
this.mConsoleView.fullScroll(View.FOCUS_DOWN);
178+
return true;
179+
default:
180+
return super.onOptionsItemSelected(item);
181+
}
182+
}
151183
}

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,12 @@ public void onServiceDisconnected(ComponentName className) {
105105
@Override
106106
public void onTerminate() {
107107
super.onTerminate();
108-
unbindService(mConnection);
108+
if (mConnection != null)
109+
unbindService(mConnection);
109110
mConnection = null;
110111
mStumblerService = null;
111-
mReceiver.unregister();
112+
if (mReceiver != null)
113+
mReceiver.unregister();
112114
mReceiver = null;
113115
Log.d(LOGTAG, "onStop");
114116
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package org.mozilla.mozstumbler.tests;
2+
3+
import android.content.ContentValues;
4+
import android.content.SyncResult;
5+
import android.database.sqlite.SQLiteDatabase;
6+
import android.os.Handler;
7+
import android.os.Message;
8+
import android.test.ApplicationTestCase;
9+
import org.mozilla.mozstumbler.client.MainApp;
10+
import org.mozilla.mozstumbler.service.datahandling.Database;
11+
import org.mozilla.mozstumbler.service.datahandling.DatabaseContract;
12+
13+
import java.util.concurrent.CountDownLatch;
14+
15+
public class AppTest extends ApplicationTestCase<MainApp> {
16+
public AppTest() {
17+
super(MainApp.class);
18+
}
19+
20+
SQLiteDatabase getStumblerDatabase() {
21+
String dbPath = Database.getFullPathToDb(this);
22+
assertTrue(dbPath != null);
23+
int endPos = dbPath.lastIndexOf('/');
24+
dbPath = dbPath.substring(0, endPos) + "/" + Database.DATABASE_NAME;
25+
SQLiteDatabase db = SQLiteDatabase.openDatabase(dbPath, null, 0);
26+
return db;
27+
}
28+
29+
@Override
30+
protected void setUp() throws Exception {
31+
createApplication();
32+
MainApp app = getApplication();
33+
}
34+
35+
// for pausing to wait for asynctask
36+
final CountDownLatch signal = new CountDownLatch(1);
37+
38+
public void testManyReportEntries() {
39+
// make sure every thing has time to load
40+
mHandler.sendMessageDelayed(mHandler.obtainMessage(), 250);
41+
42+
try {
43+
signal.await();
44+
} catch (Exception e) {
45+
}
46+
}
47+
48+
private Handler mHandler = new Handler() {
49+
public void handleMessage(Message m) {
50+
SQLiteDatabase db = getStumblerDatabase();
51+
ContentValues values = new ContentValues();
52+
values.put(DatabaseContract.Reports.TIME, 666);
53+
values.put(DatabaseContract.Reports.LAT, 0.0);
54+
values.put(DatabaseContract.Reports.LON, 0.0);
55+
values.put(DatabaseContract.Reports.ALTITUDE, 0);
56+
values.put(DatabaseContract.Reports.ACCURACY, 0);
57+
values.put(DatabaseContract.Reports.RADIO, "gsm");
58+
values.put(DatabaseContract.Reports.CELL, "[{\"asu\":18,\"radio\":\"umts\",\"mnc\":720,\"psc\":426,\"cid\":2906773,\"mcc\":302,\"lac\":60013},{\"asu\":-81,\"radio\":\"umts\",\"mnc\":720,\"psc\":274,\"mcc\":302}]");
59+
values.put(DatabaseContract.Reports.WIFI, "[{\"signal\":-76,\"key\":\"001e58eb0dcf\",\"frequency\":2437},{\"signal\":-86,\"key\":\"00223f026f0a\",\"frequency\":2437},{\"signal\":-55,\"key\":\"60a44cc82952\",\"frequency\":2417},{\"signal\":-88,\"key\":\"001e582594bf\",\"frequency\":2452},{\"signal\":-89,\"key\":\"0018f8f3d1c2\",\"frequency\":2437},{\"signal\":-83,\"key\":\"0023f89aebdf\",\"frequency\":2437},{\"signal\":-61,\"key\":\"00265ac972ef\",\"frequency\":2457}]");
60+
values.put(DatabaseContract.Reports.CELL_COUNT, 2);
61+
values.put(DatabaseContract.Reports.WIFI_COUNT, 7);
62+
63+
for (int i = 0; i < 10000; i++) {
64+
db.insert("reports", null, values);
65+
values.put(DatabaseContract.Reports.TIME, 666 + i);
66+
}
67+
68+
signal.countDown();
69+
}
70+
};
71+
}

src/org/mozilla/mozstumbler/tests/ServiceTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public void testPassiveService() {
280280
long sentCells = statsMap.get(DatabaseContract.Stats.KEY_CELLS_SENT);
281281
long sentWifis = statsMap.get(DatabaseContract.Stats.KEY_WIFIS_SENT);
282282

283-
assertTrue(sentObs - sentObsOrig >=1000 && sentObs - sentObsOrig < 1010);
283+
assertTrue(sentObs - sentObsOrig > 5);
284284
assertTrue(sentCells - sentCellsOrig >= kNewCells);
285285
assertTrue(sentWifis - sentWifisOrig >= kNewWifis);
286286

0 commit comments

Comments
 (0)