Skip to content
Browse files

Added startviewserver argument to ViewClient

- Start the server if specified
- Eat optional command line arguments
- Added UML
  • Loading branch information...
1 parent 19b3db9 commit 357e6b548717e3b17c59671653fd5dfe2c03aa8d @dtmilano committed Nov 4, 2012
View
4 .gitignore
@@ -10,3 +10,7 @@
# vi files #
############
.*.swp
+
+# other files #
+##########
+*~
View
11 AndroidViewClient/examples/temperature-converter-get-conversion.py
@@ -35,8 +35,13 @@
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
-
-device, serialno = ViewClient.connectToDeviceOrExit()
+print sys.argv
+localViewServer = False
+if len(sys.argv) > 1 and sys.argv[1] == '--localViewServer':
+ localViewServer = True
+ sys.argv.pop(1)
+
+device, serialno = ViewClient.connectToDeviceOrExit(ignoresecuredevice=localViewServer)
FLAG_ACTIVITY_NEW_TASK = 0x10000000
package = 'com.example.i2at.tc'
@@ -50,7 +55,7 @@
device.type("123")
MonkeyRunner.sleep(3)
-vc = ViewClient(device, serialno)
+vc = ViewClient(device, serialno, startviewserver=(not localViewServer))
# obtain the views by id
celsius = vc.findViewByIdOrRaise("id/celsius")
View
32 AndroidViewClient/examples/viewserveractivity-new-activity.py
@@ -0,0 +1,32 @@
+#! /usr/bin/env monkeyrunner
+'''
+Copyright (C) 2012 Diego Torres Milano
+Created on Feb 3, 2012
+
+@author: diego
+'''
+
+
+import sys
+import os
+
+# This must be imported before MonkeyRunner and MonkeyDevice,
+# otherwise the import fails.
+# PyDev sets PYTHONPATH, use it
+try:
+ for p in os.environ['PYTHONPATH'].split(':'):
+ if not p in sys.path:
+ sys.path.append(p)
+except:
+ pass
+
+try:
+ sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
+except:
+ pass
+
+from com.dtmilano.android.viewclient import ViewClient
+
+device, serialno = ViewClient.connectToDeviceOrExit(ignoresecuredevice=True)
+vc = ViewClient(device=device, serialno=serialno, startviewserver=False)
+vc.findViewWithTextOrRaise("New activity").touch()
View
18 AndroidViewClient/src/com/dtmilano/android/viewclient.py
@@ -683,7 +683,7 @@ class ViewClient:
mapping is created.
'''
- def __init__(self, device, serialno='emulator-5554', adb=os.path.join(ANDROID_HOME, 'platform-tools', ADB), autodump=True):
+ def __init__(self, device, serialno='emulator-5554', adb=os.path.join(ANDROID_HOME, 'platform-tools', ADB), autodump=True, startviewserver=True):
'''
Constructor
@@ -695,18 +695,21 @@ def __init__(self, device, serialno='emulator-5554', adb=os.path.join(ANDROID_HO
@param adb: the path of the C{adb} executable
@type autodump: boolean
@param autodump: whether an automatic dump is performed at the end of this constructor
+ @type startviewserverparam: boolean
+ @param startviewserverparam: Whether to start the B{global} ViewServer
'''
if not device:
raise Exception('Device is not connected')
if not os.access(adb, os.X_OK):
raise Exception('adb="%s" is not executable. Did you forget to set ANDROID_HOME in the environment?' % adb)
- if not self.serviceResponse(device.shell('service call window 3')):
- try:
- self.assertServiceResponse(device.shell('service call window 1 i32 %d' %
+ if startviewserver:
+ if not self.serviceResponse(device.shell('service call window 3')):
+ try:
+ self.assertServiceResponse(device.shell('service call window 1 i32 %d' %
VIEW_SERVER_PORT))
- except:
- raise Exception('Cannot start View server.\n'
+ except:
+ raise Exception('Cannot start View server.\n'
'This only works on emulator and devices running developer versions.\n'
'Does hierarchyviewer work on your device ?')
@@ -775,6 +778,9 @@ def connectToDeviceOrExit(timeout=60, verbose=False, ignoresecuredevice=False):
'''
progname = os.path.basename(sys.argv[0])
+ # eat all the extra options the invoking script may have added
+ while len(sys.argv) > 1 and sys.argv[1][0] == '-':
+ sys.argv.pop(1)
serialno = sys.argv[1] if len(sys.argv) > 1 else 'emulator-5554'
if verbose:
print 'Connecting to a device with serialno=%s with a timeout of %d secs...' % (serialno, timeout)
View
BIN AndroidViewClient/uml/AndroidViewClient.zargo
Binary file not shown.

0 comments on commit 357e6b5

Please sign in to comment.
Something went wrong with that request. Please try again.