Skip to content

Commit

Permalink
Updated replay policy to create a utg after replay
Browse files Browse the repository at this point in the history
  • Loading branch information
codeslord authored Mar 31, 2021
1 parent 2c7a66b commit c46e49a
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions droidbot/input_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,14 @@ def __init__(self, device, app, replay_output):
next(os.walk(event_dir))[2]
if x.endswith(".json")])
# skip HOME and start app intent
self.device = device
self.app = app
self.event_idx = 2
self.num_replay_tries = 0
self.utg = UTG(device=device, app=app, random_input=None)
self.last_event = None
self.last_state = None
self.current_state = None

def generate_event(self):
"""
Expand All @@ -570,6 +576,7 @@ def generate_event(self):
return KeyEvent(name="BACK")

curr_event_idx = self.event_idx
self.__update_utg()
while curr_event_idx < len(self.event_paths):
event_path = self.event_paths[curr_event_idx]
with open(event_path, "r") as f:
Expand All @@ -583,15 +590,27 @@ def generate_event(self):

if event_dict["start_state"] != current_state.state_str:
continue

if not self.device.is_foreground(self.app):
# if current app is in background, bring it to foreground
component = self.app.get_package_name()
if self.app.get_main_activity():
component += "/%s" % self.app.get_main_activity()
return IntentEvent(Intent(suffix=component))

self.logger.info("Replaying %s" % event_path)
self.event_idx = curr_event_idx
self.num_replay_tries = 0
return InputEvent.from_dict(event_dict["event"])
# return InputEvent.from_dict(event_dict["event"])
event = InputEvent.from_dict(event_dict["event"])
self.last_state = self.current_state
self.last_event = event
return event

time.sleep(5)

raise InputInterruptedException("No more record can be replayed.")
# raise InputInterruptedException("No more record can be replayed.")
def __update_utg(self):
self.utg.add_transition(self.last_event, self.last_state, self.current_state)


class ManualPolicy(UtgBasedInputPolicy):
Expand Down

0 comments on commit c46e49a

Please sign in to comment.