# Lint as: python3 """Utils for blue tooth tests. Partly ported from acts/framework/acts/test_utils/bt/bt_test_utils.py """ from __future__ import absolute_import from __future__ import division from __future__ import print_function import logging as log import os import random import string import time import wave from queue import Empty from typing import Optional from blueberry.tests.gd_sl4a.lib.ble_lib import generate_ble_advertise_objects from blueberry.tests.gd_sl4a.lib.bt_constants import adv_succ from blueberry.tests.gd_sl4a.lib.bt_constants import ble_advertise_settings_modes from blueberry.tests.gd_sl4a.lib.bt_constants import ble_advertise_settings_tx_powers from blueberry.tests.gd_sl4a.lib.bt_constants import bt_default_timeout from mobly.controllers.android_device import AndroidDevice class BtTestUtilsError(Exception): pass def convert_pcm_to_wav(pcm_file_path, wave_file_path, audio_params): """Converts raw pcm data into wave file. Args: pcm_file_path: File path of origin pcm file. wave_file_path: File path of converted wave file. audio_params: A dict with audio configuration. """ with open(pcm_file_path, 'rb') as pcm_file: frames = pcm_file.read() write_record_file(wave_file_path, audio_params, frames) def create_vcf_from_vcard(output_path: str, num_of_contacts: int, first_name: Optional[str] = None, last_name: Optional[str] = None, phone_number: Optional[int] = None) -> str: """Creates a vcf file from vCard. Args: output_path: Path of the output vcf file. num_of_contacts: Number of contacts to be generated. first_name: First name of the contacts. last_name: Last name of the contacts. phone_number: Phone number of the contacts. Returns: vcf_file_path: Path of the output vcf file. E.g. "//contacts_