Change generic Bt Enums to IntEnums

Modify the BtEnum.py enums such that
integer based enums are treated as ints.
This removes the need to add ".value"
when using an int enum.

Bug: b/30372898
Change-Id: I1b51a98bfb04a75b246a73bf3b912c2e7d30017f
(cherry picked from commit 97a7b657d4825231cd6fc39463b8f6f3341e7467)
diff --git a/acts/framework/acts/test_utils/bt/BtEnum.py b/acts/framework/acts/test_utils/bt/BtEnum.py
index 0f69037..5d9e022 100644
--- a/acts/framework/acts/test_utils/bt/BtEnum.py
+++ b/acts/framework/acts/test_utils/bt/BtEnum.py
@@ -15,16 +15,17 @@
 # the License.
 
 from enum import Enum
+from enum import IntEnum
 
 
-class BluetoothScanModeType(Enum):
+class BluetoothScanModeType(IntEnum):
     STATE_OFF = -1
     SCAN_MODE_NONE = 0
     SCAN_MODE_CONNECTABLE = 1
     SCAN_MODE_CONNECTABLE_DISCOVERABLE = 3
 
 
-class BluetoothAdapterState(Enum):
+class BluetoothAdapterState(IntEnum):
     STATE_OFF = 10
     STATE_TURNING_ON = 11
     STATE_ON = 12
@@ -35,3 +36,19 @@
 
 class RfcommUuid(Enum):
     DEFAULT_UUID = "457807c0-4897-11df-9879-0800200c9a66"
+
+class BluetoothProfile(IntEnum):
+    # Should be kept in sync with BluetoothProfile.java
+    # Add more profile types as necessary.
+    A2DP_SINK = 11
+    AVRCP_CONTROLLER = 12
+    HEADSET_CLIENT = 16
+    PBAP_CLIENT = 17
+
+class BluetoothProfileState(IntEnum):
+    # Should be kept in sync with BluetoothProfile#STATE_* constants.
+    STATE_DISCONNECTED = 0
+    STATE_CONNECTING = 1
+    STATE_CONNECTED = 2
+    STATE_DISCONNECTING = 3
+
diff --git a/acts/framework/acts/test_utils/bt/bt_test_utils.py b/acts/framework/acts/test_utils/bt/bt_test_utils.py
index 5cbb0d0..8400500 100644
--- a/acts/framework/acts/test_utils/bt/bt_test_utils.py
+++ b/acts/framework/acts/test_utils/bt/bt_test_utils.py
@@ -419,25 +419,25 @@
 
 def set_bt_scan_mode(ad, scan_mode_value):
     droid, ed = ad.droid, ad.ed
-    if scan_mode_value == BluetoothScanModeType.STATE_OFF.value:
+    if scan_mode_value == BluetoothScanModeType.STATE_OFF:
         disable_bluetooth(droid, ed)
         scan_mode = droid.bluetoothGetScanMode()
         reset_bluetooth([ad])
         if scan_mode != scan_mode_value:
             return False
-    elif scan_mode_value == BluetoothScanModeType.SCAN_MODE_NONE.value:
+    elif scan_mode_value == BluetoothScanModeType.SCAN_MODE_NONE:
         droid.bluetoothMakeUndiscoverable()
         scan_mode = droid.bluetoothGetScanMode()
         if scan_mode != scan_mode_value:
             return False
-    elif scan_mode_value == BluetoothScanModeType.SCAN_MODE_CONNECTABLE.value:
+    elif scan_mode_value == BluetoothScanModeType.SCAN_MODE_CONNECTABLE:
         droid.bluetoothMakeUndiscoverable()
         droid.bluetoothMakeConnectable()
         scan_mode = droid.bluetoothGetScanMode()
         if scan_mode != scan_mode_value:
             return False
     elif (scan_mode_value ==
-          BluetoothScanModeType.SCAN_MODE_CONNECTABLE_DISCOVERABLE.value):
+          BluetoothScanModeType.SCAN_MODE_CONNECTABLE_DISCOVERABLE):
         droid.bluetoothMakeDiscoverable()
         scan_mode = droid.bluetoothGetScanMode()
         if scan_mode != scan_mode_value:
@@ -564,7 +564,7 @@
         state = profile_event['data']['state']
         device_addr = profile_event['data']['addr']
 
