Update for hidlized hwservicemanager.
Test: end to end
Bug: 32313592
Change-Id: I11496e4c3dd6d0d43f635886b46609cb8e430efc
diff --git a/include/hidl/HidlSupport.h b/include/hidl/HidlSupport.h
index 4fbe826..b78d0a9 100644
--- a/include/hidl/HidlSupport.h
+++ b/include/hidl/HidlSupport.h
@@ -553,7 +553,7 @@
public:
constexpr hidl_version(uint16_t major, uint16_t minor) : mMajor(major), mMinor(minor) {}
- bool operator==(const hidl_version& other) {
+ bool operator==(const hidl_version& other) const {
return (mMajor == other.get_major() && mMinor == other.get_minor());
}
@@ -633,22 +633,32 @@
#define DECLARE_REGISTER_AND_GET_SERVICE(INTERFACE) \
static ::android::sp<I##INTERFACE> getService( \
const std::string &serviceName, bool getStub=false); \
- status_t registerAsService( \
+ ::android::status_t registerAsService( \
const std::string &serviceName); \
#define IMPLEMENT_REGISTER_AND_GET_SERVICE(INTERFACE, LIB) \
::android::sp<I##INTERFACE> I##INTERFACE::getService( \
const std::string &serviceName, bool getStub) \
{ \
+ using ::android::sp; \
+ using ::android::hardware::defaultServiceManager; \
+ using ::android::hardware::IBinder; \
+ using ::android::hidl::manager::V1_0::IServiceManager; \
sp<I##INTERFACE> iface; \
const struct timespec DELAY {1,0}; \
unsigned retries = 3; \
const sp<IServiceManager> sm = defaultServiceManager(); \
if (sm != nullptr && !getStub) { \
do { \
- sp<IBinder> binderIface = \
- sm->checkService(String16(serviceName.c_str()), \
- I##INTERFACE::version); \
+ sp<IBinder> binderIface; \
+ IServiceManager::Version version { \
+ .major = I##INTERFACE::version.get_major(), \
+ .minor = I##INTERFACE::version.get_minor(), \
+ }; \
+ sm->get(serviceName.c_str(), version, \
+ [&binderIface](sp<IBinder> iface) { \
+ binderIface = iface; \
+ }); \
iface = IHw##INTERFACE::asInterface(binderIface); \
if (iface != nullptr) { \
return iface; \
@@ -677,13 +687,21 @@
} \
return iface; \
} \
- status_t I##INTERFACE::registerAsService( \
+ ::android::status_t I##INTERFACE::registerAsService( \
const std::string &serviceName) \
{ \
+ using ::android::sp; \
+ using ::android::hardware::defaultServiceManager; \
+ using ::android::hidl::manager::V1_0::IServiceManager; \
sp<Bn##INTERFACE> binderIface = new Bn##INTERFACE(this); \
const sp<IServiceManager> sm = defaultServiceManager(); \
- return sm->addService(String16(serviceName.c_str()), binderIface, \
- I##INTERFACE::version); \
+ IServiceManager::Version version { \
+ .major = I##INTERFACE::version.get_major(), \
+ .minor = I##INTERFACE::version.get_minor(), \
+ }; \
+ sm->add(serviceName.c_str(), binderIface, version); \
+ /* TODO return value */ \
+ return ::android::OK; \
}
// ----------------------------------------------------------------------
diff --git a/include/hidl/IServiceManager.h b/include/hidl/IServiceManager.h
deleted file mode 100644
index 4013cbf..0000000
--- a/include/hidl/IServiceManager.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) 2016 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 ANDROID_HARDWARE_ISERVICE_MANAGER_H
-#define ANDROID_HARDWARE_ISERVICE_MANAGER_H
-
-#include <hidl/HidlSupport.h>
-#include <hwbinder/IInterface.h>
-#include <hwbinder/Parcel.h>
-#include <utils/String16.h>
-
-namespace android {
-namespace hardware {
-
-class IServiceManager : virtual public RefBase
-{
-public:
- /**
- * Retrieve an existing service, blocking for a few seconds
- * if it doesn't yet exist.
- */
- virtual sp<IBinder> getService( const String16& name,
- const android::hardware::hidl_version& version
- ) const = 0;
-
- /**
- * Retrieve an existing service, non-blocking.
- */
- virtual sp<IBinder> checkService( const String16& name,
- const android::hardware::hidl_version& version
- ) const = 0;
-
- /**
- * Register a service.
- */
- virtual status_t addService( const String16& name,
- const sp<IBinder>& service,
- const android::hardware::hidl_version& version,
- bool allowIsolated = false) = 0;
-
-};
-
-struct IHwServiceManager : public IServiceManager, public IInterface {
- DECLARE_HWBINDER_META_INTERFACE(ServiceManager)
-
- enum Call {
- GET_SERVICE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
- CHECK_SERVICE_TRANSACTION,
- ADD_SERVICE_TRANSACTION,
- LIST_SERVICES_TRANSACTION,
- };
-};
-
-sp<IServiceManager> defaultServiceManager();
-
-template<typename INTERFACE>
-status_t getService(const String16& name, android::hardware::hidl_version version,
- sp<INTERFACE>* outService)
-{
- const sp<IServiceManager> sm = defaultServiceManager();
- if (sm != NULL) {
- *outService = interface_cast<INTERFACE>(sm->getService(name, version));
- if ((*outService) != NULL) return NO_ERROR;
- }
- return NAME_NOT_FOUND;
-}
-
-}; // namespace hardware
-}; // namespace android
-
-#endif // ANDROID_HARDWARE_ISERVICE_MANAGER_H
-
diff --git a/include/hidl/LegacySupport.h b/include/hidl/LegacySupport.h
index 5acc1d0..6e030ce 100644
--- a/include/hidl/LegacySupport.h
+++ b/include/hidl/LegacySupport.h
@@ -16,7 +16,6 @@
#include <utils/Log.h>
-#include "IServiceManager.h"
#include <hwbinder/IPCThreadState.h>
#include <hwbinder/ProcessState.h>
#include <utils/Errors.h>
diff --git a/include/hidl/ServiceManagement.h b/include/hidl/ServiceManagement.h
new file mode 100644
index 0000000..51faf0b
--- /dev/null
+++ b/include/hidl/ServiceManagement.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2016 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 ANDROID_HARDWARE_ISERVICE_MANAGER_H
+#define ANDROID_HARDWARE_ISERVICE_MANAGER_H
+
+#include <utils/StrongPointer.h>
+
+namespace android {
+
+namespace hidl {
+namespace manager {
+namespace V1_0 {
+ struct IServiceManager;
+}; // namespace V1_0
+}; // namespace manager
+}; // namespace hidl
+
+namespace hardware {
+
+sp<::android::hidl::manager::V1_0::IServiceManager> defaultServiceManager();
+
+}; // namespace hardware
+}; // namespace android
+
+#endif // ANDROID_HARDWARE_ISERVICE_MANAGER_H
+
diff --git a/include/hidl/Static.h b/include/hidl/Static.h
index a021e6e..00db8a7 100644
--- a/include/hidl/Static.h
+++ b/include/hidl/Static.h
@@ -18,14 +18,14 @@
// destruction order in the library.
#include <utils/threads.h>
-#include <hidl/IServiceManager.h>
+#include <android/hidl/manager/1.0/IServiceManager.h>
namespace android {
namespace hardware {
-// For IServiceManager.cpp
+// For ServiceManagement.cpp
extern Mutex gDefaultServiceManagerLock;
-extern sp<IServiceManager> gDefaultServiceManager;
+extern sp<android::hidl::manager::V1_0::IServiceManager> gDefaultServiceManager;
} // namespace hardware
} // namespace android