diff options
author | Peter Qiu <zqiu@google.com> | 2015-09-22 11:25:15 -0700 |
---|---|---|
committer | Peter Qiu <zqiu@google.com> | 2015-09-22 11:59:18 -0700 |
commit | 7a420d3e06aa7fb5eba305dc587624eb58bde7b7 (patch) | |
tree | 20b84c3dd7d25862a1e838374e1a61ccded25a7a | |
parent | 37328b81d1a5042042261f7320480ad31d3a5125 (diff) | |
download | apmanager-7a420d3e06aa7fb5eba305dc587624eb58bde7b7.tar.gz |
Compile apmanager on Android
Noticeable changes to get apmanager to compile on Android:
- Conditional include headers for D-Bus service constants
based on the target platform.
- Use firewalld proxy instead of permission_broker proxy on
Android.
- Use stub shill proxy instead of the real one until libshill-client
is ready.
Bug: 24164800
TEST=Compile apmanager on both Android and Chrome OS
TEST=Run apmanager on Chrome OS device
Change-Id: I7885323796e0043a1e3cc46c129e2736faf4fced
-rw-r--r-- | Android.mk | 135 | ||||
-rw-r--r-- | config.cc | 5 | ||||
-rw-r--r-- | config_unittest.cc | 7 | ||||
-rw-r--r-- | firewall_manager.cc | 16 | ||||
-rw-r--r-- | init.apmanager.rc | 6 | ||||
-rw-r--r-- | manager.cc | 5 | ||||
-rw-r--r-- | run_all_tests.cc | 21 | ||||
-rw-r--r-- | service.cc | 7 | ||||
-rw-r--r-- | service_unittest.cc | 7 | ||||
-rw-r--r-- | shill_manager.cc | 11 | ||||
-rw-r--r-- | shill_stub_proxy.cc | 35 | ||||
-rw-r--r-- | shill_stub_proxy.h | 43 |
12 files changed, 290 insertions, 8 deletions
diff --git a/Android.mk b/Android.mk new file mode 100644 index 0000000..5aabb1c --- /dev/null +++ b/Android.mk @@ -0,0 +1,135 @@ +# +# Copyright (C) 2015 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. +# + +LOCAL_PATH := $(call my-dir) + +# Definitions applying to all targets. Be sure to $(eval) this last. +define apmanager_common + LOCAL_CPP_EXTENSION := .cc + LOCAL_RTTI_FLAG := -frtti + LOCAL_CLANG := true + LOCAL_SHARED_LIBRARIES += \ + libchrome \ + libchrome-dbus \ + libchromeos \ + libchromeos-dbus \ + libchromeos-minijail \ + libdbus \ + libfirewalld-client \ + libminijail \ + libshill-net + LOCAL_C_INCLUDES += \ + $(LOCAL_PATH)/.. \ + external/cros/system_api # D-Bus service constants. + LOCAL_CFLAGS += -Wall -Werror -Wno-unused-parameter + # -Wno-non-virtual-dtor: for generated D-Bus adaptors. + # -Wno-missing-field-initializers: for LAZY_INSTANCE_INITIALIZER. + LOCAL_CPPFLAGS += \ + -Wno-sign-promo \ + -Wno-non-virtual-dtor \ + -Wno-missing-field-initializers +endef + +ifeq ($(HOST_OS),linux) + +# === libapmanager-client (shared library) === +include $(CLEAR_VARS) +LOCAL_MODULE := libapmanager-client +LOCAL_SRC_FILES := \ + dbus_bindings/dbus-service-config.json \ + dbus_bindings/org.chromium.apmanager.Config.dbus-xml \ + dbus_bindings/org.chromium.apmanager.Device.dbus-xml \ + dbus_bindings/org.chromium.apmanager.Manager.dbus-xml \ + dbus_bindings/org.chromium.apmanager.Service.dbus-xml +LOCAL_DBUS_PROXY_PREFIX := apmanager +include $(BUILD_SHARED_LIBRARY) + +# === libapmanager (static library) === +include $(CLEAR_VARS) +LOCAL_MODULE := libapmanager +LOCAL_SRC_FILES := \ + dbus_bindings/dbus-service-config.json \ + dbus_bindings/org.chromium.apmanager.Config.dbus-xml \ + dbus_bindings/org.chromium.apmanager.Device.dbus-xml \ + dbus_bindings/org.chromium.apmanager.Manager.dbus-xml \ + dbus_bindings/org.chromium.apmanager.Service.dbus-xml \ + config.cc \ + daemon.cc \ + device.cc \ + device_info.cc \ + dhcp_server.cc \ + dhcp_server_factory.cc \ + event_dispatcher.cc \ + file_writer.cc \ + firewall_manager.cc \ + firewalld_dbus_proxy.cc \ + hostapd_monitor.cc \ + manager.cc \ + process_factory.cc \ + service.cc \ + shill_manager.cc \ + shill_stub_proxy.cc +$(eval $(apmanager_common)) +include $(BUILD_STATIC_TEST_LIBRARY) + +# === apmanager === +include $(CLEAR_VARS) +LOCAL_MODULE := apmanager +#LOCAL_REQUIRED_MODULES := init.apmanager.rc +LOCAL_SRC_FILES := \ + main.cc +LOCAL_STATIC_LIBRARIES := libapmanager +LOCAL_C_INCLUDES += external/gtest/include +$(eval $(apmanager_common)) +include $(BUILD_EXECUTABLE) + +# === init.apmanager.rc (brillo only) === +ifdef TARGET_COPY_OUT_INITRCD +include $(CLEAR_VARS) +LOCAL_MODULE := init.apmanager.rc +LOCAL_SRC_FILES := $(LOCAL_MODULE) +LOCAL_MODULE_CLASS := ETC +LOCAL_MODULE_PATH := $(PRODUCT_OUT)/$(TARGET_COPY_OUT_INITRCD) +include $(BUILD_PREBUILT) +endif + +# === unittest === +include $(CLEAR_VARS) +LOCAL_MODULE := apmanager_unittest +LOCAL_SRC_FILES := \ + config_unittest.cc \ + device_info_unittest.cc \ + device_unittest.cc \ + dhcp_server_unittest.cc \ + hostapd_monitor_unittest.cc \ + manager_unittest.cc \ + mock_config.cc \ + mock_device.cc \ + mock_dhcp_server.cc \ + mock_dhcp_server_factory.cc \ + mock_event_dispatcher.cc \ + mock_file_writer.cc \ + mock_hostapd_monitor.cc \ + mock_manager.cc \ + mock_process_factory.cc \ + mock_service.cc \ + service_unittest.cc \ + run_all_tests.cc +LOCAL_STATIC_LIBRARIES := libapmanager libgmock +$(eval $(apmanager_common)) +include $(BUILD_NATIVE_TEST) + +endif # HOST_OS == linux @@ -17,7 +17,12 @@ #include "apmanager/config.h" #include <base/strings/stringprintf.h> + +#if !defined(__ANDROID__) #include <chromeos/dbus/service_constants.h> +#else +#include "dbus/apmanager/dbus-constants.h" +#endif // __ANDROID__ #include "apmanager/daemon.h" #include "apmanager/device.h" diff --git a/config_unittest.cc b/config_unittest.cc index 36aed97..bb25c54 100644 --- a/config_unittest.cc +++ b/config_unittest.cc @@ -20,10 +20,15 @@ #include <base/strings/string_util.h> #include <base/strings/stringprintf.h> -#include <chromeos/dbus/service_constants.h> #include <gmock/gmock.h> #include <gtest/gtest.h> +#if !defined(__ANDROID__) +#include <chromeos/dbus/service_constants.h> +#else +#include "dbus/apmanager/dbus-constants.h" +#endif + #include "apmanager/mock_device.h" #include "apmanager/mock_manager.h" diff --git a/firewall_manager.cc b/firewall_manager.cc index 765b2b5..412f007 100644 --- a/firewall_manager.cc +++ b/firewall_manager.cc @@ -19,8 +19,11 @@ #include <base/bind.h> #include <chromeos/errors/error.h> -// TODO(zqiu): should put this under a compiler flag. +#if !defined(__ANDROID__) #include "apmanager/permission_broker_dbus_proxy.h" +#else +#include "apmanager/firewalld_dbus_proxy.h" +#endif // __ANDROID__ using std::string; @@ -36,7 +39,7 @@ FirewallManager::~FirewallManager() {} void FirewallManager::Init(const scoped_refptr<dbus::Bus>& bus) { CHECK(!firewall_proxy_) << "Already started"; - // TODO(zqiu): should put this under a compiler flag. +#if !defined(__ANDROID__) firewall_proxy_.reset( new PermissionBrokerDBusProxy( bus, @@ -44,6 +47,15 @@ void FirewallManager::Init(const scoped_refptr<dbus::Bus>& bus) { weak_factory_.GetWeakPtr()), base::Bind(&FirewallManager::OnFirewallServiceVanished, weak_factory_.GetWeakPtr()))); +#else + firewall_proxy_.reset( + new FirewalldDBusProxy( + bus, + base::Bind(&FirewallManager::OnFirewallServiceAppeared, + weak_factory_.GetWeakPtr()), + base::Bind(&FirewallManager::OnFirewallServiceVanished, + weak_factory_.GetWeakPtr()))); +#endif // __ANDROID__ } void FirewallManager::RequestDHCPPortAccess(const std::string& interface) { diff --git a/init.apmanager.rc b/init.apmanager.rc new file mode 100644 index 0000000..4947de9 --- /dev/null +++ b/init.apmanager.rc @@ -0,0 +1,6 @@ +service apmanager /system/bin/apmanager + class main + user system + group system dbus net_admin net_raw + seclabel u:r:brillo:s0 + disabled @@ -17,7 +17,12 @@ #include "apmanager/manager.h" #include <base/bind.h> + +#if !defined(__ANDROID__) #include <chromeos/dbus/service_constants.h> +#else +#include "dbus/apmanager/dbus-constants.h" +#endif // __ANDROID__ using chromeos::dbus_utils::AsyncEventSequencer; using chromeos::dbus_utils::ExportedObjectManager; diff --git a/run_all_tests.cc b/run_all_tests.cc new file mode 100644 index 0000000..243bc95 --- /dev/null +++ b/run_all_tests.cc @@ -0,0 +1,21 @@ +// +// Copyright (C) 2015 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 <gtest/gtest.h> + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} @@ -19,9 +19,14 @@ #include <signal.h> #include <base/strings/stringprintf.h> -#include <chromeos/dbus/service_constants.h> #include <chromeos/errors/error.h> +#if !defined(__ANDROID__) +#include <chromeos/dbus/service_constants.h> +#else +#include "dbus/apmanager/dbus-constants.h" +#endif // __ANDROID__ + #include "apmanager/manager.h" using chromeos::dbus_utils::AsyncEventSequencer; diff --git a/service_unittest.cc b/service_unittest.cc index 6870c75..db13d80 100644 --- a/service_unittest.cc +++ b/service_unittest.cc @@ -20,11 +20,16 @@ #include <base/strings/string_util.h> #include <base/strings/stringprintf.h> -#include <chromeos/dbus/service_constants.h> #include <chromeos/process_mock.h> #include <gmock/gmock.h> #include <gtest/gtest.h> +#if !defined(__ANDROID__) +#include <chromeos/dbus/service_constants.h> +#else +#include "dbus/apmanager/dbus-constants.h" +#endif // __ANDROID__ + #include "apmanager/mock_config.h" #include "apmanager/mock_dhcp_server.h" #include "apmanager/mock_dhcp_server_factory.h" diff --git a/shill_manager.cc b/shill_manager.cc index c39db86..ed97211 100644 --- a/shill_manager.cc +++ b/shill_manager.cc @@ -17,11 +17,13 @@ #include "apmanager/shill_manager.h" #include <base/bind.h> -#include <chromeos/dbus/service_constants.h> #include <chromeos/errors/error.h> -// TODO(zqiu): move this to control interface. +#if !defined(__ANDROID__) #include "apmanager/shill_dbus_proxy.h" +#else +#include "apmanager/shill_stub_proxy.h" +#endif // __ANDROID__ using std::string; @@ -33,7 +35,7 @@ ShillManager::~ShillManager() {} void ShillManager::Init(const scoped_refptr<dbus::Bus>& bus) { CHECK(!shill_proxy_) << "Already init"; - // TODO(zqiu): use control interface for proxy creation. +#if !defined(__ANDROID__) shill_proxy_.reset( new ShillDBusProxy( bus, @@ -41,6 +43,9 @@ void ShillManager::Init(const scoped_refptr<dbus::Bus>& bus) { weak_factory_.GetWeakPtr()), base::Bind(&ShillManager::OnShillServiceVanished, weak_factory_.GetWeakPtr()))); +#else + shill_proxy_.reset(new ShillStubProxy()); +#endif // __ANDROID__ } void ShillManager::ClaimInterface(const string& interface_name) { diff --git a/shill_stub_proxy.cc b/shill_stub_proxy.cc new file mode 100644 index 0000000..f6eec63 --- /dev/null +++ b/shill_stub_proxy.cc @@ -0,0 +1,35 @@ +// +// Copyright (C) 2015 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 "apmanager/shill_stub_proxy.h" + +using std::string; + +namespace apmanager { + +ShillStubProxy::ShillStubProxy() {} + +ShillStubProxy::~ShillStubProxy() {} + +bool ShillStubProxy::ClaimInterface(const string& interface_name) { + return true; +} + +bool ShillStubProxy::ReleaseInterface(const string& interface_name) { + return true; +} + +} // namespace apmanager diff --git a/shill_stub_proxy.h b/shill_stub_proxy.h new file mode 100644 index 0000000..cfe0ad0 --- /dev/null +++ b/shill_stub_proxy.h @@ -0,0 +1,43 @@ +// +// Copyright (C) 2015 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. +// + +#ifndef APMANAGER_SHILL_STUB_PROXY_H_ +#define APMANAGER_SHILL_STUB_PROXY_H_ + +#include <string> + +#include <base/macros.h> + +#include "apmanager/shill_proxy_interface.h" + +namespace apmanager { + +class ShillStubProxy : public ShillProxyInterface { + public: + ShillStubProxy(); + ~ShillStubProxy() override; + + // Implementation of ShillProxyInterface. + bool ClaimInterface(const std::string& interface_name) override; + bool ReleaseInterface(const std::string& interface_name) override; + + private: + DISALLOW_COPY_AND_ASSIGN(ShillStubProxy); +}; + +} // namespace apmanager + +#endif // APMANAGER_SHILL_STUB_PROXY_H_ |