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"""
17Bluetooth Config Pusher
18"""
19
20from acts_contrib.test_utils.bt.bt_gatt_utils import disconnect_gatt_connection
21from acts_contrib.test_utils.bt.bt_gatt_utils import setup_gatt_connection
22from acts_contrib.test_utils.bt.bt_gatt_utils import setup_gatt_mtu
23from acts_contrib.test_utils.bt.bt_gatt_utils import log_gatt_server_uuids
24
25import os
26
27
28class ConfigLib():
29    bluetooth_config_path = "/system/etc/bluetooth/bt_stack.conf"
30    conf_path = "{}/configs".format(os.path.dirname(
31        os.path.realpath(__file__)))
32    reset_config_path = "{}/bt_stack.conf".format(conf_path)
33    non_bond_config_path = "{}/non_bond_bt_stack.conf".format(conf_path)
34    disable_mitm_config_path = "{}/dis_mitm_bt_stack.conf".format(conf_path)
35
36    def __init__(self, log, dut):
37        self.dut = dut
38        self.log = log
39
40    def _reset_bluetooth(self):
41        self.dut.droid.bluetoothToggleState(False)
42        self.dut.droid.bluetoothToggleState(True)
43
44    def reset(self):
45        self.dut.adb.push("{} {}".format(self.reset_config_path,
46                                         self.bluetooth_config_path))
47        self._reset_bluetooth()
48
49    def set_nonbond(self):
50        self.dut.adb.push("{} {}".format(self.non_bond_config_path,
51                                         self.bluetooth_config_path))
52        self._reset_bluetooth()
53
54    def set_disable_mitm(self):
55        self.dut.adb.push("{} {}".format(self.disable_mitm_config_path,
56                                         self.bluetooth_config_path))
57        self._reset_bluetooth()
58