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