Skip to content

Commit

Permalink
Merge pull request #683 from garvankeeley/provider-to-client
Browse files Browse the repository at this point in the history
Log activity ease-of-use improvements
  • Loading branch information
garvankeeley committed Jul 6, 2014
2 parents 4a597b7 + d524785 commit 49ab325
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 6 deletions.
14 changes: 14 additions & 0 deletions res/menu/log_menu.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/scroll_to_start"
android:icon="@android:drawable/arrow_up_float"
android:showAsAction="always"
android:title="@string/scroll_to_start"/>
<item
android:id="@+id/scroll_to_end"
android:icon="@android:drawable/arrow_down_float"
android:showAsAction="always"
android:title="@string/scroll_to_end"/>
</menu>
2 changes: 2 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,7 @@
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>
<string name="action_view_log">View Log</string>
<string name="scroll_to_start">Scroll to Top</string>
<string name="scroll_to_end">Scroll to End</string>

</resources>
2 changes: 1 addition & 1 deletion src/org/mozilla/mozstumbler/client/DefaultCellScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected boolean addCellToList(List<CellInfo> cells,
added = true;
}
else {
if (SharedConstants.isDebug) Log.d(LOGTAG, String.format("Invalid-> mnc:%d mcc:%d", ident.getMnc(), ident.getMcc()));
//if (SharedConstants.isDebug) Log.d(LOGTAG, String.format("Invalid-> mnc:%d mcc:%d", ident.getMnc(), ident.getMcc()));
}
}
return added || super.addCellToList(cells, observedCell, tm);
Expand Down
36 changes: 34 additions & 2 deletions src/org/mozilla/mozstumbler/client/LogActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import android.os.Bundle;
import android.text.Html;
import android.util.AttributeSet;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ScrollView;
import android.widget.TextView;
import org.mozilla.mozstumbler.R;
Expand All @@ -32,8 +35,11 @@ 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);
String msg = null;
do {
msg = SharedConstants.guiLogMessageBuffer.poll();
addMessageToBuffer(msg);
} while (msg != null);
}
};

Expand Down Expand Up @@ -62,6 +68,11 @@ void addMessageToBuffer(String s) {
if (buffer.size() > MAX_SIZE) {
buffer.removeFirst();
}

if (s.length() > 100) {
s = s.substring(0, 100) + " ...";
}

buffer.add(s);
if (sConsoleView != null) {
sConsoleView.println(s);
Expand Down Expand Up @@ -148,4 +159,25 @@ public void clear() {
this.scrollTo(0, 0);
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.log_menu, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.scroll_to_start:
this.mConsoleView.fullScroll(View.FOCUS_UP);
return true;
case R.id.scroll_to_end:
this.mConsoleView.fullScroll(View.FOCUS_DOWN);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
6 changes: 4 additions & 2 deletions src/org/mozilla/mozstumbler/client/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ public void onServiceDisconnected(ComponentName className) {
@Override
public void onTerminate() {
super.onTerminate();
unbindService(mConnection);
if (mConnection != null)
unbindService(mConnection);
mConnection = null;
mStumblerService = null;
mReceiver.unregister();
if (mReceiver != null)
mReceiver.unregister();
mReceiver = null;
Log.d(LOGTAG, "onStop");
}
Expand Down
71 changes: 71 additions & 0 deletions src/org/mozilla/mozstumbler/tests/AppTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package org.mozilla.mozstumbler.tests;

import android.content.ContentValues;
import android.content.SyncResult;
import android.database.sqlite.SQLiteDatabase;
import android.os.Handler;
import android.os.Message;
import android.test.ApplicationTestCase;
import org.mozilla.mozstumbler.client.MainApp;
import org.mozilla.mozstumbler.service.datahandling.Database;
import org.mozilla.mozstumbler.service.datahandling.DatabaseContract;

import java.util.concurrent.CountDownLatch;

public class AppTest extends ApplicationTestCase<MainApp> {
public AppTest() {
super(MainApp.class);
}

SQLiteDatabase getStumblerDatabase() {
String dbPath = Database.getFullPathToDb(this);
assertTrue(dbPath != null);
int endPos = dbPath.lastIndexOf('/');
dbPath = dbPath.substring(0, endPos) + "/" + Database.DATABASE_NAME;
SQLiteDatabase db = SQLiteDatabase.openDatabase(dbPath, null, 0);
return db;
}

@Override
protected void setUp() throws Exception {
createApplication();
MainApp app = getApplication();
}

// for pausing to wait for asynctask
final CountDownLatch signal = new CountDownLatch(1);

public void testManyReportEntries() {
// make sure every thing has time to load
mHandler.sendMessageDelayed(mHandler.obtainMessage(), 250);

try {
signal.await();
} catch (Exception e) {
}
}

private Handler mHandler = new Handler() {
public void handleMessage(Message m) {
SQLiteDatabase db = getStumblerDatabase();
ContentValues values = new ContentValues();
values.put(DatabaseContract.Reports.TIME, 666);
values.put(DatabaseContract.Reports.LAT, 0.0);
values.put(DatabaseContract.Reports.LON, 0.0);
values.put(DatabaseContract.Reports.ALTITUDE, 0);
values.put(DatabaseContract.Reports.ACCURACY, 0);
values.put(DatabaseContract.Reports.RADIO, "gsm");
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}]");
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}]");
values.put(DatabaseContract.Reports.CELL_COUNT, 2);
values.put(DatabaseContract.Reports.WIFI_COUNT, 7);

for (int i = 0; i < 10000; i++) {
db.insert("reports", null, values);
values.put(DatabaseContract.Reports.TIME, 666 + i);
}

signal.countDown();
}
};
}
2 changes: 1 addition & 1 deletion src/org/mozilla/mozstumbler/tests/ServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public void testPassiveService() {
long sentCells = statsMap.get(DatabaseContract.Stats.KEY_CELLS_SENT);
long sentWifis = statsMap.get(DatabaseContract.Stats.KEY_WIFIS_SENT);

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

Expand Down

0 comments on commit 49ab325

Please sign in to comment.