Beispiel #1
0
    def __init__(self, app_path, device_serial=None, output_dir=None,
                 env_policy=None, event_policy=None, with_droidbox=False,
                 event_count=None, event_interval=None, event_duration=None, quiet=False):
        """
        initiate droidbot with configurations
        :return:
        """
        logging.basicConfig(level=logging.WARNING if quiet else logging.INFO)

        self.logger = logging.getLogger('DroidBot')
        DroidBot.instance = self

        self.output_dir = output_dir
        if self.output_dir is None:
            self.output_dir = os.path.abspath("droidbot_out")
        if not os.path.exists(self.output_dir):
            os.mkdir(self.output_dir)

        if device_serial is None:
            # Dirty Workaround: Set device_serial to Default='.*', because com/dtmilano/android/viewclient.py
            #  set serial to an arbitrary argument. IN connectToDeviceOrExit(..) line 2539f.
            device_serial = '.*'

        self.device = Device(device_serial, output_dir=self.output_dir)
        self.app = App(app_path, output_dir=self.output_dir)

        self.droidbox = None
        if with_droidbox:
            self.droidbox = DroidBox(output_dir=self.output_dir)

        self.env_manager = AppEnvManager(self.device, self.app, env_policy)
        self.event_manager = AppEventManager(self.device, self.app, event_policy,
                                             event_count, event_interval,
                                             event_duration)
Beispiel #2
0
    def __init__(self,
                 app_path,
                 device_serial=None,
                 output_dir=None,
                 env_policy=None,
                 event_policy=None,
                 with_droidbox=False,
                 event_count=None,
                 event_interval=None,
                 event_duration=None,
                 quiet=False):
        """
        initiate droidbot with configurations
        :return:
        """
        logging.basicConfig(level=logging.WARNING if quiet else logging.INFO)

        self.logger = logging.getLogger('DroidBot')
        DroidBot.instance = self

        self.output_dir = output_dir
        if self.output_dir is None:
            self.output_dir = os.path.abspath("droidbot_out")
        if not os.path.exists(self.output_dir):
            os.mkdir(self.output_dir)

        if device_serial is None:
            # Dirty Workaround: Set device_serial to Default='.*', because com/dtmilano/android/viewclient.py
            #  set serial to an arbitrary argument. IN connectToDeviceOrExit(..) line 2539f.
            device_serial = '.*'

        self.device = Device(device_serial, output_dir=self.output_dir)
        self.app = App(app_path, output_dir=self.output_dir)

        self.droidbox = None
        if with_droidbox:
            self.droidbox = DroidBox(output_dir=self.output_dir)

        self.env_manager = AppEnvManager(self.device, self.app, env_policy)
        self.event_manager = AppEventManager(self.device, self.app,
                                             event_policy, event_count,
                                             event_interval, event_duration)
Beispiel #3
0
class DroidBot(object):
    """
    The main class of droidbot
    A robot which interact with Android automatically
    """
    # this is a single instance class
    instance = None

    def __init__(self,
                 app_path,
                 device_serial=None,
                 output_dir=None,
                 env_policy=None,
                 event_policy=None,
                 with_droidbox=False,
                 event_count=None,
                 event_interval=None,
                 event_duration=None,
                 quiet=False):
        """
        initiate droidbot with configurations
        :return:
        """
        logging.basicConfig(level=logging.WARNING if quiet else logging.INFO)

        self.logger = logging.getLogger('DroidBot')
        DroidBot.instance = self

        self.output_dir = output_dir
        if self.output_dir is None:
            self.output_dir = os.path.abspath("droidbot_out")
        if not os.path.exists(self.output_dir):
            os.mkdir(self.output_dir)

        if device_serial is None:
            # Dirty Workaround: Set device_serial to Default='.*', because com/dtmilano/android/viewclient.py
            #  set serial to an arbitrary argument. IN connectToDeviceOrExit(..) line 2539f.
            device_serial = '.*'

        self.device = Device(device_serial, output_dir=self.output_dir)
        self.app = App(app_path, output_dir=self.output_dir)

        self.droidbox = None
        if with_droidbox:
            self.droidbox = DroidBox(output_dir=self.output_dir)

        self.env_manager = AppEnvManager(self.device, self.app, env_policy)
        self.event_manager = AppEventManager(self.device, self.app,
                                             event_policy, event_count,
                                             event_interval, event_duration)

    @staticmethod
    def get_instance():
        if DroidBot.instance is None:
            print "Error: DroidBot is not initiated!"
            sys.exit(-1)
        return DroidBot.instance

    def start(self):
        """
        start interacting
        :return:
        """
        self.logger.info("Starting DroidBot")
        try:
            self.device.install_app(self.app)
            self.env_manager.deploy()

            if self.droidbox is not None:
                self.droidbox.set_apk(self.app.app_path)
                self.droidbox.start_unblocked()
                self.event_manager.start()
                self.droidbox.stop()
                self.droidbox.get_output()
            else:
                self.event_manager.start()
        except KeyboardInterrupt:
            pass

        self.stop()
        self.logger.info("DroidBot Stopped")

    def stop(self):
        self.env_manager.stop()
        self.event_manager.stop()
        if self.droidbox is not None:
            self.droidbox.stop()
        self.device.uninstall_app(self.app)
        self.device.disconnect()
Beispiel #4
0
class DroidBot(object):
    """
    The main class of droidbot
    A robot which interact with Android automatically
    """
    # this is a single instance class
    instance = None

    def __init__(self, device_serial=None, package_name=None, app_path=None, output_dir=None,
                 env_policy=None, event_policy=None, with_droidbox=False,
                 event_count=None, event_interval=None, event_duration=None, quiet=False):
        """
        initiate droidbot with configurations
        :param options: the options which contain configurations of droidbot
        :return:
        """
        logging.basicConfig(level=logging.WARNING if quiet else logging.INFO)

        self.logger = logging.getLogger('DroidBot')
        DroidBot.instance = self

        self.enabled = True

        self.output_dir = output_dir
        if output_dir is None:
            self.output_dir = "droidbot_out"
        if not os.path.exists(self.output_dir):
            os.mkdir(self.output_dir)

        if device_serial is None:
            # Dirty Workaround: Set device_serial to Default='.*', because com/dtmilano/android/viewclient.py
            #  set serial to an arbitrary argument. IN connectToDeviceOrExit(..) line 2539f.
            device_serial = '.*'

        self.device = Device(device_serial)
        self.app = App(package_name, app_path)

        self.droidbox = None
        if with_droidbox:
            self.droidbox = DroidBox(output_dir=self.output_dir)

        self.env_manager = AppEnvManager(self.device, self.app, env_policy)
        self.event_manager = AppEventManager(self.device, self.app, event_policy,
                                             event_count, event_interval,
                                             event_duration)

    @staticmethod
    def get_instance():
        if DroidBot.instance is None:
            print "Error: DroidBot is not initiated!"
            sys.exit(-1)
        return DroidBot.instance

    def start(self):
        """
        start interacting
        :return:
        """
        try:
            if not self.enabled:
                return
            self.env_manager.deploy()

            if self.droidbox is not None:
                self.droidbox.set_apk(self.app.app_path)
                self.droidbox.start_unblocked()
                if not self.enabled:
                    return
                self.event_manager.start()
                self.droidbox.stop()
                self.droidbox.get_output()
            else:
                if not self.enabled:
                    return
                self.event_manager.start()
        except KeyboardInterrupt:
            pass
        self.device.disconnect()

    def stop(self):
        self.enabled = False
        self.event_manager.stop()
        if self.droidbox is not None:
            self.droidbox.stop()