Commit 12e71741 authored by Howard Chung's avatar Howard Chung Committed by Commit Bot

Power off bluetooth adapter if policy disallow

When DeviceAllowBluetooth is set to False, users can still use
crosh > bt_console to scan/pair etc.

This patch power off the bluetooth adapter when DeviceAllowBluetooth is
applied. Since crosh > bt_console launches bluetoothctl in restricted
mode, which disallow any power operations, users will no longer be able
to bypass enterprise policy in this way.

BUG=b:158568520
TEST=set DeviceAllowBluetooth to False and verify the above method won't
work.

Change-Id: Ic02be25a19f2b73033c4c83e78fc3c707f86e48f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2467637
Commit-Queue: Yun-Hao Chung <howardchung@google.com>
Reviewed-by: default avatarJames Vecore <vecore@google.com>
Reviewed-by: default avatarAnqing Zhao <anqing@chromium.org>
Cr-Commit-Position: refs/heads/master@{#817791}
parent 3e1e3086
...@@ -46,6 +46,7 @@ void BluetoothPolicyHandler::SetBluetoothPolicy( ...@@ -46,6 +46,7 @@ void BluetoothPolicyHandler::SetBluetoothPolicy(
if (!allow_bluetooth) { if (!allow_bluetooth) {
adapter_ = adapter; adapter_ = adapter;
adapter_->SetPowered(false, base::DoNothing(), base::DoNothing());
adapter_->Shutdown(); adapter_->Shutdown();
} }
} }
......
...@@ -20,13 +20,19 @@ class BluetoothPolicyHandlerTest : public testing::Test { ...@@ -20,13 +20,19 @@ class BluetoothPolicyHandlerTest : public testing::Test {
~TestingBluetoothAdapter() override {} ~TestingBluetoothAdapter() override {}
public: public:
TestingBluetoothAdapter() : is_shutdown_(false) {} TestingBluetoothAdapter() : is_shutdown_(false), is_powered_(true) {}
void Shutdown() override { is_shutdown_ = true; } void Shutdown() override { is_shutdown_ = true; }
void SetPowered(bool powered, base::OnceClosure callack,
ErrorCallback error_callback) override {
is_powered_ = powered;
}
bool IsPresent() const override { return !is_shutdown_; } bool IsPresent() const override { return !is_shutdown_; }
bool IsPowered() const override { return is_powered_; }
protected: protected:
bool is_shutdown_; bool is_shutdown_;
bool is_powered_;
}; };
BluetoothPolicyHandlerTest() : adapter_(new TestingBluetoothAdapter) {} BluetoothPolicyHandlerTest() : adapter_(new TestingBluetoothAdapter) {}
...@@ -60,6 +66,7 @@ TEST_F(BluetoothPolicyHandlerTest, TestZeroOnOffOn) { ...@@ -60,6 +66,7 @@ TEST_F(BluetoothPolicyHandlerTest, TestZeroOnOffOn) {
SetAllowBluetooth(false); SetAllowBluetooth(false);
EXPECT_FALSE(adapter_->IsPresent()); EXPECT_FALSE(adapter_->IsPresent());
EXPECT_FALSE(adapter_->IsPowered());
// Once the Bluetooth stack goes down, it needs a reboot to come back up. // Once the Bluetooth stack goes down, it needs a reboot to come back up.
SetAllowBluetooth(true); SetAllowBluetooth(true);
...@@ -70,6 +77,7 @@ TEST_F(BluetoothPolicyHandlerTest, OffDuringStartup) { ...@@ -70,6 +77,7 @@ TEST_F(BluetoothPolicyHandlerTest, OffDuringStartup) {
SetAllowBluetooth(false); SetAllowBluetooth(false);
BluetoothPolicyHandler shutdown_policy_handler(chromeos::CrosSettings::Get()); BluetoothPolicyHandler shutdown_policy_handler(chromeos::CrosSettings::Get());
EXPECT_FALSE(adapter_->IsPresent()); EXPECT_FALSE(adapter_->IsPresent());
EXPECT_FALSE(adapter_->IsPowered());
} }
TEST_F(BluetoothPolicyHandlerTest, OnDuringStartup) { TEST_F(BluetoothPolicyHandlerTest, OnDuringStartup) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment