コード例 #1
0
 def __init__(self,
              seed='WTF',
              specialEvents=[
                  'wifi', 'cellular', 'toggleScreen', 'rotateScreen',
                  'pressBack', 'pressHome'
              ],
              number=25):
     """SpecialEvents is a list containing the names of all possible special events.
         current possible special events:
             wifi
             cellular
             toggleScreen
             rotateScreen
             pressBack
             pressHome
     """
     random.seed(seed)
     seq = specialEvents * (number / len(specialEvents) + 1)
     self.randomSeries = random.sample(seq, number)
     self.insertChoice = []
     while self.insertChoice.count(True) < number:
         self.insertChoice.extend(random.sample([True, False], 1))
     self.prevGesture = None
     self.idx = 0
     self.insertionIdx = 0
     self.parcel = PipelineParcel()
コード例 #2
0
 def next(self, dummy):
     parcel = PipelineParcel()
     line = self.p.stdout.readline()
     if self.mustTerminate or (line == '' and self.p.poll() != None):
         return parcel
     parcel.enqueue(line)
     return parcel
コード例 #3
0
 def next(self, dummy):
     parcel = PipelineParcel()
     line = self.p.stdout.readline()
     if self.mustTerminate or (line == '' and self.p.poll() != None):
         return parcel
     parcel.enqueue(line)
     return parcel
コード例 #4
0
 def next(self, specialEvent):
     """ Takes a specialEvent and produces a scaled specialEvent with given factors
     """
     for e in specialEvent:
         self.scaleXY(e)
     parcel = PipelineParcel()
     parcel.enqueue(specialEvent)
     return parcel
コード例 #5
0
 def next(self, listMotionEvents):
     if self.baseTimestamp is None:
         self.baseTimestamp = listMotionEvents[0].timestamp
     for e in listMotionEvents:
         e.timestamp -= self.baseTimestamp
     parcel = PipelineParcel()
     parcel.enqueue(listMotionEvents)
     return parcel
コード例 #6
0
 def next(self, dummy):
     """ Takes nothing and produces lines from the file
     """
     parcel = PipelineParcel()
     line = self.fp.readline()
     if line != "":
         parcel.enqueue(line)
     return parcel
コード例 #7
0
 def next(self, specialEvent):
     """ Takes a specialEvent and produces a time-scaled specialEvent
     """
     for e in specialEvent:
         e.timestamp *= self.factor
     parcel = PipelineParcel()
     parcel.enqueue(specialEvent)
     return parcel
コード例 #8
0
 def next(self, listMotionEvent):
     """ Take a stream a motion events and produce adjusted motion events
     """
     parcel = PipelineParcel()
     for e in listMotionEvent:
         e.x = (e.x - self.xmin) * self.dev.displayWidth / (self.xmax - self.xmin)
         e.y = (e.y - self.ymin) * self.dev.displayHeight / (self.ymax - self.ymin)
     parcel.enqueue(listMotionEvent)
     return parcel
コード例 #9
0
class TroubleInjector(PipelineComponent):
    """Inject random events into the replay trace,
    the randomness of these events are controlled by a seed, thus reproducible
    """
    def __init__(self,
                 seed='WTF',
                 specialEvents=[
                     'wifi', 'cellular', 'toggleScreen', 'rotateScreen',
                     'pressBack', 'pressHome'
                 ],
                 number=25):
        """SpecialEvents is a list containing the names of all possible special events.
            current possible special events:
                wifi
                cellular
                toggleScreen
                rotateScreen
                pressBack
                pressHome
        """
        random.seed(seed)
        seq = specialEvents * (number / len(specialEvents) + 1)
        self.randomSeries = random.sample(seq, number)
        self.insertChoice = []
        while self.insertChoice.count(True) < number:
            self.insertChoice.extend(random.sample([True, False], 1))
        self.prevGesture = None
        self.idx = 0
        self.insertionIdx = 0
        self.parcel = PipelineParcel()

    def next(self, gestureEvent):
        """read in the trails and inject special events
        """
        if self.prevGesture:
            if self.idx < len(self.randomSeries):
                if self.insertChoice[self.insertionIdx]:
                    timestamp = (self.prevGesture.timestamp +
                                 gestureEvent.timestamp) / 2
                    injection = SpecialEvent(self.randomSeries[self.idx],
                                             timestamp)
                    self.parcel.enqueue(injection)
                    self.idx = self.idx + 1
                else:
                    pass
                self.insertionIdx = self.insertionIdx + 1
            else:
                pass
        else:
            pass
        self.parcel.enqueue(gestureEvent)
        self.prevGesture = gestureEvent
        return PipelineParcel()

    def handleEOF(self):
        return self.parcel
