summaryrefslogtreecommitdiffstats
path: root/tests/DumpRenderTree2
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2010-11-09 12:28:56 +0000
committerSteve Block <steveblock@google.com>2010-11-09 12:33:28 +0000
commitcda9448206494b67c0812b9591cc066ca070a7a6 (patch)
tree7dbc0effddeb168ef67d3273ae0622a4335135ca /tests/DumpRenderTree2
parent01b04e10df00dcf16bfb92f88b3b1932f579632e (diff)
downloadframeworks_base-cda9448206494b67c0812b9591cc066ca070a7a6.zip
frameworks_base-cda9448206494b67c0812b9591cc066ca070a7a6.tar.gz
frameworks_base-cda9448206494b67c0812b9591cc066ca070a7a6.tar.bz2
Fix FsUtils.readDataFromUrl() to do the network request on a background thread
This is required now that doing network requests on the main thread throws NetworkOnMainThreadException. Also updates TestsListPreloaderThread to create the FileFilter lazily and removes a superfluous FileFilter param from the Summarizer constructor. Change-Id: If15fddac934cd8be611f6693b25837657abbddc3
Diffstat (limited to 'tests/DumpRenderTree2')
-rw-r--r--tests/DumpRenderTree2/src/com/android/dumprendertree2/FsUtils.java93
-rw-r--r--tests/DumpRenderTree2/src/com/android/dumprendertree2/ManagerService.java4
-rw-r--r--tests/DumpRenderTree2/src/com/android/dumprendertree2/Summarizer.java4
-rw-r--r--tests/DumpRenderTree2/src/com/android/dumprendertree2/TestsListPreloaderThread.java2
4 files changed, 64 insertions, 39 deletions
diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/FsUtils.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/FsUtils.java
index 4f9a737..a79aead 100644
--- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/FsUtils.java
+++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/FsUtils.java
@@ -131,45 +131,72 @@ public class FsUtils {
return bytes;
}
- public static byte[] readDataFromUrl(URL url) {
- if (url == null) {
- Log.w(LOG_TAG, "readDataFromUrl(): url is null!");
- return null;
+ static class UrlDataGetter extends Thread {
+ private URL mUrl;
+ private byte[] mBytes;
+ private boolean mGetComplete;
+ public UrlDataGetter(URL url) {
+ mUrl = url;
}
-
- HttpGet httpRequest = new HttpGet(url.toString());
- ResponseHandler<byte[]> handler = new ResponseHandler<byte[]>() {
- @Override
- public byte[] handleResponse(HttpResponse response) throws IOException {
- if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
- return null;
+ public byte[] get() {
+ start();
+ synchronized(this) {
+ while (!mGetComplete) {
+ try{
+ wait();
+ } catch(InterruptedException e) {
+ }
}
- HttpEntity entity = response.getEntity();
- return (entity == null ? null : EntityUtils.toByteArray(entity));
}
- };
-
- byte[] bytes = null;
- try {
- /**
- * TODO: Not exactly sure why some requests hang indefinitely, but adding this
- * timeout (in static getter for http client) in loop helps.
- */
- boolean timedOut;
- do {
- timedOut = false;
- try {
- bytes = getHttpClient().execute(httpRequest, handler);
- } catch (SocketTimeoutException e) {
- timedOut = true;
- Log.w(LOG_TAG, "Expected SocketTimeoutException: " + url, e);
+ return mBytes;
+ }
+ public synchronized void run() {
+ mGetComplete = false;
+ HttpGet httpRequest = new HttpGet(mUrl.toString());
+ ResponseHandler<byte[]> handler = new ResponseHandler<byte[]>() {
+ @Override
+ public byte[] handleResponse(HttpResponse response) throws IOException {
+ if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
+ return null;
+ }
+ HttpEntity entity = response.getEntity();
+ return (entity == null ? null : EntityUtils.toByteArray(entity));
}
- } while (timedOut);
- } catch (IOException e) {
- Log.e(LOG_TAG, "url=" + url, e);
+ };
+
+ mBytes = null;
+ try {
+ /**
+ * TODO: Not exactly sure why some requests hang indefinitely, but adding this
+ * timeout (in static getter for http client) in loop helps.
+ */
+ boolean timedOut;
+ do {
+ timedOut = false;
+ try {
+ mBytes = getHttpClient().execute(httpRequest, handler);
+ } catch (SocketTimeoutException e) {
+ timedOut = true;
+ Log.w(LOG_TAG, "Expected SocketTimeoutException: " + mUrl, e);
+ }
+ } while (timedOut);
+ } catch (IOException e) {
+ Log.e(LOG_TAG, "url=" + mUrl, e);
+ }
+
+ mGetComplete = true;
+ notify();
}
+ }
- return bytes;
+ public static byte[] readDataFromUrl(URL url) {
+ if (url == null) {
+ Log.w(LOG_TAG, "readDataFromUrl(): url is null!");
+ return null;
+ }
+
+ UrlDataGetter getter = new UrlDataGetter(url);
+ return getter.get();
}
public static List<String> getLayoutTestsDirContents(String dirRelativePath, boolean recurse,
diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/ManagerService.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/ManagerService.java
index f42dc86..333612e 100644
--- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/ManagerService.java
+++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/ManagerService.java
@@ -127,7 +127,6 @@ public class ManagerService extends Service {
}
};
- private FileFilter mFileFilter;
private Summarizer mSummarizer;
private String mCurrentlyRunningTest;
@@ -146,8 +145,7 @@ public class ManagerService extends Service {
public void onCreate() {
super.onCreate();
- mFileFilter = new FileFilter();
- mSummarizer = new Summarizer(mFileFilter, RESULTS_ROOT_DIR_PATH, getApplicationContext());
+ mSummarizer = new Summarizer(RESULTS_ROOT_DIR_PATH, getApplicationContext());
}
@Override
diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/Summarizer.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/Summarizer.java
index bd8c4ad..65c6964 100644
--- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/Summarizer.java
+++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/Summarizer.java
@@ -213,8 +213,8 @@ public class Summarizer {
private SummarizerDBHelper mDbHelper;
- public Summarizer(FileFilter fileFilter, String resultsRootDirPath, Context context) {
- mFileFilter = fileFilter;
+ public Summarizer(String resultsRootDirPath, Context context) {
+ mFileFilter = new FileFilter();
mResultsRootDirPath = resultsRootDirPath;
/**
diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/TestsListPreloaderThread.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/TestsListPreloaderThread.java
index 0e7d47a..ab98830 100644
--- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/TestsListPreloaderThread.java
+++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/TestsListPreloaderThread.java
@@ -50,13 +50,13 @@ public class TestsListPreloaderThread extends Thread {
* @param doneMsg
*/
public TestsListPreloaderThread(String path, Message doneMsg) {
- mFileFilter = new FileFilter();
mRelativePath = path;
mDoneMsg = doneMsg;
}
@Override
public void run() {
+ mFileFilter = new FileFilter();
if (FileFilter.isTestFile(mRelativePath)) {
mTestsList.add(mRelativePath);
} else {