FileDocCategorySizeDatePackage
SchedulingPolicyService.javaAPI DocAndroid 5.1 API2601Thu Mar 12 22:22:42 GMT 2015com.android.server.os

SchedulingPolicyService

public class SchedulingPolicyService extends ISchedulingPolicyService.Stub
The implementation of the scheduling policy service interface.
hide

Fields Summary
private static final String
TAG
private static final int
PRIORITY_MIN
private static final int
PRIORITY_MAX
Constructors Summary
public SchedulingPolicyService()


      
    
Methods Summary
public intrequestPriority(int pid, int tid, int prio)

        //Log.i(TAG, "requestPriority(pid=" + pid + ", tid=" + tid + ", prio=" + prio + ")");

        // Verify that caller is mediaserver, priority is in range, and that the
        // callback thread specified by app belongs to the app that called mediaserver.
        // Once we've verified that the caller is mediaserver, 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 (Binder.getCallingUid() != Process.MEDIA_UID || prio < PRIORITY_MIN ||
                prio > PRIORITY_MAX || Process.getThreadGroupLeader(tid) != pid) {
            return PackageManager.PERMISSION_DENIED;
        }
        try {
            // make good use of our CAP_SYS_NICE capability
            Process.setThreadGroup(tid, Binder.getCallingPid() == pid ?
                    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, prio);
        } catch (RuntimeException e) {
            return PackageManager.PERMISSION_DENIED;
        }
        return PackageManager.PERMISSION_GRANTED;