コード例 #10
0
ファイル: Replayer.py プロジェクト: tldev3000/MonkeyHelper
 def next(self, replayEvent):
     for r in self.replayers:
         if r.canAccept(replayEvent):
             pp = r.next(replayEvent)
             # sync all timestamps
             for rp in self.replayers:
                 rp.setTimestamp(r.getTimestamp())
             return pp
     pp = PipelineParcel()
     pp.enqueue(replayEvent)
     return pp
コード例 #11
0
class TroubleInjector(PipelineComponent):

    """Inject random events into the replay trace,
    the randomness of these events are controlled by a seed, thus reproducible
    """

    def __init__(self, seed='WTF', specialEvents=['wifi', 'cellular', 'toggleScreen', 'rotateScreen', 'pressBack', 'pressHome'], number=25):
        """SpecialEvents is a list containing the names of all possible special events.
            current possible special events:
                wifi
                cellular
                toggleScreen
                rotateScreen
                pressBack
                pressHome
        """
        random.seed(seed)
        seq = specialEvents * (number / len(specialEvents) + 1)
        self.randomSeries = random.sample(seq, number)
        self.insertChoice = []
        while self.insertChoice.count(True) < number:
            self.insertChoice.extend(random.sample([True, False], 1))
        self.prevGesture = None
        self.idx = 0
        self.insertionIdx = 0
        self.parcel = PipelineParcel()

    def next(self, gestureEvent):
        """read in the trails and inject special events
        """
        if self.prevGesture:
            if self.idx < len(self.randomSeries):
                if self.insertChoice[self.insertionIdx]:
                    timestamp = (
                        self.prevGesture.timestamp + gestureEvent.timestamp) / 2
                    injection = SpecialEvent(
                        self.randomSeries[self.idx], timestamp)
                    self.parcel.enqueue(injection)
                    self.idx = self.idx + 1
                else:
                    pass
                self.insertionIdx = self.insertionIdx + 1
            else:
                pass
        else:
            pass
        self.parcel.enqueue(gestureEvent)
        self.prevGesture = gestureEvent
        return PipelineParcel()

    def handleEOF(self):
        return self.parcel
