Skip to main content

ADB Python wrapper library with enhanced functionality and image recognition

Project description

My ADB Lib

Thư viện Python wrapper cho Android Debug Bridge (ADB) với chức năng nhận diện hình ảnh sử dụng OpenCV.

Giới thiệu

My ADB Lib là một thư viện Python giúp tương tác với thiết bị Android thông qua ADB (Android Debug Bridge). Thư viện này được thiết kế để đơn giản hóa việc sử dụng các lệnh ADB trong các ứng dụng Python, tự động hóa kiểm thử, và quản lý thiết bị Android. Phiên bản mới nhất bổ sung chức năng nhận diện hình ảnh mạnh mẽ sử dụng OpenCV, cho phép tìm kiếm và tương tác với các phần tử trên màn hình dựa trên hình ảnh mẫu thay vì tọa độ cố định.

Yêu cầu

  • Python 3.6 trở lên
  • ADB đã được cài đặt và có trong PATH
  • OpenCV (tự động cài đặt khi cài đặt thư viện)
  • NumPy (tự động cài đặt khi cài đặt thư viện)

Cài đặt

pip install oiadb

Hoặc cài đặt từ mã nguồn:

git clone https://github.com/tiendung102k3/oiadb
cd oiadb
pip install -e .

Cách sử dụng

Khởi tạo

from oiadb import MyADB

# Khởi tạo với thiết bị mặc định
adb = MyADB()

# Hoặc chỉ định thiết bị cụ thể
adb = MyADB(device_id="emulator-5554")

Các thao tác cơ bản

# Liệt kê các thiết bị đã kết nối
devices = adb.get_devices()
print(devices)

# Cài đặt ứng dụng
adb.install_app("/path/to/app.apk")

# Gỡ cài đặt ứng dụng
adb.uninstall_app("com.example.app")

# Khởi động lại thiết bị
adb.reboot_device()

Tương tác với thiết bị

from oiadb.commands import interaction

# Nhấn vào tọa độ màn hình
interaction.tap(500, 500)

# Vuốt màn hình
interaction.swipe(100, 500, 600, 500)

# Nhập văn bản
interaction.text_input("Hello World")

# Nhấn phím Home
interaction.home()

Tương tác dựa trên nhận diện hình ảnh

from oiadb.commands import image_interaction

# Tìm và nhấp vào hình ảnh
image_interaction.tap_image("/path/to/button.png", threshold=0.8)

# Đợi hình ảnh xuất hiện và nhấp vào
image_interaction.wait_and_tap_image("/path/to/button.png", timeout=10)

# Kiểm tra xem hình ảnh có xuất hiện không
if image_interaction.is_image_present("/path/to/element.png"):
    print("Hình ảnh xuất hiện trên màn hình")

# Kéo từ hình ảnh này đến hình ảnh khác
image_interaction.drag_image_to_image("/path/to/source.png", "/path/to/target.png")

Quản lý file

from oiadb.commands import file_ops

# Đẩy file từ máy tính lên thiết bị
file_ops.push("/path/on/computer", "/path/on/device")

# Lấy file từ thiết bị về máy tính
file_ops.pull("/path/on/device", "/path/on/computer")

Xem log

from oiadb.commands import logs

# Xem logcat
logcat_output = logs.logcat()
print(logcat_output)

# Tạo báo cáo lỗi
bugreport = logs.bugreport()

Tài liệu API

Lớp MyADB

Lớp chính để tương tác với ADB.

  • __init__(device_id=None): Khởi tạo đối tượng ADB với ID thiết bị tùy chọn
  • run(command): Chạy lệnh ADB tùy chỉnh
  • get_devices(): Liệt kê các thiết bị đã kết nối
  • reboot_device(): Khởi động lại thiết bị
  • install_app(apk_path): Cài đặt ứng dụng từ file APK
  • uninstall_app(package_name): Gỡ cài đặt ứng dụng
  • push_file(local_path, remote_path): Đẩy file lên thiết bị
  • pull_file(remote_path, local_path): Lấy file từ thiết bị
  • get_device_info(): Lấy thông tin thiết bị

Module commands

Các module lệnh chuyên biệt:

  • app_info: Lấy thông tin ứng dụng
  • apps: Quản lý ứng dụng
  • basic: Các lệnh ADB cơ bản
  • connect: Kết nối thiết bị qua mạng
  • device_actions: Các hành động thiết bị
  • device_info: Thông tin thiết bị
  • file_ops: Thao tác file
  • interaction: Tương tác với thiết bị
  • image_interaction: Tương tác dựa trên nhận diện hình ảnh
  • logs: Xem log thiết bị
  • permissions: Quản lý quyền

Tài liệu bổ sung

Để biết thêm chi tiết về chức năng nhận diện hình ảnh, vui lòng xem file image_recognition_documentation.md.

Đóng góp

Đóng góp luôn được chào đón! Vui lòng tạo issue hoặc pull request trên GitHub.

Giấy phép

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oiadb-0.3.0.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oiadb-0.3.0-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file oiadb-0.3.0.tar.gz.

File metadata

  • Download URL: oiadb-0.3.0.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for oiadb-0.3.0.tar.gz
Algorithm Hash digest
SHA256 dd9abe30ad977c1a6efabc5ee0b506b066d0f88cc973092b55b022de18026e3c
MD5 457559f43f7e48367bf69db8b9b24357
BLAKE2b-256 0358875a6035779e30ff41c6397f6c1c581fd38e0f14ce13ce7d684090726d82

See more details on using hashes here.

File details

Details for the file oiadb-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: oiadb-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for oiadb-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ca309e0168b95ea99e56720e6e7bbb90c8db6f324884660fe21bedf4d1e4c5a
MD5 4a2347d5d30f39654ccc0a24f9c7ba65
BLAKE2b-256 75b0c0e18350d9040ac0f77d6e9b9b69792457b4d7b82ba2fd62e98d106469ac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page