From cb394350fcff833791b908f0ddfb715f23bd7e05 Mon Sep 17 00:00:00 2001 From: Michael Sun Date: Mon, 2 Nov 2020 07:17:47 +0000 Subject: [PATCH] btaa: introduce btif interface for btaa Add a new btif interface for Activity Attribution to help communicate between JNI and BTAA core module Tag: #feature Bug: 172501038 Test: m Change-Id: Idc7fbb126040bc0b2757b871e9ff6ef8ae889dcf --- btif/Android.bp | 1 + btif/include/btif_activity_attribution.h | 25 +++++++++++++ btif/src/bluetooth.cc | 6 +++ btif/src/btif_activity_attribution.cc | 63 ++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+) create mode 100644 btif/include/btif_activity_attribution.h create mode 100644 btif/src/btif_activity_attribution.cc diff --git a/btif/Android.bp b/btif/Android.bp index fde708902..4975a5446 100755 --- a/btif/Android.bp +++ b/btif/Android.bp @@ -49,6 +49,7 @@ cc_library_static { "src/btif_a2dp_control.cc", "src/btif_a2dp_sink.cc", "src/btif_a2dp_source.cc", + "src/btif_activity_attribution.cc", "src/btif_av.cc", "src/btif_avrcp_audio_track.cc", "src/btif_ble_advertiser.cc", diff --git a/btif/include/btif_activity_attribution.h b/btif/include/btif_activity_attribution.h new file mode 100644 index 000000000..3194d3321 --- /dev/null +++ b/btif/include/btif_activity_attribution.h @@ -0,0 +1,25 @@ +/* + * 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 + +namespace bluetooth { +namespace activity_attribution { + +ActivityAttributionInterface* getActivityAttributionInterface(); + +} // namespace activity_attribution +} // namespace bluetooth \ No newline at end of file diff --git a/btif/src/bluetooth.cc b/btif/src/bluetooth.cc index 07ed4cfe0..c272cf119 100644 --- a/btif/src/bluetooth.cc +++ b/btif/src/bluetooth.cc @@ -49,6 +49,7 @@ #include "bta/include/bta_hf_client_api.h" #include "btif/avrcp/avrcp_service.h" #include "btif_a2dp.h" +#include "btif_activity_attribution.h" #include "btif_api.h" #include "btif_av.h" #include "btif_bqr.h" @@ -430,6 +431,11 @@ static const void* get_profile_interface(const char* profile_id) { if (is_profile(profile_id, BT_KEYSTORE_ID)) return bluetooth::bluetooth_keystore::getBluetoothKeystoreInterface(); + + if (is_profile(profile_id, BT_ACTIVITY_ATTRIBUTION_ID)) { + return bluetooth::activity_attribution::getActivityAttributionInterface(); + } + return NULL; } diff --git a/btif/src/btif_activity_attribution.cc b/btif/src/btif_activity_attribution.cc new file mode 100644 index 000000000..a618ae659 --- /dev/null +++ b/btif/src/btif_activity_attribution.cc @@ -0,0 +1,63 @@ +/****************************************************************************** + * + * 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. + * + ******************************************************************************/ + +/* Activity Attribution Interface */ + +#include + +#include "btif/include/btif_common.h" +#include "stack/include/btu.h" + +using base::Bind; +using base::Unretained; + +namespace bluetooth { +namespace activity_attribution { + +std::unique_ptr activityAttributionInstance; + +class ActivityAttributionInterfaceImpl : public ActivityAttributionCallbacks, + public ActivityAttributionInterface { + ~ActivityAttributionInterfaceImpl() override = default; + + void Init(ActivityAttributionCallbacks* callbacks) override { + this->callbacks = callbacks; + } + + void OnWakeup(Activity activity, const RawAddress& address) override { + VLOG(2) << __func__ << " activity: " << (int)activity + << " address: " << address; + do_in_jni_thread(FROM_HERE, Bind(&ActivityAttributionCallbacks::OnWakeup, + Unretained(callbacks), activity, address)); + } + + void Cleanup(void) override {} + + private: + ActivityAttributionCallbacks* callbacks; +}; + +ActivityAttributionInterface* getActivityAttributionInterface() { + if (!activityAttributionInstance) + activityAttributionInstance.reset(new ActivityAttributionInterfaceImpl()); + + return activityAttributionInstance.get(); +} + +} // namespace activity_attribution +} // namespace bluetooth -- 2.11.0