Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions examples/install_apks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from android_device_manager import AndroidDevice
from android_device_manager.avd import AVDConfiguration
from android_device_manager.emulator import EmulatorConfiguration

# Configure your AVD
avd_config = AVDConfiguration(
name="example_avd",
package="system-images;android-36;google_apis;x86_64"
)

# Configure your Emulator
emulator_config = EmulatorConfiguration(
no_window=False
)

with AndroidDevice(avd_config,emulator_config) as device:
# Install APK
device.install_multi_package([
"/home/jwoirhay/Bureau/temp/apk_download/apks/safetravelsmain.apk",
"/home/jwoirhay/Bureau/temp/apk_download/apks/sitiosarequipa.apk"
])

# List installed packages
packages = device.list_installed_packages()
print("Installed packages:")
for p in packages:
print(f"\t- {p}")
21 changes: 21 additions & 0 deletions src/android_device_manager/adb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,27 @@ def install_apk(self, apk_path: str, timeout: int = 60):
except ADBError as e:
raise ADBError(f"Failed to install APK {apk_path}: {str(e)}")

def install_multi_package(self, apk_paths: list[str], timeout: int = 120):
"""
Install multiple APKs in a single transaction using 'adb install-multi-package'.

Args:
apk_paths (list[str]): List of APK file paths on the host.
timeout (int): Timeout in seconds for the installation.

Raises:
ADBError: If the installation fails.
"""
if not apk_paths:
raise ADBError("No APKs provided for installation.")

try:
args = ["install-multi-package", *apk_paths]
self._run_adb_command(args, check=True, timeout=timeout)
logger.info(f"Successfully installed APKs {apk_paths} on {self._serial}")
except ADBError as e:
raise ADBError(f"Failed to install APKs {apk_paths}: {str(e)}")

def uninstall_package(
self, package_name: str, keep_data: bool = False, timeout: int = 60
) -> None:
Expand Down
15 changes: 15 additions & 0 deletions src/android_device_manager/android_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,21 @@ def install_apk(self, apk_path: str, timeout: int = 30) -> None:
self._ensure_running()
self._adb_client.install_apk(apk_path, timeout=timeout)

def install_multi_package(self, apk_paths: list[str], timeout: int = 60) -> None:
"""
Install multiple APKs on the device in a single transaction.

Args:
apk_paths (list[str]): A list of file paths to the APKs.
timeout (int): Timeout in seconds for the installation process (default: 60).

Raises:
AndroidDeviceError: If the device is not running or the ADB client is not initialized.
ADBError: If the command fails.
"""
self._ensure_running()
self._adb_client.install_multi_package(apk_paths, timeout=timeout)

def uninstall_package(self, package_name: str, keep_data: bool = False) -> None:
"""
Uninstall a package from the device.
Expand Down