Skip to Content.
Sympa Menu

ndt-dev - [ndt-dev] [ndt] r412 committed - Drastically simplify comms between service, activity; now tests update...

Subject: NDT-DEV email list created

List archive

[ndt-dev] [ndt] r412 committed - Drastically simplify comms between service, activity; now tests update...


Chronological Thread 
  • From:
  • To:
  • Subject: [ndt-dev] [ndt] r412 committed - Drastically simplify comms between service, activity; now tests update...
  • Date: Thu, 07 Jul 2011 18:16:57 +0000

Revision: 412
Author:

Date: Thu Jul 7 11:15:40 2011
Log: Drastically simplify comms between service, activity; now tests update the UI through completion.
http://code.google.com/p/ndt/source/detail?r=412

Modified:
/branches/android/Android/src/net/measurementlab/ndt/NdtService.java
/branches/android/Android/src/net/measurementlab/ndt/ServerLocation.java

=======================================
--- /branches/android/Android/src/net/measurementlab/ndt/NdtService.java Tue Jul 5 13:57:42 2011
+++ /branches/android/Android/src/net/measurementlab/ndt/NdtService.java Thu Jul 7 11:15:40 2011
@@ -3,7 +3,6 @@
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
-import android.os.RemoteException;
import android.util.Log;

public class NdtService extends Service {
@@ -12,27 +11,25 @@
public static final int DOWNLOADING = 2;
public static final int COMPLETE = 3;

- public static final String INTENT_UPDATE = "net.measurementlab.ndt.Update";
+ public static final String INTENT_UPDATE_STATUS = "net.measurementlab.ndt.UpdateStatus";
+ public static final String EXTRA_STATE = "status";

private Intent intent;

- private TestReporter testReporter = new TestReporter();
-
private String networkType;

private boolean testRunning;

@Override
public IBinder onBind(Intent intent) {
- Log.i("ndt", "Service bound.");
- return testReporter;
+ return null;
}

@Override
public void onCreate() {
super.onCreate();
Log.i("ndt", "Service created.");
- intent = new Intent(INTENT_UPDATE);
+ intent = new Intent(INTENT_UPDATE_STATUS);
}

@Override
@@ -60,19 +57,6 @@
super.onDestroy();
Log.i("ndt", "Finishing NDT service.");
}
-
- private class TestReporter extends ITestReporter.Stub {
- private int state = PREPARING;
-
- @Override
- public int getState() throws RemoteException {
- return this.state;
- }
-
- public void setState(int state) {
- this.state = state;
- }
- }

private class CaptiveUiServices implements UiServices {

@@ -83,20 +67,16 @@

if (str.contains("client-to-server") && 0 == viewId) {
Log.i("ndt", "Starting upload test.");
- testReporter.setState(UPLOADING);
+ intent.putExtra("status", UPLOADING);
sendBroadcast(intent);
+ Log.i("ndt", "Broadcast status change.");
}

if (str.contains("server-to-client") && 0 == viewId) {
- Log.i("ndt", "Starting upload test.");
- testReporter.setState(DOWNLOADING);
+ Log.i("ndt", "Starting download test.");
+ intent.putExtra("status", DOWNLOADING);
sendBroadcast(intent);
- }
-
- if (str.contains("Test ended") && 0 == viewId) {
- Log.i("ndt", "Starting upload test.");
- testReporter.setState(COMPLETE);
- sendBroadcast(intent);
+ Log.i("ndt", "Broadcast status change.");
}
}

@@ -118,6 +98,9 @@
@Override
public void onEndTest() {
Log.d("ndt", "Test ended.");
+ intent.putExtra("status", COMPLETE);
+ sendBroadcast(intent);
+ Log.i("ndt", "Broadcast status change.");
}

@Override
=======================================
--- /branches/android/Android/src/net/measurementlab/ndt/ServerLocation.java Tue Jul 5 13:57:42 2011
+++ /branches/android/Android/src/net/measurementlab/ndt/ServerLocation.java Thu Jul 7 11:15:40 2011
@@ -2,21 +2,15 @@

package net.measurementlab.ndt;

-import java.util.concurrent.TimeUnit;
-
import android.app.Activity;
import android.content.BroadcastReceiver;
-import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
-import android.content.ServiceConnection;
import android.graphics.Typeface;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
-import android.os.IBinder;
-import android.os.RemoteException;
import android.util.Log;
import android.widget.TextView;

