1#!/usr/bin/env python3 2# 3# Copyright 2019 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17from acts import asserts 18 19from acts.controllers import android_device 20from acts_contrib.test_utils.bt.bt_test_utils import bluetooth_enabled_check 21 22# TODO: This class to be deprecated for 23# ../acts/test_utils/abstract_devices/bluetooth_handsfree_abstract_device.py 24 25 26class SimulatedCarkitDevice(): 27 def __init__(self, serial): 28 self.ad = android_device.create(serial)[0] 29 if not bluetooth_enabled_check(self.ad): 30 asserts.fail("No able to turn on bluetooth") 31 self.mac_address = self.ad.droid.bluetoothGetLocalAddress() 32 self.ad.droid.bluetoothToggleState(False) 33 self.ad.droid.bluetoothMediaConnectToCarMBS() 34 35 def destroy(self): 36 self.ad.clean_up() 37 38 def accept_call(self): 39 return self.ad.droid.telecomAcceptRingingCall(None) 40 41 def end_call(self): 42 return self.ad.droid.telecomEndCall() 43 44 def enter_pairing_mode(self): 45 self.ad.droid.bluetoothStartPairingHelper(True) 46 return self.ad.droid.bluetoothMakeDiscoverable() 47 48 def next_track(self): 49 return self.ad.droid.bluetoothMediaPassthrough("skipNext") 50 51 def pause(self): 52 return self.ad.droid.bluetoothMediaPassthrough("pause") 53 54 def play(self): 55 return self.ad.droid.bluetoothMediaPassthrough("play") 56 57 def power_off(self): 58 return self.ad.droid.bluetoothToggleState(False) 59 60 def power_on(self): 61 return self.ad.droid.bluetoothToggleState(True) 62 63 def previous_track(self): 64 return self.ad.droid.bluetoothMediaPassthrough("skipPrev") 65 66 def reject_call(self): 67 return self.ad.droid.telecomCallDisconnect( 68 self.ad.droid.telecomCallGetCallIds()[0]) 69 70 def volume_down(self): 71 target_step = self.ad.droid.getMediaVolume() - 1 72 target_step = max(target_step, 0) 73 return self.ad.droid.setMediaVolume(target_step) 74 75 def volume_up(self): 76 target_step = self.ad.droid.getMediaVolume() + 1 77 max_step = self.ad.droid.getMaxMediaVolume() 78 target_step = min(target_step, max_step) 79 return self.ad.droid.setMediaVolume(target_step) 80