Merge "Move getRawServiceInternal to ServiceManagement."
diff --git a/transport/HidlTransportSupport.cpp b/transport/HidlTransportSupport.cpp
index 0d2f1bf..9bb8148 100644
--- a/transport/HidlTransportSupport.cpp
+++ b/transport/HidlTransportSupport.cpp
@@ -14,10 +14,7 @@
* limitations under the License.
*/
#include <hidl/HidlTransportSupport.h>
-
-#include <android/hidl/manager/1.0/IServiceManager.h>
#include <hidl/HidlBinderSupport.h>
-#include <hidl/ServiceManagement.h>
namespace android {
namespace hardware {
@@ -56,116 +53,5 @@
return true;
}
-namespace details {
-
-sp<::android::hidl::base::V1_0::IBase> getRawServiceInternal(const std::string& descriptor,
- const std::string& instance,
- bool retry, bool getStub) {
- using Transport = ::android::hidl::manager::V1_0::IServiceManager::Transport;
- using ::android::hidl::base::V1_0::IBase;
- using ::android::hidl::manager::V1_0::IServiceManager;
-
- const sp<IServiceManager> sm = defaultServiceManager();
- if (sm == nullptr) {
- ALOGE("getService: defaultServiceManager() is null");
- return nullptr;
- }
-
- Return<Transport> transportRet = sm->getTransport(descriptor, instance);
-
- if (!transportRet.isOk()) {
- ALOGE("getService: defaultServiceManager()->getTransport returns %s",
- transportRet.description().c_str());
- return nullptr;
- }
- Transport transport = transportRet;
- const bool vintfHwbinder = (transport == Transport::HWBINDER);
- const bool vintfPassthru = (transport == Transport::PASSTHROUGH);
-
-#ifdef LIBHIDL_TARGET_TREBLE
-
-#ifdef LIBHIDL_TARGET_DEBUGGABLE
- const char* env = std::getenv("TREBLE_TESTING_OVERRIDE");
- const bool trebleTestingOverride = env && !strcmp(env, "true");
- const bool vintfLegacy = (transport == Transport::EMPTY) && trebleTestingOverride;
-#else // LIBHIDL_TARGET_TREBLE but not LIBHIDL_TARGET_DEBUGGABLE
- const bool trebleTestingOverride = false;
- const bool vintfLegacy = false;
-#endif // LIBHIDL_TARGET_DEBUGGABLE
-
-#else // not LIBHIDL_TARGET_TREBLE
- const char* env = std::getenv("TREBLE_TESTING_OVERRIDE");
- const bool trebleTestingOverride = env && !strcmp(env, "true");
- const bool vintfLegacy = (transport == Transport::EMPTY);
-#endif // LIBHIDL_TARGET_TREBLE
-
- for (int tries = 0;
- !getStub && (vintfHwbinder || (vintfLegacy && tries == 0)) && (retry || tries < 1);
- tries++) {
- if (tries > 1) {
- ALOGI("getService: Will do try %d for %s/%s in 1s...", tries, descriptor.c_str(),
- instance.c_str());
- sleep(1); // TODO(b/67425500): remove and update waitForHwService function
- }
- if (vintfHwbinder && tries > 0) {
- waitForHwService(descriptor, instance);
- }
- Return<sp<IBase>> ret = sm->get(descriptor, instance);
- if (!ret.isOk()) {
- ALOGE("getService: defaultServiceManager()->get returns %s for %s/%s.",
- ret.description().c_str(), descriptor.c_str(), instance.c_str());
- break;
- }
- sp<IBase> base = ret;
- if (base == nullptr) {
- if (tries > 0) {
- ALOGW("getService: found unexpected null hwbinder interface for %s/%s.",
- descriptor.c_str(), instance.c_str());
- }
- continue;
- }
-
- Return<bool> canCastRet =
- details::canCastInterface(base.get(), descriptor.c_str(), true /* emitError */);
-
- if (!canCastRet.isOk()) {
- if (canCastRet.isDeadObject()) {
- ALOGW("getService: found dead hwbinder service for %s/%s.", descriptor.c_str(),
- instance.c_str());
- continue;
- }
- // TODO(b/67425500): breaks getService == nullptr => hal available assumptions if the
- // service has a transaction failure (one example of this is if the service's binder
- // buffer is full). If this isn't here, you get an infinite loop when you don't have
- // permission to talk to a service.
- ALOGW("getService: unable to call into hwbinder service for %s/%s.", descriptor.c_str(),
- instance.c_str());
- break;
- }
-
- if (!canCastRet) {
- ALOGW("getService: received incompatible service (bug in hwservicemanager?) for %s/%s.",
- descriptor.c_str(), instance.c_str());
- break;
- }
-
- return base; // still needs to be wrapped by Bp class.
- }
-
- if (getStub || vintfPassthru || vintfLegacy) {
- const sp<IServiceManager> pm = getPassthroughServiceManager();
- if (pm != nullptr) {
- sp<IBase> base = pm->get(descriptor, instance).withDefault(nullptr);
- if (!getStub || trebleTestingOverride) {
- base = wrapPassthrough(base);
- }
- return base;
- }
- }
-
- return nullptr;
-}
-
-} // namespace details
} // namespace hardware
} // namespace android
diff --git a/transport/ServiceManagement.cpp b/transport/ServiceManagement.cpp
index c6c43a7..c9ee29a 100644
--- a/transport/ServiceManagement.cpp
+++ b/transport/ServiceManagement.cpp
@@ -539,6 +539,114 @@
}
}
+sp<::android::hidl::base::V1_0::IBase> getRawServiceInternal(const std::string& descriptor,
+ const std::string& instance,
+ bool retry, bool getStub) {
+ using Transport = ::android::hidl::manager::V1_0::IServiceManager::Transport;
+ using ::android::hidl::base::V1_0::IBase;
+ using ::android::hidl::manager::V1_0::IServiceManager;
+
+ const sp<IServiceManager> sm = defaultServiceManager();
+ if (sm == nullptr) {
+ ALOGE("getService: defaultServiceManager() is null");
+ return nullptr;
+ }
+
+ Return<Transport> transportRet = sm->getTransport(descriptor, instance);
+
+ if (!transportRet.isOk()) {
+ ALOGE("getService: defaultServiceManager()->getTransport returns %s",
+ transportRet.description().c_str());
+ return nullptr;
+ }
+ Transport transport = transportRet;
+ const bool vintfHwbinder = (transport == Transport::HWBINDER);
+ const bool vintfPassthru = (transport == Transport::PASSTHROUGH);
+
+#ifdef LIBHIDL_TARGET_TREBLE
+
+#ifdef LIBHIDL_TARGET_DEBUGGABLE
+ const char* env = std::getenv("TREBLE_TESTING_OVERRIDE");
+ const bool trebleTestingOverride = env && !strcmp(env, "true");
+ const bool vintfLegacy = (transport == Transport::EMPTY) && trebleTestingOverride;
+#else // LIBHIDL_TARGET_TREBLE but not LIBHIDL_TARGET_DEBUGGABLE
+ const bool trebleTestingOverride = false;
+ const bool vintfLegacy = false;
+#endif // LIBHIDL_TARGET_DEBUGGABLE
+
+#else // not LIBHIDL_TARGET_TREBLE
+ const char* env = std::getenv("TREBLE_TESTING_OVERRIDE");
+ const bool trebleTestingOverride = env && !strcmp(env, "true");
+ const bool vintfLegacy = (transport == Transport::EMPTY);
+#endif // LIBHIDL_TARGET_TREBLE
+
+ for (int tries = 0;
+ !getStub && (vintfHwbinder || (vintfLegacy && tries == 0)) && (retry || tries < 1);
+ tries++) {
+ if (tries > 1) {
+ ALOGI("getService: Will do try %d for %s/%s in 1s...", tries, descriptor.c_str(),
+ instance.c_str());
+ sleep(1); // TODO(b/67425500): remove and update waitForHwService function
+ }
+ if (vintfHwbinder && tries > 0) {
+ waitForHwService(descriptor, instance);
+ }
+ Return<sp<IBase>> ret = sm->get(descriptor, instance);
+ if (!ret.isOk()) {
+ ALOGE("getService: defaultServiceManager()->get returns %s for %s/%s.",
+ ret.description().c_str(), descriptor.c_str(), instance.c_str());
+ break;
+ }
+ sp<IBase> base = ret;
+ if (base == nullptr) {
+ if (tries > 0) {
+ ALOGW("getService: found unexpected null hwbinder interface for %s/%s.",
+ descriptor.c_str(), instance.c_str());
+ }
+ continue;
+ }
+
+ Return<bool> canCastRet =
+ details::canCastInterface(base.get(), descriptor.c_str(), true /* emitError */);
+
+ if (!canCastRet.isOk()) {
+ if (canCastRet.isDeadObject()) {
+ ALOGW("getService: found dead hwbinder service for %s/%s.", descriptor.c_str(),
+ instance.c_str());
+ continue;
+ }
+ // TODO(b/67425500): breaks getService == nullptr => hal available assumptions if the
+ // service has a transaction failure (one example of this is if the service's binder
+ // buffer is full). If this isn't here, you get an infinite loop when you don't have
+ // permission to talk to a service.
+ ALOGW("getService: unable to call into hwbinder service for %s/%s.", descriptor.c_str(),
+ instance.c_str());
+ break;
+ }
+
+ if (!canCastRet) {
+ ALOGW("getService: received incompatible service (bug in hwservicemanager?) for %s/%s.",
+ descriptor.c_str(), instance.c_str());
+ break;
+ }
+
+ return base; // still needs to be wrapped by Bp class.
+ }
+
+ if (getStub || vintfPassthru || vintfLegacy) {
+ const sp<IServiceManager> pm = getPassthroughServiceManager();
+ if (pm != nullptr) {
+ sp<IBase> base = pm->get(descriptor, instance).withDefault(nullptr);
+ if (!getStub || trebleTestingOverride) {
+ base = wrapPassthrough(base);
+ }
+ return base;
+ }
+ }
+
+ return nullptr;
+}
+
}; // namespace details
}; // namespace hardware
diff --git a/transport/include/hidl/HidlTransportSupport.h b/transport/include/hidl/HidlTransportSupport.h
index 4c9a881..730727c 100644
--- a/transport/include/hidl/HidlTransportSupport.h
+++ b/transport/include/hidl/HidlTransportSupport.h
@@ -22,6 +22,7 @@
#include <hidl/HidlPassthroughSupport.h>
#include <hidl/HidlSupport.h>
#include <hidl/HidlTransportUtils.h>
+#include <hidl/ServiceManagement.h>
namespace android {
namespace hardware {
@@ -111,16 +112,6 @@
return sp<IChild>(static_cast<IChild *>(parent.get()));
}
-// Returns a service with the following constraints:
-// - retry => service is waited for and returned if available in this process
-// - 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
-// a passthrough service, this function returns the appropriately wrapped Bs child object.
-sp<::android::hidl::base::V1_0::IBase> getRawServiceInternal(const std::string& descriptor,
- const std::string& instance,
- bool retry, bool getStub);
-
template <typename BpType, typename IType = typename BpType::Pure,
typename = std::enable_if_t<std::is_same<i_tag, typename IType::_hidl_tag>::value>,
typename = std::enable_if_t<std::is_same<bphw_tag, typename BpType::_hidl_tag>::value>>
diff --git a/transport/include/hidl/ServiceManagement.h b/transport/include/hidl/ServiceManagement.h
index d53cd7e..4df156b 100644
--- a/transport/include/hidl/ServiceManagement.h
+++ b/transport/include/hidl/ServiceManagement.h
@@ -18,6 +18,8 @@
#define ANDROID_HARDWARE_ISERVICE_MANAGER_H
#include <string>
+
+#include <android/hidl/base/1.0/IBase.h>
#include <utils/StrongPointer.h>
namespace android {
@@ -45,6 +47,16 @@
void waitForHwService(const std::string &interface, const std::string &instanceName);
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
+// - 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
+// a passthrough service, this function returns the appropriately wrapped Bs child object.
+sp<::android::hidl::base::V1_0::IBase> getRawServiceInternal(const std::string& descriptor,
+ const std::string& instance,
+ bool retry, bool getStub);
};
// These functions are for internal use by hidl. If you want to get ahold