class SpringBoardServiceTestCase(unittest.TestCase): def setUp(self): self.spring_board_service = SpringBoardService() self.device_service = DeviceService() def _create_device(self): udid = self._get_udid() device = self.device_service.new_device(udid) print("device", device) self.assertIsNotNone(device) return device def _get_udid(self): device_service = DeviceService() device_list = device_service.get_device_list() self.assertIsNotNone(device_list) self.assertTrue(len(device_list) > 0) return device_list[0]['udid'] def test_get_icon_pngdata(self): device = self._create_device() client = self.spring_board_service.new_client(device) self.assertIsNotNone(client) pngdata = self.spring_board_service.get_icon_pngdata(client, "com.apple.Preferences") self.assertIsNotNone(pngdata) print("pngdata:", pngdata) self.spring_board_service.free_client(client) tmpfile = NamedTemporaryFile(suffix=".png", delete=False) tmpfile.write(pngdata) tmpfile.close() print("png file %s" % tmpfile.name)
class SyslogRelayServiceTestCase(unittest.TestCase): def setUp(self): self.syslog_relay_service = SyslogRelayService() self.device_service = DeviceService() def _create_device(self): udid = self._get_udid() device = self.device_service.new_device(udid) print("device", device) self.assertIsNotNone(device) return device def _get_udid(self): device_service = DeviceService() device_list = device_service.get_device_list() self.assertIsNotNone(device_list) self.assertTrue(len(device_list) > 0) return device_list[0]['udid'] def test_start_capture(self): device = self._create_device() client = self.syslog_relay_service.new_client(device) self.assertIsNotNone(client) def callback(char_data, user_data): print(char_data, end="") result = self.syslog_relay_service.start_capture(client, callback) self.assertTrue(result)
class ImageMounterServiceTestCase(unittest.TestCase): def setUp(self): self.image_mounter_service = ImageMounterService() self.device_service = DeviceService() def _create_device(self): udid = self._get_udid() device = self.device_service.new_device(udid) print("device", device) self.assertIsNotNone(device) return device def _get_udid(self): device_service = DeviceService() device_list = device_service.get_device_list() self.assertIsNotNone(device_list) self.assertTrue(len(device_list) > 0) return device_list[0]['udid'] def test_lookup_image(self): device = self._create_device() client = self.image_mounter_service.new_client(device) self.assertIsNotNone(client) product_version = "13.2" image_type = "Developer" image_mounted, error = self.image_mounter_service.lookup_image( client, image_type, product_version) print(error) self.assertIsNone(error) self.assertTrue(image_mounted) self.image_mounter_service.hangup(client) self.image_mounter_service.free_client(client) def test_upload_and_mount_image(self): device = self._create_device() client = self.image_mounter_service.new_client(device) self.assertIsNotNone(client) image_type = "Developer" image_file = r"F:\lds\DeviceSupport\DeviceSupport\13.3\DeveloperDiskImage.dmg" image_signature_file = r"F:\lds\DeviceSupport\DeviceSupport\13.3\DeveloperDiskImage.dmg.signature" result = self.image_mounter_service.upload_image( client, image_type, image_file, image_signature_file) print("result", result) self.assertTrue(result) image_type = "Developer" image_path = "/private/var/mobile/Media/PublicStaging/staging.dimage" image_signature_file = r"F:\lds\DeviceSupport\DeviceSupport\13.3\DeveloperDiskImage.dmg.signature" result, error = self.image_mounter_service.mount_image( client, image_type, image_path, image_signature_file) print("result", result, error) self.assertIsNone(error) self.assertTrue(result)
class InstallationProxyServiceTestCase(unittest.TestCase): def setUp(self): self.installation_proxy_service = InstallationProxyService() self.device_service = DeviceService() def _create_device(self): udid = self._get_udid() device = self.device_service.new_device(udid) print("device", device) self.assertIsNotNone(device) return device def _get_udid(self): device_service = DeviceService() device_list = device_service.get_device_list() self.assertIsNotNone(device_list) self.assertTrue(len(device_list) > 0) return device_list[0]['udid'] def test_browse(self): device = self._create_device() client = self.installation_proxy_service.new_client(device) self.assertIsNotNone(client) apps = self.installation_proxy_service.browse(client, "User") self.assertIsNotNone(apps) self.assertTrue(len(apps) > 0) print("List of applications:") for app in apps: for key, value in app.items(): print("%s: %s" % (key, value)) print("") self.installation_proxy_service.free_client(client) def test1_install(self): device = self._create_device() client = self.installation_proxy_service.new_client(device) self.assertIsNotNone(client) print("start install") apps = self.installation_proxy_service.install( device, client, "/Users/jimmy/Downloads/tmp.ipa") print("finsih install") self.installation_proxy_service.free_client(client) def test_uninstall(self): device = self._create_device() client = self.installation_proxy_service.new_client(device) self.assertIsNotNone(client) print("start uninstall") apps = self.installation_proxy_service.uninstall( device, client, "com.seasun.jxpocket.tako") print("finsih uninstall") self.installation_proxy_service.free_client(client)
class House_arrest_proxy_serviceTestCase(unittest.TestCase): def setUp(self): self.house_arrest_proxy_service = House_arrest_proxy_service() self.device_service = DeviceService() def _create_device(self): udid = self._get_udid() device = self.device_service.new_device(udid) print("device", device) self.assertIsNotNone(device) return device def _get_udid(self): device_service = DeviceService() device_list = device_service.get_device_list() self.assertIsNotNone(device_list) self.assertTrue(len(device_list) > 0) return device_list[0]['udid'] def test_open_sand_box(self): device = self._create_device() client = self.house_arrest_proxy_service.new_client(device) #com.jimmy.test2 afcClient = self.house_arrest_proxy_service.open_sandbox_with_appid(client, 1, "com.seasun.tmgp.jx3m") self.afc_service = AfcService() tmp = self.afc_service.new_client(device) dir_list = self.afc_service.read_directory(afcClient, "/Documents") self.assertIsNotNone(device) self.assertIsNotNone(afcClient) self.assertIsNotNone(dir_list) self.assertIsNotNone(client) for file in dir_list: print(file['filename']) self.afc_service.free_client(afcClient) self.device_service.free_device(device) self.house_arrest_proxy_service.free_client(client)
class DeviceServiceTestCase(unittest.TestCase): def setUp(self): self.device_service = DeviceService() def _get_udid(self): device_service = DeviceService() device_list = device_service.get_device_list() self.assertIsNotNone(device_list) self.assertTrue(len(device_list) > 0) return device_list[0]['udid'] def test_get_device_info(self): device_list = self.device_service.get_device_list() print("device_list", device_list) self.assertIsNotNone(device_list, msg="Device List is None") self.assertTrue(len(device_list) > 0, msg="Device List is Empty") def test_subscribe(self): def on_device_changed(event): print("on_device_changed", event) self.device_service.subscribe(on_device_changed) retry = 0 while retry < 20: print("wait for device event...", retry) time.sleep(1) retry += 1 self.device_service.subscribe() def test_new_device(self): udid = self._get_udid() device = self.device_service.new_device(udid) print("device", device) self.assertIsNotNone(device) success = self.device_service.free_device(device) self.assertTrue(success) print("free device")
class ScreenshotrServiceTestCase(unittest.TestCase): def setUp(self): self.screenshotr_service = ScreenshotrService() self.device_service = DeviceService() def _create_device(self): udid = self._get_udid() device = self.device_service.new_device(udid) print("device", device) self.assertIsNotNone(device) return device def _get_udid(self): device_service = DeviceService() device_list = device_service.get_device_list() self.assertIsNotNone(device_list) self.assertTrue(len(device_list) > 0) return device_list[0]['udid'] def test_take_screenshot(self): device = self._create_device() client = self.screenshotr_service.new_client(device) self.assertIsNotNone(client) imgdata, file_ext = self.screenshotr_service.take_screenshot(client) self.assertIsNotNone(imgdata) print("imgdata:", imgdata) self.screenshotr_service.free_client(client) if file_ext == ".data": print("WARNING: screenshot data has unexpected image format.") tmpfile = NamedTemporaryFile(suffix=file_ext, delete=False) tmpfile.write(imgdata) tmpfile.close() print("png file %s" % tmpfile.name)
class DeviceManager(object): def __init__(self): self._device_service = DeviceService() self._device_service.subscribe(self._on_device_changed) self._device_map = {} self._listeners = [] self._refresh_device_map() def __del__(self): pass def _refresh_device_map(self): devices = self._device_service.get_device_list() for device in devices: udid = device['udid'] if udid not in self._device_map: device_info, error = self.get_device_info(udid) device_name = "unknown" product_type = "unknown" if device_info: device_name = device_info['device_name'] product_type = device_info['product_type'] device = Device(udid, device_name, product_type, device_info, connected=True) self._device_map[udid] = device def _on_device_changed(self, event): print("on_device_changed", event) self._refresh_device_map() device = self._device_map[event['udid']] if event['type'] == IDeviceEventType.IDEVICE_DEVICE_ADD: device.connected = True for l in self._listeners: l.on_device_connect(device) elif event['type'] == IDeviceEventType.IDEVICE_DEVICE_REMOVE: device.connected = False for l in self._listeners: l.on_device_disconnect(device) def register_device_change_listener(self, listener): self._listeners.append(listener) def unregister_device_change_listener(self, listener): self._listeners.remove(listener) def get_device_info(self, udid): device = self._device_service.new_device(udid) if not device: return None, "No device connected with udid(%s)" % udid lockdown_service = LockdownService() lockdown_client = lockdown_service.new_client(device) values, error = lockdown_service.get_value(lockdown_client, key=None) if error: return None, error device_name = values['DeviceName'] product_version = values['ProductVersion'] build_version = values['BuildVersion'] product_type = values['ProductType'] unique_device_id = values['UniqueDeviceID'] os = "%s(%s)" % (product_version, build_version) device_info = self._get_device_info_from_configs(product_type) device_type = device_info['deviceType'] cpu_type = device_info['cpuInfo']['hwType'] cpu_arch = device_info['cpuInfo']['processor'] cpu_core_num = device_info['cpuInfo']['coreNum'] min_cpu_freq = int(int(device_info['cpuInfo']['minCpuFreq']) / 1000) max_cpu_freq = int(int(device_info['cpuInfo']['maxCpuFreq']) / 1000) cpu_freq = "[%s, %s]" % (str(min_cpu_freq), str(max_cpu_freq)) gpu_type = device_info['gpuInfo'] battery_info = device_info['batteryInfo'] # TODO: lockdown_service.free_client(lockdown_client) self._device_service.free_device(device) return { "os_type": "iOS", "device_name": device_name, "device_type": device_type, "product_type": product_type, "os": os, "cpu_type": cpu_type, "cpu_arch": cpu_arch, "cpu_core_num": cpu_core_num, "cpu_freq": cpu_freq, "gpu_type": gpu_type, }, None def _get_device_info_from_configs(self, product_type): with open(os.path.join(ROOT_DIR, "ios_deviceinfo_new.json")) as fp: # TODO: device_info_map = json.load(fp) if product_type in device_info_map: return device_info_map[product_type] return None def get_connected_devices(self): return list(self._device_map.values())
class AfcServiceTestCase(unittest.TestCase): def setUp(self): self.afc_service = AfcService() self.device_service = DeviceService() def _create_device(self): udid = self._get_udid() device = self.device_service.new_device(udid) print("device", device) self.assertIsNotNone(device) return device def _get_udid(self): device_service = DeviceService() device_list = device_service.get_device_list() self.assertIsNotNone(device_list) self.assertTrue(len(device_list) > 0) return device_list[0]['udid'] def test_read_directory(self): device = self._create_device() client = self.afc_service.new_client(device) self.assertIsNotNone(client) dir_list = self.afc_service.read_directory(client, ".") self.assertIsNotNone(dir_list) for file in dir_list: print(file['filename'], file['st_ifmt'], file['st_size']) if file['st_ifmt'] == "S_IFDIR": sub_dir_list = self.afc_service.read_directory( client, file['filepath']) for subfile in sub_dir_list: print("\t", subfile['filename'], subfile['st_ifmt'], subfile['st_size']) self.afc_service.free_client(client) self.device_service.free_device(device) def test_read_file(self): device = self._create_device() client = self.afc_service.new_client(device) self.assertIsNotNone(client) filename = "./Downloads/downloads.28.sqlitedb" afc_file = self.afc_service.open_file(client, filename, "r") while True: buffer = afc_file.read(1024) if not buffer: print("EOF") break print(buffer) afc_file.close() self.afc_service.free_client(client) self.device_service.free_device(device) def test_make_directory(self): device = self._create_device() client = self.afc_service.new_client(device) self.assertIsNotNone(client) dirname = "./Downloads/Test/Test1/Test2/Test3" success = self.afc_service.make_directory(client, dirname) self.assertTrue(success) self.afc_service.free_client(client) self.device_service.free_device(device) def test_remove_path(self): device = self._create_device() client = self.afc_service.new_client(device) self.assertIsNotNone(client) dirname = "./Downloads/Test/Test1/Test2/Test3" success = self.afc_service.remove_path(client, dirname) self.assertTrue(success) self.afc_service.free_client(client) self.device_service.free_device(device) def test_write_file(self): device = self._create_device() client = self.afc_service.new_client(device) self.assertIsNotNone(client) filename = "./Downloads/test.txt" afc_file = self.afc_service.open_file(client, filename, "w") afc_file.write(b"test") afc_file.close() self.afc_service.free_client(client) self.device_service.free_device(device)
class LockdownServiceTestCase(unittest.TestCase): def setUp(self): self.device_service = DeviceService() self.lockdown_service = LockdownService() def _create_device(self): udid = self._get_udid() device = self.device_service.new_device(udid) print("device", device) self.assertIsNotNone(device) return device def _get_udid(self): device_service = DeviceService() device_list = device_service.get_device_list() self.assertIsNotNone(device_list) self.assertTrue(len(device_list) > 0) return device_list[0]['udid'] def test_new_client(self): device = self._create_device() client = self.lockdown_service.new_client(device) print("client", client) self.assertIsNotNone(client) self.lockdown_service.free_client(client) self.device_service.free_device(device) def test_get_value(self): device = self._create_device() client = self.lockdown_service.new_client(device, handshake=False) print("client", client) self.assertIsNotNone(client) #values = self.lockdown_service.get_value(client, "ProductVersion") values, error = self.lockdown_service.get_value(client, None) print("values", type(values), values) # self.assertTrue("DeviceName" in values) # self.assertTrue("UniqueDeviceID" in values) # self.assertTrue("ProductVersion" in values) self.lockdown_service.free_client(client) self.device_service.free_device(device) def test_get_domain_value(self): device = self._create_device() client = self.lockdown_service.new_client(device) print("client", client) self.assertIsNotNone(client) #values = self.lockdown_service.get_value(client, "ProductVersion") values = self.lockdown_service.get_domain_Value( client, "com.apple.iTunes", None) print("values", type(values), values) self.lockdown_service.free_client(client) self.device_service.free_device(device) def test_set_domain_value(self): device = self._create_device() client = self.lockdown_service.new_client(device) print("client", client) self.assertIsNotNone(client) #values = self.lockdown_service.get_value(client, "ProductVersion") values = self.lockdown_service.get_domain_Value(client, None, None) self.lockdown_service.set_domain_Value( client, None, "DeviceName", plist_new_string("DeviceName".encode("utf-8"))) values = self.lockdown_service.get_domain_Value(client, None, None) print("after values", type(values), values) self.lockdown_service.free_client(client) self.device_service.free_device(device)