Skip to content

Commit 4267a3e

Browse files
committed
Added 'adb get-serialno' to obtain serial number in case there's only
one device. - Fixed error message - Check existence of qemu property
1 parent 45aa68e commit 4267a3e

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

AndroidViewClient/src/com/dtmilano/android/viewclient.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ def __init__(self, device, serialno, adb=None, autodump=True, forceviewserveruse
874874

875875
if adb:
876876
if not os.access(adb, os.X_OK):
877-
raise Exception('adb="%s" is not executable')
877+
raise Exception('adb="%s" is not executable' % adb)
878878
else:
879879
adb = ViewClient.__obtainAdbPath()
880880

@@ -1018,11 +1018,18 @@ def __obtainDeviceSerialNumber(device):
10181018
if not serialno:
10191019
serialno = device.shell('getprop ro.serialno')[:-2]
10201020
if not serialno:
1021-
if int(device.shell('getprop ro.kernel.qemu')[:-2]) == 1:
1021+
qemu = device.shell('getprop ro.kernel.qemu')[:-2]
1022+
if qemu and int(qemu) == 1:
10221023
# FIXME !!!!!
10231024
# this must be calculated from somewhere, though using a fixed serialno for now
10241025
warnings.warn("Running on emulator but no serial number was specified then 'emulator-5554' is used")
10251026
serialno = 'emulator-5554'
1027+
if not serialno:
1028+
# If there's only one device connected get its serialno
1029+
adb = ViewClient.__obtainAdbPath()
1030+
s = subprocess.Popen([adb, 'get-serialno'], stdout=subprocess.PIPE).communicate()[0][:-1]
1031+
if s != 'unknown':
1032+
serialno = s
10261033
return serialno
10271034

10281035
@staticmethod

0 commit comments

Comments
 (0)