-        if state == BluetoothProfileState.STATE_CONNECTED.value and \
+        if state == BluetoothProfileState.STATE_CONNECTED and \
             device_addr == sec_droid.bluetoothGetLocalAddress():
             profile_connected.add(profile)
         log.info("Profiles connected until now {}".format(profile_connected))
diff --git a/acts/tests/google/ble/scan/BleBackgroundScanTest.py b/acts/tests/google/ble/scan/BleBackgroundScanTest.py
index 0f9cf76..d8b9b00 100644
--- a/acts/tests/google/ble/scan/BleBackgroundScanTest.py
+++ b/acts/tests/google/ble/scan/BleBackgroundScanTest.py
@@ -47,7 +47,7 @@
     def setup_test(self):
         self.log.debug(log_energy_info(self.android_devices, "Start"))
         if (self.scn_ad.droid.bluetoothGetLeState() ==
-                BluetoothAdapterState.STATE_OFF.value):
+                BluetoothAdapterState.STATE_OFF):
             self.scn_ad.droid.bluetoothEnableBLE()
             self.scn_ad.ed.pop_event("BleStateChangedOn")
         for a in self.android_devices:
diff --git a/acts/tests/google/bt/BtBasicFunctionalityTest.py b/acts/tests/google/bt/BtBasicFunctionalityTest.py
index ef405ea..0cb419a 100644
--- a/acts/tests/google/bt/BtBasicFunctionalityTest.py
+++ b/acts/tests/google/bt/BtBasicFunctionalityTest.py
@@ -107,7 +107,7 @@
         self.droid_ad.droid.bluetoothMakeDiscoverable()
         scan_mode = self.droid_ad.droid.bluetoothGetScanMode()
         if (scan_mode ==
-                BluetoothScanModeType.SCAN_MODE_CONNECTABLE_DISCOVERABLE.value):
+                BluetoothScanModeType.SCAN_MODE_CONNECTABLE_DISCOVERABLE):
             self.log.debug("Android device1 scan mode is "
                            "SCAN_MODE_CONNECTABLE_DISCOVERABLE")
         else:
@@ -170,9 +170,9 @@
         """
         self.droid_ad.droid.bluetoothMakeUndiscoverable()
         set_bt_scan_mode(self.droid1_ad,
-                         BluetoothScanModeType.SCAN_MODE_NONE.value)
+                         BluetoothScanModeType.SCAN_MODE_NONE)
         scan_mode = self.droid1_ad.droid.bluetoothGetScanMode()
-        if scan_mode == BluetoothScanModeType.SCAN_MODE_NONE.value:
+        if scan_mode == BluetoothScanModeType.SCAN_MODE_NONE:
             self.log.debug("Android device1 scan mode is SCAN_MODE_NONE")
         else:
             self.log.debug("Android device1 scan mode is not SCAN_MODE_NONE")
@@ -252,7 +252,7 @@
         """
         self.log.debug("Test scan mode STATE_OFF.")
         return set_bt_scan_mode(self.droid_ad,
-                                BluetoothScanModeType.STATE_OFF.value)
+                                BluetoothScanModeType.STATE_OFF)
 
     @BluetoothBaseTest.bt_test_wrap
     def test_scan_mode_none(self):
@@ -277,7 +277,7 @@
         """
         self.log.debug("Test scan mode SCAN_MODE_NONE.")
         return set_bt_scan_mode(self.droid_ad,
-                                BluetoothScanModeType.SCAN_MODE_NONE.value)
+                                BluetoothScanModeType.SCAN_MODE_NONE)
 
     @BluetoothBaseTest.bt_test_wrap
     def test_scan_mode_connectable(self):
@@ -302,7 +302,7 @@
         """
         self.log.debug("Test scan mode SCAN_MODE_CONNECTABLE.")
         return set_bt_scan_mode(
-            self.droid_ad, BluetoothScanModeType.SCAN_MODE_CONNECTABLE.value)
+            self.droid_ad, BluetoothScanModeType.SCAN_MODE_CONNECTABLE)
 
     @BluetoothBaseTest.bt_test_wrap
     def test_scan_mode_connectable_discoverable(self):