コード例 #12
0
 def next(self, geteventCmd):
     """ Take a stream of getevent commands and produce motion events
     """
     parcel = PipelineParcel()
     if geteventCmd.evType == "EV_ABS":
         if self.currentSlot is None:
             self.currentSlot = MotionEvent()
         if geteventCmd.evCmd == "ABS_MT_POSITION_X" or geteventCmd.evCmd == "ABS_X":
             self.currentSlot.x = geteventCmd.evVal
         elif geteventCmd.evCmd == "ABS_MT_POSITION_Y" or geteventCmd.evCmd == "ABS_Y":
             self.currentSlot.y = geteventCmd.evVal
         elif geteventCmd.evCmd == "ABS_MT_TRACKING_ID":
             if geteventCmd.evVal == 0xFFFFFFFF:
                 self.currentSlot = None
             else:
                 self.currentSlot.tracking_id = geteventCmd.evVal
         elif geteventCmd.evCmd == "ABS_MT_PRESSURE":
             self.currentSlot.pressure = geteventCmd.evVal
         elif geteventCmd.evCmd == "ABS_MT_TOUCH_MAJOR":
             self.currentSlot.touch_major = geteventCmd.evVal
         elif geteventCmd.evCmd == "ABS_MISC":
             self.dontReport = True
         else:
             print("[WARN] Type A MT meets unknown evCmd" + str(geteventCmd))
     elif geteventCmd.evType == "EV_KEY":
         if geteventCmd.evCmd == "BTN_TOUCH":
             print("[WARN] TypeA MT ignores BTN_TOUCH")
         else:
             print("[WARN] TypeA MT meets unknown evCmd" + str(geteventCmd))
     elif geteventCmd.evType == "EV_SYN":
         if geteventCmd.evCmd == "SYN_REPORT":
             if self.currentSlot is not None:
                 self.currentSlot.timestamp = geteventCmd.timestamp
                 self.listMotions.append(self.currentSlot)
                 self.currentSlot = self.currentSlot.clone()
             if self.dontReport:
                 self.dontReport = False
             else:
                 parcel.enqueue(self.listMotions)
             self.listMotions = []
         elif geteventCmd.evCmd == "SYN_MT_REPORT":
             if self.currentSlot is not None:
                 self.currentSlot.timestamp = geteventCmd.timestamp
                 self.listMotions.append(self.currentSlot)
                 self.currentSlot = None
         else:
             print("[WARN] TypeA MT meets unknown evCmd" + str(geteventCmd))
     else:
         print("[WARN] TypeA MT skips unknown line:" + str(geteventCmd))
     return parcel
コード例 #13
0
 def next(self, listMotionEvents):
     """ Takes a list of motion events and produces finger trails
     """
     prev = self.tracker
     alive = {}
     for e in listMotionEvents:
         if e.tracking_id in prev:
             t = prev[e.tracking_id]
             t.append(e)
             del prev[e.tracking_id]
             alive[e.tracking_id] = t
         else:
             alive[e.tracking_id] = [e]
     self.tracker = alive
     parcel = PipelineParcel()
     for specialEvent in prev.values():
         parcel.enqueue(specialEvent)
     return parcel
コード例 #14
0
 def handleEOF(self):
     parcel = PipelineParcel()
     for e in self.tracker.values():
         parcel.enqueue(e)
     self.tracker = {}
     parcel.enqueue(Pipeline.EOF)
     return parcel
コード例 #15
0
 def next(self, geteventCmd):
     """ Takes a stream of getevent commands and produce motion events
     """
     parcel = PipelineParcel()
     if geteventCmd.evType == "EV_ABS":
         if geteventCmd.evCmd == "ABS_MT_SLOT":
             self.currentSlotIndex = geteventCmd.evVal
             if geteventCmd.evVal >= len(self.slots):
                 self.slots.extend([None] * (geteventCmd.evVal + 1 - len(self.slots)))
                 self.slots[geteventCmd.evVal] = MotionEvent()
             self.currentSlot = self.slots[self.currentSlotIndex]
         elif geteventCmd.evCmd == "ABS_MT_POSITION_X":
             self.currentSlot.x = geteventCmd.evVal
         elif geteventCmd.evCmd == "ABS_MT_POSITION_Y":
             self.currentSlot.y = geteventCmd.evVal
         elif geteventCmd.evCmd == "ABS_MT_TRACKING_ID":
             if geteventCmd.evVal == 0xFFFFFFFF:
                 # unbinding
                 self.slots[self.currentSlotIndex] = MotionEvent()
             else:
                 # binding tracking_id to slot
                 self.currentSlot.tracking_id = geteventCmd.evVal
         elif geteventCmd.evCmd == "ABS_MT_PRESSURE":
             self.currentSlot.pressure = geteventCmd.evVal
         elif geteventCmd.evCmd == "ABS_MT_TOUCH_MAJOR":
             self.currentSlot.touch_major = geteventCmd.evVal
         else:
             print("[WARN] Type B MT meets unknown evCmd" + str(geteventCmd))
     elif geteventCmd.evType == "EV_SYN":
         if geteventCmd.evCmd == "SYN_REPORT":
             for motionEvent in self.slots:
                 if motionEvent.tracking_id != 0xFFFFFFFF:
                     motionEvent.timestamp = geteventCmd.timestamp
                     parcel.enqueue(motionEvent)
         else:
             print("[WARN] Type B MT meets unknown evCmd" + str(geteventCmd))
     else:
         print("[WARN] Type B MT skips unknown line:" + str(geteventCmd))
     return parcel
