コード例 #1
0
    def startActivityFromPackage(self, packageName, activityName):
        """
        Starts the specified activity from the specified package name on the device.
        This method has to be called when package name is different from main activity.
        """
        if self.state != AndroidDevice.STATE_STARTED:
            raise Exception(
                "Cannot start an activity since the device is not started.")

        if activityName is None or len(activityName) == 0:
            raise Exception("Activity name is null.")

        if packageName is None or len(packageName) == 0:
            raise Exception("Package name is null.")

        self._logger.info("Starting activity {0}/{1} on device {2}".format(
            packageName, activityName, self.name))

        # $ adb shell am start -n activityPackage/activity
        cmd = [
            self.mainConfiguration.adbPath, "-s", self.serialNumber, "shell",
            "am", "start", "-n", "{0}/{1}".format(packageName, activityName)
        ]
        p = OSCommand.executeAsyncCommand(cmd)
        stdout, stderr = p.communicate()
        self._logger.debug("{0}".format(stdout))
コード例 #2
0
    def _pullResults(self):
        """Pull results of analysis"""
        self._logger.info("Pulling results of analysis")
        cmd = [
            self.mainConfiguration.adbPath, "-s", self.serialNumber, "pull",
            "/sdcard/dnadroid/events.logs", "{0}{1}-events.logs".format(
                self.mainConfiguration.androidTemporaryPath,
                datetime.datetime.now().strftime("%Y-%m-%d-%H:%M"))
        ]
        p = OSCommand.executeAsyncCommand(cmd)
        stdout, stderr = p.communicate()
        self._logger.debug("{0}".format(stdout))

        self._logger.info("Event logs has been pulled in {0}".format(
            self.mainConfiguration.androidTemporaryPath))
コード例 #3
0
    def stimulateWithMonkey(self, packageName):
        """Stimulates application with monkey"""

        if packageName is None or len(packageName) == 0:
            raise Exception("Cannot stimulate package that has no name.")

        self._logger.info(
            "Stimulating package {0} with monkey.".format(packageName))
        cmd = [
            self.mainConfiguration.adbPath, "-s", self.serialNumber, "shell",
            "monkey", "-p", packageName, "-v", "500", "--throttle", "6000",
            "--ignore-timeouts"
        ]
        p = OSCommand.executeAsyncCommand(cmd)
        stdout, stderr = p.communicate()
        self._logger.debug("{0}".format(stdout))
コード例 #4
0
ファイル: AVDEmulator.py プロジェクト: amirhgharib/dnadroid
    def start(self):
        """Starts the emulator"""
        if self.state != AndroidDevice.STATE_PREPARED:
            raise Exception(
                "Cannot start the emulator. (expected state was {0}, current state is {1})"
                .format(AndroidDevice.STATE_PREPARED, self.state))

        # clean the temporary directory
        self.__cleanTemporaryDirectory()
        if self.__partitionSize is None:
            raise Exception("Partition size cannot be None")

        cmd = [
            self.mainConfiguration.emulatorPath, "@{0}".format(self.name),
            "-partition-size",
            str(self.__partitionSize), "-no-snapshot-save", "-netspeed",
            "full", "-netdelay", "none", "-port",
            str(self.adbPort)
        ]

        self.__emulatorProcess = OSCommand.executeAsyncCommand(cmd)
        time.sleep(2)
        if self.__emulatorProcess.poll() is not None:
            raise Exception(self.__emulatorProcess.communicate())

        self.state = AndroidDevice.STATE_STARTING

        # Waits for device to be ready
        self._waitForDeviceToBeReady()

        # Set the same time as host!
        self._logger.info("Setting emulator at the same time as host")
        localTime = datetime.datetime.now().strftime("%Y%m%d.%H%M%S")
        cmd = [
            self.mainConfiguration.adbPath, "-s", self.serialNumber, "shell",
            "date", "-s", localTime
        ]
        self._logger.debug(OSCommand.executeCommand(cmd))

        # Checks that APKInstrumenter is install
        self.checkAPKInstrumenter()