-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathExecutor.py
More file actions
887 lines (785 loc) · 30.2 KB
/
Executor.py
File metadata and controls
887 lines (785 loc) · 30.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
# -*- coding: utf-8 -*-
'''
Created on 2015年10月7日
@author: jerrychen
'''
import threading
import os
import re
import time
import uiautomator
import json
import socket
import binascii
from minicap import MiniServer, MiniReader
from Adb import AdbDevice
from subprocess import CalledProcessError
from PySide import QtCore, QtGui
from autoSense import AutoSenseItem
from constants import Setting, Global, JudgeState as State
def workExecutor(cmd, arg1=None):
if arg1:
if type(arg1) is tuple:
threading.Thread(target=cmd, args=arg1).start()
else:
threading.Thread(target=cmd, args=(arg1,)).start()
else:
threading.Thread(target=cmd).start()
class Runner(QtCore.QRunnable):
def __init__(self, runner, arg=None, replyId=None):
super(Runner, self).__init__()
self.arg = arg
self.replyId = replyId
self.runner = runner
def run(self):
if self.arg:
self.runner(self.arg)
else:
self.runner()
class ApkInstaller(QtCore.QThread):
onStatus = QtCore.Signal(str, str)
done = QtCore.Signal()
INSTALL = 'install'
INSTALLED = 'installed'
UNINSTALL = 'uninstall'
UNINSTALLED = 'uninstalled'
FINISHED = 'finished'
FORCESTOP = 'force stop'
def __init__(self, device, installList):
super(ApkInstaller, self).__init__()
self.installList = installList
self.device = device
def stop(self):
self.isStop = True
def run(self):
self.isStop = False
for apk in self.installList:
if not self.isStop:
if os.path.exists(apk):
self.onStatus.emit(self.INSTALL, apk)
self.device.install(apk)
self.onStatus.emit(self.INSTALLED,os.path.basename(apk))
else:
self.done.emit()
return
self.done.emit()
class RunTest(QtCore.QThread):
"""
Handle the reproduced actions and send back to device
"""
actionResult = State.FAIL
isStopRun = False
limit = 0
picData = None
picImage = QtGui.QImage()
finish = QtCore.Signal()
currentAction = QtCore.Signal(AutoSenseItem)
actionDone = QtCore.Signal(AutoSenseItem, int, int)
def __init__(self, times=1, device=None):
super(RunTest, self).__init__()
self.setTimes(times)
self.setDevice(device)
self.setMinicap()
self.actionSwitcher = {
'Power': self.actionPower,
'Unlock': self.actionUnlock,
'Back': self.actionBack,
'Click': self.actionClick,
'Home': self.actionHome,
'Swipe': self.actionSwipe,
'Drag': self.actionDrag,
'LongClick': self.actionLongClick,
'Delay': self.actionDelay,
'Menu': self.actionMenu,
'Exist': self.actionCheckExist,
'NoExist': self.actionCheckNoExist,
'IsBlank': self.actionCheckBlank,
'RelativeCheck': self.actionRelativeCheck,
'Type': self.actionType,
'MediaCheck': self.actionMediaCheck,
'HideKeyboard': self.actionHideKeyboard,
'CheckPoint': self.actionCheckPoint}
def setMinicap(self):
self.miniReader = MiniReader(self._device)
self.miniServer = MiniServer(self._device)
def setTimes(self, times):
"""
Set repeat times of running a script. It should set before running.
:param times: Set by user.
"""
self.times = times
def setActions(self, actions):
"""
Assign actions that want to play.
:param actions: List of AutoSense item.
"""
self.actions = actions
def setDevice(self, device):
"""
Assign a instance of device.
:param device: AdbDevice
"""
self._device = device
def setPlayName(self, name):
self.playName = name
def checkMedia(self, passTime, timeout, isHold):
decryptRE = re.compile('[lL]ast\s+write\s+occurred\s+\(msecs\):\s+(?P<last_write>\d+)')
current_sec_time = lambda: time.time()
isAlreadyPass = False
idle = current_sec_time()
work = idle
hold = True if isHold == 'True' else False
while not self.isStopRun:
output = self._device.cmd.dumpsys(['media.audio_flinger'])
decryptMatch = decryptRE.search(output)
if decryptMatch is not None:
lastWriteTime = int(decryptMatch.group('last_write'))
if lastWriteTime < 1000:
idle = current_sec_time()
playTime = current_sec_time() - work
print 'play time = ' + str(playTime) + ' passTime: ' + str(passTime)
if playTime > passTime:
if hold:
isAlreadyPass = True
timeout = 2
else:
return {'result': True, 'reason': ''}
else:
work = current_sec_time()
idleTime = current_sec_time() - idle
print 'idleTime = ' + str(idleTime) + ', idleTime > timeout: ' + str(idleTime > timeout)
if idleTime > timeout:
if isAlreadyPass:
return {'result': True, 'reason': ''}
else:
return {'result': False, 'reason': 'timeout'}
else:
print 'It can\'t figure out last write time.'
return {'result': False, 'reason': 'Program can\'t define whether media is playing.'}
time.sleep(0.1)
def actionMediaCheck(self, param, refer=None):
t, timeout, isHold = param
result = self.checkMedia(int(t), int(timeout), isHold)
if result is not None:
if result['result']:
self.actionResult = State.PASS
def actionRelativeCheck(self, param, refer=None):
pass
def actionCheckPoint(self, param, refer=None):
self.actionResult = State.SEMI
def actionType(self, param, refer=None):
"""
Action of typing text.
:param param: a string
:param refer: None
"""
self._device.type(param[0])
self.actionResult = State.PASS
def actionDelay(self, param, refer=None):
"""
:param param: (int). in second.
:param refer: None
"""
t = int(param[0])
D_value = 0
container = []
startTime = float(self._device.cmd.shell(['echo', '$EPOCHREALTIME'], output=True))
while not self.isStopRun and D_value < t:
currentTime = float(self._device.cmd.shell(['echo', '$EPOCHREALTIME'], output=True))
D_value = currentTime - startTime
self.removeLastLog.emit()
container.append(D_value)
if len(container) > 1:
if not self._device.isScreenOn():
self._device.powerBtn()
if self._device.isLocked():
self._device.unlock()
del container[:]
time.sleep(1)
self.actionResult = State.PASS
def actionUnlock(self, param, refer=None):
"""
Unlock screen. If screen is not locked, it will do nothing.
:param param: None
:param refer: None
"""
self._device.unlock()
self.actionResult = State.PASS
def actionMenu(self, param, refer=None):
"""
Simulate menu button is pressed.
:param param: None
:param refer: None
"""
self._device.cmd.inputKeyevnt('MENU')
self.actionResult = State.PASS
def actionPower(self, param, refer=None):
"""
Simulate power button is pressed.
:param param: None
:param refer: None
"""
self._device.cmd.inputKeyevnt('POWER')
self.actionResult = State.PASS
def actionHome(self, param, refer=None):
"""
Simulate home button is pressed.
:param param: None
:param refer: None
"""
self._device.cmd.inputKeyevnt('HOME')
self.actionResult = State.PASS
def actionLongClick(self, param, refer=None):
"""
Simulate long click.
:param param: [x, y, duration]
:param refer: A json object include view information.
"""
info = json.loads(refer)
x, y, duration = param
point = (int(x), int(y))
self._device.longClick(point[0], point[1], int(duration))
self.actionResult = State.PASS
def actionDrag(self, param, refer=None):
"""
Simulate drag action. It can drag a view object if it can be dragged.
:param param: [x1, y1, x2, y2, duration]
:param refer: None
"""
start = (param[0], param[1])
end = (param[2], param[3])
self._device.drag(start, end, int(param[4]))
self.actionResult = State.PASS
def actionSwipe(self, param, refer=None):
"""
Simulate swipe action. View won't be dragged
:param param: [x1, y1, x2, y2, duration]
:param refer: None
"""
start = (param[0], param[1])
end = (param[2], param[3])
# ensure page flow
self._device.swipe(start, end, int(param[4]))
self.actionResult = State.PASS
def actionBack(self, param, refer=None):
"""
Simulate back button.
:param param: None
:param refer: None
"""
self._device.backBtn()
self.actionResult = State.PASS
def actionClick(self, param, refer=None):
"""
Simulate click action.
:param param: [x, y]
:param refer: A json object include view information.
"""
info = json.loads(refer)
if len(param) == 2:
x, y = param
else:
x, y, _ = param
point = (int(x), int(y))
noShow = False
wait = 5
while self._device.isConnected() and not self.isStopRun and wait > 0:
try:
if not self._device.isScreenOn():
self._device.powerBtn()
if self._device.isLocked():
self._device.unlock()
result = self._device.checkSamePoint(point, info)
print 'reason = '+result['reason']
if result['answer']:
self.actionResult = State.PASS
break
elif not noShow:
print 'wait view'
time.sleep(1)
wait -= 1
except uiautomator.JsonRPCError as m:
print 'JsonRPCError: ' + m.message
break
def actionCheckBlank(self, param, refer=None):
"""
Check the target view should not have any child view.
:param param: [Identification, x, y]. There are 4 kinds of identification(resourceId, text, description, className).
:param refer: None
"""
benchmark, x, y = param
attribute, value = benchmark.split('=')
point = (int(x), int(y))
if attribute == 'text':
selector = self._device.retrieveSelector(point, self._device.d(text=value))
if selector:
if selector.childCount == 0:
self.actionResult = State.PASS
else:
self.actionResult = State.PASS
elif attribute == 'description':
selector = self._device.retrieveSelector(point, self._device.d(description=value))
if selector:
if selector.childCount == 0:
self.actionResult = State.PASS
else:
self.actionResult = State.PASS
elif attribute == 'resourceId':
selector = self._device.retrieveSelector(point, self._device.d(resourceId=value))
if selector:
if selector.childCount == 0:
self.actionResult = State.PASS
else:
self.actionResult = State.PASS
elif attribute == 'className':
selector = self._device.retrieveSelector(point, self._device.d(className=value))
if selector:
if selector.childCount == 0:
self.actionResult = State.PASS
else:
self.actionResult = State.PASS
def actionCheckExist(self, param, refer=None):
"""
Check the target view whether is existed on the screen.
:param param: [Identification, x, y]. There are 4 kinds of identification(resourceId, text, description, className).
:param refer: None
"""
benchmark, x, y = param
attribute, value = benchmark.split('=')
point = (int(x), int(y))
if attribute == 'text':
if self._device.retrieveSelector(point, self._device.d(text=value)):
self.actionResult = State.PASS
# self.report.emit(INFO, 'Pass: View exist', True)
else:
pass
# self.report.emit(ERROR, 'Fail: View not exist', True)
# self.isStopRun = True
elif attribute == 'description':
if self._device.retrieveSelector(point, self._device.d(description=value)):
self.actionResult = State.PASS
# self.report.emit(INFO, 'Pass: View exist', True)
else:
pass
# self.report.emit(ERROR, 'Fail: View not exist', True)
# self.isStopRun = True
elif attribute == 'resourceId':
if self._device.retrieveSelector(point, self._device.d(resourceId=value)):
self.actionResult = State.PASS
# self.report.emit(INFO, 'Pass: View exist', True)
else:
pass
# self.report.emit(ERROR, 'Fail: View not exist', True)
# self.isStopRun = True
elif attribute == 'className':
if self._device.retrieveSelector(point, self._device.d(className=value)):
self.actionResult = State.PASS
# self.report.emit(INFO, 'Pass: View exist', True)
else:
pass
# self.report.emit(ERROR, 'Fail: View not exist', True)
# self.isStopRun = True
def actionCheckNoExist(self, param, refer=None):
"""
Check the target view whether isn't existed on the screen.
:param param: [Identification, x, y]. There are 4 kinds of identification(resourceId, text, description, className).
:param refer: None
"""
benchmark, x, y = param
attribute, value = benchmark.split('=')
point = (int(x), int(y))
if attribute == 'text':
if not self._device.retrieveSelector(point, self._device.d(text=value)):
self.actionResult = State.PASS
elif attribute == 'description':
if not self._device.retrieveSelector(point, self._device.d(description=value)):
self.actionResult = State.PASS
elif attribute == 'resourceId':
if not self._device.retrieveSelector(point, self._device.d(resourceId=value)):
self.actionResult = State.PASS
elif attribute == 'className':
if not self._device.retrieveSelector(point, self._device.d(className=value)):
self.actionResult = State.PASS
def actionHideKeyboard(self, param, refer=None):
"""
Hide soft keyboard. If keyboard isn't showed, it will do nothing.
:param param: None
:param refer: None
"""
self._device.hideKeyboard()
self.actionResult = State.PASS
def stop(self):
"""
Exit this process.
"""
self.isStopRun = True
def setStartIndex(self, index):
"""
chose a start index of actions.
:param index: integer
"""
self.startIndex = index
def takeScreenShot(self, path):
self.picData = self.miniReader.getDisplay()
self.picImage.loadFromData(self.picData)
self.picImage.save(path, 'JPEG')
def run(self):
self.isStopRun = False
self.limit = 0
try:
self.miniServer.start()
''' wait for active '''
while not self.miniServer.isActive():
time.sleep(0.5)
self.takeScreenShot(Global.IMAGE_FOLDER + '/%s_%d.jpg' % (self.playName, 0))
while self.limit < self.times and not self.isStopRun:
self.limit += 1
for index in range(len(self.actions)):
if not self.isStopRun and self.startIndex <= index:
self.index = index + 1
item = self.actions[index]
if self._device.isConnected():
self.actionResult = State.FAIL
self.currentAction.emit(item)
self.actionSwitcher.get(item.action())(item.parameter(), item.information())
self.actionDone.emit(item, self.actionResult, index)
self.takeScreenShot(Global.IMAGE_FOLDER + '/%s_%d.jpg' % (self.playName, self.index))
time.sleep(0.5)
else:
self.isStopRun = True
break
except socket.error:
print 'socket.error: device offline'
self.isStopRun = True
except ValueError as e:
print 'ValueError: ' + e.message
self.isStopRun = True
except CalledProcessError, exc:
print 'CalledProcessError: ' + str(exc)
self.isStopRun = True
finally:
self.finish.emit()
class UpdateScreen(QtCore.QThread):
"""
Keep capturing screen in the background.
"""
loadDone = QtCore.Signal()
startLoad = QtCore.Signal()
deviceOffline = QtCore.Signal()
isStop = False
isPause = False
def __init__(self, device, picPath):
super(UpdateScreen, self).__init__()
self.isStop = False
self._device = device
self.delay = 0
self.picPath = picPath
self.lastFrameTime = 0
self.isRefresh = False
self.nconcurrent = threading.BoundedSemaphore(5)
self.miniServer = MiniServer(self._device)
self.miniReader = MiniReader(self._device)
def stop(self):
""" Stop capturing """
self.isStop = True
self.miniServer.stop()
# def pause(self):
# """ Pause capturing """
# self.isPause = True
# self.miniServer.stop()
#
# def resume(self):
# """ resume capturing """
# self.isPause = False
# # self.start()
def setDelay(self, delay=0):
""" Set a delay time to start capturing """
self.delay = delay
def run(self):
time.sleep(self.delay)
try:
self.miniServer.start()
self.isStop = False
while not self.isStop:
if self.miniServer.isActive():
if not self.miniServer.needRestart():
self.startLoad.emit()
self.screenshot(path=self.picPath + '/' + self._device.serialno + '_screen.jpg')
else:
self.miniServer.reStart()
else:
time.sleep(0.5)
# self.isPause = True
except:
print 'device not found'
self.lastFrameTime = 0
self.deviceOffline.emit()
finally:
self.miniServer.stop()
def monitorFrame(self):
"""
monitor the screen has changed, it helps to reduce capturing frequency.
"""
decryptRE = re.compile('\s+events-delivered:\s+(?P<number>\d+)')
output = self._device.cmd.dumpsys(['SurfaceFlinger'])
if output:
m = decryptRE.search(output)
if m is not None:
tmpTime = m.group('number')
if tmpTime != self.lastFrameTime:
self.lastFrameTime = tmpTime
return True
def screenshot(self, path, delay=0):
"""
Do screen capture
:param path: save pic path
:param delay: delay to capture screen. In second.
"""
try:
# self.nconcurrent.acquire()
time.sleep(delay)
pp = time.time()
if self._device.isConnected():
if self.miniServer.isActive():
byteData = self.miniReader.getDisplay()
im = QtGui.QImage.fromData(QtCore.QByteArray.fromRawData(byteData))
im.loadFromData(byteData)
im.save(path, 'JPEG')
else:
if not self.isStop:
self.deviceOffline.emit()
print time.time() - pp
if not self.isStop:
self.loadDone.emit()
except AttributeError as e:
print e.message
except IOError as e:
print e.message
# finally:
# self.nconcurrent.release()
def __byteToHex(self, bs):
return ''.join(['%02X ' % ord(byte) for byte in bs])
def __parsePicSize(self, data):
return int(binascii.hexlify(data[::-1]), 16)
def __parseBanner(self, data):
if len(data) == 24:
banner = dict()
banner['version'] = int(binascii.hexlify(data[0]), 16)
banner['length'] = int(binascii.hexlify(data[1]), 16)
banner['pid'] = int(binascii.hexlify(data[2:5][::-1]), 16)
banner['real.width'] = int(binascii.hexlify(data[6:9][::-1]), 16)
banner['real.height'] = int(binascii.hexlify(data[10:13][::-1]), 16)
banner['virtual.width'] = int(binascii.hexlify(data[14:17][::-1]), 16)
banner['virtual.height'] = int(binascii.hexlify(data[18:21][::-1]), 16)
banner['orient'] = int(binascii.hexlify(data[22]), 16)
banner['policy'] = int(binascii.hexlify(data[23]), 16)
return banner
class WaitForDevice(QtCore.QThread):
'''
Monitor device to be connected to computer.
'''
online = QtCore.Signal()
def __init__(self, device):
super(WaitForDevice, self).__init__()
self.device = device
self.isStop = False
def stop(self):
"""
Stop to wait device
"""
self.isStop = True
def run(self):
print 'start to monitor'
self.isStop = False
while not self.isStop:
if self.device.isConnected():
# try:
print 'start to connect'
self.device.connect()
if not self.isStop:
self.online.emit()
break
# except:
# print 'Keep searching'
time.sleep(1)
class DeviceInfoThread(QtCore.QThread):
"""
Get device information in background. Include brand,
modle name, serial number, android version, region, resolution,
manufacturer name, product name and kernel number.
"""
onDeviceInfo = QtCore.Signal(dict)
def __init__(self, serialno=None):
super(DeviceInfoThread, self).__init__()
self.serialNo = serialno
def setDeviceId(self, ID):
"""
Set a seria; number of target device.
:param ID: device serial number
"""
self.serialNo = ID
def run(self):
holdInfo = dict()
device = AdbDevice(self.serialNo)
for prop in device.getProp().split('\n'):
proper = prop.replace('[', '').replace(']', '').split(':')
if proper[0] == 'ro.product.brand':
holdInfo['brand'] = proper[1].strip()
elif proper[0] == 'ro.product.model':
holdInfo['model'] = proper[1].strip()
elif proper[0] == 'ro.serialno':
holdInfo['serialNo'] = proper[1].strip()
elif proper[0] == 'ro.build.version.release':
holdInfo['android'] = proper[1].strip()
elif proper[0] == 'ro.build.display.id':
holdInfo['buildNo'] = proper[1].strip()
elif proper[0] == 'ro.product.locale.region':
holdInfo['region'] = proper[1].strip()
elif proper[0] == 'ro.product.manufacturer':
holdInfo['manufacturer'] = proper[1].strip()
elif proper[0] == 'ro.product.name':
holdInfo['name'] = proper[1].strip()
holdInfo['kernelNo'] = device.cmd.shell(['cat', 'proc/version'], output=True).strip('\r\n')
display = device.getRealDisplay()
holdInfo['resolution'] = str(display['width']) + ' x ' + str(display['height'])
self.onDeviceInfo.emit(holdInfo)
class DeviceSettingsThread(QtCore.QThread):
"""
Get device environment states. Include NFC, WiFi, airplan mode,
GPS, AutoRotate, Bluetooth, Brightness, install unknown app,
Vibrate, Auto-Brightness, Window animator, transition animator,
duration animation and no keep activity.
"""
currentSettings = QtCore.Signal(dict, bool)
device = None
def __init__(self):
super(DeviceSettingsThread, self).__init__()
def setDevice(self, device):
"""
Set target device.
:param device: AdbDevice
"""
self.device = device
def run(self):
try:
xx = dict()
xx[Setting.NFC] = self.device.isNfcOn()
xx[Setting.WIFI] = self.device.isWifiOn()
xx[Setting.AIRPLANE] = self.device.isAirPlaneModeOn()
xx[Setting.GPS] = self.device.isGpsOn()
xx[Setting.AUTO_ROTATE] = self.device.isAutoRotateOn()
xx[Setting.BLUETOOTH] = self.device.isBtOn()
xx[Setting.DATA_ROAMING] = self.device.isDataRoamingOn()
xx[Setting.ALLOW_APP] = self.device.isInstallUnknownSources()
xx[Setting.NO_KEEP_ACTIVITY] = self.device.isNoKeepActivityOn()
xx[Setting.AUTO_BRIGHTNESS] = self.device.isAutoBrightnessOn()
xx[Setting.BRIGHTNESS_SET] = self.device.screenTimeout()
xx[Setting.VIBRATE] = self.device.isVibrateWhenRingOn()
xx[Setting.WINDOW_ANIMATOR] = self.device.isWindowAniOn()
xx[Setting.TRANSITION_ANIMATOR] = self.device.isTransitionAnuOn()
xx[Setting.DURATION_ANIMATION] = self.device.isDurationAniOn()
self.currentSettings.emit(xx, True)
except CalledProcessError:
self.currentSettings.emit(dict(), False)
class PackagesThread(QtCore.QThread):
"""
Get packages name in device. Include all, system, 3rd party and recent.
"""
currentPackages = QtCore.Signal(list)
device = None
t = ''
def __init__(self):
super(PackagesThread, self).__init__()
def setDevice(self, device):
"""
Set target device.
:param device: AdbDevice
"""
self.device = device
def setType(self, t):
"""
Set package type
:param t: request package type
"""
self.t = t
def run(self):
self.currentPackages.emit(self.device.requestPackage(self.t))
class SendSettingThread(QtCore.QThread):
"""
Set device environment states. Include NFC, WiFi, airplan mode,
GPS, AutoRotate, Bluetooth, Brightness, install unknown app,
Vibrate, Auto-Brightness, Window animator, transition animator,
duration animation and no keep activity.
"""
mDict = dict()
done = QtCore.Signal()
def __init__(self, settingDict, device):
super(SendSettingThread, self).__init__()
self.mDict = settingDict
self.device = device
def run(self):
needReboot = False
for key, value in self.mDict.iteritems():
print 'key = ' + key
if key == Setting.AIRPLANE:
self.device.enableAirplaneMode(value)
elif key == Setting.NFC:
self.device.enableNfc(value)
elif key == Setting.ALLOW_APP:
self.device.enableInstallUnknownSources(value)
elif key == Setting.WIFI:
self.device.enableWifi(value)
elif key == Setting.BLUETOOTH:
self.device.enableBluetooth(value)
elif key == Setting.NO_KEEP_ACTIVITY:
self.device.enableNoKeepActivity(value)
elif key == Setting.DATA_ROAMING:
self.device.enableDataRoaming(value)
elif key == Setting.AUTO_ROTATE:
self.device.enableAutoRotate(value)
elif key == Setting.GPS:
self.device.enableGps(value)
elif key == Setting.AUTO_BRIGHTNESS:
self.device.enableAutoBrightness(value)
elif key == Setting.VIBRATE:
self.device.enableVibrateWhenRing(value)
elif key == Setting.BRIGHTNESS_SET:
self.device.setScreenTimeout(str(long(value) * 1000))
elif key == Setting.WINDOW_ANIMATOR:
if self.device.isWindowAniOn() != value:
self.device.enableWindowAnimator(not value)
needReboot = True
elif key == Setting.TRANSITION_ANIMATOR:
if self.device.isTransitionAnuOn() != value:
self.device.enableTransitionAnimator(not value)
needReboot = True
elif key == Setting.DURATION_ANIMATION:
print self.device.isDurationAniOn() != value
if self.device.isDurationAniOn() != value:
self.device.enableDurationAnimation(not value)
needReboot = True
self.sleep(5)
if needReboot:
print 'reboot'
self.device.reboot()
while needReboot:
self.sleep(2)
try:
if self.device.isConnected():
self.device.screenTimeout()
needReboot = False
except ValueError:
pass
self.done.emit()
class InstallThread(QtCore.QThread):
"""
Install app
"""
done = QtCore.Signal()
def __init__(self, f, device):
super(InstallThread, self).__init__()
self.f = f
self.device = device
def run(self):
self.device.install(self.f)
self.done.emit()