Add ability to choose ExecServer port on Android
authorPyry Haulos <phaulos@google.com>
Tue, 6 Oct 2015 22:46:39 +0000 (15:46 -0700)
committerPyry Haulos <phaulos@google.com>
Wed, 7 Oct 2015 17:10:10 +0000 (10:10 -0700)
Both ExecService and ServiceStarter will now use "port" integer extra,
if supplied as part of intent, to choose port.

Bug: 23429375
Change-Id: Ia4c5f6f4c90e01f8879aa76a9ba48c8addfc9669

android/package/AndroidManifest.xml
android/package/src/com/drawelements/deqp/execserver/ExecServerActivity.java
android/package/src/com/drawelements/deqp/execserver/ExecService.java
android/package/src/com/drawelements/deqp/execserver/ServiceStarter.java
android/package/src/com/drawelements/deqp/testercore/RemoteAPI.java
framework/platform/android/tcuAndroidExecService.cpp
framework/platform/android/tcuAndroidExecService.hpp
framework/platform/android/tcuAndroidJNI.cpp

index 4bc0d4b..322ad47 100644 (file)
@@ -1,21 +1,16 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-             package="com.drawelements.deqp"
-             android:versionCode="1"
-             android:versionName="1.0">
-    <application android:label="dEQP Tests"
+                 package="com.drawelements.deqp"
+                 android:versionCode="1"
+                 android:versionName="1.0">
+       <application android:label="dEQP Tests"
                                 android:icon="@drawable/deqp_app">
                <activity android:name="com.drawelements.deqp.execserver.ExecServerActivity"
                                  android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
                                  android:label="dEQP ExecServer"
                                  android:launchMode="singleTask"
                                  android:process=":execserverui"
-                                 android:exported="true">
-                       <intent-filter>
-                               <action android:name="android.intent.action.MAIN" />
-                               <category android:name="android.intent.category.LAUNCHER" />
-                       </intent-filter>
-               </activity>
+                                 android:exported="true" />
                <activity android:name="com.drawelements.deqp.execserver.ServiceStarter"
                                  android:theme="@android:style/Theme.NoDisplay"
                                  android:label="dEQP ExecServer Launcher"
@@ -39,9 +34,9 @@
                </activity>
        </application>
 
-       <uses-sdk android:minSdkVersion="13"/>
-       <uses-sdk android:targetSdkVersion="19"/>
-    <uses-feature android:glEsVersion="0x00020000"/>
+       <uses-sdk android:minSdkVersion="13"/>
+       <uses-sdk android:targetSdkVersion="19"/>
+       <uses-feature android:glEsVersion="0x00020000"/>
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.GET_TASKS" />
        <uses-permission android:name="android.permission.INTERNET" />
