diff options
| author | 2021-01-19 20:03:25 -0800 | |
|---|---|---|
| committer | 2021-02-01 22:58:05 +0000 | |
| commit | 08f29c81e4a5aec111b047889396e04481feeace (patch) | |
| tree | 0823e771f8ca449cea7a47291f970be4fe078062 | |
| parent | c86d26f3548b9ec3fc25495c09b4905387431ae6 (diff) | |
Make build tweaks to support newer libchrome
Android uses a very old version of libchrome and there are several
breaking changes in the latest libchrome. Using BASE_VER defined in the
libchrome provided by ChromeOS, we add a few abstractions:
* AbstractMessageLoop to replace MessageLoop
* AbstractObserverList to replace ObserverList
* Work around ExportedObject::ResponseSender changing from
base::RepeatingCallback to base::OnceCallback
Also add a few more workarounds for libchrome differences (missing
includes, unresolved symbols, etc).
Bug: 177961465
Tag: #refactor
Test: run --host bluetooth_test_gd
Test: run --host bluetooth_test_common
Change-Id: I94bc3dd4cd86bd357d869f23e95de9e53184696d
32 files changed, 240 insertions, 85 deletions
diff --git a/system/btif/avrcp/avrcp_service.cc b/system/btif/avrcp/avrcp_service.cc index d9887ea16c..9fd2dc441e 100644 --- a/system/btif/avrcp/avrcp_service.cc +++ b/system/btif/avrcp/avrcp_service.cc @@ -23,9 +23,10 @@ #include <mutex> #include <sstream> +#include "abstract_message_loop.h" #include "btif_av.h" -#include "btif_dm.h" #include "btif_common.h" +#include "btif_dm.h" #include "device.h" #include "stack/include/btu.h" @@ -36,7 +37,7 @@ AvrcpService* AvrcpService::instance_ = nullptr; AvrcpService::ServiceInterfaceImpl* AvrcpService::service_interface_ = nullptr; std::mutex jni_mutex_; -base::MessageLoop* jni_message_loop_ = nullptr; +btbase::AbstractMessageLoop* jni_message_loop_ = nullptr; base::CancelableTaskTracker task_tracker_; void do_in_avrcp_jni(const base::Closure& task) { diff --git a/system/btif/include/btif_common.h b/system/btif/include/btif_common.h index fc517cda24..21799ef0af 100644 --- a/system/btif/include/btif_common.h +++ b/system/btif/include/btif_common.h @@ -24,9 +24,9 @@ #include <base/bind.h> #include <base/location.h> -#include <base/message_loop/message_loop.h> #include <hardware/bluetooth.h> +#include "abstract_message_loop.h" #include "bt_types.h" #include "bta/include/bta_api.h" #include "osi/include/log.h" @@ -154,7 +154,7 @@ extern bt_status_t do_in_jni_thread(base::OnceClosure task); extern bt_status_t do_in_jni_thread(const base::Location& from_here, base::OnceClosure task); extern bool is_on_jni_thread(); -extern base::MessageLoop* get_jni_message_loop(); +extern btbase::AbstractMessageLoop* get_jni_message_loop(); /** * This template wraps callback into callback that will be executed on jni * thread diff --git a/system/btif/src/btif_core.cc b/system/btif/src/btif_core.cc index e003643d56..4d79bdbed8 100644 --- a/system/btif/src/btif_core.cc +++ b/system/btif/src/btif_core.cc @@ -43,6 +43,7 @@ #include <sys/types.h> #include <unistd.h> +#include "abstract_message_loop.h" #include "bt_common.h" #include "bt_utils.h" #include "bta_api.h" @@ -183,7 +184,9 @@ bool is_on_jni_thread() { return jni_thread.GetThreadId() == PlatformThread::CurrentId(); } -base::MessageLoop* get_jni_message_loop() { return jni_thread.message_loop(); } +btbase::AbstractMessageLoop* get_jni_message_loop() { + return jni_thread.message_loop(); +} /******************************************************************************* * diff --git a/system/common/benchmark/thread_performance_benchmark.cc b/system/common/benchmark/thread_performance_benchmark.cc index 74f157f85b..8538dac05f 100644 --- a/system/common/benchmark/thread_performance_benchmark.cc +++ b/system/common/benchmark/thread_performance_benchmark.cc @@ -23,6 +23,7 @@ #include <memory> #include <thread> +#include "abstract_message_loop.h" #include "common/message_loop_thread.h" #include "osi/include/fixed_queue.h" #include "osi/include/thread.h" @@ -93,7 +94,7 @@ class BM_MessageLoop : public BM_ThreadPerformance { return nullptr; } void RunMessageLoop() { - message_loop_ = new base::MessageLoop(); + message_loop_ = new btbase::AbstractMessageLoop(); run_loop_ = new base::RunLoop(); message_loop_->task_runner()->PostTask( FROM_HERE, base::BindOnce(&std::promise<void>::set_value, @@ -106,7 +107,7 @@ class BM_MessageLoop : public BM_ThreadPerformance { } protected: - base::MessageLoop* message_loop_ = nullptr; + btbase::AbstractMessageLoop* message_loop_ = nullptr; base::RunLoop* run_loop_ = nullptr; }; diff --git a/system/common/message_loop_thread.cc b/system/common/message_loop_thread.cc index 639e43355b..643de64421 100644 --- a/system/common/message_loop_thread.cc +++ b/system/common/message_loop_thread.cc @@ -180,7 +180,7 @@ void MessageLoopThread::RunThread(MessageLoopThread* thread, thread->Run(std::move(start_up_promise)); } -base::MessageLoop* MessageLoopThread::message_loop() const { +btbase::AbstractMessageLoop* MessageLoopThread::message_loop() const { ASSERT_LOG(!is_main_, "you are not allowed to get the main thread's message loop"); @@ -224,7 +224,7 @@ void MessageLoopThread::Run(std::promise<void> start_up_promise) { LOG(INFO) << __func__ << ": message loop starting for thread " << thread_name_; base::PlatformThread::SetName(thread_name_); - message_loop_ = new base::MessageLoop(); + message_loop_ = new btbase::AbstractMessageLoop(); run_loop_ = new base::RunLoop(); thread_id_ = base::PlatformThread::CurrentId(); linux_tid_ = static_cast<pid_t>(syscall(SYS_gettid)); diff --git a/system/common/message_loop_thread.h b/system/common/message_loop_thread.h index c1af035b43..7420dbcb26 100644 --- a/system/common/message_loop_thread.h +++ b/system/common/message_loop_thread.h @@ -24,11 +24,12 @@ #include <base/bind.h> #include <base/location.h> -#include <base/message_loop/message_loop.h> #include <base/run_loop.h> #include <base/threading/platform_thread.h> #include "src/message_loop_thread.rs.h" +#include "abstract_message_loop.h" + namespace bluetooth { namespace common { @@ -135,7 +136,7 @@ class MessageLoopThread final { * @return message loop associated with this thread, nullptr if thread is not * running */ - base::MessageLoop* message_loop() const; + btbase::AbstractMessageLoop* message_loop() const; /** * Post a task to run on this thread after a specified delay. If the task @@ -188,7 +189,7 @@ class MessageLoopThread final { mutable std::recursive_mutex api_mutex_; const std::string thread_name_; - base::MessageLoop* message_loop_; + btbase::AbstractMessageLoop* message_loop_; base::RunLoop* run_loop_; std::thread* thread_; base::PlatformThreadId thread_id_; diff --git a/system/common/test/thread_performance_test.cc b/system/common/test/thread_performance_test.cc index 4c38feda91..b9ab10605b 100644 --- a/system/common/test/thread_performance_test.cc +++ b/system/common/test/thread_performance_test.cc @@ -26,6 +26,7 @@ #include <iostream> #include <thread> +#include "abstract_message_loop.h" #include "common/message_loop_thread.h" #include "osi/include/fixed_queue.h" #include "osi/include/thread.h" @@ -76,7 +77,7 @@ class MessageLoopPerformanceTest : public PerformanceTest { return nullptr; } void RunMessageLoop() { - message_loop_ = new base::MessageLoop(); + message_loop_ = new btbase::AbstractMessageLoop(); run_loop_ = new base::RunLoop(); message_loop_->task_runner()->PostTask( FROM_HERE, base::Bind(&std::promise<void>::set_value, @@ -89,7 +90,7 @@ class MessageLoopPerformanceTest : public PerformanceTest { } protected: - base::MessageLoop* message_loop_ = nullptr; + btbase::AbstractMessageLoop* message_loop_ = nullptr; base::RunLoop* run_loop_ = nullptr; }; diff --git a/system/include/abstract_message_loop.h b/system/include/abstract_message_loop.h new file mode 100644 index 0000000000..9816e0df4a --- /dev/null +++ b/system/include/abstract_message_loop.h @@ -0,0 +1,81 @@ +// +// Copyright 2021 Google, Inc. +// +// 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. +// + +#pragma once + +#if defined(BASE_VER) && BASE_VER > 780000 +/* libchrome version < 780000 still has the old message loop. Android still uses + * the old libchrome version so use the basic messageloop where that's required. + * Elsewhere, use the SingleThreadTaskExecutor instead. + */ +#include <base/message_loop/message_loop_current.h> +#include <base/message_loop/message_pump.h> +#include <base/task/single_thread_task_executor.h> +#include <base/test/task_environment.h> +#include <base/threading/thread.h> +#include <base/threading/thread_task_runner_handle.h> +#else +#include <base/message_loop/message_loop.h> +#include <base/threading/thread.h> +#endif + +namespace btbase { + +#if defined(BASE_VER) && BASE_VER > 780000 + +class AbstractMessageLoop : public base::SingleThreadTaskExecutor { + public: + static scoped_refptr<base::SingleThreadTaskRunner> current_task_runner() { + return base::ThreadTaskRunnerHandle::Get(); + } +}; + +class AbstractTestMessageLoop : public base::test::TaskEnvironment { + public: + static scoped_refptr<base::SingleThreadTaskRunner> current_task_runner() { + return base::ThreadTaskRunnerHandle::Get(); + } +}; + +// Initialize the test task environment +#define DEFINE_TEST_TASK_ENV(var) \ + base::AbstractTestMessageLoop var { \ + base::test::TaskEnvironment::ThreadingMode::MAIN_THREAD_ONLY \ + } + +inline void set_message_loop_type_IO(base::Thread::Options& options) { + options.message_pump_type = base::MessagePumpType::IO; +} + +#else +class AbstractMessageLoop : public base::MessageLoop { + public: + static scoped_refptr<base::SingleThreadTaskRunner> current_task_runner() { + return base::MessageLoop::current()->task_runner(); + } +}; + +class AbstractTestMessageLoop : public AbstractMessageLoop {}; + +#define DEFINE_TEST_TASK_ENV(var) base::AbstractTestMessageLoop* var + +inline void set_message_loop_type_IO(base::Thread::Options& options) { + options.message_loop_type = base::MessageLoop::TYPE_IO; +} + +#endif + +} // namespace btbase diff --git a/system/include/abstract_observer_list.h b/system/include/abstract_observer_list.h new file mode 100644 index 0000000000..0f882599ec --- /dev/null +++ b/system/include/abstract_observer_list.h @@ -0,0 +1,36 @@ +// +// Copyright 2021 Google, Inc. +// +// 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. +// + +#pragma once + +#include <base/observer_list.h> + +namespace btbase { +#if defined(BASE_VER) && BASE_VER > 780000 + +// Checked Observers aren't supported in the older libchrome so use unchecked +// ones instead to preserve behavior. +template <class ObserverType> +class AbstractObserverList + : public base::ObserverList<ObserverType>::Unchecked {}; + +#else + +template <class ObserverType> +class AbstractObserverList : public base::ObserverList<ObserverType> {}; + +#endif +} // namespace btbase diff --git a/system/osi/src/alarm.cc b/system/osi/src/alarm.cc index 46ebd85e18..6e5d22f43e 100644 --- a/system/osi/src/alarm.cc +++ b/system/osi/src/alarm.cc @@ -24,7 +24,6 @@ #include <base/cancelable_callback.h> #include <base/logging.h> -#include <base/message_loop/message_loop.h> #include <errno.h> #include <fcntl.h> #include <inttypes.h> @@ -50,7 +49,6 @@ using base::Bind; using base::CancelableClosure; -using base::MessageLoop; // Callback and timer threads should run at RT priority in order to ensure they // meet audio deadlines. Use this priority for all audio/timer related thread. diff --git a/system/osi/test/alarm_test.cc b/system/osi/test/alarm_test.cc index 6977ec541b..7c30bf353e 100644 --- a/system/osi/test/alarm_test.cc +++ b/system/osi/test/alarm_test.cc @@ -16,7 +16,6 @@ * ******************************************************************************/ -#include <base/message_loop/message_loop.h> #include <base/run_loop.h> #include <gtest/gtest.h> diff --git a/system/profile/avrcp/device.cc b/system/profile/avrcp/device.cc index a31ed917b8..4bd262c9e8 100644 --- a/system/profile/avrcp/device.cc +++ b/system/profile/avrcp/device.cc @@ -15,8 +15,7 @@ */ #include "device.h" -#include <base/message_loop/message_loop.h> - +#include "abstract_message_loop.h" #include "connection_handler.h" #include "packet/avrcp/avrcp_reject_packet.h" #include "packet/avrcp/general_reject_packet.h" @@ -539,7 +538,7 @@ void Device::PlaybackPosNotificationResponse(uint8_t label, bool interim, DEVICE_VLOG(0) << __func__ << ": Queue next play position update"; play_pos_update_cb_.Reset(base::Bind(&Device::HandlePlayPosUpdate, weak_ptr_factory_.GetWeakPtr())); - base::MessageLoop::current()->task_runner()->PostDelayedTask( + btbase::AbstractMessageLoop::current_task_runner()->PostDelayedTask( FROM_HERE, play_pos_update_cb_.callback(), base::TimeDelta::FromSeconds(play_pos_interval_)); } diff --git a/system/profile/avrcp/tests/avrcp_connection_handler_test.cc b/system/profile/avrcp/tests/avrcp_connection_handler_test.cc index 5a811b27c4..e2765fab77 100644 --- a/system/profile/avrcp/tests/avrcp_connection_handler_test.cc +++ b/system/profile/avrcp/tests/avrcp_connection_handler_test.cc @@ -16,7 +16,6 @@ #include <base/bind.h> #include <base/logging.h> -#include <base/message_loop/message_loop.h> #include <gmock/gmock.h> #include <gtest/gtest.h> diff --git a/system/service/adapter.cc b/system/service/adapter.cc index 4d414dddcf..1724fcdfed 100644 --- a/system/service/adapter.cc +++ b/system/service/adapter.cc @@ -24,6 +24,7 @@ #include <base/logging.h> #include <base/observer_list.h> +#include "abstract_observer_list.h" #include "service/a2dp_sink.h" #include "service/a2dp_source.h" #include "service/avrcp_control.h" @@ -761,7 +762,7 @@ class AdapterImpl : public Adapter, public hal::BluetoothInterface::Observer { // List of observers that are interested in notifications from us. std::mutex observers_lock_; - base::ObserverList<Adapter::Observer> observers_; + btbase::AbstractObserverList<Adapter::Observer> observers_; // List of devices addresses that are currently connected. std::mutex connected_devices_lock_; diff --git a/system/service/daemon.cc b/system/service/daemon.cc index 439c2c2fab..4cd384285b 100644 --- a/system/service/daemon.cc +++ b/system/service/daemon.cc @@ -21,6 +21,7 @@ #include <base/logging.h> #include <base/run_loop.h> +#include "abstract_message_loop.h" #include "service/adapter.h" #include "service/hal/bluetooth_av_interface.h" #include "service/hal/bluetooth_avrcp_interface.h" @@ -51,7 +52,7 @@ class DaemonImpl : public Daemon, public ipc::IPCManager::Delegate { Settings* GetSettings() const override { return settings_.get(); } - base::MessageLoop* GetMessageLoop() const override { + btbase::AbstractMessageLoop* GetMessageLoop() const override { return message_loop_.get(); } @@ -128,7 +129,7 @@ class DaemonImpl : public Daemon, public ipc::IPCManager::Delegate { bool Init() override { CHECK(!initialized_); - message_loop_.reset(new base::MessageLoop()); + message_loop_.reset(new btbase::AbstractMessageLoop()); settings_.reset(new Settings()); if (!settings_->Init()) { @@ -156,7 +157,7 @@ class DaemonImpl : public Daemon, public ipc::IPCManager::Delegate { } bool initialized_; - std::unique_ptr<base::MessageLoop> message_loop_; + std::unique_ptr<btbase::AbstractMessageLoop> message_loop_; std::unique_ptr<Settings> settings_; std::unique_ptr<Adapter> adapter_; std::unique_ptr<ipc::IPCManager> ipc_manager_; diff --git a/system/service/daemon.h b/system/service/daemon.h index 0d6474b657..06afe91008 100644 --- a/system/service/daemon.h +++ b/system/service/daemon.h @@ -17,7 +17,7 @@ #pragma once #include <base/macros.h> -#include <base/message_loop/message_loop.h> +#include "abstract_message_loop.h" namespace ipc { class IPCManager; @@ -55,7 +55,7 @@ class Daemon { // The main event loop. This should be used for any events and delayed tasks // that should be executed on the daemon's main thread. - virtual base::MessageLoop* GetMessageLoop() const = 0; + virtual btbase::AbstractMessageLoop* GetMessageLoop() const = 0; // Starts the daemon's main loop. virtual void StartMainLoop() = 0; diff --git a/system/service/example/heart_rate/server_main.cc b/system/service/example/heart_rate/server_main.cc index 7423462f0c..f8953f16a4 100644 --- a/system/service/example/heart_rate/server_main.cc +++ b/system/service/example/heart_rate/server_main.cc @@ -19,7 +19,6 @@ #include <base/command_line.h> #include <base/location.h> #include <base/logging.h> -#include <base/message_loop/message_loop.h> #include <base/run_loop.h> #include <binder/IPCThreadState.h> @@ -28,6 +27,7 @@ #include <android/bluetooth/IBluetooth.h> +#include "abstract_message_loop.h" #include "heart_rate_server.h" using android::sp; @@ -85,7 +85,7 @@ int main(int argc, char* argv[]) { // Set up a message loop so that we can schedule timed Heart Rate // notifications. - base::MessageLoop main_loop; + btbase::AbstractMessageLoop main_loop; LOG(INFO) << "Starting GATT Heart Rate Service sample"; diff --git a/system/service/hal/bluetooth_av_interface.cc b/system/service/hal/bluetooth_av_interface.cc index 4700cce4ec..670242f003 100644 --- a/system/service/hal/bluetooth_av_interface.cc +++ b/system/service/hal/bluetooth_av_interface.cc @@ -22,6 +22,7 @@ #include <base/memory/ptr_util.h> #include <base/observer_list.h> +#include "abstract_observer_list.h" #include "service/hal/bluetooth_interface.h" namespace bluetooth { @@ -41,9 +42,9 @@ using shared_mutex_impl = std::shared_timed_mutex; // use unique_lock. If only accessing |g_interface| use shared lock. shared_mutex_impl g_instance_lock; -base::ObserverList<BluetoothAvInterface::A2dpSourceObserver>* +btbase::AbstractObserverList<BluetoothAvInterface::A2dpSourceObserver>* GetA2dpSourceObservers(); -base::ObserverList<BluetoothAvInterface::A2dpSinkObserver>* +btbase::AbstractObserverList<BluetoothAvInterface::A2dpSinkObserver>* GetA2dpSinkObservers(); #define VERIFY_INTERFACE_OR_RETURN(...) \ @@ -250,17 +251,17 @@ class BluetoothAvInterfaceImpl : public BluetoothAvInterface { return A2dpSinkEnable(); } - base::ObserverList<A2dpSourceObserver>* source_observers() { + btbase::AbstractObserverList<A2dpSourceObserver>* source_observers() { return &a2dp_source_observers_; } - base::ObserverList<A2dpSinkObserver>* sink_observers() { + btbase::AbstractObserverList<A2dpSinkObserver>* sink_observers() { return &a2dp_sink_observers_; } private: - base::ObserverList<A2dpSourceObserver> a2dp_source_observers_; - base::ObserverList<A2dpSinkObserver> a2dp_sink_observers_; + btbase::AbstractObserverList<A2dpSourceObserver> a2dp_source_observers_; + btbase::AbstractObserverList<A2dpSinkObserver> a2dp_sink_observers_; const btav_source_interface_t* hal_source_iface_ = nullptr; const btav_sink_interface_t* hal_sink_iface_ = nullptr; @@ -273,14 +274,14 @@ class BluetoothAvInterfaceImpl : public BluetoothAvInterface { namespace { -base::ObserverList<BluetoothAvInterface::A2dpSourceObserver>* +btbase::AbstractObserverList<BluetoothAvInterface::A2dpSourceObserver>* GetA2dpSourceObservers() { CHECK(g_interface); return static_cast<BluetoothAvInterfaceImpl*>(g_interface) ->source_observers(); } -base::ObserverList<BluetoothAvInterface::A2dpSinkObserver>* +btbase::AbstractObserverList<BluetoothAvInterface::A2dpSinkObserver>* GetA2dpSinkObservers() { CHECK(g_interface); return static_cast<BluetoothAvInterfaceImpl*>(g_interface)->sink_observers(); diff --git a/system/service/hal/bluetooth_avrcp_interface.cc b/system/service/hal/bluetooth_avrcp_interface.cc index 02e7316b1d..68746aec04 100644 --- a/system/service/hal/bluetooth_avrcp_interface.cc +++ b/system/service/hal/bluetooth_avrcp_interface.cc @@ -22,6 +22,7 @@ #include <base/logging.h> #include <base/observer_list.h> +#include "abstract_observer_list.h" #include "service/hal/bluetooth_interface.h" #include "service/logging_helpers.h" @@ -51,10 +52,10 @@ shared_mutex_impl g_instance_lock; // Helper for obtaining the observer lists. This is forward declared here // and defined below since it depends on BluetoothInterfaceImpl. -base::ObserverList<BluetoothAvrcpInterface::TargetObserver>* +btbase::AbstractObserverList<BluetoothAvrcpInterface::TargetObserver>* GetTargetObservers(); -base::ObserverList<BluetoothAvrcpInterface::ControlObserver>* +btbase::AbstractObserverList<BluetoothAvrcpInterface::ControlObserver>* GetControlObservers(); #define VERIFY_INTERFACE_OR_RETURN() \ @@ -589,11 +590,11 @@ class BluetoothAvrcpInterfaceImpl : public BluetoothAvrcpInterface { return AvrcpControlEnable(); } - base::ObserverList<TargetObserver>* target_observers() { + btbase::AbstractObserverList<TargetObserver>* target_observers() { return &target_observers_; } - base::ObserverList<ControlObserver>* control_observers() { + btbase::AbstractObserverList<ControlObserver>* control_observers() { return &control_observers_; } @@ -602,8 +603,8 @@ class BluetoothAvrcpInterfaceImpl : public BluetoothAvrcpInterface { // We're not using a base::ObserverListThreadSafe, which it posts observer // events automatically on the origin threads, as we want to avoid that // overhead and simply forward the events to the upper layer. - base::ObserverList<TargetObserver> target_observers_; - base::ObserverList<ControlObserver> control_observers_; + btbase::AbstractObserverList<TargetObserver> target_observers_; + btbase::AbstractObserverList<ControlObserver> control_observers_; // The HAL handle obtained from the shared library. We hold a weak reference // to this since the actual data resides in the shared Bluetooth library. @@ -618,14 +619,14 @@ class BluetoothAvrcpInterfaceImpl : public BluetoothAvrcpInterface { namespace { -base::ObserverList<BluetoothAvrcpInterface::TargetObserver>* +btbase::AbstractObserverList<BluetoothAvrcpInterface::TargetObserver>* GetTargetObservers() { CHECK(g_interface); return static_cast<BluetoothAvrcpInterfaceImpl*>(g_interface) ->target_observers(); } -base::ObserverList<BluetoothAvrcpInterface::ControlObserver>* +btbase::AbstractObserverList<BluetoothAvrcpInterface::ControlObserver>* GetControlObservers() { CHECK(g_interface); return static_cast<BluetoothAvrcpInterfaceImpl*>(g_interface) diff --git a/system/service/hal/bluetooth_gatt_interface.cc b/system/service/hal/bluetooth_gatt_interface.cc index 21f6a887e3..505f3fc1ed 100644 --- a/system/service/hal/bluetooth_gatt_interface.cc +++ b/system/service/hal/bluetooth_gatt_interface.cc @@ -22,6 +22,7 @@ #include <base/logging.h> #include <base/observer_list.h> +#include "abstract_observer_list.h" #include "service/hal/bluetooth_interface.h" #include "service/logging_helpers.h" @@ -51,11 +52,11 @@ shared_mutex_impl g_instance_lock; // Helper for obtaining the observer lists. This is forward declared here // and defined below since it depends on BluetoothInterfaceImpl. -base::ObserverList<BluetoothGattInterface::ScannerObserver>* +btbase::AbstractObserverList<BluetoothGattInterface::ScannerObserver>* GetScannerObservers(); -base::ObserverList<BluetoothGattInterface::ClientObserver>* +btbase::AbstractObserverList<BluetoothGattInterface::ClientObserver>* GetClientObservers(); -base::ObserverList<BluetoothGattInterface::ServerObserver>* +btbase::AbstractObserverList<BluetoothGattInterface::ServerObserver>* GetServerObservers(); #define FOR_EACH_SCANNER_OBSERVER(func) \ @@ -506,15 +507,15 @@ class BluetoothGattInterfaceImpl : public BluetoothGattInterface { return true; } - base::ObserverList<ScannerObserver>* scanner_observers() { + btbase::AbstractObserverList<ScannerObserver>* scanner_observers() { return &scanner_observers_; } - base::ObserverList<ClientObserver>* client_observers() { + btbase::AbstractObserverList<ClientObserver>* client_observers() { return &client_observers_; } - base::ObserverList<ServerObserver>* server_observers() { + btbase::AbstractObserverList<ServerObserver>* server_observers() { return &server_observers_; } @@ -523,9 +524,9 @@ class BluetoothGattInterfaceImpl : public BluetoothGattInterface { // We're not using a base::ObserverListThreadSafe, which it posts observer // events automatically on the origin threads, as we want to avoid that // overhead and simply forward the events to the upper layer. - base::ObserverList<ScannerObserver> scanner_observers_; - base::ObserverList<ClientObserver> client_observers_; - base::ObserverList<ServerObserver> server_observers_; + btbase::AbstractObserverList<ScannerObserver> scanner_observers_; + btbase::AbstractObserverList<ClientObserver> client_observers_; + btbase::AbstractObserverList<ServerObserver> server_observers_; // The HAL handle obtained from the shared library. We hold a weak reference // to this since the actual data resides in the shared Bluetooth library. @@ -536,21 +537,21 @@ class BluetoothGattInterfaceImpl : public BluetoothGattInterface { namespace { -base::ObserverList<BluetoothGattInterface::ScannerObserver>* +btbase::AbstractObserverList<BluetoothGattInterface::ScannerObserver>* GetScannerObservers() { CHECK(g_interface); return static_cast<BluetoothGattInterfaceImpl*>(g_interface) ->scanner_observers(); } -base::ObserverList<BluetoothGattInterface::ClientObserver>* +btbase::AbstractObserverList<BluetoothGattInterface::ClientObserver>* GetClientObservers() { CHECK(g_interface); return static_cast<BluetoothGattInterfaceImpl*>(g_interface) ->client_observers(); } -base::ObserverList<BluetoothGattInterface::ServerObserver>* +btbase::AbstractObserverList<BluetoothGattInterface::ServerObserver>* GetServerObservers() { CHECK(g_interface); return static_cast<BluetoothGattInterfaceImpl*>(g_interface) diff --git a/system/service/hal/bluetooth_interface.cc b/system/service/hal/bluetooth_interface.cc index 049c59ad49..2b01a983ee 100644 --- a/system/service/hal/bluetooth_interface.cc +++ b/system/service/hal/bluetooth_interface.cc @@ -22,6 +22,7 @@ #include <base/logging.h> #include <base/observer_list.h> +#include "abstract_observer_list.h" #include "service/logging_helpers.h" #include "btcore/include/hal_util.h" @@ -52,7 +53,7 @@ shared_mutex_impl g_instance_lock; // Helper for obtaining the observer list. This is forward declared here and // defined below since it depends on BluetoothInterfaceImpl. -base::ObserverList<BluetoothInterface::Observer>* GetObservers(); +btbase::AbstractObserverList<BluetoothInterface::Observer>* GetObservers(); #define FOR_EACH_BLUETOOTH_OBSERVER(func) \ for (auto& observer : *GetObservers()) { \ @@ -269,14 +270,14 @@ class BluetoothInterfaceImpl : public BluetoothInterface { return true; } - base::ObserverList<Observer>* observers() { return &observers_; } + btbase::AbstractObserverList<Observer>* observers() { return &observers_; } private: // List of observers that are interested in notifications from us. We're not // using a base::ObserverListThreadSafe, which it posts observer events // automatically on the origin threads, as we want to avoid that overhead and // simply forward the events to the upper layer. - base::ObserverList<Observer> observers_; + btbase::AbstractObserverList<Observer> observers_; // The HAL handle obtained from the shared library. We hold a weak reference // to this since the actual data resides in the shared Bluetooth library. @@ -289,7 +290,7 @@ namespace { // Helper for obtaining the observer list from the global instance. This // function is NOT thread safe. -base::ObserverList<BluetoothInterface::Observer>* GetObservers() { +btbase::AbstractObserverList<BluetoothInterface::Observer>* GetObservers() { CHECK(g_bluetooth_interface); return static_cast<BluetoothInterfaceImpl*>(g_bluetooth_interface) ->observers(); diff --git a/system/service/hal/fake_bluetooth_av_interface.h b/system/service/hal/fake_bluetooth_av_interface.h index 34aeac8720..ee431b077c 100644 --- a/system/service/hal/fake_bluetooth_av_interface.h +++ b/system/service/hal/fake_bluetooth_av_interface.h @@ -19,6 +19,7 @@ #include <base/macros.h> #include <base/observer_list.h> +#include "abstract_observer_list.h" #include "service/hal/bluetooth_av_interface.h" namespace bluetooth { @@ -88,8 +89,8 @@ class FakeBluetoothAvInterface : public BluetoothAvInterface { const btav_sink_interface_t* GetA2dpSinkHALInterface() override; private: - base::ObserverList<A2dpSourceObserver> a2dp_source_observers_; - base::ObserverList<A2dpSinkObserver> a2dp_sink_observers_; + btbase::AbstractObserverList<A2dpSourceObserver> a2dp_source_observers_; + btbase::AbstractObserverList<A2dpSinkObserver> a2dp_sink_observers_; DISALLOW_COPY_AND_ASSIGN(FakeBluetoothAvInterface); }; diff --git a/system/service/hal/fake_bluetooth_gatt_interface.h b/system/service/hal/fake_bluetooth_gatt_interface.h index 71ee3f5f69..b71d5f43be 100644 --- a/system/service/hal/fake_bluetooth_gatt_interface.h +++ b/system/service/hal/fake_bluetooth_gatt_interface.h @@ -21,6 +21,7 @@ #include <base/macros.h> #include <base/observer_list.h> +#include "abstract_observer_list.h" #include "service/hal/bluetooth_gatt_interface.h" namespace bluetooth { @@ -140,9 +141,9 @@ class FakeBluetoothGattInterface : public BluetoothGattInterface { const btgatt_server_interface_t* GetServerHALInterface() const override; private: - base::ObserverList<ScannerObserver> scanner_observers_; - base::ObserverList<ClientObserver> client_observers_; - base::ObserverList<ServerObserver> server_observers_; + btbase::AbstractObserverList<ScannerObserver> scanner_observers_; + btbase::AbstractObserverList<ClientObserver> client_observers_; + btbase::AbstractObserverList<ServerObserver> server_observers_; std::shared_ptr<BleScannerInterface> scanner_handler_; std::shared_ptr<TestClientHandler> client_handler_; std::shared_ptr<TestServerHandler> server_handler_; diff --git a/system/service/hal/fake_bluetooth_interface.h b/system/service/hal/fake_bluetooth_interface.h index b7dc83259a..93ec076652 100644 --- a/system/service/hal/fake_bluetooth_interface.h +++ b/system/service/hal/fake_bluetooth_interface.h @@ -17,6 +17,7 @@ #include <base/macros.h> #include <base/observer_list.h> +#include "abstract_observer_list.h" #include "service/hal/bluetooth_interface.h" namespace bluetooth { @@ -65,7 +66,7 @@ class FakeBluetoothInterface : public BluetoothInterface { bt_callbacks_t* GetHALCallbacks() const override; private: - base::ObserverList<Observer> observers_; + btbase::AbstractObserverList<Observer> observers_; DISALLOW_COPY_AND_ASSIGN(FakeBluetoothInterface); }; diff --git a/system/service/ipc/binder/ipc_handler_binder.cc b/system/service/ipc/binder/ipc_handler_binder.cc index becd6e82c8..11ff66fc6b 100644 --- a/system/service/ipc/binder/ipc_handler_binder.cc +++ b/system/service/ipc/binder/ipc_handler_binder.cc @@ -18,11 +18,11 @@ #include <base/bind.h> #include <base/logging.h> -#include <base/message_loop/message_loop.h> #include <binder/IPCThreadState.h> #include <binder/IServiceManager.h> #include <binder/ProcessState.h> +#include "abstract_message_loop.h" #include "service/ipc/binder/bluetooth_binder_server.h" using android::defaultServiceManager; @@ -56,7 +56,7 @@ bool IPCHandlerBinder::Run() { // Notify the delegate. We do this in the message loop to avoid reentrancy. if (delegate()) { - base::MessageLoop::current()->task_runner()->PostTask( + btbase::AbstractMessageLoop::current_task_runner()->PostTask( FROM_HERE, base::Bind(&IPCHandlerBinder::NotifyStarted, this)); } diff --git a/system/service/ipc/dbus/bluetooth_adapter.cc b/system/service/ipc/dbus/bluetooth_adapter.cc index 70ee19f188..6831c1b932 100644 --- a/system/service/ipc/dbus/bluetooth_adapter.cc +++ b/system/service/ipc/dbus/bluetooth_adapter.cc @@ -46,6 +46,20 @@ const char kDBusIntrospectMethod[] = "Introspect"; namespace ipc { namespace dbus { +#if defined(BASE_VER) && BASE_VER > 780000 +// New libchrome treats ResponseSender as base::OnceCallback so we need to move +// ownership before calling ::Run() +inline void RunResponse(std::unique_ptr<Response> response, + ExportedObject::ResponseSender& response_sender) { + std::move(response_sender).Run(std::move(response)); +} +#else +inline void RunResponse(std::unique_ptr<Response> response, + ExportedObject::ResponseSender& response_sender) { + response_sender.Run(std::move(response)); +} +#endif + BluetoothAdapter::BluetoothAdapter(scoped_refptr<Bus> bus, bluetooth::Adapter* adapter) : adapter_(adapter) { @@ -73,14 +87,14 @@ void BluetoothAdapter::Enable(MethodCall* method_call, ExportedObject::ResponseSender response_sender) { VLOG(1) << __func__; adapter_->Enable(); - response_sender.Run(Response::FromMethodCall(method_call)); + RunResponse(Response::FromMethodCall(method_call), response_sender); } void BluetoothAdapter::Disable(MethodCall* method_call, ExportedObject::ResponseSender response_sender) { VLOG(1) << __func__; adapter_->Disable(); - response_sender.Run(Response::FromMethodCall(method_call)); + RunResponse(Response::FromMethodCall(method_call), response_sender); } void BluetoothAdapter::Introspect( @@ -90,14 +104,16 @@ void BluetoothAdapter::Introspect( std::string output; if (!base::ReadFileToString(base::FilePath(kBindingsPath), &output)) { PLOG(ERROR) << "Can't read XML bindings from disk:"; - response_sender.Run(ErrorResponse::FromMethodCall( - method_call, "Can't read XML bindings from disk.", "")); + RunResponse(ErrorResponse::FromMethodCall( + method_call, "Can't read XML bindings from disk.", ""), + response_sender); } + std::unique_ptr<Response> response(Response::FromMethodCall(method_call)); MessageWriter writer(response.get()); writer.AppendString(output); - response_sender.Run(std::move(response)); + RunResponse(std::move(response), response_sender); } BluetoothAdapter::~BluetoothAdapter() {} diff --git a/system/service/ipc/dbus/ipc_handler_dbus.cc b/system/service/ipc/dbus/ipc_handler_dbus.cc index c8922d32ed..8abd2449d9 100644 --- a/system/service/ipc/dbus/ipc_handler_dbus.cc +++ b/system/service/ipc/dbus/ipc_handler_dbus.cc @@ -37,7 +37,7 @@ bool IPCHandlerDBus::Run() { dbus_thread_ = new base::Thread("D-Bus Thread"); base::Thread::Options thread_options; - thread_options.message_loop_type = base::MessageLoop::TYPE_IO; + btbase::set_message_loop_type_IO(thread_options); dbus_thread_->StartWithOptions(thread_options); dbus_thread_->task_runner()->PostTask( diff --git a/system/service/ipc/ipc_handler_linux.cc b/system/service/ipc/ipc_handler_linux.cc index ebfae12941..fa7727a87c 100644 --- a/system/service/ipc/ipc_handler_linux.cc +++ b/system/service/ipc/ipc_handler_linux.cc @@ -21,6 +21,7 @@ #include <base/bind.h> +#include "abstract_message_loop.h" #include "osi/include/socket_utils/sockets.h" #include "service/daemon.h" #include "service/ipc/linux_ipc_host.h" @@ -56,8 +57,9 @@ bool IPCHandlerLinux::Run() { return false; } - CHECK(base::MessageLoop::current()); // An origin event loop is required. - origin_task_runner_ = base::MessageLoop::current()->task_runner(); + // An origin event loop is required. + CHECK(btbase::AbstractMessageLoop::current_task_runner()); + origin_task_runner_ = btbase::AbstractMessageLoop::current_task_runner(); if (!android_suffix.empty()) { int server_fd = osi_android_get_control_socket(android_suffix.c_str()); @@ -102,7 +104,8 @@ bool IPCHandlerLinux::Run() { running_ = true; // Set this here before launching the thread. // Start an IO thread and post the listening task. - base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); + base::Thread::Options options; + btbase::set_message_loop_type_IO(options); if (!thread_.StartWithOptions(options)) { LOG(ERROR) << "Failed to start IPCHandlerLinux thread"; running_ = false; diff --git a/system/service/settings.cc b/system/service/settings.cc index af67fbe970..b3dc201431 100644 --- a/system/service/settings.cc +++ b/system/service/settings.cc @@ -16,7 +16,6 @@ #include "service/settings.h" -#include <base/base_switches.h> #include <base/command_line.h> #include <base/logging.h> @@ -24,6 +23,12 @@ namespace bluetooth { +namespace switches { +// Verbose switch that should be part of base_switches but doesn't seem to be +// exported as part of libbase. +const char kV[] = "v"; +}; // namespace switches + Settings::Settings() : initialized_(false), enable_on_start_(false) {} Settings::~Settings() {} @@ -67,7 +72,7 @@ bool Settings::Init() { } // Check for libbase logging switches. These get processed by // logging::InitLogging directly. - else if (iter.first != ::switches::kV) { + else if (iter.first != switches::kV) { LOG(ERROR) << "Unexpected command-line switches found: " << iter.first; return false; } diff --git a/system/service/test/ipc_linux_unittest.cc b/system/service/test/ipc_linux_unittest.cc index 762eb88649..176cd6a320 100644 --- a/system/service/test/ipc_linux_unittest.cc +++ b/system/service/test/ipc_linux_unittest.cc @@ -27,6 +27,7 @@ #include <base/strings/stringprintf.h> #include <gtest/gtest.h> +#include "abstract_message_loop" #include "array_utils.h" #include "service/adapter.h" #include "service/hal/fake_bluetooth_gatt_interface.h" @@ -102,7 +103,7 @@ class IPCLinuxTest : public ::testing::Test { protected: base::AtExitManager exit_manager_; - base::MessageLoop message_loop_; + DEFINE_TEST_TASK_ENV(message_loop_); bluetooth::Settings settings_; std::unique_ptr<bluetooth::Adapter> adapter_; @@ -135,13 +136,13 @@ class TestDelegate : public ipc::IPCManager::Delegate, void OnIPCHandlerStarted(ipc::IPCManager::Type type) override { ASSERT_EQ(ipc::IPCManager::TYPE_LINUX, type); started_count_++; - base::MessageLoop::current()->QuitWhenIdle(); + btbase::AbstractTestMessageLoop::currentIO()->QuitWhenIdle(); } void OnIPCHandlerStopped(ipc::IPCManager::Type type) override { ASSERT_EQ(ipc::IPCManager::TYPE_LINUX, type); stopped_count_++; - base::MessageLoop::current()->QuitWhenIdle(); + btbase::AbstractTestMessageLoop::currentIO()->QuitWhenIdle(); } int started_count() const { return started_count_; } diff --git a/system/service/test/mock_daemon.h b/system/service/test/mock_daemon.h index 9947915bce..1c026221d2 100644 --- a/system/service/test/mock_daemon.h +++ b/system/service/test/mock_daemon.h @@ -18,6 +18,7 @@ #include <gmock/gmock.h> +#include "abstract_message_loop.h" #include "service/daemon.h" namespace bluetooth { @@ -29,7 +30,7 @@ class MockDaemon : public Daemon { ~MockDaemon() override = default; MOCK_CONST_METHOD0(GetSettings, Settings*()); - MOCK_CONST_METHOD0(GetMessageLoop, base::MessageLoop*()); + MOCK_CONST_METHOD0(GetMessageLoop, btbase::AbstractMessageLoop*()); MOCK_METHOD0(StartMainLoop, void()); MOCK_METHOD0(Init, bool()); diff --git a/system/stack/crypto_toolbox/crypto_toolbox.h b/system/stack/crypto_toolbox/crypto_toolbox.h index b445fa24e2..0796833ade 100644 --- a/system/stack/crypto_toolbox/crypto_toolbox.h +++ b/system/stack/crypto_toolbox/crypto_toolbox.h @@ -15,6 +15,7 @@ */ #pragma once +#include <base/logging.h> #include "stack/include/bt_types.h" @@ -61,4 +62,4 @@ inline Octet16 aes_cmac(const Octet16& key, const Octet16& message) { return aes_cmac(key, message.data(), message.size()); } -} // namespace crypto_toolbox
\ No newline at end of file +} // namespace crypto_toolbox |