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
def handleEOF(self): parcel = PipelineParcel() for e in self.tracker.values(): parcel.enqueue(e) self.tracker = {} parcel.enqueue(Pipeline.EOF) return parcel
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
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
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
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
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
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
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
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
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
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
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
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
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
def next(self, dummy): parcel = PipelineParcel() if self.list: parcel.enqueue(self.list.pop()) return parcel
def next(self, specialEvent): pp = PipelineParcel() pp.enqueue(GestureReplayEvent(specialEvent)) return pp