Start android.frameworks.sensorservice@1.0 in system_server
Bug: 35219747
Test: marlin boots
Test: lshal -ipm | grep android.frameworks.sensorservice@1.0
Change-Id: I67dfb217d1b568e140cefce0bdba3f8f4dbe679c
diff --git a/services/core/jni/Android.mk b/services/core/jni/Android.mk
index ac95db5..b5ed266 100644
--- a/services/core/jni/Android.mk
+++ b/services/core/jni/Android.mk
@@ -65,6 +65,7 @@
libinputflinger \
libinputservice \
libsensorservice \
+ libsensorservicehidl \
libskia \
libgui \
libusbhost \
@@ -88,5 +89,6 @@
android.hardware.tv.input@1.0 \
android.hardware.vibrator@1.0 \
android.hardware.vr@1.0 \
+ android.frameworks.sensorservice@1.0 \
-LOCAL_STATIC_LIBRARIES += libscrypt_static
\ No newline at end of file
+LOCAL_STATIC_LIBRARIES += libscrypt_static
diff --git a/services/core/jni/com_android_server_SystemServer.cpp b/services/core/jni/com_android_server_SystemServer.cpp
index 3120af5..8ad88ed 100644
--- a/services/core/jni/com_android_server_SystemServer.cpp
+++ b/services/core/jni/com_android_server_SystemServer.cpp
@@ -17,7 +17,10 @@
#include <jni.h>
#include <JNIHelp.h>
+#include <hidl/HidlTransportSupport.h>
+
#include <sensorservice/SensorService.h>
+#include <sensorservicehidl/SensorManager.h>
#include <cutils/properties.h>
#include <utils/Log.h>
@@ -32,6 +35,21 @@
if (strcmp(propBuf, "1") == 0) {
SensorService::instantiate();
}
+
+}
+
+static void android_server_SystemServer_startHidlServices(JNIEnv* /* env */, jobject /* clazz */) {
+ using ::android::frameworks::sensorservice::V1_0::ISensorManager;
+ using ::android::frameworks::sensorservice::V1_0::implementation::SensorManager;
+ using ::android::hardware::configureRpcThreadpool;
+
+ configureRpcThreadpool(1, false /* callerWillJoin */);
+ sp<ISensorManager> sensorService = new SensorManager();
+ status_t err = sensorService->registerAsService();
+ if (err != OK) {
+ ALOGE("Cannot register ::android::frameworks::sensorservice::V1_0::"
+ "implementation::SensorManager: %d", err);
+ }
}
/*
@@ -40,6 +58,7 @@
static const JNINativeMethod gMethods[] = {
/* name, signature, funcPtr */
{ "startSensorService", "()V", (void*) android_server_SystemServer_startSensorService },
+ { "startHidlServices", "()V", (void*) android_server_SystemServer_startHidlServices },
};
int register_android_server_SystemServer(JNIEnv* env)
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index a8423e2..a707761 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -235,16 +235,24 @@
private final boolean mRuntimeRestart;
private static final String START_SENSOR_SERVICE = "StartSensorService";
+ private static final String START_HIDL_SERVICES = "StartHidlServices";
+
+
private Future<?> mSensorServiceStart;
private Future<?> mZygotePreload;
-
/**
* Start the sensor service. This is a blocking call and can take time.
*/
private static native void startSensorService();
/**
+ * Start all HIDL services that are run inside the system server. This
+ * may take some time.
+ */
+ private static native void startHidlServices();
+
+ /**
* The main entry point from zygote.
*/
public static void main(String[] args) {
@@ -610,6 +618,7 @@
startSensorService();
traceLog.traceEnd();
}, START_SENSOR_SERVICE);
+
}
/**
@@ -637,6 +646,14 @@
traceBeginAndSlog("StartWebViewUpdateService");
mWebViewUpdateService = mSystemServiceManager.startService(WebViewUpdateService.class);
traceEnd();
+
+ // Start receiving calls from HIDL services. Start in in a separate thread
+ // because it need to connect to SensorManager.
+ SystemServerInitThreadPool.get().submit(() -> {
+ traceBeginAndSlog(START_HIDL_SERVICES);
+ startHidlServices();
+ traceEnd();
+ }, START_HIDL_SERVICES);
}
/**