• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3# Copyright (C) 2016 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6# use this file except in compliance with the License. You may obtain a copy of
7# 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, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations under
15# the License.
16"""
17Test script to test BluetoothAdapter's resetFactory method.
18"""
19from acts.test_decorators import test_tracker_info
20from acts_contrib.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
21from acts_contrib.test_utils.bt.bt_test_utils import pair_pri_to_sec
22
23
24class BtFactoryResetTest(BluetoothBaseTest):
25    default_timeout = 10
26    grace_timeout = 4
27
28    def setup_class(self):
29        super().setup_class()
30        self.pri_dut = self.android_devices[0]
31        self.sec_dut = self.android_devices[1]
32
33    @BluetoothBaseTest.bt_test_wrap
34    @test_tracker_info(uuid='800bce6a-87ef-4fd1-82a5-4c60c4133be1')
35    def test_factory_reset_bluetooth(self):
36        """Test that BluetoothAdapter.factoryReset removes bonded devices
37
38        After having bonded devices, call the factoryReset method
39        in BluetoothAdapter to clear all bonded devices. Verify that
40        no bonded devices exist after calling function.
41
42        Steps:
43        1. Two Android devices should bond successfully.
44        2. Factory Reset Bluetooth on dut.
45        3. Verify that there are no bonded devices on dut.
46
47        Expected Result:
48        BluetoothAdapter should not have any bonded devices.
49
50        Returns:
51          Pass if True
52          Fail if False
53
54        TAGS: Bluetooth, Factory Reset
55        Priority: 2
56        """
57        if not pair_pri_to_sec(self.pri_dut, self.sec_dut, attempts=1):
58            self.log.error("Failed to bond devices.")
59            return False
60        if not self.pri_dut.droid.bluetoothFactoryReset():
61            self.log.error("BluetoothAdapter failed to factory reset.")
62        self.log.info("Verifying There are no bonded devices.")
63        if len(self.pri_dut.droid.bluetoothGetBondedDevices()) > 0:
64            print(self.pri_dut.droid.bluetoothGetBondedDevices())
65            self.log.error("Bonded devices still exist.")
66            return False
67        return True
68