From 3d8166f88534c32b5ba7614e6cebe6f2439b6abe Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Fri, 7 Apr 2017 10:47:06 -0700 Subject: [PATCH] Start service from libscheduleservicehidl. Test: internal camera successfully sets priority. Bug: 29251823 Change-Id: I3c3caeb3e2e169dee483da25cc8217e1aad14adf --- .../server/os/SchedulingPolicyService.java | 12 ++++++++---- services/core/jni/Android.mk | 2 ++ .../jni/com_android_server_SystemServer.cpp | 17 ++++++++++++----- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/services/core/java/com/android/server/os/SchedulingPolicyService.java b/services/core/java/com/android/server/os/SchedulingPolicyService.java index 5d72d5056715a..a8bb80905cd22 100644 --- a/services/core/java/com/android/server/os/SchedulingPolicyService.java +++ b/services/core/java/com/android/server/os/SchedulingPolicyService.java @@ -48,7 +48,7 @@ public class SchedulingPolicyService extends ISchedulingPolicyService.Stub { // Once we've verified that the caller uid is permitted, we can trust the pid but // we can't trust the tid. No need to explicitly check for pid == 0 || tid == 0, // since if not the case then the getThreadGroupLeader() test will also fail. - if (!isPermittedCallingUid() || prio < PRIORITY_MIN || + if (!isPermitted() || prio < PRIORITY_MIN || prio > PRIORITY_MAX || Process.getThreadGroupLeader(tid) != pid) { return PackageManager.PERMISSION_DENIED; } @@ -65,9 +65,13 @@ public class SchedulingPolicyService extends ISchedulingPolicyService.Stub { return PackageManager.PERMISSION_GRANTED; } - private boolean isPermittedCallingUid() { - final int callingUid = Binder.getCallingUid(); - switch (callingUid) { + private boolean isPermitted() { + // schedulerservice hidl + if (Binder.getCallingPid() == Process.myPid()) { + return true; + } + + switch (Binder.getCallingUid()) { case Process.AUDIOSERVER_UID: // fastcapture, fastmixer case Process.CAMERASERVER_UID: // camera high frame rate recording return true; diff --git a/services/core/jni/Android.mk b/services/core/jni/Android.mk index b5ed26630b239..23637de70f9cf 100644 --- a/services/core/jni/Android.mk +++ b/services/core/jni/Android.mk @@ -64,6 +64,7 @@ LOCAL_SHARED_LIBRARIES += \ libinput \ libinputflinger \ libinputservice \ + libschedulerservicehidl \ libsensorservice \ libsensorservicehidl \ libskia \ @@ -89,6 +90,7 @@ LOCAL_SHARED_LIBRARIES += \ android.hardware.tv.input@1.0 \ android.hardware.vibrator@1.0 \ android.hardware.vr@1.0 \ + android.frameworks.schedulerservice@1.0 \ android.frameworks.sensorservice@1.0 \ 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 8ad88eddd73bc..4a08ce4aebb7c 100644 --- a/services/core/jni/com_android_server_SystemServer.cpp +++ b/services/core/jni/com_android_server_SystemServer.cpp @@ -19,6 +19,7 @@ #include +#include #include #include @@ -39,17 +40,23 @@ static void android_server_SystemServer_startSensorService(JNIEnv* /* env */, jo } static void android_server_SystemServer_startHidlServices(JNIEnv* /* env */, jobject /* clazz */) { + using ::android::frameworks::schedulerservice::V1_0::ISchedulingPolicyService; + using ::android::frameworks::schedulerservice::V1_0::implementation::SchedulingPolicyService; using ::android::frameworks::sensorservice::V1_0::ISensorManager; using ::android::frameworks::sensorservice::V1_0::implementation::SensorManager; using ::android::hardware::configureRpcThreadpool; + status_t err; + configureRpcThreadpool(1, false /* callerWillJoin */); + sp sensorService = new SensorManager(); - status_t err = sensorService->registerAsService(); - if (err != OK) { - ALOGE("Cannot register ::android::frameworks::sensorservice::V1_0::" - "implementation::SensorManager: %d", err); - } + err = sensorService->registerAsService(); + ALOGE_IF(err != OK, "Cannot register %s: %d", ISensorManager::descriptor, err); + + sp schedulingService = new SchedulingPolicyService(); + err = schedulingService->registerAsService(); + ALOGE_IF(err != OK, "Cannot register %s: %d", ISchedulingPolicyService::descriptor, err); } /*