@@ -328,7 +328,7 @@
         self.log.debug("Test scan mode SCAN_MODE_CONNECTABLE_DISCOVERABLE.")
         return set_bt_scan_mode(
             self.droid_ad,
-            BluetoothScanModeType.SCAN_MODE_CONNECTABLE_DISCOVERABLE.value)
+            BluetoothScanModeType.SCAN_MODE_CONNECTABLE_DISCOVERABLE)
 
     @BluetoothBaseTest.bt_test_wrap
     def test_if_support_hid_profile(self):
diff --git a/acts/tests/google/bt/car_bt/BtCarHfpTest.py b/acts/tests/google/bt/car_bt/BtCarHfpTest.py
new file mode 100644
index 0000000..285a0ab
--- /dev/null
+++ b/acts/tests/google/bt/car_bt/BtCarHfpTest.py
@@ -0,0 +1,304 @@
+#/usr/bin/env python3.4
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may not
+# use this file except in compliance with the License. You may obtain a copy of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations under
+# the License.
+
+"""
+Test the HFP profile for basic calling functionality.
+"""
+
+import time
+
+from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
+from acts.test_utils.bt import BtEnum
+from acts.test_utils.bt import bt_test_utils
+from acts.test_utils.car import car_telecom_utils
+from acts.test_utils.tel import tel_defines
+
+BLUETOOTH_PKG_NAME = "com.android.bluetooth"
+CALL_TYPE_OUTGOING = "CALL_TYPE_OUTGOING"
+CALL_TYPE_INCOMING = "CALL_TYPE_INCOMING"
+default_timeout = 20
+
+class BtCarHfpTest(BluetoothBaseTest):
+    def setup_class(self):
+        self.hf = self.android_devices[0]
+        self.ag = self.android_devices[1]
+        self.re = self.android_devices[2]
+        self.ag_phone_number = "tel:{}".format(
+            self.ag.droid.telephonyGetLine1Number())
+        self.re_phone_number = "tel:{}".format(
+            self.re.droid.telephonyGetLine1Number())
+        self.log.info("ag tel: {} re tel: {}".format(
+            self.ag_phone_number, self.re_phone_number))
+
+        # Setup includes pairing and connecting the devices.
+        bt_test_utils.setup_multiple_devices_for_bt_test([self.hf, self.ag])
+        bt_test_utils.reset_bluetooth([self.hf, self.ag])
+
+        # Pair and connect the devices.
+        if not bt_test_utils.pair_pri_to_sec(self.hf.droid, self.ag.droid):
+            self.log.error("Failed to pair")
+            return False
+
+        # Connect the devices now, try twice.
+        attempts = 2
+        connected = False
+        while attempts > 0 and not connected:
+            connected = bt_test_utils.connect_pri_to_sec(
+                self.log, self.hf, self.ag.droid,
+                set([BtEnum.BluetoothProfile.HEADSET_CLIENT]))
+            self.log.info("Connected {}".format(connected))
+            attempts -= 1
+        return connected
+
+    def setup_test(self):
+        # Reset the devices.
+        self.log.debug(
+            bt_test_utils.log_energy_info(self.android_devices, "Start"))
+        for d in self.android_devices:
+            d.ed.clear_all_events()
+
+    def on_fail(self, test_name, begin_time):
+        self.log.debug("Test {} failed.".format(test_name))
+
+    def teardown_test(self):
+        self.log.debug(
+            bt_test_utils.log_energy_info(self.android_devices, "End"))
+
+    @BluetoothBaseTest.bt_test_wrap
+    def test_default_calling_account(self):
+        """
+        Tests if the default calling account is coming from the
+        bluetooth pacakge.
+
+        Precondition:
+        1. Devices are connected.
+
+        Steps:
+        1. Check if the default calling account is via Bluetooth package.
+
+        Returns:
+          Pass if True
+          Fail if False
+
+        Priority: 0
+        """
+        selected_acc = \
+            self.hf.droid.telecomGetUserSelectedOutgoingPhoneAccount()
+        if not selected_acc:
+            self.log.info("No default account found.")
+            return False
+
+        # Check if the default account is from the Bluetooth package. This is a
+        # light weight check.
+        try:
+            acc_component_id = selected_acc['ComponentName']
+        except KeyError:
+            self.log.info(
+                "No component name for account {}".format(selected_acc))
+            return False
+        if not acc_component_id.startswith(BLUETOOTH_PKG_NAME):
+            self.log.info(
+                "Component name does not start with pkg name {}".format(
+                    selected_acc))
+            return False
+
+    @BluetoothBaseTest.bt_test_wrap
+    def test_outgoing_call_hf(self):
+        """
+        Tests if we can make a phone call from HF role and disconnect from HF
+        role.
+
+        Precondition:
+        1. Devices are connected.
+
+        Steps:
+        1. Make a call from HF role.
+        2. Wait for the HF, AG to be dialing and RE to see the call ringing.
+        3. Hangup the call on HF role.
+        4. Wait for all devices to hangup the call.
+
+        Returns:
+          Pass if True
+          Fail if False
+
+        Priority: 0
+        """
+        return self.dial_a_hangup_b(self.hf, self.hf)
+
+
+    @BluetoothBaseTest.bt_test_wrap
+    def test_outgoing_call_ag(self):
+        """
+        Tests if we can make a phone call from AG role and disconnect from AG
+        role.
+
+        Precondition:
+        1. Devices are connected.
+
+        Steps:
+        1. Make a call from AG role.
+        2. Wait for the HF, AG to be in dialing and RE to see the call ringing.
+        3. Hangup the call on AG role.
+        4. Wait for all devices to hangup the call.
+
+        Returns:
+          Pass if True
+          Fail if False
+
+        Priority: 0
+        """
+        return self.dial_a_hangup_b(self.ag, self.ag)
+
+    @BluetoothBaseTest.bt_test_wrap
+    def test_outgoing_dial_ag_hangup_hf(self):
+        """
+        Tests if we can make a phone call from AG role and disconnect from HF
+        role.
+
+        Precondition:
+        1. Devices are connected.
+
+        Steps:
+        1. Make a call from AG role.
+        2. Wait for the HF, AG to show dialing and RE to see the call ringing.
+        3. Hangup the call on HF role.
+        4. Wait for all devices to hangup the call.
+
+        Returns:
+          Pass if True
+          Fail if False
+
+        Priority: 0
+        """
+        return self.dial_a_hangup_b(self.ag, self.hf)
+
+    @BluetoothBaseTest.bt_test_wrap
+    def test_outgoing_dial_hf_hangup_ag(self):
+        """
+        Tests if we can make a phone call from HF role and disconnect from AG
+        role.
+
+        Precondition:
+        1. Devices are connected.
+
+        Steps:
+        1. Make a call from HF role.
+        2. Wait for the HF, AG to show dialing and RE to see the call ringing.
+        3. Hangup the call on AG role.
+        4. Wait for all devices to hangup the call.
+
+        Returns:
+          Pass if True
+          Fail if False
+
+        Priority: 0
+        """
+        return self.dial_a_hangup_b(self.hf, self.ag)
+
+    @BluetoothBaseTest.bt_test_wrap
+    def test_incoming_dial_re_hangup_re(self):
+        """
+        Tests if we can make a phone call from remote and disconnect from
+        remote.
+
+        Precondition:
+        1. Devices are connected.
+
+        Steps:
+        1. Make a call from RE role.
+        2. Wait for the HF, AG to show ringing and RE to see the call dialing.
+        3. Hangup the call on RE role.
+        4. Wait for all devices to hangup the call.
+
+        Returns:
+          Pass if True
+          Fail if False
+
+        Priority: 0
+        """
+        return self.dial_a_hangup_b(self.re, self.re, self.ag_phone_number)
+
+    def dial_a_hangup_b(self, a, b, ph=""):
+        """
+        a, b and c can be either of AG, HF or Remote.
+        1. Make a call from 'a' on a fixed number.
+        2. Wait for the call to get connected (check on both 'a' and 'b')
+           Check that 'c' is in ringing state.
+        3. Hangup the call on 'b'.
+        4. Wait for call to get completely disconnected
+        (check on both 'a' and 'b')
+        It is assumed that scenarios will not go into voice mail.
+        """
+        if ph == "": ph = self.re_phone_number
+
+        # Determine if this is outgoing or incoming call.
+        call_type = None
+        if a == self.ag or a == self.hf:
+            call_type = CALL_TYPE_OUTGOING
+            if b != self.ag and b != self.hf:
+                self.log.info("outgoing call should terminate at AG or HF")
+                return False
+        elif a == self.re:
+            call_type = CALL_TYPE_INCOMING
+            if b != self.re:
+                self.log.info("Incoming call should terminate at Re")
+                return False
+
+        self.log.info("Call type is {}".format(call_type))
+
+        # make a call on 'a'
+        if not car_telecom_utils.dial_number(self.log, a, ph):
+            return False
+
+        # Check that everyone is in dialing/ringing state.
+        ret = True
+        if call_type == CALL_TYPE_OUTGOING:
+            ret &= car_telecom_utils.wait_for_dialing(self.log, self.hf)
+            ret &= car_telecom_utils.wait_for_dialing(self.log, self.ag)
+            ret &= car_telecom_utils.wait_for_ringing(self.log, self.re)
+        else:
+            ret &= car_telecom_utils.wait_for_ringing(self.log, self.hf)
+            ret &= car_telecom_utils.wait_for_ringing(self.log, self.ag)
+            ret &= car_telecom_utils.wait_for_dialing(self.log, self.re)
+        if not ret:
+            return False
+
+        # Check if we have any calls with dialing or active state on 'b'.
+        # We assume we never disconnect from 'ringing' state since it will lead
+        # to voicemail.
+        call_state_dialing_or_active = \
+            [tel_defines.CALL_STATE_CONNECTING,
+             tel_defines.CALL_STATE_DIALING,
+             tel_defines.CALL_STATE_ACTIVE]
+
+        calls_in_dialing_or_active = car_telecom_utils.get_calls_in_states(
+            self.log, b, call_state_dialing_or_active)
+
+        # Make sure there is only one!
+        if len(calls_in_dialing_or_active) != 1:
+            self.log.info("Call State in dialing or active failed {}".format(
+                calls_in_dialing_or_active))
+            return False
+
+        # Hangup the *only* call on 'b'
+        if not car_telecom_utils.hangup_call(
+            self.log, b, calls_in_dialing_or_active[0]):
+            return False
+
+        # Make sure everyone got out of in call state.
+        for d in self.android_devices:
+            ret &= car_telecom_utils.wait_for_not_in_call(self.log, d)
+        return ret
diff --git a/acts/tests/google/bt/car_bt/BtCarPairedConnectDisconnectTest.py b/acts/tests/google/bt/car_bt/BtCarPairedConnectDisconnectTest.py
index 7168edb..ea00032 100644
--- a/acts/tests/google/bt/car_bt/BtCarPairedConnectDisconnectTest.py
+++ b/acts/tests/google/bt/car_bt/BtCarPairedConnectDisconnectTest.py
@@ -30,12 +30,15 @@
 
 from acts.base_test import BaseTestClass
 from acts.test_utils.bt import bt_test_utils
