Skip to content

Commit

Permalink
change exploration policy
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanchun-li committed Aug 10, 2016
1 parent 0a3097f commit 96b3b9c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
8 changes: 8 additions & 0 deletions droidbot/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ def get_start_intent(self):
package_name += "/%s" % self.get_main_activity()
return Intent(suffix=package_name)

def get_stop_intent(self):
"""
get an intent to stop the app
:return: Intent
"""
package_name = self.get_package_name()
return Intent(prefix="force-stop", suffix=package_name)

def get_possible_broadcasts(self):
possible_broadcasts = set()

Expand Down
22 changes: 17 additions & 5 deletions droidbot/app_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,7 @@ def gen_event_based_on_state(self, state):

EVENT_FLAG_STARTED = "+started"
EVENT_FLAG_START_APP = "+start_app"
EVENT_FLAG_STOP_APP = "+stop_app"
EVENT_FLAG_TOUCH = "+touch"


Expand Down Expand Up @@ -1422,6 +1423,14 @@ def gen_event_based_on_state(self, state):
# select a view to click
view_to_touch = self.select_a_view(state)

# if no view can be selected, restart the app
if view_to_touch is None:
stop_app_intent = self.app.get_stop_intent()
self.last_event_flag += EVENT_FLAG_STOP_APP
self.last_touched_view_str = None
self.last_state = state
return IntentEvent(stop_app_intent)

view_to_touch_str = view_to_touch['view_str']
if view_to_touch_str.startswith('BACK'):
result = KeyEvent('BACK')
Expand Down Expand Up @@ -1449,8 +1458,8 @@ def select_a_view(self, state):
random.shuffle(views)

# add a "BACK" view, consider go back first
mock_view_back = {'view_str': 'BACK_%s' % state.foreground_activity}
views.insert(0, mock_view_back)
# mock_view_back = {'view_str': 'BACK_%s' % state.foreground_activity}
# views.insert(0, mock_view_back)

# first try to find a un-clicked view
for view in views:
Expand All @@ -1467,9 +1476,12 @@ def select_a_view(self, state):
return view

# no window transition found, just return a random view
view = views[0]
self.device.logger.info("selected a random view: %s" % view['view_str'])
return view
# view = views[0]
# self.device.logger.info("selected a random view: %s" % view['view_str'])
# return view

# DroidBot stuck on current state, return None
return None

def save_state_transition(self, event_str, old_state, new_state):
"""
Expand Down

0 comments on commit 96b3b9c

Please sign in to comment.