Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c4b7f139 authored by Himanshu Rawat's avatar Himanshu Rawat
Browse files

Remove restricted devices only in non-restricted mode

GD storage module does not know if the mode is restricted or not. It
always remves the restricted devices on startup.
This change moves the decision to remove restricted devices from the
storage to btif_storage module.
This change also links the device record created in restricted mode to
the user ID. This ensures that different guests cannot access each
other's devices.

Test: mmm packages/modules/Bluetooth
Test: Manual | Pair with a device in guest mode and restart the BT,
paired device must still be available in the guest mode
Flag: com.android.bluetooth.flags.guest_mode_bond
Bug: 346337854
Bug: 349882273

Change-Id: I909053c7ffc5f5ac2ff2b8fc3840f3b77c7b543a
parent d657641b
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -48,6 +48,8 @@ bool btif_config_remove(const std::string& section, const std::string& key);

void btif_config_remove_device(const std::string& section);

void btif_config_remove_device_with_key(const std::string& key);

size_t btif_config_get_bin_length(const std::string& section, const std::string& key);

std::vector<RawAddress> btif_config_get_paired_devices();
+11 −0
Original line number Diff line number Diff line
@@ -334,6 +334,17 @@ void btif_storage_set_leaudio_has_acceptlist(const RawAddress& address, bool add
 ******************************************************************************/
bool btif_storage_is_restricted_device(const RawAddress* remote_bd_addr);

/*******************************************************************************
 *
 * Function         btif_storage_prune_devices
 *
 * Description      Removes restricted mode devices in non-restricted mode
 *
 * Returns          none
 *
 ******************************************************************************/
void btif_storage_prune_devices();

bt_status_t btif_storage_add_ble_bonding_key(RawAddress* remote_bd_addr, const uint8_t* key,
                                             uint8_t key_type, uint8_t key_length);
bt_status_t btif_storage_get_ble_bonding_key(const RawAddress& remote_bd_addr, uint8_t key_type,
+6 −0
Original line number Diff line number Diff line
@@ -314,6 +314,12 @@ void btif_config_remove_device(const std::string& section) {
  bluetooth::shim::BtifConfigInterface::RemoveSection(section);
}

void btif_config_remove_device_with_key(const std::string& key) {
  log::assert_that(bluetooth::shim::is_gd_stack_started_up(),
                   "assert failed: bluetooth::shim::is_gd_stack_started_up()");
  bluetooth::shim::BtifConfigInterface::RemoveSectionWithProperty(key);
}

bool btif_config_clear(void) {
  log::assert_that(bluetooth::shim::is_gd_stack_started_up(),
                   "assert failed: bluetooth::shim::is_gd_stack_started_up()");
+4 −1
Original line number Diff line number Diff line
@@ -59,7 +59,6 @@
#include "btif_api.h"
#include "btif_bqr.h"
#include "btif_config.h"
#include "btif_dm.h"
#include "btif_metrics_logging.h"
#include "btif_sdp.h"
#include "btif_storage.h"
@@ -1923,6 +1922,10 @@ void BTIF_dm_report_inquiry_status_change(tBTM_INQUIRY_STATE status) {
}

void BTIF_dm_enable() {
  if (com::android::bluetooth::flags::guest_mode_bond()) {
    btif_storage_prune_devices();
  }

  BD_NAME bdname;
  bt_status_t status;
  bt_property_t prop;
+31 −0
Original line number Diff line number Diff line
@@ -1316,6 +1316,37 @@ bool btif_storage_is_restricted_device(const RawAddress* remote_bd_addr) {
  return btif_config_get_int(remote_bd_addr->ToString(), BTIF_STORAGE_KEY_RESTRICTED, &val);
}

/*******************************************************************************
 *
 * Function         btif_storage_prune_devices
 *
 * Description      Removes restricted mode devices in non-restricted mode
 *
 * Returns          none
 *
 ******************************************************************************/
void btif_storage_prune_devices() {
  if (GetInterfaceToProfiles()->config->isRestrictedMode()) {
    int user_id = btif_storage_get_user_id();

    // Remove the devices with different user id
    for (const auto& bd_addr : btif_config_get_paired_devices()) {
      auto name = bd_addr.ToString();
      int id = 0;
      if (btif_config_get_int(name, BTIF_STORAGE_KEY_RESTRICTED, &id)) {
        // Restricted device, remove if user ID is different
        if (id != user_id) {
          log::info("Removing {} since user changed from {} to {}", bd_addr, id, user_id);
          btif_config_remove_device(name);
        }
      }
    }
  } else {
    // Default user, remove all restricted devices
    btif_config_remove_device_with_key(BTIF_STORAGE_KEY_RESTRICTED);
  }
}

// Get the name of a device from btif for interop database matching.
bool btif_storage_get_stored_remote_name(const RawAddress& bd_addr, char* name) {
  bt_property_t property;
Loading