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

Commit 5354178a authored by Martin Brabham's avatar Martin Brabham Committed by android-build-merger
Browse files

NIAP: Add a new argument to determine single user mode status.

am: e02a8bec

Change-Id: Ic11ae11c2101131880701812eec4380e98e8226a
parents 932d1b3f e02a8bec
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -103,6 +103,19 @@ bt_status_t btif_cleanup_bluetooth(void);
 ******************************************************************************/
bool is_restricted_mode(void);

/*******************************************************************************
 *
 * Function         is_single_user_mode_
 *
 * Description      Checks if BT was enabled in single user mode. In this
 *                  mode, use of keystore for key attestation of LTK is limitee
 *                  to this mode defined by UserManager.
 *
 * Returns          bool
 *
 ******************************************************************************/
bool is_single_user_mode(void);

/*******************************************************************************
 *
 * Function         btif_get_adapter_properties
+9 −7
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ using bluetooth::hearing_aid::HearingAidInterface;

bt_callbacks_t* bt_hal_cbacks = NULL;
bool restricted_mode = false;
bool single_user_mode = false;

/*******************************************************************************
 *  Externs
@@ -132,8 +133,10 @@ static bool is_profile(const char* p1, const char* p2) {
 *
 ****************************************************************************/

static int init(bt_callbacks_t* callbacks) {
  LOG_INFO(LOG_TAG, "%s", __func__);
static int init(bt_callbacks_t* callbacks, bool start_restricted,
                bool is_single_user_mode) {
  LOG_INFO(LOG_TAG, "%s: start restricted = %d ; single user = %d", __func__,
           start_restricted, is_single_user_mode);

  if (interface_ready()) return BT_STATUS_DONE;

@@ -142,16 +145,14 @@ static int init(bt_callbacks_t* callbacks) {
#endif

  bt_hal_cbacks = callbacks;
  restricted_mode = start_restricted;
  single_user_mode = is_single_user_mode;
  stack_manager_get_interface()->init_stack();
  btif_debug_init();
  return BT_STATUS_SUCCESS;
}

static int enable(bool start_restricted) {
  LOG_INFO(LOG_TAG, "%s: start restricted = %d", __func__, start_restricted);

  restricted_mode = start_restricted;

static int enable() {
  if (!interface_ready()) return BT_STATUS_NOT_READY;

  stack_manager_get_interface()->start_up_stack_async();
@@ -168,6 +169,7 @@ static int disable(void) {
static void cleanup(void) { stack_manager_get_interface()->clean_up_stack(); }

bool is_restricted_mode() { return restricted_mode; }
bool is_single_user_mode() { return single_user_mode; }

static int get_adapter_properties(void) {
  /* sanity check */
+3 −1
Original line number Diff line number Diff line
@@ -60,7 +60,9 @@ static const char* TIME_STRING_FORMAT = "%Y-%m-%d %H:%M:%S";

constexpr int kBufferSize = 400 * 10;  // initial file is ~400B

static bool use_key_attestation() { return getuid() == AID_BLUETOOTH; }
static bool use_key_attestation() {
  return getuid() == AID_BLUETOOTH && is_single_user_mode();
}

#define BT_CONFIG_METRICS_SECTION "Metrics"
#define BT_CONFIG_METRICS_SALT_256BIT "Salt256Bit"
+7 −2
Original line number Diff line number Diff line
@@ -466,11 +466,16 @@ typedef struct {
  /**
   * Opens the interface and provides the callback routines
   * to the implemenation of this interface.
   * The |start_restricted| flag inits the adapter in restricted mode. In
   * restricted mode, bonds that are created are marked as restricted in the
   * config file. These devices are deleted upon leaving restricted mode.
   * The |is_single_user_mode| flag inits the adapter in NIAP mode.
   */
  int (*init)(bt_callbacks_t* callbacks);
  int (*init)(bt_callbacks_t* callbacks, bool guest_mode,
              bool is_single_user_mode);

  /** Enable Bluetooth. */
  int (*enable)(bool guest_mode);
  int (*enable)();

  /** Disable Bluetooth. */
  int (*disable)(void);
+2 −3
Original line number Diff line number Diff line
@@ -230,7 +230,7 @@ class AdapterImpl : public Adapter, public hal::BluetoothInterface::Observer {

  bool IsEnabled() const override { return state_.load() == ADAPTER_STATE_ON; }

  bool Enable(bool start_restricted) override {
  bool Enable() override {
    AdapterState current_state = GetState();
    if (current_state != ADAPTER_STATE_OFF) {
      LOG(INFO) << "Adapter not disabled - state: "
@@ -243,8 +243,7 @@ class AdapterImpl : public Adapter, public hal::BluetoothInterface::Observer {
    state_ = ADAPTER_STATE_TURNING_ON;
    NotifyAdapterStateChanged(current_state, state_);

    int status = hal::BluetoothInterface::Get()->GetHALInterface()->enable(
        start_restricted);
    int status = hal::BluetoothInterface::Get()->GetHALInterface()->enable();
    if (status != BT_STATUS_SUCCESS) {
      LOG(ERROR) << "Failed to enable Bluetooth - status: "
                 << BtStatusText((const bt_status_t)status);
Loading