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 PAN testcases.
18
19Test Script assumes that an internet connection
20is available through a telephony provider that has
21tethering allowed.
22
23This device was not intended to run in a sheild box.
24"""
25from acts.test_decorators import test_tracker_info
26from acts.test_utils.bt.BluetoothBaseTest import BluetoothBaseTest
27from acts.test_utils.bt.bt_test_utils import bluetooth_enabled_check
28from acts.test_utils.bt.bt_test_utils import orchestrate_and_verify_pan_connection
29from acts.test_utils.tel.tel_test_utils import verify_http_connection
30from queue import Empty
31import time
32
33
34class BtPanTest(BluetoothBaseTest):
35    def setup_class(self):
36        super().setup_class()
37        self.pan_dut = self.android_devices[0]
38        self.panu_dut = self.android_devices[1]
39
40    @BluetoothBaseTest.bt_test_wrap
41    @test_tracker_info(uuid='54f86e21-6d31-439c-bf57-426e9005cbc3')
42    def test_pan_connection(self):
43        """Test bluetooth PAN connection
44
45        Test basic PAN connection between two devices.
46
47        Steps:
48        1. Enable Airplane mode on PANU device. Enable Bluetooth only.
49        2. Enable Bluetooth tethering on PAN Service device.
50        3. Pair the PAN Service device to the PANU device.
51        4. Verify that Bluetooth tethering is enabled on PAN Service device.
52        5. Enable PAN profile from PANU device to PAN Service device.
53        6. Verify HTTP connection on PANU device.
54
55        Expected Result:
56        PANU device has internet access.
57
58        Returns:
59          Pass if True
60          Fail if False
61
62        TAGS: Classic, PAN, tethering
63        Priority: 1
64        """
65        return orchestrate_and_verify_pan_connection(self.pan_dut,
66                                                     self.panu_dut)
67
68    @BluetoothBaseTest.bt_test_wrap
69    @test_tracker_info(uuid='fa40a0b9-f326-4382-967a-fe4c73483a68')
70    def test_pan_connection_then_disconnect(self):
71        """Test bluetooth PAN connection then disconnect service
72
73        Test basic PAN connection between two devices then disconnect
74        service.
75
76        Steps:
77        1. Enable Airplane mode on PANU device. Enable Bluetooth only.
78        2. Enable Bluetooth tethering on PAN Service device.
79        3. Pair the PAN Service device to the PANU device.
80        4. Verify that Bluetooth tethering is enabled on PAN Service device.
81        5. Enable PAN profile from PANU device to PAN Service device.
82        6. Verify HTTP connection on PANU device.
83        7. Disable Bluetooth tethering on PAN Service device.
84        8. Verify no HTTP connection on PANU device.
85
86        Expected Result:
87        PANU device does not have internet access.
88
89        Returns:
90          Pass if True
91          Fail if False
92
93        TAGS: Classic, PAN, tethering
94        Priority: 1
95        """
96        if not orchestrate_and_verify_pan_connection(self.pan_dut,
97                                                     self.panu_dut):
98            self.log.error("Could not establish a PAN connection.")
99            return False
100        self.pan_dut.droid.bluetoothPanSetBluetoothTethering(False)
101        if not verify_http_connection(self.log, self.panu_dut,
102                                      expected_state=False):
103            self.log.error("PANU device still has internet access.")
104            return False
105        self.log.info("PANU device has no internet access as expected.")
106        return True
107