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)
Пример #2
0
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")
Пример #3
0
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())
Пример #4
0
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)
Пример #5
0
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)