Merge "Load SP-HAL impls from the sphal namespace" into oc-dev
diff --git a/manifest.xml b/manifest.xml
index d3a6e66..693bcbe 100644
--- a/manifest.xml
+++ b/manifest.xml
@@ -36,6 +36,15 @@
</interface>
</hal>
<hal>
+ <name>android.frameworks.schedulerservice</name>
+ <transport>hwbinder</transport>
+ <version>1.0</version>
+ <interface>
+ <name>ISchedulingPolicyService</name>
+ <instance>default</instance>
+ </interface>
+ </hal>
+ <hal>
<name>android.frameworks.sensorservice</name>
<transport>hwbinder</transport>
<version>1.0</version>
diff --git a/transport/ServiceManagement.cpp b/transport/ServiceManagement.cpp
index 29b4c16..9c692da 100644
--- a/transport/ServiceManagement.cpp
+++ b/transport/ServiceManagement.cpp
@@ -20,6 +20,8 @@
#include <condition_variable>
#include <dlfcn.h>
#include <dirent.h>
+#include <fstream>
+#include <pthread.h>
#include <unistd.h>
#include <mutex>
@@ -71,13 +73,74 @@
}
}
-sp<IServiceManager> defaultServiceManager() {
+bool endsWith(const std::string &in, const std::string &suffix) {
+ return in.size() >= suffix.size() &&
+ in.substr(in.size() - suffix.size()) == suffix;
+}
+bool startsWith(const std::string &in, const std::string &prefix) {
+ return in.size() >= prefix.size() &&
+ in.substr(0, prefix.size()) == prefix;
+}
+
+std::string binaryName() {
+ std::ifstream ifs("/proc/self/cmdline");
+ std::string cmdline;
+ if (!ifs.is_open()) {
+ return "";
+ }
+ ifs >> cmdline;
+
+ size_t idx = cmdline.rfind("/");
+ if (idx != std::string::npos) {
+ cmdline = cmdline.substr(idx + 1);
+ }
+
+ return cmdline;
+}
+
+void tryShortenProcessName(const std::string &packageName) {
+ std::string processName = binaryName();
+
+ if (!startsWith(processName, packageName)) {
+ return;
+ }
+
+ // e.x. android.hardware.module.foo@1.0 -> foo@1.0
+ size_t lastDot = packageName.rfind('.');
+ size_t secondDot = packageName.rfind('.', lastDot - 1);
+
+ if (secondDot == std::string::npos) {
+ return;
+ }
+
+ std::string newName = processName.substr(secondDot + 1,
+ 16 /* TASK_COMM_LEN */ - 1);
+ ALOGI("Removing namespace from process name %s to %s.",
+ processName.c_str(), newName.c_str());
+
+ int rc = pthread_setname_np(pthread_self(), newName.c_str());
+ ALOGI_IF(rc != 0, "Removing namespace from process name %s failed.",
+ processName.c_str());
+}
+
+namespace details {
+
+void onRegistration(const std::string &packageName,
+ const std::string& /* interfaceName */,
+ const std::string& /* instanceName */) {
+ tryShortenProcessName(packageName);
+}
+
+} // details
+
+sp<IServiceManager> defaultServiceManager() {
{
AutoMutex _l(details::gDefaultServiceManagerLock);
if (details::gDefaultServiceManager != NULL) {
return details::gDefaultServiceManager;
}
+
if (access("/dev/hwbinder", F_OK|R_OK|W_OK) != 0) {
// HwBinder not available on this device or not accessible to
// this process.
@@ -100,16 +163,6 @@
return details::gDefaultServiceManager;
}
-bool endsWith(const std::string &in, const std::string &suffix) {
- return in.size() >= suffix.size() &&
- in.substr(in.size() - suffix.size()) == suffix;
-}
-
-bool startsWith(const std::string &in, const std::string &prefix) {
- return in.size() >= prefix.size() &&
- in.substr(0, prefix.size()) == prefix;
-}
-
std::vector<std::string> search(const std::string &path,
const std::string &prefix,
const std::string &suffix) {
diff --git a/transport/include/hidl/ServiceManagement.h b/transport/include/hidl/ServiceManagement.h
index 2035fb7..2b2266b 100644
--- a/transport/include/hidl/ServiceManagement.h
+++ b/transport/include/hidl/ServiceManagement.h
@@ -39,6 +39,12 @@
sp<::android::hidl::manager::V1_0::IServiceManager> getPassthroughServiceManager();
namespace details {
+// e.x.: android.hardware.foo@1.0, IFoo, default
+void onRegistration(const std::string &packageName,
+ const std::string &interfaceName,
+ const std::string &instanceName);
+
+// e.x.: android.hardware.foo@1.0::IFoo, default
void waitForHwService(const std::string &interface, const std::string &instanceName);
};