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

Commit 6b7bed47 authored by weichinweng's avatar weichinweng Committed by Automerger Merge Worker
Browse files

NIAP: implement bluetooth keystore interface.(2/2) am: 40c1d32a

Change-Id: I27ffcc0e79363810292582cdf8867e06ef984824
parents c9e4d1f7 40c1d32a
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -87,6 +87,7 @@ cc_library_static {
        "src/btif_storage.cc",
        "src/btif_storage.cc",
        "src/btif_uid.cc",
        "src/btif_uid.cc",
        "src/btif_util.cc",
        "src/btif_util.cc",
        "src/btif_keystore.cc",
        "src/stack_manager.cc",
        "src/stack_manager.cc",
    ],
    ],
    header_libs: [
    header_libs: [
+25 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <hardware/bt_keystore.h>

namespace bluetooth {
namespace bluetooth_keystore {

BluetoothKeystoreInterface* getBluetoothKeystoreInterface();

}  // namespace bluetooth_keystore
}  // namespace bluetooth
 No newline at end of file
+4 −0
Original line number Original line Diff line number Diff line
@@ -59,6 +59,7 @@
#include "btif_debug_btsnoop.h"
#include "btif_debug_btsnoop.h"
#include "btif_debug_conn.h"
#include "btif_debug_conn.h"
#include "btif_hf.h"
#include "btif_hf.h"
#include "btif_keystore.h"
#include "btif_storage.h"
#include "btif_storage.h"
#include "btsnoop.h"
#include "btsnoop.h"
#include "btsnoop_mem.h"
#include "btsnoop_mem.h"
@@ -398,6 +399,9 @@ static const void* get_profile_interface(const char* profile_id) {


  if (is_profile(profile_id, BT_PROFILE_HEARING_AID_ID))
  if (is_profile(profile_id, BT_PROFILE_HEARING_AID_ID))
    return btif_hearing_aid_get_interface();
    return btif_hearing_aid_get_interface();

  if (is_profile(profile_id, BT_KEYSTORE_ID))
    return bluetooth::bluetooth_keystore::getBluetoothKeystoreInterface();
  return NULL;
  return NULL;
}
}


+86 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* BluetoothKeystore Interface */

#include <btif_common.h>
#include <btif_keystore.h>

#include <base/bind.h>
#include <base/location.h>
#include <base/logging.h>
#include <hardware/bluetooth.h>

using base::Bind;
using base::Unretained;
using bluetooth::bluetooth_keystore::BluetoothKeystoreCallbacks;
using bluetooth::bluetooth_keystore::BluetoothKeystoreInterface;

namespace bluetooth {
namespace bluetooth_keystore {
class BluetoothKeystoreInterfaceImpl;
std::unique_ptr<BluetoothKeystoreInterface> bluetoothKeystoreInstance;

class BluetoothKeystoreInterfaceImpl
    : public bluetooth::bluetooth_keystore::BluetoothKeystoreInterface,
      public bluetooth::bluetooth_keystore::BluetoothKeystoreCallbacks {
  ~BluetoothKeystoreInterfaceImpl() override = default;

  void init(BluetoothKeystoreCallbacks* callbacks) override {
    DVLOG(2) << __func__;
    this->callbacks = callbacks;
  }

  void set_encrypt_key_or_remove_key(std::string prefix,
                                     std::string decryptedString) override {
    DVLOG(2) << __func__ << " prefix: " << prefix;

    if (!callbacks) {
      LOG(WARNING) << __func__ << " callback isn't ready. prefix: " << prefix;
      return;
    }

    do_in_jni_thread(
        base::Bind(&bluetooth::bluetooth_keystore::BluetoothKeystoreCallbacks::
                       set_encrypt_key_or_remove_key,
                   base::Unretained(callbacks), prefix, decryptedString));
  }

  std::string get_key(std::string prefix) override {
    DVLOG(2) << __func__ << " prefix: " << prefix;

    if (!callbacks) {
      LOG(WARNING) << __func__ << " callback isn't ready. prefix: " << prefix;
      return "";
    }

    return callbacks->get_key(prefix);
  }

 private:
  BluetoothKeystoreCallbacks* callbacks = nullptr;
};

BluetoothKeystoreInterface* getBluetoothKeystoreInterface() {
  if (!bluetoothKeystoreInstance) {
    bluetoothKeystoreInstance.reset(new BluetoothKeystoreInterfaceImpl());
  }

  return bluetoothKeystoreInstance.get();
}

}  // namespace bluetooth_keystore
}  // namespace bluetooth
+1 −0
Original line number Original line Diff line number Diff line
@@ -48,6 +48,7 @@
#define BT_PROFILE_AV_RC_ID "avrcp"
#define BT_PROFILE_AV_RC_ID "avrcp"
#define BT_PROFILE_AV_RC_CTRL_ID "avrcp_ctrl"
#define BT_PROFILE_AV_RC_CTRL_ID "avrcp_ctrl"
#define BT_PROFILE_HEARING_AID_ID "hearing_aid"
#define BT_PROFILE_HEARING_AID_ID "hearing_aid"
#define BT_KEYSTORE_ID "bluetooth_keystore"


/** Bluetooth Device Name */
/** Bluetooth Device Name */
typedef struct { uint8_t name[249]; } __attribute__((packed)) bt_bdname_t;
typedef struct { uint8_t name[249]; } __attribute__((packed)) bt_bdname_t;
Loading