def get_airplane_mode_status(adb_path, device_id): command = [adb_path, '-s', device_id, 'shell', 'settings', 'get', 'global', 'airplane_mode_on'] result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, creationflags=subprocess.CREATE_NO_WINDOW) status = result.stdout.decode('utf-8').strip() return status # Function to open and collapse Quick Settings panel def airplane_window_open(device_id): expand_settings_command = ["adb", "-s", device_id, "shell", "cmd", "statusbar", "expand-settings"] subprocess.run(expand_settings_command, creationflags=subprocess.CREATE_NO_WINDOW) print("Quick Settings panel opened.") def airplane_window_closed(device_id): collapse_settings_command = ["adb", "-s", device_id, "shell", "cmd", "statusbar", "collapse"] subprocess.run(collapse_settings_command, creationflags=subprocess.CREATE_NO_WINDOW) print("Quick Settings panel closed.") def airplane_off_on(device_id): airplane_window_open(device_id) # Step 1: Dump & Find Airplane Mode to turn ON xml_path = dump_ui(device_id) target_text = ["Airplane mode"] matched_text, bounds = find_element_in_xml(xml_path, target_text, y_min=10, y_max=2000) if bounds: print(f"✅ [{device_id}] Found '{matched_text}' at {bounds} — Turning ON") tap_on_bounds(device_id, bounds) time.sleep(9) # Step 2: Dump again & Find Airplane Mode to turn OFF xml_path = dump_ui(device_id) matched_text, bounds = find_element_in_xml(xml_path, target_text, y_min=10, y_max=2000) if bounds: print(f"✅ [{device_id}] Found '{matched_text}' at {bounds} — Turning OFF") tap_on_bounds(device_id, bounds) else: print(f"❌ [{device_id}] Couldn't find Airplane mode after turning ON.") else: print(f"❌ [{device_id}] Airplane mode not found in notification bar.") airplane_window_closed(device_id)