diff options
Diffstat (limited to 'transport')
24 files changed, 467 insertions, 198 deletions
diff --git a/transport/Android.bp b/transport/Android.bp index 86603ee..10f31a7 100644 --- a/transport/Android.bp +++ b/transport/Android.bp @@ -12,6 +12,15 @@ // 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"], +} + hidl_package_root { name: "android.hidl", } diff --git a/transport/HidlLazyUtils.cpp b/transport/HidlLazyUtils.cpp index 08ed676..c5f8c74 100644 --- a/transport/HidlLazyUtils.cpp +++ b/transport/HidlLazyUtils.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#define LOG_TAG "HidlLazyUtils" + #include <hidl/HidlLazyUtils.h> #include <hidl/HidlTransportSupport.h> @@ -29,55 +31,85 @@ namespace details { using ::android::hidl::base::V1_0::IBase; class ClientCounterCallback : public ::android::hidl::manager::V1_2::IClientCallback { - public: - ClientCounterCallback() : mNumConnectedServices(0) {} + public: + ClientCounterCallback() {} bool addRegisteredService(const sp<IBase>& service, const std::string& name); - protected: + bool tryUnregisterLocked(); + + void reRegisterLocked(); + + void setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback); + + protected: Return<void> onClients(const sp<IBase>& service, bool clients) override; - private: + private: + struct Service { + sp<IBase> service; + std::string name; + bool clients = false; + // Used to keep track of unregistered services to allow re-registry + bool registered = true; + }; + + /** + * Looks up service that is guaranteed to be registered (service from + * onClients). + */ + Service& assertRegisteredServiceLocked(const sp<IBase>& service); + /** * Registers or re-registers services. Returns whether successful. */ - bool registerService(const sp<IBase>& service, const std::string& name); + bool registerServiceLocked(const sp<IBase>& service, const std::string& name); /** * Unregisters all services that we can. If we can't unregister all, re-register other * services. */ - void tryShutdown(); + void tryShutdownLocked(); /** - * Counter of the number of services that currently have at least one client. + * For below. */ - size_t mNumConnectedServices; + std::mutex mMutex; - struct Service { - sp<IBase> service; - std::string name; - }; /** * Number of services that have been registered. */ std::vector<Service> mRegisteredServices; + + /** + * Callback for reporting the number of services with clients. + */ + std::function<bool(bool)> mActiveServicesCallback; + + /** + * Previous value passed to the active services callback. + */ + std::optional<bool> mPreviousHasClients; }; class LazyServiceRegistrarImpl { - public: + public: LazyServiceRegistrarImpl() : mClientCallback(new ClientCounterCallback) {} status_t registerService(const sp<::android::hidl::base::V1_0::IBase>& service, const std::string& name); + bool tryUnregister(); + void reRegister(); + void setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback); - private: + private: sp<ClientCounterCallback> mClientCallback; }; bool ClientCounterCallback::addRegisteredService(const sp<IBase>& service, const std::string& name) { - bool success = registerService(service, name); + std::lock_guard<std::mutex> lock(mMutex); + bool success = registerServiceLocked(service, name); if (success) { mRegisteredServices.push_back({service, name}); @@ -86,7 +118,19 @@ bool ClientCounterCallback::addRegisteredService(const sp<IBase>& service, return success; } -bool ClientCounterCallback::registerService(const sp<IBase>& service, const std::string& name) { +ClientCounterCallback::Service& ClientCounterCallback::assertRegisteredServiceLocked( + const sp<IBase>& service) { + for (Service& registered : mRegisteredServices) { + if (registered.service != service) continue; + return registered; + } + LOG(FATAL) << "Got callback on service " << getDescriptor(service.get()) + << " which we did not register."; + __builtin_unreachable(); +} + +bool ClientCounterCallback::registerServiceLocked(const sp<IBase>& service, + const std::string& name) { auto manager = hardware::defaultServiceManager1_2(); const std::string descriptor = getDescriptor(service.get()); @@ -108,62 +152,99 @@ bool ClientCounterCallback::registerService(const sp<IBase>& service, const std: return true; } -/** - * onClients is oneway, so no need to worry about multi-threading. Note that this means multiple - * invocations could occur on different threads however. - */ Return<void> ClientCounterCallback::onClients(const sp<::android::hidl::base::V1_0::IBase>& service, bool clients) { - if (clients) { - mNumConnectedServices++; - } else { - mNumConnectedServices--; + std::lock_guard<std::mutex> lock(mMutex); + Service& registered = assertRegisteredServiceLocked(service); + if (registered.clients == clients) { + LOG(FATAL) << "Process already thought " << getDescriptor(service.get()) << "/" + << registered.name << " had clients: " << registered.clients + << " but hwservicemanager has notified has clients: " << clients; + } + registered.clients = clients; + + size_t numWithClients = 0; + for (const Service& registered : mRegisteredServices) { + if (registered.clients) numWithClients++; } - LOG(INFO) << "Process has " << mNumConnectedServices << " (of " << mRegisteredServices.size() + LOG(INFO) << "Process has " << numWithClients << " (of " << mRegisteredServices.size() << " available) client(s) in use after notification " << getDescriptor(service.get()) - << " has clients: " << clients; + << "/" << registered.name << " has clients: " << clients; + + bool handledInCallback = false; + if (mActiveServicesCallback != nullptr) { + bool hasClients = numWithClients != 0; + if (hasClients != mPreviousHasClients) { + handledInCallback = mActiveServicesCallback(hasClients); + mPreviousHasClients = hasClients; + } + } - if (mNumConnectedServices == 0) { - tryShutdown(); + // If there is no callback defined or the callback did not handle this + // client count change event, try to shutdown the process if its services + // have no clients. + if (!handledInCallback && numWithClients == 0) { + tryShutdownLocked(); } return Status::ok(); } -void ClientCounterCallback::tryShutdown() { - LOG(INFO) << "Trying to exit HAL. No clients in use for any service in process."; - +bool ClientCounterCallback::tryUnregisterLocked() { auto manager = hardware::defaultServiceManager1_2(); - auto unRegisterIt = mRegisteredServices.begin(); - for (; unRegisterIt != mRegisteredServices.end(); ++unRegisterIt) { - auto& entry = (*unRegisterIt); - + for (Service& entry : mRegisteredServices) { const std::string descriptor = getDescriptor(entry.service.get()); bool success = manager->tryUnregister(descriptor, entry.name, entry.service); if (!success) { LOG(INFO) << "Failed to unregister HAL " << descriptor << "/" << entry.name; - break; + return false; } - } - if (unRegisterIt == mRegisteredServices.end()) { - LOG(INFO) << "Unregistered all clients and exiting"; - exit(EXIT_SUCCESS); + // Mark the entry unregistered, but do not remove it (may still be re-registered) + entry.registered = false; } - for (auto reRegisterIt = mRegisteredServices.begin(); reRegisterIt != unRegisterIt; - reRegisterIt++) { - auto& entry = (*reRegisterIt); + return true; +} + +void ClientCounterCallback::reRegisterLocked() { + for (Service& entry : mRegisteredServices) { + // re-register entry if not already registered + if (entry.registered) { + continue; + } - // re-register entry - if (!registerService(entry.service, entry.name)) { + if (!registerServiceLocked(entry.service, entry.name)) { // Must restart. Otherwise, clients will never be able to get ahold of this service. LOG(FATAL) << "Bad state: could not re-register " << getDescriptor(entry.service.get()); } + + entry.registered = true; + } +} + +void ClientCounterCallback::tryShutdownLocked() { + LOG(INFO) << "Trying to exit HAL. No clients in use for any service in process."; + + if (tryUnregisterLocked()) { + LOG(INFO) << "Unregistered all clients and exiting"; + exit(EXIT_SUCCESS); } + + // At this point, we failed to unregister some of the services, leaving the + // server in an inconsistent state. Re-register all services that were + // unregistered by tryUnregisterLocked(). + reRegisterLocked(); +} + +void ClientCounterCallback::setActiveServicesCallback( + const std::function<bool(bool)>& activeServicesCallback) { + std::lock_guard<std::mutex> lock(mMutex); + + mActiveServicesCallback = activeServicesCallback; } status_t LazyServiceRegistrarImpl::registerService( @@ -175,6 +256,23 @@ status_t LazyServiceRegistrarImpl::registerService( return ::android::OK; } +bool LazyServiceRegistrarImpl::tryUnregister() { + // see comments in header, this should only be called from the active + // services callback, see also b/191781736 + return mClientCallback->tryUnregisterLocked(); +} + +void LazyServiceRegistrarImpl::reRegister() { + // see comments in header, this should only be called from the active + // services callback, see also b/191781736 + mClientCallback->reRegisterLocked(); +} + +void LazyServiceRegistrarImpl::setActiveServicesCallback( + const std::function<bool(bool)>& activeServicesCallback) { + mClientCallback->setActiveServicesCallback(activeServicesCallback); +} + } // namespace details LazyServiceRegistrar::LazyServiceRegistrar() { @@ -191,5 +289,18 @@ status_t LazyServiceRegistrar::registerService( return mImpl->registerService(service, name); } +bool LazyServiceRegistrar::tryUnregister() { + return mImpl->tryUnregister(); +} + +void LazyServiceRegistrar::reRegister() { + mImpl->reRegister(); +} + +void LazyServiceRegistrar::setActiveServicesCallback( + const std::function<bool(bool)>& activeServicesCallback) { + mImpl->setActiveServicesCallback(activeServicesCallback); +} + } // namespace hardware } // namespace android diff --git a/transport/HidlTransportSupport.cpp b/transport/HidlTransportSupport.cpp index e645cd0..d0ac243 100644 --- a/transport/HidlTransportSupport.cpp +++ b/transport/HidlTransportSupport.cpp @@ -128,12 +128,7 @@ bool interfacesEqual(const sp<IBase>& left, const sp<IBase>& right) { namespace details { int32_t getPidIfSharable() { -#if LIBHIDL_TARGET_DEBUGGABLE return getpid(); -#else - using android::hidl::manager::V1_0::IServiceManager; - return static_cast<int32_t>(IServiceManager::PidConstant::NO_PID); -#endif } } // namespace details diff --git a/transport/ServiceManagement.cpp b/transport/ServiceManagement.cpp index 8f59f38..c638279 100644 --- a/transport/ServiceManagement.cpp +++ b/transport/ServiceManagement.cpp @@ -87,7 +87,7 @@ static void waitForHwServiceManager() { static std::string binaryName() { std::ifstream ifs("/proc/self/cmdline"); std::string cmdline; - if (!ifs.is_open()) { + if (!ifs) { return ""; } ifs >> cmdline; @@ -106,7 +106,7 @@ static std::string packageWithoutVersion(const std::string& packageAndVersion) { return packageAndVersion.substr(0, at); } -static void tryShortenProcessName(const std::string& descriptor) { +__attribute__((noinline)) static void tryShortenProcessName(const std::string& descriptor) { const static std::string kTasks = "/proc/self/task/"; // make sure that this binary name is in the same package @@ -135,17 +135,17 @@ static void tryShortenProcessName(const std::string& descriptor) { if (dp->d_name[0] == '.') continue; std::fstream fs(kTasks + dp->d_name + "/comm"); - if (!fs.is_open()) { + if (!fs) { ALOGI("Could not rename process, failed read comm for %s.", dp->d_name); continue; } std::string oldComm; - fs >> oldComm; + if (!(fs >> oldComm)) continue; // don't rename if it already has an explicit name if (base::StartsWith(descriptor, oldComm)) { - fs.seekg(0, fs.beg); + if (!fs.seekg(0, fs.beg)) continue; fs << newName; } } @@ -153,45 +153,41 @@ static void tryShortenProcessName(const std::string& descriptor) { namespace details { -/* - * Returns the age of the current process by reading /proc/self/stat and comparing starttime to the - * current time. This is useful for measuring how long it took a HAL to register itself. - */ -static long getProcessAgeMs() { - constexpr const int PROCFS_STAT_STARTTIME_INDEX = 21; - std::string content; - android::base::ReadFileToString("/proc/self/stat", &content, false); - auto stats = android::base::Split(content, " "); - if (stats.size() <= PROCFS_STAT_STARTTIME_INDEX) { - LOG(INFO) << "Could not read starttime from /proc/self/stat"; - return -1; - } - const std::string& startTimeString = stats[PROCFS_STAT_STARTTIME_INDEX]; - static const int64_t ticksPerSecond = sysconf(_SC_CLK_TCK); - const int64_t uptime = android::uptimeMillis(); - - unsigned long long startTimeInClockTicks = 0; - if (android::base::ParseUint(startTimeString, &startTimeInClockTicks)) { - long startTimeMs = 1000ULL * startTimeInClockTicks / ticksPerSecond; - return uptime - startTimeMs; - } - return -1; +#ifdef ENFORCE_VINTF_MANIFEST +static constexpr bool kEnforceVintfManifest = true; +#else +static constexpr bool kEnforceVintfManifest = false; +#endif + +static bool* getTrebleTestingOverridePtr() { + static bool gTrebleTestingOverride = false; + return &gTrebleTestingOverride; } -static void onRegistrationImpl(const std::string& descriptor, const std::string& instanceName) { - long halStartDelay = getProcessAgeMs(); - if (halStartDelay >= 0) { - // The "start delay" printed here is an estimate of how long it took the HAL to go from - // process creation to registering itself as a HAL. Actual start time could be longer - // because the process might not have joined the threadpool yet, so it might not be ready to - // process transactions. - LOG(INFO) << "Registered " << descriptor << "/" << instanceName << " (start delay of " - << halStartDelay << "ms)"; +void setTrebleTestingOverride(bool testingOverride) { + *getTrebleTestingOverridePtr() = testingOverride; +} + +static bool isDebuggable() { + static bool debuggable = base::GetBoolProperty("ro.debuggable", false); + return debuggable; +} + +static inline bool isTrebleTestingOverride() { + if (kEnforceVintfManifest && !isDebuggable()) { + // don't allow testing override in production + return false; } + return *getTrebleTestingOverridePtr(); +} + +static void onRegistrationImpl(const std::string& descriptor, const std::string& instanceName) { + LOG(INFO) << "Registered " << descriptor << "/" << instanceName; tryShortenProcessName(descriptor); } +// only used by prebuilts - should be able to remove void onRegistration(const std::string& packageName, const std::string& interfaceName, const std::string& instanceName) { return onRegistrationImpl(packageName + "::" + interfaceName, instanceName); @@ -371,10 +367,7 @@ struct PassthroughServiceManager : IServiceManager1_1 { #endif }; -#ifdef LIBHIDL_TARGET_DEBUGGABLE - const char* env = std::getenv("TREBLE_TESTING_OVERRIDE"); - const bool trebleTestingOverride = env && !strcmp(env, "true"); - if (trebleTestingOverride) { + if (details::isTrebleTestingOverride()) { // Load HAL implementations that are statically linked handle = dlopen(nullptr, dlMode); if (handle == nullptr) { @@ -385,7 +378,6 @@ struct PassthroughServiceManager : IServiceManager1_1 { return; } } -#endif for (const std::string& path : paths) { std::vector<std::string> libs = findFiles(path, prefix, ".so"); @@ -424,18 +416,27 @@ struct PassthroughServiceManager : IServiceManager1_1 { *(void **)(&generator) = dlsym(handle, sym.c_str()); if(!generator) { const char* error = dlerror(); - LOG(ERROR) << "Passthrough lookup opened " << lib - << " but could not find symbol " << sym << ": " - << (error == nullptr ? "unknown error" : error); - dlclose(handle); - return true; + LOG(ERROR) << "Passthrough lookup opened " << lib << " but could not find symbol " + << sym << ": " << (error == nullptr ? "unknown error" : error) + << ". Keeping library open."; + + // dlclose too problematic in multi-threaded environment + // dlclose(handle); + + return true; // continue } ret = (*generator)(name.c_str()); if (ret == nullptr) { - dlclose(handle); - return true; // this module doesn't provide this instance name + LOG(ERROR) << "Could not find instance '" << name.c_str() << "' in library " << lib + << ". Keeping library open."; + + // dlclose too problematic in multi-threaded environment + // dlclose(handle); + + // this module doesn't provide this particular instance + return true; // continue } // Actual fqname might be a subclass. @@ -734,28 +735,6 @@ bool handleCastError(const Return<bool>& castReturn, const std::string& descript return false; } -#ifdef ENFORCE_VINTF_MANIFEST -static constexpr bool kEnforceVintfManifest = true; -#else -static constexpr bool kEnforceVintfManifest = false; -#endif - -#ifdef LIBHIDL_TARGET_DEBUGGABLE -static constexpr bool kDebuggable = true; -#else -static constexpr bool kDebuggable = false; -#endif - -static inline bool isTrebleTestingOverride() { - if (kEnforceVintfManifest && !kDebuggable) { - // don't allow testing override in production - return false; - } - - const char* env = std::getenv("TREBLE_TESTING_OVERRIDE"); - return env && !strcmp(env, "true"); -} - sp<::android::hidl::base::V1_0::IBase> getRawServiceInternal(const std::string& descriptor, const std::string& instance, bool retry, bool getStub) { @@ -786,7 +765,7 @@ sp<::android::hidl::base::V1_0::IBase> getRawServiceInternal(const std::string& const bool vintfHwbinder = (transport == Transport::HWBINDER); const bool vintfPassthru = (transport == Transport::PASSTHROUGH); const bool trebleTestingOverride = isTrebleTestingOverride(); - const bool allowLegacy = !kEnforceVintfManifest || (trebleTestingOverride && kDebuggable); + const bool allowLegacy = !kEnforceVintfManifest || (trebleTestingOverride && isDebuggable()); const bool vintfLegacy = (transport == Transport::EMPTY) && allowLegacy; if (!kEnforceVintfManifest) { @@ -868,7 +847,13 @@ status_t registerAsServiceInternal(const sp<IBase>& service, const std::string& if (kEnforceVintfManifest && !isTrebleTestingOverride()) { using Transport = IServiceManager1_0::Transport; - Transport transport = sm->getTransport(descriptor, name); + Return<Transport> transport = sm->getTransport(descriptor, name); + + if (!transport.isOk()) { + LOG(ERROR) << "Could not get transport for " << descriptor << "/" << name << ": " + << transport.description(); + return UNKNOWN_ERROR; + } if (transport != Transport::HWBINDER) { LOG(ERROR) << "Service " << descriptor << "/" << name diff --git a/transport/allocator/1.0/Android.bp b/transport/allocator/1.0/Android.bp index 6da3793..0cc3b62 100644 --- a/transport/allocator/1.0/Android.bp +++ b/transport/allocator/1.0/Android.bp @@ -1,13 +1,19 @@ // This file is autogenerated by hidl-gen -Landroidbp. +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"], +} + hidl_interface { name: "android.hidl.allocator@1.0", root: "android.hidl", // TODO(b/153609531): remove when no longer needed. native_bridge_supported: true, - vndk: { - enabled: true, - }, srcs: [ "IAllocator.hal", ], @@ -15,4 +21,8 @@ hidl_interface { "android.hidl.base@1.0", ], gen_java: false, + apex_available: [ + "//apex_available:anyapex", + "//apex_available:platform", + ], } diff --git a/transport/allocator/1.0/default/Android.bp b/transport/allocator/1.0/default/Android.bp index 1116f1d..42abe9c 100644 --- a/transport/allocator/1.0/default/Android.bp +++ b/transport/allocator/1.0/default/Android.bp @@ -12,6 +12,15 @@ // 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_binary { name: "android.hidl.allocator@1.0-service", relative_install_path: "hw", diff --git a/transport/allocator/1.0/utils/Android.bp b/transport/allocator/1.0/utils/Android.bp index b324ef1..f21047d 100644 --- a/transport/allocator/1.0/utils/Android.bp +++ b/transport/allocator/1.0/utils/Android.bp @@ -12,6 +12,15 @@ // 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: "libhidlallocatorutils", vendor_available: true, diff --git a/transport/allocator/1.0/vts/functional/Android.bp b/transport/allocator/1.0/vts/functional/Android.bp index 31d9821..f53fc4f 100644 --- a/transport/allocator/1.0/vts/functional/Android.bp +++ b/transport/allocator/1.0/vts/functional/Android.bp @@ -14,6 +14,15 @@ // 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_test { name: "VtsHidlAllocatorV1_0TargetTest", defaults: ["VtsHalTargetTestDefaults"], @@ -26,4 +35,3 @@ cc_test { ], test_suites: ["general-tests", "vts"], } - diff --git a/transport/base/1.0/Android.bp b/transport/base/1.0/Android.bp index 8c796b2..461f7e7 100644 --- a/transport/base/1.0/Android.bp +++ b/transport/base/1.0/Android.bp @@ -1,16 +1,26 @@ // This file is autogenerated by hidl-gen -Landroidbp. +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"], +} + hidl_interface { name: "android.hidl.base@1.0", root: "android.hidl", // TODO(b/153609531): remove when no longer needed. native_bridge_supported: true, - vndk: { - enabled: true, - }, srcs: [ "types.hal", "IBase.hal", ], gen_java: true, + apex_available: [ + "//apex_available:anyapex", + "//apex_available:platform", + ], } diff --git a/transport/base/1.0/vts/functional/Android.bp b/transport/base/1.0/vts/functional/Android.bp index 0c814ae..f25aaaa 100644 --- a/transport/base/1.0/vts/functional/Android.bp +++ b/transport/base/1.0/vts/functional/Android.bp @@ -12,6 +12,15 @@ // 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_test { name: "vts_ibase_test", defaults: ["libinit_test_utils_libraries_defaults"], diff --git a/transport/base/1.0/vts/functional/Android.mk b/transport/base/1.0/vts/functional/Android.mk deleted file mode 100644 index 61c6e31..0000000 --- a/transport/base/1.0/vts/functional/Android.mk +++ /dev/null @@ -1,22 +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. -# - -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := VtsHalBaseV1_0TargetTest --include test/vts/tools/build/Android.host_config.mk diff --git a/transport/base/1.0/vts/functional/AndroidTest.xml b/transport/base/1.0/vts/functional/AndroidTest.xml deleted file mode 100644 index 80154f2..0000000 --- a/transport/base/1.0/vts/functional/AndroidTest.xml +++ /dev/null @@ -1,32 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- 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. ---> -<configuration description="Config for VTS VtsHalBaseV1_0TargetTest test cases"> - <option name="config-descriptor:metadata" key="plan" value="vts-treble" /> - <target_preparer class="com.android.compatibility.common.tradefed.targetprep.VtsFilePusher"> - <option name="abort-on-push-failure" value="false"/> - <option name="push-group" value="HalHidlTargetTest.push"/> - </target_preparer> - <multi_target_preparer class="com.android.tradefed.targetprep.VtsPythonVirtualenvPreparer" /> - <test class="com.android.tradefed.testtype.VtsMultiDeviceTest"> - <option name="test-module-name" value="VtsHalBaseV1_0TargetTest"/> - <option name="binary-test-working-directory" value="_32bit::/data/nativetest/" /> - <option name="binary-test-working-directory" value="_64bit::/data/nativetest64/" /> - <option name="binary-test-source" value="_32bit::DATA/nativetest/vts_ibase_test/vts_ibase_test" /> - <option name="binary-test-source" value="_64bit::DATA/nativetest64/vts_ibase_test/vts_ibase_test" /> - <option name="binary-test-type" value="gtest"/> - <option name="test-timeout" value="5m"/> - </test> -</configuration> diff --git a/transport/include/hidl/HidlLazyUtils.h b/transport/include/hidl/HidlLazyUtils.h index 6a62c97..376b6ab 100644 --- a/transport/include/hidl/HidlLazyUtils.h +++ b/transport/include/hidl/HidlLazyUtils.h @@ -16,6 +16,8 @@ #pragma once +#include <functional> + #include <android/hidl/base/1.0/IBase.h> #include <utils/RefBase.h> #include <utils/StrongPointer.h> @@ -26,12 +28,54 @@ namespace details { class LazyServiceRegistrarImpl; } // namespace details -/** Exits when all HALs registered through this object have 0 clients */ +/** + * Exits when all HALs registered through this object have 0 clients + * + * In order to use this class, it's expected that your service: + * - registers all services in the process with this API + * - configures services as oneshot + disabled in init .rc files + * - uses 'interface' declarations in init .rc files + * + * For more information on init .rc configuration, see system/core/init/README.md + **/ class LazyServiceRegistrar { public: static LazyServiceRegistrar& getInstance(); status_t registerService(const sp<::android::hidl::base::V1_0::IBase>& service, const std::string& name = "default"); + /** + * Set a callback that is invoked when the active HAL count (i.e. HALs with clients) + * registered with this process drops to zero (or becomes nonzero). + * The callback takes a boolean argument, which is 'true' if there is + * at least one HAL with clients. + * + * Callback return value: + * - false: Default behavior for lazy HALs (shut down the process if there + * are no clients). + * - true: Don't shut down the process even if there are no clients. + * + * This callback gives a chance to: + * 1 - Perform some additional operations before exiting; + * 2 - Prevent the process from exiting by returning "true" from the + * callback. + * + * This method should be called before 'registerService' to avoid races. + */ + void setActiveServicesCallback(const std::function<bool(bool)>& activeServicesCallback); + + /** + * Try to unregister all services previously registered with 'registerService'. + * Returns 'true' if successful. This should only be called within + * the callback registered by setActiveServicesCallback. + */ + bool tryUnregister(); + + /** + * Re-register services that were unregistered by 'tryUnregister'. + * This method should be called in the case 'tryUnregister' fails + * (and should be called on the same thread). + */ + void reRegister(); private: std::shared_ptr<details::LazyServiceRegistrarImpl> mImpl; diff --git a/transport/include/hidl/ServiceManagement.h b/transport/include/hidl/ServiceManagement.h index 4573a25..886e816 100644 --- a/transport/include/hidl/ServiceManagement.h +++ b/transport/include/hidl/ServiceManagement.h @@ -47,10 +47,17 @@ namespace details { // e.x.: android.hardware.foo@1.0::IFoo, default void waitForHwService(const std::string &interface, const std::string &instanceName); +// Only works on userdebug/eng builds. This allows getService to bypass the +// VINTF manifest for testing only. +void setTrebleTestingOverride(bool testingOverride); + void preloadPassthroughService(const std::string &descriptor); // Returns a service with the following constraints: -// - retry => service is waited for and returned if available in this process +// - retry => service is waited for and returned if it is declared in the +// manifest AND it is available in this process (if errors indicate an +// sepolicy denial, then this will return - TODO(b/28321379) more precise +// errors to handle more cases) // - getStub => internal only. Forces to get the unwrapped (no BsFoo) if available. // TODO(b/65843592) // If the service is a remote service, this function returns BpBase. If the service is diff --git a/transport/manager/1.0/Android.bp b/transport/manager/1.0/Android.bp index c91dcd2..4a84b86 100644 --- a/transport/manager/1.0/Android.bp +++ b/transport/manager/1.0/Android.bp @@ -1,11 +1,17 @@ // This file is autogenerated by hidl-gen -Landroidbp. +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"], +} + hidl_interface { name: "android.hidl.manager@1.0", root: "android.hidl", - vndk: { - enabled: true, - }, srcs: [ "IServiceManager.hal", "IServiceNotification.hal", @@ -14,4 +20,8 @@ hidl_interface { "android.hidl.base@1.0", ], gen_java: true, + apex_available: [ + "//apex_available:anyapex", + "//apex_available:platform", + ], } diff --git a/transport/manager/1.1/Android.bp b/transport/manager/1.1/Android.bp index 82545e5..c9e22c9 100644 --- a/transport/manager/1.1/Android.bp +++ b/transport/manager/1.1/Android.bp @@ -1,11 +1,17 @@ // This file is autogenerated by hidl-gen -Landroidbp. +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"], +} + hidl_interface { name: "android.hidl.manager@1.1", root: "android.hidl", - vndk: { - enabled: true, - }, srcs: [ "IServiceManager.hal", ], @@ -14,4 +20,8 @@ hidl_interface { "android.hidl.manager@1.0", ], gen_java: true, + apex_available: [ + "//apex_available:anyapex", + "//apex_available:platform", + ], } diff --git a/transport/manager/1.2/Android.bp b/transport/manager/1.2/Android.bp index e7ee143..a58c12e 100644 --- a/transport/manager/1.2/Android.bp +++ b/transport/manager/1.2/Android.bp @@ -1,11 +1,17 @@ // This file is autogenerated by hidl-gen -Landroidbp. +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"], +} + hidl_interface { name: "android.hidl.manager@1.2", root: "android.hidl", - vndk: { - enabled: true, - }, srcs: [ "IClientCallback.hal", "IServiceManager.hal", @@ -16,4 +22,8 @@ hidl_interface { "android.hidl.manager@1.1", ], gen_java: true, + apex_available: [ + "//apex_available:anyapex", + "//apex_available:platform", + ], } diff --git a/transport/memory/1.0/Android.bp b/transport/memory/1.0/Android.bp index 9ce04ed..8e066a9 100644 --- a/transport/memory/1.0/Android.bp +++ b/transport/memory/1.0/Android.bp @@ -1,5 +1,14 @@ // This file is autogenerated by hidl-gen -Landroidbp. +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"], +} + hidl_interface { name: "android.hidl.memory@1.0", root: "android.hidl", @@ -17,4 +26,8 @@ hidl_interface { "android.hidl.base@1.0", ], gen_java: false, + apex_available: [ + "//apex_available:anyapex", + "//apex_available:platform", + ], } diff --git a/transport/memory/1.0/default/Android.bp b/transport/memory/1.0/default/Android.bp index f56ee95..a44a0db 100644 --- a/transport/memory/1.0/default/Android.bp +++ b/transport/memory/1.0/default/Android.bp @@ -12,6 +12,15 @@ // 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_shared { name: "android.hidl.memory@1.0-impl", vendor_available: true, diff --git a/transport/memory/block/1.0/Android.bp b/transport/memory/block/1.0/Android.bp index f26a6d3..bfaf139 100644 --- a/transport/memory/block/1.0/Android.bp +++ b/transport/memory/block/1.0/Android.bp @@ -1,11 +1,17 @@ // This file is autogenerated by hidl-gen -Landroidbp. +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"], +} + hidl_interface { name: "android.hidl.memory.block@1.0", root: "android.hidl", - vndk: { - enabled: true, - }, srcs: [ "types.hal", ], diff --git a/transport/memory/token/1.0/Android.bp b/transport/memory/token/1.0/Android.bp index 46c3387..c304284 100644 --- a/transport/memory/token/1.0/Android.bp +++ b/transport/memory/token/1.0/Android.bp @@ -1,5 +1,14 @@ // This file is autogenerated by hidl-gen -Landroidbp. +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"], +} + hidl_interface { name: "android.hidl.memory.token@1.0", root: "android.hidl", @@ -16,4 +25,8 @@ hidl_interface { "android.hidl.base@1.0", ], gen_java: true, + apex_available: [ + "//apex_available:anyapex", + "//apex_available:platform", + ], } diff --git a/transport/safe_union/1.0/Android.bp b/transport/safe_union/1.0/Android.bp index 2760863..cae92dd 100644 --- a/transport/safe_union/1.0/Android.bp +++ b/transport/safe_union/1.0/Android.bp @@ -1,5 +1,14 @@ // This file is autogenerated by hidl-gen -Landroidbp. +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"], +} + hidl_interface { name: "android.hidl.safe_union@1.0", root: "android.hidl", @@ -11,4 +20,8 @@ hidl_interface { "types.hal", ], gen_java: true, + apex_available: [ + "//apex_available:anyapex", + "//apex_available:platform", + ], } diff --git a/transport/token/1.0/Android.bp b/transport/token/1.0/Android.bp index 28f16f7..8bda482 100644 --- a/transport/token/1.0/Android.bp +++ b/transport/token/1.0/Android.bp @@ -1,5 +1,14 @@ // This file is autogenerated by hidl-gen -Landroidbp. +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"], +} + hidl_interface { name: "android.hidl.token@1.0", root: "android.hidl", @@ -13,4 +22,8 @@ hidl_interface { "android.hidl.base@1.0", ], gen_java: true, + apex_available: [ + "//apex_available:anyapex", + "//apex_available:platform", + ], } diff --git a/transport/token/1.0/utils/Android.bp b/transport/token/1.0/utils/Android.bp index 5ccbe75..84f6f0f 100644 --- a/transport/token/1.0/utils/Android.bp +++ b/transport/token/1.0/utils/Android.bp @@ -12,10 +12,26 @@ // 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: "android.hidl.token@1.0-utils", defaults: ["libhidl-defaults"], vendor_available: true, + // Host support is needed for testing only + host_supported: true, + target: { + darwin: { + enabled: false, + }, + }, vndk: { enabled: true, }, @@ -48,4 +64,8 @@ cc_library { "include", ], min_sdk_version: "29", + apex_available: [ + "//apex_available:anyapex", + "//apex_available:platform", + ], } |