0

For some reason no matter what I do I can't issue a 'drag' command to my external android device using AndroidViewClient. Here is my code:

import sys
import os
import time

try:
    sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
    pass

from com.dtmilano.android.adb.adbclient import AdbClient
from com.dtmilano.android.viewclient import ViewClient, View

print 'Connecting to device...'
device, serialno = ViewClient.connectToDeviceOrExit()

 time.sleep(.5)
 AdbClient(serialno='.*').drag((500,1000),(500,100), 1, 10)

I have also tried

device.drag((500,1000),(500,100), 1, 10)

which also does not work. (btw, how does device.drag() differ from AdbClient.drag()?)

Also, I am NOT getting any errors from the above. Everything runs, and no errors are found. It just does not drag the screen.

Yet, touch events and keyboard events work:

device.touch(400,200, 'DOWN_AND_UP')

Note: my version of AndroidViewCLient is 7.0.2. My android device is Jellybean 4.1

EDIT: Ouput for my android device:

C:\Users\Me>adb shell input
usage: input ...
       input text <string>
       input keyevent <key code number or name>
       input tap <x> <y>
       input swipe <x1> <y1> <x2> <y2>
Micro
  • 10,303
  • 14
  • 82
  • 120
  • What's the output of `adb shell input`? API level 16? – Diego Torres Milano May 30 '14 at 21:02
  • @dtmilano Jellybean 4.1 is API level 16, yes. When I run `adb shell swipe 500 1000 500 100` it works and swipes the device. Would be awesome if the AdbClient worked too =) (p.s. I love what you have created so far with AndroidViewClient and AdbClient classes) – Micro May 31 '14 at 03:16
  • Thanks. Still need the output of `adb shell input`. However, `drag()` is doing ` elif version <= 17: self.shell('input swipe %d %d %d %d' % (x0, y0, x1, y1)) ` – Diego Torres Milano May 31 '14 at 04:34
  • @dtmilano oh sorry. Added it to the question above. – Micro May 31 '14 at 04:47
  • **AVC** should be doing exactly the same as you manually do. try adding some debug messages to print which `input` command is run. – Diego Torres Milano Jun 02 '14 at 18:54
  • @dtmilano If I put `device.shell('input swipe 500 1000 500 100')` into my script it will drag. However, 'device.shell('input swipe 500 1000 500 100 1')' or 'device.shell('input swipe 500 1000 500 100 1, 10') will NOT drag. So maybe it can only take four coordinates? And since the `device.drag()` requires a tuple, the shell just does nothing? What is a good line to put in to adbclient.py under the `if` statements of the `drag` to output what is being sent to the shell? – Micro Jun 05 '14 at 20:37
  • If you set `DEBUG = True` in adbclient.py then `shell()` will print every command it executes: ` if DEBUG: print >> sys.stderr, "shell(cmd=%s)" % cmd`. Thanks for helping debug this issue. – Diego Torres Milano Jun 06 '14 at 13:43
  • @dtmilano I'm pretty sure I am doing everything right, but editing or even deleting this file `C:\Users\me\Documents\AndroidViewClient-master\AndroidViewClient\src\com\dtmilano\android\adb\adbclient.py` does not change how my scripts run. All the path variables (`ANDROID_VIEW_CLIENT_HOME = C:\Users\me\Documents\AndroidViewClient-master\AndroidViewClient`)are set right and the code I am using to import is the same as above in the question. Is the above code importing from someplace else? This is really bizarre. – Micro Jun 06 '14 at 14:17
  • It should import from the directories listed in `sys.path` in order. Try to print its content and find if you have other adbclient.py somewhere else. – Diego Torres Milano Jun 06 '14 at 14:22
  • @dtmilano Ah, it was importing from `python27\Lib\site-packages`. I forgot I used easy_install before. So what is happening is that adbclient.py is thinking that my Samsung Galaxy Note 2 has API version greater than 17. It is running `self.shell('input touchscreen swipe %d %d %d %d %d' % (x0, y0, x1, y1, duration))` in the `AdbClient.drag()` method, which does not work on the Note 2. Which is strange, because monkeyrunner.drag((500,1000),(500,100), 1, 10) works. That is, I can specify a duration and steps. – Micro Jun 06 '14 at 14:45
  • For your reference it is Android Version 4.1.2 (API 16). Maybe it is right no the borderline? – Micro Jun 06 '14 at 14:49
  • So, swipe with no duration does what you expect. You can also turn DEBUG on in the adbclient.py installed by easy_install. You can also print the value of `version` in `AdbClient.drag()` to see if it's what we expect. – Diego Torres Milano Jun 06 '14 at 15:44
  • @dtmilano Yes. Swipe with no duration does what I expect. Putting in the duration even in the `adb shell` does not work. – Micro Jun 06 '14 at 15:53

1 Answers1

2

I found the problem. When AdbClient gets the API level (version) it's not converted to int so then the comparison in AdbClient.drag() fails because it's a string and the wrong command is sent to API 16. This:

__send(shell:input touchscreen swipe 500 400 100 400 1, checkok=True, reconnect=False)

instead of

__send(shell:input swipe 500 400 100 400, checkok=True, reconnect=False)

It will be fixed in AVC 7.0.4.

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134