@@ -24,26 +18,7 @@
* Animated progress while selecting server location.
*/
public class ServerLocation extends Activity {
- private ITestReporter testReporter;
- private boolean bound;
- private BroadcastReceiver receiver;
-
- private ServiceConnection connection = new ServiceConnection() {
-
- @Override
- public void onServiceDisconnected(ComponentName name) {
- Log.i("ndt", "Service disconnected.");
- testReporter = null;
- bound = false;
- }
-
- @Override
- public void onServiceConnected(ComponentName name, IBinder
service) {
- Log.i("ndt", "Service connected.");
- testReporter =
ITestReporter.Stub.asInterface(service);
- bound = true;
- }
- };
+ private BroadcastReceiver statusReceiver;

/**
* Initializes the activity.
@@ -62,68 +37,70 @@
intent.putExtra("networkType", getNetworkType());
startService(intent);

- bindService(new Intent(getApplicationContext(),
NdtService.class),
- this.connection, Context.BIND_AUTO_CREATE);
- bound = true;
-
- receiver = new BroadcastReceiver() {
-
- @Override
- public void onReceive(Context context, Intent intent)
{
- try {
- switch ((null == testReporter) ? 0 :
testReporter
- .getState()) {
- case NdtService.PREPARING:
- updateHeader("Preparing...");
- break;
- case NdtService.UPLOADING:
- updateHeader("Testing
upload...");
- break;
- case NdtService.DOWNLOADING:
- updateHeader("Testing
download...");
- break;
- case NdtService.COMPLETE:
- updateHeader("Test
complete.");
- break;
- }
- } catch (RemoteException e) {
- Log.e("ndt", "Error in busy-wait
loop.", e);
- }
- }
- };
+ bindAndRegister();
}

@Override
protected void onStart() {
super.onStart();
Log.i("ndt", "Server location started.");
- if (!bound) {
- registerReceiver(receiver, new
IntentFilter(NdtService.INTENT_UPDATE));
- bindService(new Intent(ITestReporter.class.getName()),
- this.connection,
Context.BIND_AUTO_CREATE);
- }
}

@Override
protected void onResume() {
super.onResume();
Log.i("ndt", "Server location resumed.");
- if (!bound) {
- registerReceiver(receiver, new
IntentFilter(NdtService.INTENT_UPDATE));
- bindService(new Intent(ITestReporter.class.getName()),
- this.connection,
Context.BIND_AUTO_CREATE);
- }
}

@Override
protected void onPause() {
super.onPause();
Log.i("ndt", "Server location paused.");
- if (bound) {
- bound = false;
- unbindService(this.connection);
- unregisterReceiver(receiver);
- }
+ unregisterReceiver(statusReceiver);
+ // TODO tell NdtService to stop test
+ // TODO reset activity state to preparing
+ }
+
+ private void bindAndRegister() {
+ statusReceiver = createReceiver();
+ registerReceiver(statusReceiver, new IntentFilter(
+ NdtService.INTENT_UPDATE_STATUS));
+ Log.i("ndt", "Status receiver registered.");
+ }
+
+ private BroadcastReceiver createReceiver() {
+ BroadcastReceiver receiver = new BroadcastReceiver() {
+
+ @Override
+ public void onReceive(Context context, Intent intent)
{
+ Log.i("ndt", "Status change received.");
+ int status = intent.getIntExtra("status",
NdtService.PREPARING);
+ switch (status) {
+ case NdtService.PREPARING:
+ Log.i("ndt", "Preparing Your
Tests...");
+ updateHeader("Preparing...");
+ break;
+ case NdtService.UPLOADING:
+ Log.i("ndt", "Testing Upload...");
+ updateHeader("Testing upload...");
+ break;
+ case NdtService.DOWNLOADING:
+ Log.i("ndt", "Testing Download...");
+ updateHeader("Testing download...");
+ break;
+ case NdtService.COMPLETE:
+ Log.i("ndt", "Testing Complete.");
+ updateHeader("Test complete.");
+ break;
+ default:
+ Log.i("ndt", "Test reporter not
initialized.");
+ break;
+ }
+ }
+ };
+ Log.i("ndt", "Status receiver created.");
+ return receiver;
+
}

private void updateHeader(String labelText) {


  • [ndt-dev] [ndt] r412 committed - Drastically simplify comms between service, activity; now tests update..., ndt, 07/07/2011

Archive powered by MHonArc 2.6.16.

Top of Page