コード例 #16
0
ファイル: Replayer.py プロジェクト: tldev3000/MonkeyHelper
 def handleEOF(self):
     # a bit trickier, harvest all objects by calling
     # all containing replayers
     mypp = PipelineParcel()
     for r in self.replayers:
         pp = r.handleEOF()
         while not pp.isEmpty():
             obj = pp.dequeue()
             if obj != Pipeline.EOF:
                 mypp.enqueue(obj)
     if mypp.isEmpty():
         mypp.enqueue(Pipeline.EOF)
     return mypp
コード例 #17
0
 def next(self, line):
     """ Takes a single line of the raw trace and produces a getevent command object
     a line is in the format of:
     time(float) evType(str) evCmd(str) evVal(int)
     refer to the Linux evdev doc for details
     here we assume the line is dumped from `getevent -lt <EVDEV>
     """
     m = self.pattern.match(line)
     e = GeteventCommand()
     if m is None:
         print("[ERROR] unidentified raw trace line:" + line)
         sys.exit()
     e.timestamp = float(m.group(1))
     e.evType = m.group(2)
     e.evCmd = m.group(3)
     if m.group(4) == "DOWN":
         e.evVal = 1  # TODO special cases for BTN_TOUCH
     elif m.group(4) == "UP":
         e.evVal = 0
     else:
         e.evVal = int(m.group(4), 16)
     parcel = PipelineParcel()
     parcel.enqueue(e)
     return parcel
コード例 #18
0
 def next(self, specialEvent):
     name = specialEvent.getName()
     lastTimeStamp = self.getTimestamp()
     if specialEvent.timestamp > lastTimeStamp:
         self.device.sleep(specialEvent.timestamp - lastTimeStamp)
     else:
         pass
     if name == 'wifi':
         print 'Injecting wifi event'
         self.wifiAgent.changeWifiStatus()
     elif name == 'cellular':
         self.cellularAgent.toggleCellularDataStatus()
         print 'Injecting cellular event'
     self.setTimestamp(specialEvent.timestamp)
     return PipelineParcel()
コード例 #19
0
 def next(self, specialEvent):
     if self.canAccept(specialEvent):
         name = specialEvent.getName()
         lastTimeStamp = self.getTimestamp()
         if specialEvent.timestamp > lastTimeStamp:
             print lastTimeStamp
             print specialEvent.timestamp
             self.device.sleep(specialEvent.timestamp - lastTimeStamp)
         else:
             pass
         self.unitReplay(name)
         self.setTimestamp(specialEvent.timestamp)
     elif isinstance(specialEvent, ReplayEvent):
         self.setTimestamp(specialEvent.timestamp)
         print self.getTimestamp()
     return PipelineParcel()
コード例 #20
0
    def __init__(self, seed='WTF', specialEvents=['wifi', 'cellular'], number=25):
        """SpecialEvents is a list containing the names of all possible special events.
            current possible special events:
                wifi
                cellular

        """
        random.seed(seed)
        seq=specialEvents * (number/len(specialEvents)+1)
        self.randomSeries = random.sample(seq, number)
        self.insertChoice=[]
        while self.insertChoice.count(True)<number:
            self.insertChoice.extend(random.sample([True,False],1))
        self.prevGesture = None
        self.idx = 0
        self.insertionIdx=0
        self.parcel = PipelineParcel()
