def get_screen_resolution(self): Saver.save_crawler_log(self.logPath, "Step : get screen resolution") command = 'adb -s ' + self.id + ' shell wm size' resolution = [] result = os.popen(command).readlines() x = '' y = '' for line in result: if 'Physical size: ' in line: r = re.findall(r'\d+', line) x = r[0] y = r[1] resolution.append(x) resolution.append(y) Saver.save_crawler_log(self.logPath, resolution) return resolution
def get_launcher_activity(self, plan): try: command = 'aapt dump badging ' + self.apkPath result = os.popen(command).readlines() activity_head = "launchable-activity: name='" end = "' " for line in result: if activity_head in line: activity_name = line[line.index(activity_head) + len(activity_head):line.index(end)] del plan, command, result, line, activity_head, end return activity_name del plan, command, result, activity_head, end return '' except Exception as e: Saver.save_crawler_log(plan.logPath, str(e)) del plan, e return ''
def get_app_name(self, plan): try: command = 'aapt dump badging ' + self.apkPath result = os.popen(command).readlines() for line in result: name_head = "application-label-zh-CN:'" if name_head in line: name = line[line.index(name_head) + len(name_head):len(line) - 2] del plan, name_head return name del line del plan, command, result return '' except Exception as e: Saver.save_crawler_log(plan.logPath, str(e)) del plan, e return ""
def save_screen_jump_out(self, package, activity): if Setting.SaveJumpOutScreen: try: Saver.save_crawler_log(self.logPath, "Step : jump out . save screenshot ") get_screenshot_command = 'adb -s ' + self.id + ' shell /system/bin/screencap -p /sdcard/screenshot.png' local_png = self.screenshotPath + '/' + str(self.saveScreenNum) + '-' + str(package) + '-' + str( activity) + '-Jump' + str(self.jump_out_time) + '.png' pull_screenshot_command = 'adb -s ' + self.id + ' pull /sdcard/screenshot.png ' + local_png os.system(get_screenshot_command) os.system(pull_screenshot_command) self.saveScreenNum += 1 self.jump_out_time += 1 del get_screenshot_command, local_png, pull_screenshot_command gc.collect() except Exception, e: print (str(e)) Saver.save_crawler_log(self, "save screen error")
def crawl_longclickable_nodes(plan, app, device, page_before_run, page_now, init): for node in nodeController.get_random_nodes( page_before_run.longClickableNodes): # if crash and not keep run , break from deep run .page_need_crawled will be None if page_now is None: Saver.save_crawler_log(device.logPath, 'Jump out to crawl') del node break # sometimes the need tap node is not shown after one deep run if not nodeController.recover_node_shown(plan, app, device, page_now, page_before_run, node): continue device.save_screen(node, True) appController.long_click_node(device, node) device.update_crawled_activity(node.currentActivity) device.update_crawled_nodes(node.nodeInfo) device.delete_uncrawled_nodes(node.nodeInfo) # if jump out the test app, try to go back & return the final page page_after_operation = pageController.check_page_after_operation( plan, app, device, page_before_run, node) if page_after_operation is None: Saver.save_crawler_log(device.logPath, 'Jump out to crawl') page_now = page_after_operation break # compare two pages before & after click . # update the after page . leave the new clickable/scrollable/longclickable/edittext nodes only. page_now = pageController.get_need_crawl_page(plan, app, device, page_before_run, page_after_operation) if pageController.page_is_crawlable(app, device, page_now): page_now.add_last_page(page_before_run) page_now.add_entry(node) # deep run if init: page_now = crawl_init_nodes(plan, app, device, page_now) else: page_now = crawl_main_nodes(plan, app, device, page_now) # if page no crawlable nodes , back to last Page, until has crawlable nodes, if back time >3, break page_now = pageController.recover_page_to_crawlable( plan, app, device, page_now) del node del plan, app, device, page_before_run, init return page_now
def get_package_name(plan, apk_path): try: command = 'aapt dump badging ' + apk_path result = os.popen(command).readlines() end = "' " package_head = "package: name='" for line in result: if package_head in line: package_name = line[line.index(package_head) + len(package_head):line.index(end)] del command, result, package_head, end, apk_path, line return package_name del line del command, result, apk_path, end, package_head return '' except Exception as e: Saver.save_crawler_log(plan.logPath, str(e)) del apk_path, e return ""
def start_activity(device, packagename, activity): Saver.save_crawler_log(device.logPath, 'Step : start up activity : ' + activity) time1 = datetime.datetime.now() result = False while not result: command = 'adb -s ' + device.id + ' shell am start -n ' + packagename + '/' + activity os.system(command) if (datetime.datetime.now() - time1).seconds < 10: top_activity_info = pageController.get_top_activity_info(device) top_packagename = top_activity_info['packagename'] top_activity = top_activity_info['activity'] if top_packagename == packagename and top_activity == activity: result = True del top_activity_info, top_packagename, top_activity else: result = True del command del device, packagename, activity, time1, result
def get_screen_resolution(self): Saver.save_crawler_log(self.logPath, "Step : get screen resolution") command = 'adb -s ' + self.id + ' shell dumpsys window' resolution = [] result = os.popen(command).readlines() x = '' y = '' for line in result: if 'init=' in line: r = re.findall(r'\d+', line) x = r[0] y = r[1] del r resolution.append(x) resolution.append(y) Saver.save_crawler_log(self.logPath, resolution) del command, result, x, y return resolution
def get_top_activity_info(device): Saver.save_crawler_log(device.logPath, "Step : get top activity info") # linux: # adb shell dumpsys activity | grep "mFocusedActivity" # windows: # adb shell dumpsys activity | findstr "mFocusedActivity" info = {} # command = 'adb -s ' + device.id + ' shell dumpsys activity | grep "mFocusedActivity"' # sometime mResumedActivity is Right try: command = 'adb -s ' + device.id + ' shell dumpsys activity | grep "mResumedActivity"' result = os.popen(command).read() packagename = '' activity = '' if 'u0' not in result and ' com.' not in result: result = os.popen(command).read() if 'u0 ' in result: packagename = result[result.find('u0 ') + len('u0 '):result.find('/')] elif ' com.' in result: packagename = result[result.find(' com.') + 1:result.find('/')] if ' t' in result: activity = result[result.find('/') + len('/'):result.find(' t')] elif '}' in result: activity = result[result.find('/') + len('/'):result.find('}')] except Exception, e: print(str(e)) command = 'adb -s ' + device.id + ' shell dumpsys activity | findstr "mResumedActivity"' result = os.popen(command).read() packagename = '' activity = '' if 'u0' not in result and ' com.' not in result: result = os.popen(command).read() if 'u0 ' in result: packagename = result[result.find('u0 ') + len('u0 '):result.find('/')] elif ' com.' in result: packagename = result[result.find(' com.') + 1:result.find('/')] if ' t' in result: activity = result[result.find('/') + len('/'):result.find(' t')] elif '}' in result: activity = result[result.find('/') + len('/'):result.find('}')]
def get_need_crawl_page(plan, app, device, page_before_run, page_after_run): Saver.save_crawler_log(device.logPath, "Step : get need crawl page now ...") if page_after_run.nodesNum == 0: page_after_run = get_page_info(plan, app, device) new_nodes_num = 0 if page_after_run is not None and page_after_run.nodesNum != 0: for node in page_after_run.nodesList: if node.nodeInfo in page_before_run.nodesInfoList: page_after_run.remove_clickable_node(node) page_after_run.remove_scrollable_node(node) page_after_run.remove_longclickable_node(node) page_after_run.remove_edit_text(node) # after type text in edit text, text & bounds will change , don't need to crawl the edit text again elif node.isEditText: info = [ node.index, node.resource_id, node.package, node.content_desc ] for n in page_before_run.editTexts: i = [n.index, n.resource_id, n.package, n.content_desc] if i == info: page_after_run.remove_edit_text(node) break del i, n # if all new shown crawable nodes are both crawled, click back to recover page shown elif not device.is_in_hascrawled_nodes( node.nodeInfo) and not device.is_in_uncrawled_nodes( node.nodeInfo): new_nodes_num += 1 del node if page_after_run.clickableNodesNum == page_after_run.longClickableNodesNum == page_after_run.editTextsNum == page_after_run.scrollableNodesNum == 0 \ and new_nodes_num > 0: Saver.save_crawler_log( device.logPath, "Step : no new unCrawled nodes , but has some unCrawlable nodes show , back ..." ) appController.click_back(device) page_after_run = get_page_info(plan, app, device) return get_need_crawl_page(plan, app, device, page_before_run, page_after_run) del plan, app, device, page_before_run return page_after_run
def get_all_activities(self, plan): try: activity_list = [] command = 'aapt dump xmlstrings ' + self.apkPath + ' AndroidManifest.xml' result = os.popen(command).readlines() for line in result: if 'Activity' in line: index = line.index(': ') activity = line[index + len(': '):len(line) - 1] if activity != self.launcherActivity and activity not in activity_list: activity_list.append(activity) del index, activity del line del plan, command, result return activity_list except Exception as e: Saver.save_crawler_log(plan.logPath, str(e)) del plan, e return []
def get_version_name(self, plan): try: command = 'aapt dump badging ' + self.apkPath result = os.popen(command).readlines() version_name_head = "versionName='" end = "' " for line in result: if version_name_head in line: line = line[line.index(version_name_head) + len(version_name_head):] version_name = line[:line.index(end)] del plan, command, result, line, version_name_head, end return version_name del line del plan, command, result, version_name_head, end return '' except Exception as e: Saver.save_crawler_log(plan.logPath, str(e)) del plan, e return ''
def get_device_list(self, app): device_list = [] string = ' ' outLine = os.popen('adb devices').readlines() for line in outLine: if string in line: device_id = line[0:line.index(string)] device = Device(self, device_id) device_list.append(device) if Setting.Login: index = device_list.index(device) accountList = Setting.AccountList[app.packageName] device.update_device_account(accountList[index]) del index, accountList del device_id, device del line Saver.save_crawler_log(self.logPath, device_list) self.deviceList = device_list self.deviceNum = str(len(device_list)) del device_list, string, outLine
def recover_page_to_crawlable(plan, app, device, page_now): t = 1 while page_now is not None and no_uncrawled_clickable_nodes_now(device, page_now) \ and no_uncrawled_longclickable_nodes_now(device, page_now) \ and no_uncrawled_edit_text_now(device, page_now): if page_now.backBtn is not None \ and nodeController.node_is_shown_in_page(device, page_now.backBtn, page_now): Saver.save_crawler_log(device.logPath, "Step : find the back btn and tap ") device.save_screen(page_now.backBtn, False) appController.tap_node(device, page_now.backBtn) t += 1 page_now = get_page_info(plan, app, device) else: Saver.save_crawler_log(device.logPath, "Step : no back btn , click back") device.save_screen_jump_out(page_now.package, page_now.currentActivity) appController.click_back(device) page_now = get_page_info(plan, app, device) t += 1 if t > 2: break return page_now
def get_top_activity_info(device): Saver.save_crawler_log(device.logPath, "Step : get top activity info") # linux: # adb shell dumpsys activity | grep "mFocusedActivity" # windows: # adb shell dumpsys activity | findstr "mFocusedActivity" info = {} packagename = '' activity = '' # command = 'adb -s ' + device.id + ' shell dumpsys activity | grep "mFocusedActivity"' # sometime mResumedActivity is Right if platform.system() != 'Windows': command = 'adb -s ' + device.id + ' shell dumpsys activity | grep "mResumedActivity"' else: command = 'adb -s ' + device.id + ' shell dumpsys activity | findstr "mResumedActivity"' result = os.popen(command).read() if 'u0' not in result and ' com.' not in result: result = os.popen(command).read() if 'u0 ' in result: packagename = result[result.find('u0 ') + len('u0 '):result.find('/')] elif ' com.' in result: packagename = result[result.find(' com.') + 1:result.find('/')] if ' t' in result: activity = result[result.find('/') + len('/'):result.find(' t')] elif '}' in result: activity = result[result.find('/') + len('/'):result.find('}')] info['packagename'] = packagename info['activity'] = activity Saver.save_crawler_log(device.logPath, 'Top activity is :' + activity) Saver.save_crawler_log(device.logPath, 'Top package is :' + packagename) del command, result, packagename, activity, device return info
def __init__(self, plan, device_id): Saver.save_crawler_log(plan.logPath, "Step : Init device : " + device_id) self.id = device_id Saver.save_crawler_log(plan.logPath, "id : " + self.id) self.statue = self.get_device_statue() Saver.save_crawler_log(plan.logPath, "statue : " + self.statue) self.logPath = self.create_device_folder(plan) self.name = self.get_device_name() self.model = self.get_device_model() self.version = self.get_device_sys_version() self.accountInfo = [] self.screenResolution = self.get_screen_resolution() self.screenshotPath = self.create_screenshot_folder() self.beginCrawlTime = datetime.datetime.now() self.endCrawlTime = datetime.datetime.now() self.unCrawledNodes = [] self.hasCrawledNodes = [] self.hasCrawledPage = [] self.hasCrawledActivities = [] self.saveScreenNum = 0 self.jump_out_time = 0 self.crawlStatue = "Uninit" self.failedTime = 0 self.page_now = PageInfo.Page()
def start_activity(device, packagename, activity): Saver.save_crawler_log(device.logPath, 'Step : start up activity : ' + activity) time1 = datetime.datetime.now() command = 'adb -s ' + device.id + ' shell am start -n ' + packagename + '/' + activity try: os.system(command) while True: start_activity_time = (datetime.datetime.now() - time1).seconds if start_activity_time < 10: top_activity_info = pageController.get_top_activity_info(device) top_packagename = top_activity_info['packagename'] top_activity = top_activity_info['activity'] if top_packagename == packagename and top_activity == activity: Saver.save_crawler_log(device.logPath, 'use time : ' + str(start_activity_time) + ' seconds') del top_activity_info, top_packagename, top_activity return True del top_activity_info, top_packagename, top_activity else: break del start_activity_time del device, packagename, activity, time1, command return False except Exception as e: Saver.save_crawler_log(device.logPath, str(e)) del device, packagename, activity, e, time1, command return False
def recover_node_shown(plan, app, device, page_now, page_before_run, node): t = 1 r = False while page_now is not None and page_now.nodesNum != 0 and node.nodeInfo not in page_now.nodesInfoList: if get_node_recover_way(device, page_now, page_before_run, node, []): r = True break Saver.save_crawler_log(device.logPath, "Step : no recover way , click back") device.save_screen_jump_out(page_now.package, page_now.currentActivity) appController.click_back(device) page_now = pageController.get_page_info(plan, app, device) t += 1 if t > 2: Saver.save_crawler_log(device.logPath, "can't find the node after back 3 times.") break if r: Saver.save_crawler_log(device.logPath, "Step : recover node shown") for n in node.recoverWay: device.save_screen(n, False) if n.crawlOperation == 'tap': appController.tap_node(device, n) elif n.crawlOperation == 'longclick': appController.long_click_node(device, n) elif n.crawlOperation == 'type': t = appController.get_random_text(8) appController.type_text(device, n, t) pageController.check_page_after_operation(plan, app, device, page_before_run, node) del n if t < 4: r = True del plan, app, device, page_now, page_before_run, node, t return r
def no_uncrawled_longclickable_nodes_now(device, page_now): if page_now is None: del device, page_now return True Saver.save_crawler_log( device.logPath, "Step : Check there are uncCrawled longClickable Nodes in the page now or not" ) result = True for node in page_now.longClickableNodes: if device.is_in_uncrawled_nodes(node.nodeInfo): result = False del node break del node if result: Saver.save_crawler_log( device.logPath, "no uncrawled longClickable nodes in this page now") del device, page_now, result return True else: Saver.save_crawler_log( device.logPath, "have some uncrawled longClickable nodes in this page now") del device, page_now, result return False
def login_by_account(plan, page, app, device): account_view = nodeController.get_node_by_id(page, app.loginViews[0]) password_view = nodeController.get_node_by_id(page, app.loginViews[1]) login_btn = nodeController.get_node_by_id(page, app.loginViews[2]) account = device.accountInfo[0] password = device.accountInfo[1] if account_view in page.editTexts and password_view in page.editTexts and login_btn in page.clickableNodes: Saver.save_crawler_log(device.logPath, "Login begin .") appController.type_text(device, account_view, account) if appController.keyboard_is_shown(device): appController.click_back(device) appController.type_text(device, password_view, password) if appController.keyboard_is_shown(device): appController.click_back(device) appController.tap_node(device, login_btn) time0 = time.time() while True: time1 = time.time() if time1 - time0 > 10: Saver.save_crawler_log(device.logPath, "Login failed , time out .") appController.click_back(device) break info = get_top_activity_info(device) if info['activity'] != app.loginActivity: Saver.save_crawler_log(device.logPath, "Login successful .") break else: appController.click_back(device) del page, account_view, password_view, login_btn, account, password return get_page_info(plan, app, device)
def save_screen(self, node, model): if Setting.SaveScreen: try: Saver.save_crawler_log(self.logPath, "Step : save screenshot ") get_screenshot_command = 'adb -s ' + self.id + ' shell /system/bin/screencap -p /sdcard/screenshot.png' activity = node.currentActivity resource_id = node.resource_id resource_id = resource_id[resource_id.find('/') + 1:] location = node.location if model: local_png = self.screenshotPath + '/' + str( self.saveScreenNum) + '-' + str(activity) + '-' + str( resource_id) + '-' + str(location[0]) + '-' + str( location[1]) + '.png' else: local_png = self.screenshotPath + '/' + str( self.saveScreenNum) + '-' + 'unCrawl' + '-' + str( activity) + '-' + str(resource_id) + '-' + str( location[0]) + '-' + str(location[1]) + '.png' pull_screenshot_command = 'adb -s ' + self.id + ' pull /sdcard/screenshot.png ' + local_png os.system(get_screenshot_command) os.system(pull_screenshot_command) self.saveScreenNum += 1 i = Image.open(local_png) for w in range(3): bounds = node.bounds for x in range(bounds[0] + w, bounds[2] - w): i.putpixel((x, bounds[1] + 1 + w), (255, 0, 0)) i.putpixel((x, bounds[3] - 1 - w), (255, 0, 0)) for y in range(bounds[1] + w, bounds[3] - w): i.putpixel((bounds[0] + 1 + w, y), (255, 0, 0)) i.putpixel((bounds[2] - 1 - w, y), (255, 0, 0)) i.save(local_png) del get_screenshot_command, activity, resource_id, location, pull_screenshot_command, local_png, i del node, model, bounds gc.collect() except Exception, e: print(str(e)) Saver.save_crawler_log(self.logPath, "save screen error")
def get_need_crawl_page(plan, app, device, page_before_run, page_after_run): Saver.save_crawler_log(device.logPath, "Step : get need crawl page now ...") if len(page_after_run.nodesList) == 0: page_after_run = get_page_info(plan, app, device) if page_after_run is not None and len(page_after_run.nodesList) != 0: for node in page_after_run.nodesList: if node in page_before_run.nodesList: page_after_run.remove_clickable_node(node) page_after_run.remove_scrollable_node(node) page_after_run.remove_longclickable_node(node) page_after_run.remove_edit_text(node) # after type text in edit text, text & bounds will change , don't need to crawl the edit text again if node.isEditText: info = [node.index, node.resource_id, node.package, node.content_desc] for n in page_after_run.editTexts: i = [n.index, n.resource_id, n.package, n.content_desc] if i == info: page_after_run.remove_edit_text(n) break del i, n del node del plan, app, device, page_before_run return page_after_run
def get_page_info(plan, app, device): if Setting.TimeModel == 'Limit': time_now = datetime.datetime.now() if (time_now - device.beginCrawlTime).seconds > (Setting.LimitTime * 60): Saver.save_crawler_log_both(plan.logPath, device.logPath, "Step : crawl time out , finish crawl.") del time_now return None Saver.save_crawler_log(device.logPath, "get all nodes in this page") page = PageInfo.Page() result = False time = 0 while not result: try: if time > 2: appController.click_back(device) get_uidump_xml_file(device) break get_uidump_xml_file(device) dom = xml.dom.minidom.parse(device.logPath + '/Uidump.xml') result = True except Exception, e: time += 1 print (str(e)) result = False
def get_device_statue(self): try: check_lock_command = "adb -s " + self.id + " shell dumpsys window policy | grep mShowingLockscreen" check_lock_statue = os.popen(check_lock_command).read() except Exception as e: Saver.save_crawler_log(self.logPath.logPath, str(e)) check_lock_command = "adb -s " + self.id + " shell dumpsys window policy | findstr mShowingLockscreen" check_lock_statue = os.popen(check_lock_command).read() del e try: check_keyguard_command = "adb -s " + self.id + " shell dumpsys window policy | grep isStatusBarKeyguard" check_keyguard_statue = os.popen(check_keyguard_command).read() except Exception as e: Saver.save_crawler_log(self.logPath, str(e)) check_keyguard_command = "adb -s " + self.id + " shell dumpsys window policy | findstr isStatusBarKeyguard" check_keyguard_statue = os.popen(check_keyguard_command).read() del e if check_lock_statue == "" and check_keyguard_statue == "": return "unConnect/powerOff" else: str1 = 'mShowingLockscreen=' str2 = 'mShowingDream=' str3 = 'isStatusBarKeyguard=' str4 = 'mNavigationBar=' index1 = check_lock_statue.find(str1) index2 = check_lock_statue.find(str2) index3 = check_keyguard_statue.find(str3) index4 = check_keyguard_statue.find(str4) check_lock_statue = check_lock_statue[index1 + len(str1):index2 - 1] check_keyguard_statue = check_keyguard_statue[index3 + len(str3):index4 - 4] if check_lock_statue != 'true' and check_keyguard_statue != 'true': del check_lock_command, check_keyguard_statue, check_lock_statue, check_keyguard_command, str1, str2, str3, str4, index1, index2, index3, index4 return "unlock" else: del check_lock_command, check_keyguard_statue, check_lock_statue, check_keyguard_command, str1, str2, str3, str4, index1, index2, index3, index4 return "screenlocked"
def uninstall_app(device, package_name): try: Saver.save_crawler_log(device.logPath, 'Step : uninstall app : ' + package_name) command = 'adb -s ' + device.id + " uninstall " + package_name os.system(command) del device, package_name, command except Exception as e: Saver.save_crawler_log(device.logPath, str(e)) del device, package_name, e Saver.save_crawler_log(device.logPath, 'uninstall app catch exception')
def install_app(device, apk_path): try: if os.path.exists(apk_path): Saver.save_crawler_log(device.logPath, 'Step : install app : ' + apk_path) command = 'adb -s ' + device.id + " install -r " + apk_path os.system(command) del device, apk_path, command except Exception as e: Saver.save_crawler_log(device.logPath, str(e)) del device, apk_path, e Saver.save_crawler_log(device.logPath, 'install app catch exception')
def get_page_info(plan, app, device): if Setting.TimeModel == 'Limit': time_now = datetime.datetime.now() if (time_now - device.beginCrawlTime).seconds > (Setting.LimitTime * 60): Saver.save_crawler_log_both( plan.logPath, device.logPath, "Step : crawl time out , finish crawl.") del plan, app, device, time_now return None Saver.save_crawler_log(device.logPath, "get all nodes in this page") page = PageInfo.Page() result = False t = 0 while not result: try: if t > 2: Saver.save_crawler_log( device.logPath, "get page error after 3 times , click back .") appController.click_back(device) time.sleep(1) get_uidump_xml_file(device) break get_uidump_xml_file(device) dom = xml.dom.minidom.parse(device.logPath + '/Uidump.xml') result = True except Exception as e: t += 1 print(str(e)) result = False try: root = dom.documentElement nodes = root.getElementsByTagName('node') Saver.save_crawler_log(device.logPath, len(nodes)) info = get_top_activity_info(device) for node in nodes: n = NodeInfo.Node(node) n.update_current_activity(info['activity']) if n.resource_id in app.firstClickViews: device.save_screen(n, False) appController.tap_node(device, n) page = get_page_info(plan, app, device) page.add_node(device, app, n) del node, n page = appController.close_sys_alert(plan, app, device, page) del result, dom, root, nodes, info, plan, app, device, t return page except Exception as e: print(str(e)) del plan, app, device, t return page
def page_is_crawlable(app, device, page): Saver.save_crawler_log(device.logPath, "Step : check page is crawlable or not") if page.nodesInfoList not in device.hasCrawledPage \ and page.package == app.packageName \ and not page.clickableNodesNum == page.scrollableNodesNum == page.longClickableNodesNum == page.editTextsNum == 0: Saver.save_crawler_log(device.logPath, "page is crawlable") del app, device, page return True else: Saver.save_crawler_log(device.logPath, "page is not crawlable") del app, device, page return False
def keyboard_is_shown(device): Saver.save_crawler_log(device.logPath, "Step : check keyboard") command = 'adb -s ' + device.id + ' shell dumpsys input_method' result = os.popen(command).read() key = 'mInputShown=' keyboard_status = result[result.index(key) + len(key):result.index(key) + len(key) + 5] if 'true' in keyboard_status: Saver.save_crawler_log(device.logPath, "keyboard is shown ") del device, command, result, key, keyboard_status return True else: Saver.save_crawler_log(device.logPath, "keyboard is not shown") del device, command, result, key, keyboard_status return False
def app_is_running(device, app): Saver.save_crawler_log(device.logPath, "Step : check app is running or not") command = "adb -s " + device.id + " shell top -n 1" output = os.popen(command) lines = output.readlines() for line in lines: if app.packageName in line: Saver.save_crawler_log(device.logPath, "app is running") del command, output, lines, device, app, line return True del line Saver.save_crawler_log(device.logPath, "app is not running") del command, output, lines, device, app return False