Пример #1
0
    def get_meminfo(dev_id, ps="") -> list:
        """
        Method return dumpsys meminfo memory snapshot, by default will return system memory
        :dev_id: device id
        :ps: pid or process name
        """

        command = "adb -s {dev} shell dumpsys  meminfo {ps}".format(dev=dev_id, ps=ps)
        return ADB.get_terminal_output(command)
Пример #2
0
    def get_list_packages(dev_id: str) -> list:
        """
        Return a list of installed packages on the device
        """

        command = "adb -s {dev_id} shell pm list packages".format(
            dev_id=dev_id)
        raw_packages = ADB.get_terminal_output(command)
        return [x.strip() for x in raw_packages]
Пример #3
0
    def pull(dev_id: str, path_from: str, path_to: str):
        """
        Print ADB pull execution into terminal
        :dev_id: device id
        :path_from: Path to file on the device
        :path_to: Path to save a file
        """

        command = "adb -s {dev_id} pull {path_from} {path_to}".format(
            dev_id=dev_id, path_from=path_from, path_to=path_to)
        output = ADB.get_terminal_output(command)
        print("I: {}".format(output))
Пример #4
0
 def get_pid(dev_id: str, ps: str) -> str:
     """
     Method return pid of package of process
     :dev_id: device id
     :ps: process or package name
     
     TODO: Fix for processes with multiple PIDs
     """
     command = "adb -s {dev} shell ps | grep {ps} | cut -d ' ' -f 4".format(dev=dev_id, ps=ps)
     print(command)
     pid = ADB.get_terminal_output(command)
     return pid[0].strip() if len(pid) > 0 else ""
Пример #5
0
    def _dump_layout(dev_id: str) -> str:
        """
        Method call the uiautomator to dump screen layout and Return path to it
        :dev_id: device id
        """

        command = "adb -s {dev_id} shell uiautomator dump".format(
            dev_id=dev_id)
        raw_path = ADB.get_terminal_output(command)[0].strip()
        if "UI hierchary dumped to" in raw_path:
            return raw_path.split(":")[1].strip()
        else:
            print("E: {}".format(raw_path))
Пример #6
0
    def all_getprop(dev_id: str) -> dict:
        """
        Return getprop values in format dict{property:value}

        :dev_id: Device ID
        """

        command = "adb -s {dev} shell getprop".format(dev=dev_id)
        raw_getprop = ADB.get_terminal_output(command)
        dict_getprop = {}
        for line in raw_getprop:
            raw = line.strip().replace("[", "").replace("]", "").split(":")
            dict_getprop[raw[0].strip()] = raw[1].strip()
        return dict_getprop
Пример #7
0
    def push(dec_id: str, path_file: str, path_to: str):
        """
        Print ADB push execution into terminal
        :dev_id: device id
        :path_file: Path to file
        :path_to: Path to save file in the device
        
        TODO: Check File existance before push
        TODO: Test
        """

        command = "adb -s {dev} push {path_file} {path_to}".format(
            dev=dec_id, path_file=path_file, path_to=path_to)
        output = ADB.get_terminal_output(command)
        print("I: {}".format(output))
Пример #8
0
    def get_package_version(dev_id: str, package: str) -> list:
        """
        Return a package version

        :dev_id: device id
        :package: package name
        """

        command = "adb -s {dev_id} shell dumpsys package {package} | grep versionName".format(
            dev_id=dev_id, package=package)
        raw_out = ADB.get_terminal_output(command)
        versions = []
        for ver in raw_out:
            versions.append(ver.strip().split("=")[1])
        return versions
Пример #9
0
    def get_current_activity(dev_id: str) -> dict:
        """
        Method return dict{activity, package} from current screen
        """

        command = "adb -s {dev} shell dumpsys window windows | grep -E 'mCurrentFocus'".format(dev=dev_id)
        output = ADB.get_terminal_output(command)[0]
        if "/" in output:
            raw = output.strip().split("/")
            activity = raw[1][:len(raw[1]) - 1:]
            package = raw[0].split(" ").pop()
            return {"activity": activity, "package": package}
        elif "StatusBar" in output:
            return {"activity": "StatusBar", "package": "AndroidStatusBar"}
        else:
            print("W: {}".format(output))
Пример #10
0
    def get_display_size(dev_id) -> dict:
        """
        Return a display size in dict{'width': <str>, 'hight': <str>}

        :dev_id: Device ID
        """
        
        size = {}
        command = "adb -s {dev} shell wm size".format(dev=dev_id)
        out = ADB.get_terminal_output(command)
        if len(out) == 1 and "Physical size:" in out[0]:
            raw = out[0].split("x")
            print(raw)
            size["width"] = int(raw[0].split(":")[1].strip())
            size["height"] = int(raw[1].strip())
        else:
            print("W: {out}".format(out=out))
        return size
Пример #11
0
    def is_locked(dev_id) -> bool:
        """
        Return is device locked

        :dev_id: Device ID
        """

        command = "adb -s {dev} shell dumpsys window | grep 'mShowingLockscreen'".format(dev=dev_id)
        out = ADB.get_terminal_output(command)[0].split()
        for line in out:
            raw = line.strip().split("=")
            if "mDreamingLockscreen" in raw[0]:
                if raw[1] == "true":
                    return True
            if "mShowingLockscreen" in raw[0]:
                if raw[1] == "true":
                    return True
        return False
Пример #12
0
    def grant_permission(dev_id: str, package: str, *android_permissions):
        """
        Method to grant permissions for package
        TODO: Unit Test

        :dev_id: device id
        :package: package name
        :permission: permission
        """

        for permission in android_permissions:
            command = "adb -s {dev} shell pm grant {package} {permission}".format(
                dev=dev_id,
                package=package,
                permission=permission.value.get("perm"))
            out = ADB.get_terminal_output(command)
            if len(out) > 0:
                print(out)
            print(
                "I: Prmissions {perm} has been granted to Device ID {dev} for package {package}"
                .format(perm=permission.value.get("name"),
                        dev=dev_id,
                        package=package))