Commit 10c15f82 authored by Ajay Panicker's avatar Ajay Panicker Committed by The Android Automerger
Browse files

Add guest mode functionality (2/3)

Add a flag to enable() to start Bluetooth in restricted
mode. In restricted mode, all devices that are paired during
restricted mode are deleted upon leaving restricted mode.
Right now restricted mode is only entered while a guest
user is active.

Bug: 27410683
Change-Id: I8f23d28ef0aa3a8df13d469c73005c8e1b894d19
parent 5b9f286d
......@@ -85,6 +85,23 @@ bt_status_t btif_disable_bluetooth(void);
*******************************************************************************/
bt_status_t btif_shutdown_bluetooth(void);
/*******************************************************************************
**
** Function is_restricted_mode
**
** Description Checks if BT was enabled in restriced mode. In restricted
** mode, bonds that are created are marked as temporary.
** These bonds persist until we leave restricted mode, at
** which point they will be deleted from the config. Also
** while in restricted mode, the user can access devices
** that are already paired before entering restricted mode,
** but they cannot remove any of these devices.
**
** Returns bool
**
*******************************************************************************/
bool is_restricted_mode(void);
/*******************************************************************************
**
** Function btif_get_adapter_properties
......
......@@ -314,6 +314,18 @@ bt_status_t btif_storage_add_device_to_autopair_blacklist(bt_bdaddr_t *remote_bd
*******************************************************************************/
BOOLEAN btif_storage_is_fixed_pin_zeros_keyboard(bt_bdaddr_t *remote_bd_addr);
/*******************************************************************************
**
** Function btif_storage_is_retricted_device
**
** Description BTIF storage API - checks if this device is a restricted device
**
** Returns TRUE if the device is labled as restricted
** FALSE otherwise
**
*******************************************************************************/
BOOLEAN btif_storage_is_restricted_device(const bt_bdaddr_t *remote_bd_addr);
#if (BLE_INCLUDED == TRUE)
bt_status_t btif_storage_add_ble_bonding_key( bt_bdaddr_t *remote_bd_addr,
char *key,
......
......@@ -45,6 +45,7 @@
#include "btif_api.h"
#include "bt_utils.h"
#include "btif_storage.h"
/************************************************************************************
** Constants & Macros
......@@ -61,6 +62,7 @@
************************************************************************************/
bt_callbacks_t *bt_hal_cbacks = NULL;
bool restricted_mode = FALSE;
/** Operating System specific callouts for resource management */
bt_os_callouts_t *bt_os_callouts = NULL;
......@@ -142,10 +144,11 @@ static int init(bt_callbacks_t* callbacks )
return BT_STATUS_SUCCESS;
}
static int enable( void )
{
static int enable(bool start_restricted) {
ALOGI("enable");
restricted_mode = start_restricted;
/* sanity check */
if (interface_ready() == FALSE)
return BT_STATUS_NOT_READY;
......@@ -175,6 +178,10 @@ static void cleanup( void )
return;
}
bool is_restricted_mode() {
return restricted_mode;
}
static int get_adapter_properties(void)
{
/* sanity check */
......@@ -285,6 +292,9 @@ static int cancel_bond(const bt_bdaddr_t *bd_addr)
static int remove_bond(const bt_bdaddr_t *bd_addr)
{
if (is_restricted_mode() && !btif_storage_is_restricted_device(bd_addr))
return BT_STATUS_SUCCESS;
/* sanity check */
if (interface_ready() == FALSE)
return BT_STATUS_NOT_READY;
......
......@@ -105,6 +105,7 @@ static int set_node(const char* section, const char* key, const char* name,
static int save_cfg();
static void load_cfg();
static short find_next_node(const cfg_node* p, short start, char* name, int* bytes);
static void btif_config_remove_restricted();
#ifdef UNIT_TEST
static void cfg_test_load();
static void cfg_test_write();
......@@ -148,6 +149,9 @@ int btif_config_init()
//cfg_test_read();
exit(0);
#endif
if (!is_restricted_mode())
btif_config_remove_restricted();
}
return pth >= 0;
}
......@@ -989,3 +993,36 @@ static void cfg_test_read()
#endif
static void btif_config_remove_restricted() {
int section_index = -1;
if ((section_index = find_inode(&root, "Remote")) < 0)
return;
cfg_node* remote_node = &root.child[section_index];
int count = GET_CHILD_COUNT(remote_node);
for (int i = 0; i < count; i ++) {
cfg_node* bdaddr_node = &remote_node->child[i];
if (find_inode(bdaddr_node, "Restricted") != -1) {
free_child(bdaddr_node, 0, GET_CHILD_COUNT(bdaddr_node));
free_child(remote_node, i, 1);
}
}
}
......@@ -787,6 +787,13 @@ bt_status_t btif_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr,
int ret = btif_config_set_int("Remote", bdstr, "LinkKeyType", (int)key_type);
ret &= btif_config_set_int("Remote", bdstr, "PinLength", (int)pin_length);
ret &= btif_config_set("Remote", bdstr, "LinkKey", (const char*)link_key, sizeof(LINK_KEY), BTIF_CFG_TYPE_BIN);
if (is_restricted_mode()) {
BTIF_TRACE_WARNING("%s: '%s' pairing will be removed if unrestricted",
__func__, bdstr);
btif_config_set_int("Remote", bdstr, "Restricted", 1);
}
/* write bonded info immediately */
btif_config_flush();
return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
......@@ -1828,3 +1835,20 @@ BOOLEAN btif_storage_is_dmt_supported_device(const bt_bdaddr_t *remote_bd_addr)
}
/*******************************************************************************
**
** Function btif_storage_is_restricted_device
**
** Description BTIF storage API - checks if this device is a restricted device
**
** Returns TRUE if the device is labeled as restricted
** FALSE otherwise
**
*******************************************************************************/
BOOLEAN btif_storage_is_restricted_device(const bt_bdaddr_t *remote_bd_addr)
{
bdstr_t bdstr;
bd2str(remote_bd_addr, &bdstr);
return btif_config_exist("Remote", bdstr, "Restricted");
}
......@@ -560,7 +560,7 @@ void bdt_enable(void)
bdt_log("Bluetooth is already enabled");
return;
}
status = sBtInterface->enable();
status = sBtInterface->enable(false);
check_return_status(status);
}
......
......@@ -24,7 +24,7 @@
bool adapter_enable_disable() {
int error;
CALL_AND_WAIT(error = bt_interface->enable(), adapter_state_changed);
CALL_AND_WAIT(error = bt_interface->enable(false), adapter_state_changed);
TASSERT(error == BT_STATUS_SUCCESS, "Error enabling Bluetooth: %d", error);
TASSERT(adapter_get_state() == BT_STATE_ON, "Adapter did not turn on.");
......
......@@ -89,7 +89,7 @@ int main(int argc, char **argv) {
// Run the full test suite.
for (size_t i = 0; i < test_suite_size; ++i) {
callbacks_init();
CALL_AND_WAIT(bt_interface->enable(), adapter_state_changed);
CALL_AND_WAIT(bt_interface->enable(false), adapter_state_changed);
if (test_suite[i].function()) {
printf("[%4d] %-64s [%sPASS%s]\n", ++case_num, test_suite[i].function_name, GREEN, GRAY);
++pass;
......
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