+from acts.test_utils.bt import BtEnum
 from acts import asserts
 
 class BtCarPairedConnectDisconnectTest(BaseTestClass):
     def setup_class(self):
-        self.droid_ad = self.android_devices[0]
-        self.droid1_ad = self.android_devices[1]
+        self.car = self.android_devices[0]
+        self.ph = self.android_devices[1]
+        self.car_bt_addr = self.car.droid.bluetoothGetLocalAddress()
+        self.ph_bt_addr = self.ph.droid.bluetoothGetLocalAddress()
 
     def setup_test(self):
         # Reset the devices in a clean state.
@@ -46,100 +49,65 @@
 
         # Pair the devices.
         # This call may block until some specified timeout in bt_test_utils.py.
-        result = bt_test_utils.pair_pri_to_sec(self.droid_ad.droid, self.droid1_ad.droid)
+        result = bt_test_utils.pair_pri_to_sec(self.car.droid, self.ph.droid)
 
         asserts.assert_true(result, "pair_pri_to_sec returned false.");
 
         # Check for successful setup of test.
-        devices = self.droid_ad.droid.bluetoothGetBondedDevices()
+        devices = self.car.droid.bluetoothGetBondedDevices()
         asserts.assert_equal(len(devices), 1, "pair_pri_to_sec succeeded but no bonded devices.")
 
     def on_fail(self, test_name, begin_time):
         bt_test_utils.take_btsnoop_logs(self.android_devices, self, test_name)
 
     def test_connect_disconnect_paired(self):
+        """
+        Tests if we can connect two devices over Headset, A2dp and then disconnect them with success
+
+        Precondition:
+        1. Devices are paired.
+
+        Steps:
+        1. Initiate connection over A2dp Sink and Headset client profiles.
+        2. Check if the connection succeeded.
+
+        Returns:
+          Pass if True
+          Fail if False
+
+        Priority: 0
+        """
+
         NUM_TEST_RUNS = 2
         failure = 0
         for i in range(NUM_TEST_RUNS):
             self.log.info("Running test [" + str(i) + "/" + str(NUM_TEST_RUNS) + "]")
-            # Connect the device.
-            devices = self.droid_ad.droid.bluetoothGetBondedDevices()
-            if (len(devices) == 0):
-                self.log.info("No bonded devices.")
-                failure = failure + 1
-                continue
-
-            self.log.info("Attempting to connect.")
-            self.droid_ad.droid.bluetoothConnectBonded(devices[0]['address'])
-            end_time = time.time() + 20
-            expected_address = self.droid1_ad.droid.bluetoothGetLocalAddress()
-            connected = False
-            a2dp_sink_connected = False
-            pbap_client_connected = False
-            hfp_client_connected = False
-
-            # Busy loop to check if we found a matching device.
-            while time.time() < end_time:
-                connected_devices = self.droid_ad.droid.bluetoothGetConnectedDevices()
-                for d in connected_devices:
-                    if d['address'] == expected_address:
-                        connected = True
-                        break
-                a2dp_sink_connected_devices = (self.droid_ad.droid
-                                               .bluetoothGetConnectedDevicesOnProfile(11))
-                for d in a2dp_sink_connected_devices:
-                    if d['address'] == expected_address:
-                        a2dp_sink_connected = True
-                        break
-
-                hfp_client_connected_devices = (self.droid_ad.droid.
-                                                bluetoothGetConnectedDevicesOnProfile(16))
-                for d in hfp_client_connected_devices:
-                    if d['address'] == expected_address:
-                        hfp_client_connected = True
-                        break
-
-                pbap_client_connected_devices = (self.droid_ad.droid.
-                                                 bluetoothGetConnectedDevicesOnProfile(17))
-                for d in hfp_client_connected_devices:
-                    if d['address'] == expected_address:
-                        pbap_client_connected = True
-                        break
-                time.sleep(5)
-
-                self.log.info("Connected " + str(connected))
-                self.log.info("A2DP Sink Connected " + str(a2dp_sink_connected))
-                self.log.info("HFP client connected " + str(hfp_client_connected))
-                self.log.info("PBAP Client connected " + str(pbap_client_connected))
-
-                if (all([connected, a2dp_sink_connected,
-                         hfp_client_connected, pbap_client_connected])):
-                    break
-
-                # Try again to overcome occasional throw away by bluetooth
-                self.droid_ad.droid.bluetoothConnectBonded(devices[0]['address'])
+            success = bt_test_utils.connect_pri_to_sec(
+                self.log, self.car, self.ph.droid,
+                set([BtEnum.BluetoothProfile.HEADSET_CLIENT,
+                     BtEnum.BluetoothProfile.A2DP_SINK]))
 
             # Check if we got connected.