index b16e4be..843c216 100644 (file)
@@ -36,10 +36,7 @@ import com.drawelements.deqp.R;
 
 public class ExecServerActivity extends Activity {
 
-       private static final String             LOG_TAG                 = "dEQP/ExecServer";
-       private static final int                PORT                    = 50016;
-
-       private TextView                                m_statusText;
+       private TextView        m_statusText;
 
        @Override
        protected void onCreate (Bundle savedInstance) {
@@ -52,18 +49,8 @@ public class ExecServerActivity extends Activity {
        @Override
        protected void onStart () {
                super.onStart();
-
-               try {
-                       Intent svc = new Intent(this, com.drawelements.deqp.execserver.ExecService.class);
-                       startService(svc);
-               }
-               catch (Exception e) {
-                       Log.e(LOG_TAG, "Service starter starting problem", e);
-                       m_statusText.setText("Failed to start ExecServer!");
-               }
-
-               // \todo [2013-05-07 pyry] Show IP address
-               m_statusText.setText(String.format("Listening on port %d", PORT));
+               // \todo [2015-10-06 pyry] Connect to service, check status, offer option for killing it
+               m_statusText.setText("dEQP ExecServer is running");
        }
 
        @Override
index d091bad..bd65f92 100644 (file)
@@ -31,9 +31,17 @@ import android.os.Binder;
 import android.os.IBinder;
 
 import com.drawelements.deqp.execserver.ExecServerActivity;
+import com.drawelements.deqp.testercore.Log;
 import com.drawelements.deqp.R;
 
 public class ExecService extends Service {
+
+       public static final String      LOG_TAG                 = "dEQP";
+       public static final int         DEFAULT_PORT    = 50016;
+
+       private int                                     m_curPort               = -1;
+       private boolean                         m_isRunning             = false;
+
        static {
                System.loadLibrary("deqp");
        }
@@ -50,12 +58,24 @@ public class ExecService extends Service {
        private final IBinder m_binder = new LocalBinder();
 
        @Override
-       public void onCreate () {
-               onCreateNative();
-       }
-
-       @Override
        public int onStartCommand (Intent intent, int flags, int startId) {
+               final int port = intent != null ? intent.getIntExtra("port", DEFAULT_PORT) : DEFAULT_PORT;
+
+               if (m_isRunning && (m_curPort != port)) {
+                       Log.i(LOG_TAG, String.format("Port changed (old: %d, new: %d), killing old server", m_curPort, port));
+                       stopServer();
+                       m_isRunning = false;
+               }
+
+               if (!m_isRunning) {
+                       startServer(port);
+
+                       m_isRunning     = true;
+                       m_curPort       = port;
+
+                       Log.i(LOG_TAG, String.format("Listening on port %d", m_curPort));
+               }
+
                // Intent to launch when notification is clicked.
                Intent launchIntent = new Intent(this, ExecServerActivity.class);
                launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -76,9 +96,12 @@ public class ExecService extends Service {
 
        @Override
        public void onDestroy () {
-               onDestroyNative();
+               if (m_isRunning) {
+                       stopServer();
+                       m_isRunning = false;
+               }
        }
 
-       private native void onCreateNative      ();
-       private native void onDestroyNative     ();
+       private native void startServer (int port);
+       private native void stopServer  ();
 }
index 8bcefd8..e26880a 100644 (file)
@@ -26,22 +26,29 @@ package com.drawelements.deqp.execserver;
 import android.app.Activity;
 import android.os.Bundle;
 import com.drawelements.deqp.testercore.Log;
+import com.drawelements.deqp.execserver.ExecService;
 import android.content.Intent;
 
-public class ServiceStarter extends Activity
-{
-       private static final String LOG_TAG = "dEQP/ServiceStarter";
+public class ServiceStarter extends Activity {
 
        @Override
-       public void onCreate(Bundle icicle)
-       {
-               super.onCreate(icicle);
+       public void onCreate(Bundle savedInstance) {
+               super.onCreate(savedInstance);
+       }
+
+       @Override
+       public void onStart() {
+               super.onStart();
+
+               final int port = getIntent().getIntExtra("port", ExecService.DEFAULT_PORT);
+
                try {
-                       Intent svc = new Intent(this, com.drawelements.deqp.execserver.ExecService.class);
+                       Intent svc = new Intent(this, ExecService.class);
+                       svc.putExtra("port", port);
                        startService(svc);
                }
                catch (Exception e) {
-                       Log.e(LOG_TAG, "Service starter starting problem", e);
+                       Log.e(ExecService.LOG_TAG, "Failed to start ExecService", e);
                }
                finish();
        }
index b1c515d..f54e5f3 100644 (file)
@@ -33,7 +33,7 @@ import java.util.List;
 
 public class RemoteAPI {
 
-       private static final String                     LOG_TAG                         = "dEQP/RemoteAPI";
+       private static final String                     LOG_TAG                         = "dEQP";
 
        private Context                                         m_context;
        private String                                          m_processName;
index 8fa2a1f..0766b38 100644 (file)
@@ -350,7 +350,7 @@ void ServerThread::stop (void)
 
 // ExecService
 
-ExecService::ExecService (JavaVM* vm, jobject context, deSocketFamily family, int port)
+ExecService::ExecService (JavaVM* vm, jobject context, int port, deSocketFamily family)
        : m_process             (vm, context)
        , m_thread              (vm, &m_process, family, port)
 {
index 1c02ff7..eef4319 100644 (file)
@@ -108,7 +108,7 @@ private:
 class ExecService
 {
 public:
-                                                       ExecService                     (JavaVM* vm, jobject context, deSocketFamily family = (deSocketFamily)DEFAULT_SOCKETFAMILY, int port = DEFAULT_PORT);
+                                                       ExecService                     (JavaVM* vm, jobject context, int port, deSocketFamily family = (deSocketFamily)DEFAULT_SOCKETFAMILY);
                                                        ~ExecService            (void);
 
        void                                    start                           (void);
index 95f2fe8..11db382 100644 (file)
@@ -67,7 +67,7 @@ static void logException (const std::exception& e)
 
 DE_BEGIN_EXTERN_C
 
-JNIEXPORT void JNICALL Java_com_drawelements_deqp_execserver_ExecService_onCreateNative (JNIEnv* env, jobject obj)
+JNIEXPORT void JNICALL Java_com_drawelements_deqp_execserver_ExecService_startServer (JNIEnv* env, jobject obj, jint port)
 {
        tcu::Android::ExecService*      service         = DE_NULL;
        JavaVM*                                         vm                      = DE_NULL;
@@ -79,7 +79,7 @@ JNIEXPORT void JNICALL Java_com_drawelements_deqp_execserver_ExecService_onCreat
                env->GetJavaVM(&vm);
                TCU_CHECK_INTERNAL(vm);
 
-               service = new tcu::Android::ExecService(vm, obj);
+               service = new tcu::Android::ExecService(vm, obj, port);
                service->start();
 
                setExecService(env, obj, service);
@@ -88,11 +88,11 @@ JNIEXPORT void JNICALL Java_com_drawelements_deqp_execserver_ExecService_onCreat
        {
                logException(e);
                delete service;
-               tcu::die("ExecService.onCreateNative() failed");
+               tcu::die("ExecService.startServer() failed");
        }
 }
 
-JNIEXPORT void JNICALL Java_com_drawelements_deqp_execserver_ExecService_onDestroyNative (JNIEnv* env, jobject obj)
+JNIEXPORT void JNICALL Java_com_drawelements_deqp_execserver_ExecService_stopServer (JNIEnv* env, jobject obj)
 {
        try
        {
@@ -107,7 +107,7 @@ JNIEXPORT void JNICALL Java_com_drawelements_deqp_execserver_ExecService_onDestr
        catch (const std::exception& e)
        {
                logException(e);
-               tcu::die("ExecService.onDestroyNative() failed");
+               tcu::die("ExecService.stopServer() failed");
        }
 }