コード例 #21
0
 def next(self, gestureReplayEvent):
     """ Takes a finger specialEvent and produces nothing
     """
     specialEvent = gestureReplayEvent.trail
     lastTimeStamp = self.getTimestamp()
     if len(specialEvent) <= 0:
         print("[WARN] perform an empty specialEvent")
     elif len(specialEvent) == 1:
         actions = [EMonkeyDevice.DOWN_AND_UP]
     else:
         actions = [EMonkeyDevice.DOWN] + [EMonkeyDevice.MOVE] * (
             len(specialEvent) - 2) + [EMonkeyDevice.UP]
     for count in range(len(specialEvent)):
         self.device.sleep(specialEvent[count].timestamp - lastTimeStamp)
         self.device.touch(specialEvent[count].x, specialEvent[count].y,
                           actions[count])
         lastTimeStamp = specialEvent[count].timestamp
     self.setTimestamp(lastTimeStamp)
     return PipelineParcel()
コード例 #22
0
 def next(self, gestureEvent):
     """read in the trails and inject special events
     """
     if self.prevGesture:
         if self.idx < len(self.randomSeries):
             if self.insertChoice[self.insertionIdx]:
                 timestamp = (self.prevGesture.timestamp +
                              gestureEvent.timestamp) / 2
                 injection = SpecialEvent(self.randomSeries[self.idx],
                                          timestamp)
                 self.parcel.enqueue(injection)
                 self.idx = self.idx + 1
             else:
                 pass
             self.insertionIdx = self.insertionIdx + 1
         else:
             pass
     else:
         pass
     self.parcel.enqueue(gestureEvent)
     self.prevGesture = gestureEvent
     return PipelineParcel()
コード例 #23
0
 def next(self, specialEvent):
     pointCount = len(specialEvent)
     duration = specialEvent[len(specialEvent) -
                             1].timestamp - specialEvent[0].timestamp
     xdelta = specialEvent[len(specialEvent) - 1].x - specialEvent[0].x
     ydelta = specialEvent[len(specialEvent) - 1].y - specialEvent[0].y
     waitTime = specialEvent[0].timestamp - self.lastTimestamp
     self.lastTimestamp = specialEvent[len(specialEvent) - 1].timestamp
     sample = (waitTime, xdelta, ydelta, duration, pointCount)
     self.samples.append(sample)
     print sample
     self.sample_count -= 1
     if self.sample_count == 0:
         print "learning finished, do statistics"
         self.reader.terminate()
         count = len(self.samples)
         total = (0, 0, 0, 0, 0)
         for (_1, _2, _3, _4, _5) in self.samples:
             total = (total[0] + _1, total[1] + _2, total[2] + _3,
                      total[3] + _4, total[4] + _5)
         self.stats = (total[0] / count, total[1] / count, total[2] / count,
                       total[3] / count, total[4] / count)
         print self.stats
     return PipelineParcel()
コード例 #24
0
 def next(self, dummy):
     parcel = PipelineParcel()
     if self.list:
         parcel.enqueue(self.list.pop())
     return parcel
コード例 #25
0
 def next(self, dummy):
     parcel = PipelineParcel()
     if self.list:
         parcel.enqueue(self.list.pop())
     return parcel
コード例 #26
0
 def next(self, specialEvent):
     pp = PipelineParcel()
     pp.enqueue(GestureReplayEvent(specialEvent))
     return pp
コード例 #27
0
 def next(self, specialEvent):
     pp = PipelineParcel()
     pp.enqueue(GestureReplayEvent(specialEvent))
     return pp
コード例 #28
0
ファイル: Replayer.py プロジェクト: tldev3000/MonkeyHelper
 def next(self, replayEvent):
     """ Process the replay event and return a parcel like other
     pipeline components
     """
     return PipelineParcel()
コード例 #29
0
 def next(self, whatever):
     """ Takes whatever object and print its string representation
     """
     print(str(whatever))
     return PipelineParcel()