-            if (not all([connected, a2dp_sink_connected, pbap_client_connected,
-                         hfp_client_connected])):
+            if not success:
                 self.log.info("Not all profiles connected.")
                 failure = failure + 1
                 continue
 
             # Disconnect the devices.
             self.log.info("Attempt to disconnect.")
-            self.droid_ad.droid.bluetoothDisconnectConnected(expected_address)
+            self.car.droid.bluetoothDisconnectConnected(self.ph_bt_addr)
 
             end_time = time.time() + 10
             disconnected = False
             # Busy loop to check if we have successfully disconnected from the
             # device
             while time.time() < end_time:
-                connectedDevices = self.droid_ad.droid.bluetoothGetConnectedDevices()
+                connectedDevices = self.car.droid.bluetoothGetConnectedDevices()
                 exists = False
-                connected_devices = self.droid_ad.droid.bluetoothGetConnectedDevices()
+                connected_devices = \
+                    self.car.droid.bluetoothGetConnectedDevices()
                 for d in connected_devices:
-                  if d['address'] == expected_address:
+                  if d['address'] == self.ph_bt_addr:
                       exists = True
                       break
                 if exists is False:
@@ -153,3 +121,4 @@
                 continue
         self.log.info("Failure {} total tests {}".format(failure, NUM_TEST_RUNS))
         asserts.assert_equal(failure, 0, "")
+