summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/jni/com_android_internal_os_Zygote.cpp3
-rw-r--r--services/core/java/com/android/server/os/SchedulingPolicyService.java20
2 files changed, 18 insertions, 5 deletions
diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp
index b95258bca49c..6000fb56299d 100644
--- a/core/jni/com_android_internal_os_Zygote.cpp
+++ b/core/jni/com_android_internal_os_Zygote.cpp
@@ -685,11 +685,14 @@ static jint com_android_internal_os_Zygote_nativeForkAndSpecialize(
// Grant CAP_WAKE_ALARM to the Bluetooth process.
// Additionally, allow bluetooth to open packet sockets so it can start the DHCP client.
+ // Grant CAP_SYS_NICE to allow Bluetooth to set RT priority for
+ // audio-related threads.
// TODO: consider making such functionality an RPC to netd.
if (multiuser_get_app_id(uid) == AID_BLUETOOTH) {
capabilities |= (1LL << CAP_WAKE_ALARM);
capabilities |= (1LL << CAP_NET_RAW);
capabilities |= (1LL << CAP_NET_BIND_SERVICE);
+ capabilities |= (1LL << CAP_SYS_NICE);
}
// Grant CAP_BLOCK_SUSPEND to processes that belong to GID "wakelock"
diff --git a/services/core/java/com/android/server/os/SchedulingPolicyService.java b/services/core/java/com/android/server/os/SchedulingPolicyService.java
index a8bb80905cd2..46be232e61c3 100644
--- a/services/core/java/com/android/server/os/SchedulingPolicyService.java
+++ b/services/core/java/com/android/server/os/SchedulingPolicyService.java
@@ -20,6 +20,7 @@ import android.content.pm.PackageManager;
import android.os.Binder;
import android.os.ISchedulingPolicyService;
import android.os.Process;
+import android.util.Log;
/**
* The implementation of the scheduling policy service interface.
@@ -50,16 +51,24 @@ public class SchedulingPolicyService extends ISchedulingPolicyService.Stub {
// since if not the case then the getThreadGroupLeader() test will also fail.
if (!isPermitted() || prio < PRIORITY_MIN ||
prio > PRIORITY_MAX || Process.getThreadGroupLeader(tid) != pid) {
- return PackageManager.PERMISSION_DENIED;
+ return PackageManager.PERMISSION_DENIED;
+ }
+ if (Binder.getCallingUid() != Process.BLUETOOTH_UID) {
+ try {
+ // make good use of our CAP_SYS_NICE capability
+ Process.setThreadGroup(tid, !isForApp ?
+ Process.THREAD_GROUP_AUDIO_SYS : Process.THREAD_GROUP_AUDIO_APP);
+ } catch (RuntimeException e) {
+ Log.e(TAG, "Failed setThreadGroup: " + e);
+ return PackageManager.PERMISSION_DENIED;
+ }
}
try {
- // make good use of our CAP_SYS_NICE capability
- Process.setThreadGroup(tid, !isForApp ?
- Process.THREAD_GROUP_AUDIO_SYS : Process.THREAD_GROUP_AUDIO_APP);
// must be in this order or it fails the schedulability constraint
Process.setThreadScheduler(tid, Process.SCHED_FIFO | Process.SCHED_RESET_ON_FORK,
- prio);
+ prio);
} catch (RuntimeException e) {
+ Log.e(TAG, "Failed setThreadScheduler: " + e);
return PackageManager.PERMISSION_DENIED;
}
return PackageManager.PERMISSION_GRANTED;
@@ -74,6 +83,7 @@ public class SchedulingPolicyService extends ISchedulingPolicyService.Stub {
switch (Binder.getCallingUid()) {
case Process.AUDIOSERVER_UID: // fastcapture, fastmixer
case Process.CAMERASERVER_UID: // camera high frame rate recording
+ case Process.BLUETOOTH_UID: // Bluetooth audio playback
return true;
default:
return false;