You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2013/06/15 02:23:02 UTC

android commit: [CB-3627] start-emulator now properly starts, waits for and unlocks an emulator, consumed by run as well.

Updated Branches:
  refs/heads/master c0a39570c -> 0efd9fcac


[CB-3627] start-emulator now properly starts, waits for and unlocks an emulator, consumed by run as well.


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/0efd9fca
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/0efd9fca
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/0efd9fca

Branch: refs/heads/master
Commit: 0efd9fcac0755255c2a050b8514caeea966f3f49
Parents: c0a3957
Author: Fil Maj <ma...@gmail.com>
Authored: Fri Jun 14 17:22:57 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Fri Jun 14 17:22:57 2013 -0700

----------------------------------------------------------------------
 .../cordova/lib/list-started-emulators          |   4 +-
 bin/templates/cordova/lib/start-emulator        |  46 +++++++++
 bin/templates/cordova/run                       | 101 ++++++-------------
 3 files changed, 77 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/0efd9fca/bin/templates/cordova/lib/list-started-emulators
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/list-started-emulators b/bin/templates/cordova/lib/list-started-emulators
index 0d5d5c1..2aa6e99 100755
--- a/bin/templates/cordova/lib/list-started-emulators
+++ b/bin/templates/cordova/lib/list-started-emulators
@@ -16,7 +16,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
-devices=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print  $1;}}' | grep 'emulator'`
+devices=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print  $1;}}' | grep 'emulator' | grep -v 'offline'`
 read -ra emulator_list <<< "$devices"
 if [[ ${#emulator_list[@]} > 0 ]] ; then
     for i in ${emulator_list[@]}
@@ -26,7 +26,7 @@ if [[ ${#emulator_list[@]} > 0 ]] ; then
     done
     exit 0
 else
-    echo "No started emulators found, you can start an emulator by using the command"
+    echo "No started emulators found (it may still be booting up), you can start an emulator by using the command"
     echo " 'cordova/lib/start-emulator'"
     exit 2
 fi

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/0efd9fca/bin/templates/cordova/lib/start-emulator
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/start-emulator b/bin/templates/cordova/lib/start-emulator
index 86b14bf..10e73ce 100755
--- a/bin/templates/cordova/lib/start-emulator
+++ b/bin/templates/cordova/lib/start-emulator
@@ -18,6 +18,50 @@
 
 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 PROJECT_PATH=$( cd "$( dirname "$0" )/../.." && pwd )
+
+function dot {
+    sleep 1
+    echo -n "."
+}
+
+function wait_for_emulator {
+    local i="0"
+    echo -n "Waiting for emulator"
+    emulator_string=$($DIR/list-started-emulators)
+    while [ $? != 0 ]
+    do
+        dot
+        i=$[i+1]
+        emulator_string=$($DIR/list-started-emulators)
+    done
+    read -ra target <<< "$emulator_string"
+    echo ""
+    echo -n "Waiting for it to boot up (this can take a while)"
+    while [ $i -lt 300 ]
+    do
+        boot_anim=$(adb -s $target shell getprop init.svc.bootanim 2>&1)
+        if [[ "$boot_anim" =~ "stopped" ]] ; then
+            break
+        else
+            i=$[i+1]
+            dot
+        fi
+    done
+    # Device timeout: emulator has not started in time
+    if [ $i -eq 300 ]
+    then
+        echo ""
+        echo "Emulator timeout!"
+        exit 69
+    else
+        echo ""
+        echo "Connected!"
+    fi
+    # Unlock the device
+    adb -s $target shell input keyevent 82
+    exit 0
+}
+
 emulator_images=$("$DIR/list-emulator-images")
 if [ $? != 0 ]; then
     echo "No emulators found, if you would like to create an emulator follow the instructions"
@@ -43,3 +87,5 @@ else
     #xterm -e emulator -avd ${emulator_list[0]} &
     emulator -avd ${emulator_list[0]} 1> /dev/null 2>&1 &
 fi
+
+wait_for_emulator

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/0efd9fca/bin/templates/cordova/run
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/run b/bin/templates/cordova/run
index d871c09..9641ab2 100755
--- a/bin/templates/cordova/run
+++ b/bin/templates/cordova/run
@@ -19,66 +19,40 @@
 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 PROJECT_PATH=$( cd "$DIR/.." && pwd )
 
-function wait_for_emulator {
-# TODO: this doesnt seem to work
-    emulator_string=$("$DIR/lib/list-started-emulators")
-    old_started=($emulator_string)
-    local new_started
-    local new_emulator_name
-    local i="0"
-    echo -n "Waiting for emulator..."
-    while [ $i -lt 300 ]
-    do
-        emulator_string=$("$DIR/lib/list-started-emulators")
-        new_started=($emulator_string)
-        if [[ ${#new_started[@]} > ${#old_started[@]} && -z "$new_emulator_name" ]] ; then
-            # get the name of the started emulator
-            local count="0"
-            if [[ ${#old_started[@]} == 0 ]] ; then
-                new_emulator_name=${new_started[$count]}
-            else
-                for count in {0...${#old_started[@]}}
-                do
-                    if [[ ! ${new_started[$count]} == ${old_started[$count]} ]] ; then
-                        new_emulator_name=${new_started[$count]}
-                    fi
-                done
-                if [[ -z "$new_emulator_name" ]] ; then
-                    count=$[count+1]
-                    new_emulator_name=${new_started[$count]}
-                fi
-            fi
-        elif [[ "$new_emulator_name" ]] ; then
-            boot_anim=`adb -s $new_emulator_name shell getprop init.svc.bootanim`
-            if [[ $boot_anim =~ "stopped" ]] ; then
-                break
-            else
-                sleep 1
-                i=$[i+1]
-                echo -n "."
-            fi
+function run_on_device_or_emulator {
+    devices=`$DIR/lib/list-devices`
+    if [ $? = 0 ]; then
+        $DIR/lib/install-device
+    else
+        run_on_emulator
+    fi
+}
+
+function run_on_emulator {
+    emulators=`$DIR/lib/list-started-emulators`
+    if [ $? = 0 ] ; then
+        $DIR/lib/install-emulator
+    else
+        images=`$DIR/lib/list-emulator-images`
+        if [ $? = 0 ] ; then
+            $DIR/lib/start-emulator
+            $DIR/lib/install-emulator
         else
-            sleep 1
-            i=$[i+1]
-            echo -n "."
+            echo "No devices/emulators started nor images available to start. How are we supposed to do this, then?"
+            exit 2
         fi
-    done
-    # Device timeout: emulator has not started in time
-    if [ $i -eq 300 ]
-    then
-        echo "emulator timeout!"
-        exit 69
-    else
-        echo "connected!"
     fi
 }
 
+
+
 if [[ "$#" -eq 2 ]] ; then
+    # TODO: the order of arguments here may be reversed from the assumption below
     $DIR/build $2
     if [[ $1 == "--device" ]] ; then
         $DIR/lib/install-device
     elif [[ $1 == "--emulator" ]] ; then
-        $DIR/lib/install-emulator
+        run_on_emulator
     elif [[ $1 =~ "--target=" ]]; then
         $DIR/lib/install-device $1
     else
@@ -87,12 +61,13 @@ if [[ "$#" -eq 2 ]] ; then
 elif [[ "$#" -eq 1 ]] ; then
     if [[ $1 == "--debug" || $1 == "--release" || $1 == "--nobuild" ]] ; then
         $DIR/build $1
+        run_on_device_or_emulator
     elif [[ $1 == "--device" ]] ; then
         $DIR/build
         $DIR/lib/install-device
     elif [[ $1 == "--emulator" ]] ; then
-        $DIR/build
-        $DIR/lib/install-emulator
+        #$DIR/build
+        run_on_emulator
     elif [[ $1 =~ "--target=" ]]; then
         $DIR/build
         $DIR/lib/install-device $1
@@ -101,24 +76,6 @@ elif [[ "$#" -eq 1 ]] ; then
     fi
 else
     echo "Warning : [ --device | --emulate | --target=<targetID> ] not specified, using defaults."
-    #$DIR/build
-    devices=$("$DIR/lib/list-devices")
-    if [ $? = 0 ]; then
-        $DIR/lib/install-device
-    else
-        emulators=$("$DIR/lib/list-started-emulators")
-        if [ $? = 0 ] ; then
-            $DIR/lib/install-emulator
-        else
-            images=$("$DIR/lib/list-emulator-images")
-            if [ $? = 0 ] ; then
-                $DIR/lib/start-emulator
-                wait_for_emulator
-                $DIR/lib/install-emulator
-            else
-                echo "No Android devices attached, nor emulator images available to start. How are we supposed to do this, then?"
-                exit 2
-            fi
-        fi
-    fi
+    $DIR/build
+    run_on_device_or_emulator
 fi