From 839938c309ce18124e5754aca45b26e79658d207 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Mon, 1 Nov 2021 16:40:02 -0700 Subject: delete HIDL adapters HIDL adapters were designed in order to demote an implementation from version x.(y+1) to x.y. However: - they were never used - we rely on fwk-only OTA tests to test framework - they never worked properly for nested interfaces (HIDL is being deprecated, and the AIDL Delegate solution technically suffers from the same solution, but sub-interfaces can be wrapped by clients) Bug: N/A Test: build only Change-Id: Ib9f4207edbf4c8778b4fd41c94347e1b07720f8e --- adapter/Android.bp | 45 ----- adapter/HidlBinderAdapter.cpp | 237 ------------------------ adapter/include/hidladapter/HidlBinderAdapter.h | 52 ------ 3 files changed, 334 deletions(-) delete mode 100644 adapter/Android.bp delete mode 100644 adapter/HidlBinderAdapter.cpp delete mode 100644 adapter/include/hidladapter/HidlBinderAdapter.h diff --git a/adapter/Android.bp b/adapter/Android.bp deleted file mode 100644 index 83609ff..0000000 --- a/adapter/Android.bp +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2017 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. - -package { - // See: http://go/android-license-faq - // A large-scale-change added 'default_applicable_licenses' to import - // all of the 'license_kinds' from "system_libhidl_license" - // to get the below license kinds: - // SPDX-license-identifier-Apache-2.0 - default_applicable_licenses: ["system_libhidl_license"], -} - -cc_library { - name: "libhidladapter", - defaults: ["libhidl-defaults"], - vendor_available: true, - product_available: true, - // TODO(b/153609531): remove when no longer needed. - native_bridge_supported: true, - srcs: [ - "HidlBinderAdapter.cpp" - ], - export_include_dirs: ["include"], - shared_libs: [ - "libbase", - "libhidlbase", - "liblog", - "libutils", - ], - export_shared_lib_headers: [ - "libhidlbase", - "libutils", - ], -} diff --git a/adapter/HidlBinderAdapter.cpp b/adapter/HidlBinderAdapter.cpp deleted file mode 100644 index ed6dad1..0000000 --- a/adapter/HidlBinderAdapter.cpp +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright (C) 2017 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 - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -namespace android { -namespace hardware { -namespace details { - -using android::base::SetProperty; -using android::base::WaitForProperty; - -const static std::string kDeactivateProp = "test.hidl.adapters.deactivated"; - -int usage(const std::string& me) { - std::cerr << "usage: " << me - << " [-p|P] [-n instance-name] interface-name instance-name number-of-threads." - << std::endl; - std::cerr << " -p: stop based on property " << kDeactivateProp << "and reset it." - << std::endl; - std::cerr << " -P: stop based on interface specific property " << kDeactivateProp - << ".." << std::endl; - std::cerr - << " -n instance-name: register as a different instance name (does not de-register)" - << std::endl; - return EINVAL; -} - -enum class StopMethod { - NONE, - ALL, - SPECIFIC, -}; - -struct Args { - StopMethod stopMethod = StopMethod::NONE; - std::string interface; // e.x. IFoo - std::string instanceName; // e.x. default - int threadNumber; - std::string registerInstanceName; // e.x. default -}; - -bool processArguments(int argc, char** argv, Args* args) { - int c; - while ((c = getopt(argc, argv, "pPn:")) != -1) { - switch (c) { - case 'p': { - args->stopMethod = StopMethod::ALL; - break; - } - case 'P': { - args->stopMethod = StopMethod::SPECIFIC; - break; - } - case 'n': { - args->registerInstanceName = optarg; - break; - } - default: { return false; } - } - } - - argc -= optind; - argv += optind; - - if (argc != 3) { - std::cerr << "ERROR: requires exactly three positional arguments for " - "interface, instance name, and number of threads, but " - << argc << " provided." << std::endl; - return false; - } - - args->interface = argv[0]; - args->instanceName = argv[1]; - args->threadNumber = std::stoi(argv[2]); - - if (args->threadNumber <= 0) { - std::cerr << "ERROR: invalid thread number " << args->threadNumber - << " must be a positive integer." << std::endl; - return false; - } - - if (args->registerInstanceName.empty()) { - args->registerInstanceName = args->instanceName; - } - - return true; -} - -// only applies for -p argument -void waitForAdaptersDeactivated(const std::string& property) { - using std::literals::chrono_literals::operator""s; - - while (!WaitForProperty(property, "true", 30s)) { - // Log this so that when using this option on testing devices, there is - // a clear indication if adapters are not properly stopped - LOG(WARNING) << "Adapter use in progress. Waiting for stop based on 'true' " << property; - } - - SetProperty(property, "false"); -} - -int adapterMain(const std::string& package, int argc, char** argv, - const AdaptersFactory& adapters) { - using android::hardware::configureRpcThreadpool; - using android::hidl::base::V1_0::IBase; - using android::hidl::manager::V1_0::IServiceManager; - - const std::string& me = argc > 0 ? argv[0] : "(error)"; - - Args args; - if (!processArguments(argc, argv, &args)) { - return usage(me); - } - - std::string interfaceName = package + "::" + args.interface; - - auto it = adapters.find(interfaceName); - if (it == adapters.end()) { - std::cerr << "ERROR: could not resolve " << interfaceName << "." << std::endl; - return 1; - } - - std::cout << "Trying to adapt down " << interfaceName << "/" << args.instanceName << " to " - << args.registerInstanceName << std::endl; - - configureRpcThreadpool(args.threadNumber, false /* callerWillJoin */); - - sp manager = IServiceManager::getService(); - if (manager == nullptr) { - std::cerr << "ERROR: could not retrieve service manager." << std::endl; - return 1; - } - - sp implementation = manager->get(interfaceName, args.instanceName).withDefault(nullptr); - if (implementation == nullptr) { - std::cerr << "ERROR: could not retrieve desired implementation" << std::endl; - return 1; - } - - sp adapter = it->second(implementation); - if (adapter == nullptr) { - std::cerr << "ERROR: could not create adapter." << std::endl; - return 1; - } - - bool replaced = manager->add(args.registerInstanceName, adapter).withDefault(false); - if (!replaced) { - std::cerr << "ERROR: could not register the service with the service manager." << std::endl; - return 1; - } - - switch (args.stopMethod) { - case StopMethod::NONE: { - std::cout << "Press any key to disassociate adapter." << std::endl; - getchar(); - break; - }; - case StopMethod::SPECIFIC: { - const std::string property = - kDeactivateProp + "." + interfaceName + "." + args.registerInstanceName; - std::cout << "Set " << property << " to true to deactivate." << std::endl; - waitForAdaptersDeactivated(property); - break; - }; - case StopMethod::ALL: { - std::cout << "Set " << kDeactivateProp << " to true to deactivate." << std::endl; - waitForAdaptersDeactivated(kDeactivateProp); - break; - }; - } - - // automatically unregistered on process exit if it is a new instance name - if (args.registerInstanceName == args.instanceName) { - bool restored = manager->add(args.instanceName, implementation).withDefault(false); - if (!restored) { - std::cerr << "ERROR: could not re-register interface with the service manager." - << std::endl; - return 1; - } - } - - std::cout << "Success." << std::endl; - - return 0; -} - -// If an interface is adapted to 1.0, it can then not be adapted to 1.1 in the same process. -// This poses a problem in the following scenario: -// auto interface = new V1_1::implementation::IFoo; -// hidlObject1_0->foo(interface) // adaptation set at 1.0 -// hidlObject1_1->bar(interface) // adaptation still is 1.0 -// This could be solved by keeping a map of IBase,fqName -> IBase, but then you end up -// with multiple names for the same interface. -sp adaptWithDefault(const sp& something, - const std::function()>& makeDefault) { - static std::map, sp> sAdapterMap; - - if (something == nullptr) { - return something; - } - - auto it = sAdapterMap.find(something); - if (it == sAdapterMap.end()) { - it = sAdapterMap.insert(it, {something, makeDefault()}); - } - - return it->second; -} - -} // namespace details -} // namespace hardware -} // namespace android diff --git a/adapter/include/hidladapter/HidlBinderAdapter.h b/adapter/include/hidladapter/HidlBinderAdapter.h deleted file mode 100644 index 46df554..0000000 --- a/adapter/include/hidladapter/HidlBinderAdapter.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2017 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 -#include - -#include - -namespace android { -namespace hardware { - -namespace details { - -using IBase = ::android::hidl::base::V1_0::IBase; - -// AdapterFactory(impl) -> adapter -using AdapterFactory = std::function(sp)>; -// AdaptersFactory(package@interface)(impl) -> adapter -using AdaptersFactory = std::map; - -int adapterMain(const std::string& package, int argc, char** argv, const AdaptersFactory& adapters); - -sp adaptWithDefault(const sp& something, - const std::function()>& makeDefault); - -} // namespace details - -template -int adapterMain(const std::string& package, int argc, char** argv) { - return details::adapterMain( - package, argc, argv, - {{Adapters::Pure::descriptor, [](sp<::android::hidl::base::V1_0::IBase> base) { - return details::adaptWithDefault( - base, [&] { return new Adapters(Adapters::Pure::castFrom(base)); }); - }}...}); -} - -} // namespace hardware -} // namespace android \ No newline at end of file -- cgit v1.2.3