ndt-dev - [ndt-dev] [ndt] r406 committed - Re-wire further so test screen can observe state changes in service an...
Subject: NDT-DEV email list created
List archive
[ndt-dev] [ndt] r406 committed - Re-wire further so test screen can observe state changes in service an...
Chronological Thread
- From:
- To:
- Subject: [ndt-dev] [ndt] r406 committed - Re-wire further so test screen can observe state changes in service an...
- Date: Tue, 21 Jun 2011 20:12:03 +0000
Revision: 406
Author:
Date: Tue Jun 21 13:11:16 2011
Log: Re-wire further so test screen can observe state changes in service and react.
http://code.google.com/p/ndt/source/detail?r=406
Added:
/branches/android/Android/res/layout/upload_testing.xml
/branches/android/Android/src/net/measurementlab/ndt/ITestReporter.aidl
/branches/android/Android/src/net/measurementlab/ndt/UploadTesting.java
Deleted:
/branches/android/Android/src/net/measurementlab/ndt/Android2UiServices.java
Modified:
/branches/android/Android/AndroidManifest.xml
/branches/android/Android/src/net/measurementlab/ndt/AndroidNdt2.java
/branches/android/Android/src/net/measurementlab/ndt/Constants.java
/branches/android/Android/src/net/measurementlab/ndt/NdtService.java
/branches/android/Android/src/net/measurementlab/ndt/ServerLocation.java
=======================================
--- /dev/null
+++ /branches/android/Android/res/layout/upload_testing.xml Tue Jun 21 13:11:16 2011
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
android:layout_height="match_parent">
+ <TextView android:text="Testing Upload..." android:id="@+id/textView1"
+ android:layout_height="wrap_content"
android:layout_width="match_parent"
+ style="@style/NdtHeader" />
+ <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content"
+ android:layout_height="wrap_content" android:src="@drawable/progress_bar_right" />
+</LinearLayout>
=======================================
--- /dev/null
+++ /branches/android/Android/src/net/measurementlab/ndt/ITestReporter.aidl Tue Jun 21 13:11:16 2011
@@ -0,0 +1,5 @@
+package net.measurementlab.ndt;
+
+interface ITestReporter {
+ int getState();
+}
=======================================
--- /dev/null
+++ /branches/android/Android/src/net/measurementlab/ndt/UploadTesting.java Tue Jun 21 13:11:16 2011
@@ -0,0 +1,29 @@
+// Copyright 2009 Google Inc. All Rights Reserved.
+
+package net.measurementlab.ndt;
+
+import android.app.Activity;
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.util.Log;
+import android.widget.TextView;
+
+/**
+ * Animated progress while selecting server location.
+ */
+public class UploadTesting extends Activity {
+
+ /**
+ * Initializes the activity.
+ */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.server_location);
+ Log.i("ndt", "Loaded!");
+ Typeface typeFace = Typeface.createFromAsset(getAssets(),
+ "fonts/League_Gothic.otf");
+ TextView textView = (TextView) findViewById(R.id.NdtServerLocationLabel);
+ textView.setTypeface(typeFace);
+ }
+}
=======================================
--- /branches/android/Android/src/net/measurementlab/ndt/Android2UiServices.java Mon Jun 20 10:08:06 2011
+++ /dev/null
@@ -1,80 +0,0 @@
-package net.measurementlab.ndt;
-
-import android.util.Log;
-
-public class Android2UiServices implements UiServices {
-
- @Override
- public void appendString(String str, int viewId) {
- Log.i("ndt", String.format("Appended: (%1$d) %2$s.", viewId, str.trim()));
- }
-
- @Override
- public void incrementProgress() {
- Log.i("ndt", "Incremented progress.");
- }
-
- @Override
- public void logError(String str) {
- Log.e("ndt", String.format("Error: %1$s.", str.trim()));
- }
-
- @Override
- public void onBeginTest() {
- Log.i("ndt", "Test begun.");
- }
-
- @Override
- public void onEndTest() {
- Log.i("ndt", "Test ended.");
- }
-
- @Override
- public void onFailure(String errorMessage) {
- Log.i("ndt", String.format("Failed: %1$s.", errorMessage));
- }
-
- @Override
- public void onLoginSent() {
- Log.i("ndt", "Login sent.");
- }
-
- @Override
- public void onPacketQueuingDetected() {
- Log.i("ndt", "Packet queuing detected.");
- }
-
- @Override
- public void setVariable(String name, int value) {
- Log.i("ndt", String.format("Setting variable, %1$s, to value,
%2$d.",
- name, value));
- }
-
- @Override
- public void setVariable(String name, double value) {
- Log.i("ndt", String.format("Setting variable, %1$s, to value,
%2$f.",
- name, value));
- }
-
- @Override
- public void setVariable(String name, Object value) {
- Log.i("ndt", String.format("Setting variable, %1$s, to value,
%2$s.",
- name, (null == value) ? "null" :
value.toString()));
- }
-
- @Override
- public void updateStatus(String status) {
- Log.i("ndt", String.format("Updating status: %1$s.", status));
- }
-
- @Override
- public void updateStatusPanel(String status) {
- Log.i("ndt", String.format("Updating status panel: %1$s.",
status));
- }
-
- @Override
- public boolean wantToStop() {
- return false;
- }
-
-}
=======================================
--- /branches/android/Android/AndroidManifest.xml Tue Jun 21 09:12:40
2011
+++ /branches/android/Android/AndroidManifest.xml Tue Jun 21 13:11:16
2011
@@ -9,12 +9,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
- <activity android:name=".ServerLocation" android:label="@string/app_name" android:theme="@style/NdtTheme">
- <intent-filter>
- <category android:name="android.intent.category.DEFAULT" />
- <action android:name="net.measurementlab.ndt.ServerLocation" />
- </intent-filter>
- </activity>
+ <activity android:name=".ServerLocation" android:label="@string/app_name" android:theme="@style/NdtTheme" />
+ <activity android:name=".UploadTesting" android:label="@string/app_name" android:theme="@style/NdtTheme" />
<!-- SelectServer.java: Options Activity for selecting the test server -->
<activity android:name=".SelectServer" android:label="@string/choice_server_title" />
<!-- Statistics.java: Report detailed information to user -->
=======================================
--- /branches/android/Android/src/net/measurementlab/ndt/AndroidNdt2.java Tue Jun 21 09:12:40 2011
+++ /branches/android/Android/src/net/measurementlab/ndt/AndroidNdt2.java Tue Jun 21 13:11:16 2011
@@ -5,8 +5,6 @@
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
-import android.net.ConnectivityManager;
-import android.net.NetworkInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
@@ -37,34 +35,12 @@
@Override
public void onClick(View v) {
- try {
- Intent intent = null;
- intent = new
Intent(getApplicationContext(), NdtService.class);
- intent.putExtra("networkType",
getNetworkType());
- startService(intent);
-
- intent = new
Intent(Constants.SERVER_LOCATION);
- startActivity(intent);
- } catch (Throwable t) {
- Log.e("ndt", "Problem invoking server
location.", t);
- }
+ Intent intent = null;
+
+ intent = new Intent(getApplicationContext(),
+ ServerLocation.class);
+ startActivity(intent);
}
});
}
-
- private String getNetworkType() {
- ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
- NetworkInfo networkInfo =
connectivityManager.getActiveNetworkInfo();
- if (null == networkInfo) {
- return NdtTests.NETWORK_UNKNOWN;
- }
- switch (networkInfo.getType()) {
- case ConnectivityManager.TYPE_MOBILE:
- return NdtTests.NETWORK_MOBILE;
- case ConnectivityManager.TYPE_WIFI:
- return NdtTests.NETWORK_WIFI;
- default:
- return NdtTests.NETWORK_UNKNOWN;
- }
- }
-}
+}
=======================================
--- /branches/android/Android/src/net/measurementlab/ndt/Constants.java Tue Jun 21 09:12:40 2011
+++ /branches/android/Android/src/net/measurementlab/ndt/Constants.java Tue Jun 21 13:11:16 2011
@@ -29,7 +29,7 @@
// Intents ID
public static final String SERVER_LOCATION = "net.measurementlab.ndt.ServerLocation";
- public static final String RUN_TESTS =
"net.measurementlab.ndt.RunTests";
+ public static final String UPLOAD_TESTING = "net.measurementlab.ndt.UploadTesting";
public static final String INTENT_SERVER_NO = "serverno";
public static final String INTENT_STATISTICS = "statistics";
public static final String INTENT_LOCATION = "location";
=======================================
--- /branches/android/Android/src/net/measurementlab/ndt/NdtService.java Tue Jun 21 09:12:40 2011
+++ /branches/android/Android/src/net/measurementlab/ndt/NdtService.java Tue Jun 21 13:11:16 2011
@@ -3,15 +3,20 @@
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 {
+ public static final int UPLOADING = 1;
+
+ private TestReporter testReporter = new TestReporter();
@Override
public IBinder onBind(Intent intent) {
- return null;
- }
-
+ Log.i("ndt", "Service bound.");
+ return testReporter;
+ }
+
@Override
public void onCreate() {
super.onCreate();
@@ -23,14 +28,115 @@
Log.i("ndt", "Starting NDT service.");
super.onStart(intent, startId);
try {
- NdtTests tests = new NdtTests(
+ new Thread(new NdtTests(
Constants.SERVER_HOST[Constants.DEFAULT_SERVER],
- new Android2UiServices(), intent
-
.getStringExtra("networkType"));
- tests.run();
+ new CaptiveUiServices(), intent
+
.getStringExtra("networkType"))).start();
} catch (Throwable tr) {
Log.e("ndt", "Problem running tests.", tr);
}
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
Log.i("ndt", "Finishing NDT service.");
+ }
+
+ private class TestReporter extends ITestReporter.Stub {
+ private int state = 0;
+
+ @Override
+ public int getState() throws RemoteException {
+ return this.state;
+ }
+
+ public void setState(int state) {
+ this.state = state;
+ }
+ }
+
+ private class CaptiveUiServices implements UiServices {
+
+ @Override
+ public void appendString(String str, int viewId) {
+ Log.d("ndt", String.format("Appended: (%1$d) %2$s.",
viewId, str
+ .trim()));
+
+ if (str.contains("client-to-server") && 1 == viewId) {
+ Log.i("ndt", "Starting upload test.");
+ testReporter.setState(UPLOADING);
+ }
+ }
+
+ @Override
+ public void incrementProgress() {
+ Log.d("ndt", "Incremented progress.");
+ }
+
+ @Override
+ public void logError(String str) {
+ Log.e("ndt", String.format("Error: %1$s.",
str.trim()));
+ }
+
+ @Override
+ public void onBeginTest() {
+ Log.d("ndt", "Test begun.");
+ }
+
+ @Override
+ public void onEndTest() {
+ Log.d("ndt", "Test ended.");
+ }
+
+ @Override
+ public void onFailure(String errorMessage) {
+ Log.d("ndt", String.format("Failed: %1$s.",
errorMessage));
+ }
+
+ @Override
+ public void onLoginSent() {
+ Log.d("ndt", "Login sent.");
+ }
+
+ @Override
+ public void onPacketQueuingDetected() {
+ Log.d("ndt", "Packet queuing detected.");
+ }
+
+ @Override
+ public void setVariable(String name, int value) {
+ Log.d("ndt", String.format(
+ "Setting variable, %1$s, to value,
%2$d.", name, value));
+ }
+
+ @Override
+ public void setVariable(String name, double value) {
+ Log.d("ndt", String.format(
+ "Setting variable, %1$s, to value,
%2$f.", name, value));
+ }
+
+ @Override
+ public void setVariable(String name, Object value) {
+ Log.d("ndt", String.format(
+ "Setting variable, %1$s, to value,
%2$s.", name,
+ (null == value) ? "null" :
value.toString()));
+ }
+
+ @Override
+ public void updateStatus(String status) {
+ Log.d("ndt", String.format("Updating status: %1$s.",
status));
+ }
+
+ @Override
+ public void updateStatusPanel(String status) {
+ Log.d("ndt", String.format("Updating status panel:
%1$s.", status));
+ }
+
+ @Override
+ public boolean wantToStop() {
+ return false;
+ }
+
}
}
=======================================
--- /branches/android/Android/src/net/measurementlab/ndt/ServerLocation.java Mon Jun 20 09:23:24 2011
+++ /branches/android/Android/src/net/measurementlab/ndt/ServerLocation.java Tue Jun 21 13:11:16 2011
@@ -2,9 +2,19 @@
package net.measurementlab.ndt;
+import java.util.concurrent.TimeUnit;
+
import android.app.Activity;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+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;
@@ -12,7 +22,26 @@
* Animated progress while selecting server location.
*/
public class ServerLocation extends Activity {
-
+ private ITestReporter testReporter;
+ private boolean bound;
+ private boolean running;
+ 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;
+ }
+ };
+
/**
* Initializes the activity.
*/
@@ -21,9 +50,83 @@
super.onCreate(savedInstanceState);
setContentView(R.layout.server_location);
Log.i("ndt", "Loaded!");
- Typeface typeFace = Typeface.createFromAsset(getAssets(),
- "fonts/League_Gothic.otf");
- TextView textView = (TextView) findViewById(R.id.NdtServerLocationLabel);
- textView.setTypeface(typeFace);
+ Typeface typeFace = Typeface.createFromAsset(getAssets(),
+ "fonts/League_Gothic.otf");
+ TextView textView = (TextView)
findViewById(R.id.NdtServerLocationLabel);
+ textView.setTypeface(typeFace);
+
+ Intent intent = new Intent(getApplicationContext(),
NdtService.class);
+ intent.putExtra("networkType", getNetworkType());
+ startService(intent);
+
+ bindService(new Intent(getApplicationContext(),
NdtService.class),
+ this.connection, Context.BIND_AUTO_CREATE);
+
+ running = true;
+ new Thread() {
+ @Override
+ public void run() {
+ try {
+ while (true == running && (null == testReporter || 0 == testReporter.getState())) {
+
TimeUnit.MILLISECONDS.sleep(500l);
+ Log.i("ndt", String.format(
+ "Checking test
state, %1$d.",
+ (null ==
testReporter) ? -1 : testReporter
+
.getState()));
+ // TODO need stop when
activity is paused
+ }
+ Intent intent = new
Intent(getApplicationContext(),
+ UploadTesting.class);
+ startActivity(intent);
+ } catch (RemoteException e) {
+ Log.e("ndt", "Error in busy-wait
loop.", e);
+ } catch (InterruptedException e) {
+ Log.e("ndt", "Sleep interrupted.", e);
+ }
+ }
+ }.start();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onStart();
+ Log.i("ndt", "Server location resumed.");
+ if (!bound) {
+ 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);
+ }
+ running = false;
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ running = false;
+ }
+
+ private String getNetworkType() {
+ ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
+ NetworkInfo networkInfo =
connectivityManager.getActiveNetworkInfo();
+ if (null == networkInfo) {
+ return NdtTests.NETWORK_UNKNOWN;
+ }
+ switch (networkInfo.getType()) {
+ case ConnectivityManager.TYPE_MOBILE:
+ return NdtTests.NETWORK_MOBILE;
+ case ConnectivityManager.TYPE_WIFI:
+ return NdtTests.NETWORK_WIFI;
+ default:
+ return NdtTests.NETWORK_UNKNOWN;
+ }
}
}
- [ndt-dev] [ndt] r406 committed - Re-wire further so test screen can observe state changes in service an..., ndt, 06/21/2011
Archive powered by MHonArc 2.6.16.