OSDN Git Service

Move SchedulingPolicyService init code to SystemServerInitThreadPool
authorChong Zhang <chz@google.com>
Sat, 21 Apr 2018 00:09:14 +0000 (17:09 -0700)
committerChong Zhang <chz@google.com>
Mon, 23 Apr 2018 17:29:17 +0000 (10:29 -0700)
To avoid slowing down service start time.

Also restrict cpuset change api use to mediaserve only.

bug: 78307194
Test:
- boottime test in go/atest-perf:
  atest google/perf/boottime/boottime-test

- Manual testing: play 1080pHDR content in modified exoplayer (that
  uses soft MediaCodec), verify media.codec is put into top-app; then
  kill system_server process during playback (using adb shell stop
  && adb shell start), and verify after restart that media.codec
  is put back into fg.

Change-Id: If761bd75a7ed893811db3f44bfd84ee3095e23e2

services/core/java/com/android/server/os/SchedulingPolicyService.java

index c64e745..5cbe1a1 100644 (file)
@@ -24,6 +24,8 @@ import android.os.Process;
 import android.os.RemoteException;
 import android.util.Log;
 
+import com.android.server.SystemServerInitThreadPool;
+
 /**
  * The implementation of the scheduling policy service interface.
  *
@@ -62,11 +64,18 @@ public class SchedulingPolicyService extends ISchedulingPolicyService.Stub {
         // (Note that if mediaserver thinks we're in boosted state before the crash,
         // the state could go out of sync temporarily until mediaserver enables/disable
         // boost next time, but this won't be a big issue.)
-        int[] nativePids = Process.getPidsForCommands(MEDIA_PROCESS_NAMES);
-        if (nativePids != null && nativePids.length == 1) {
-            mBoostedPid = nativePids[0];
-            disableCpusetBoost(nativePids[0]);
-        }
+        SystemServerInitThreadPool.get().submit(() -> {
+            synchronized (mDeathRecipient) {
+                // only do this if we haven't already got a request to boost.
+                if (mBoostedPid == -1) {
+                    int[] nativePids = Process.getPidsForCommands(MEDIA_PROCESS_NAMES);
+                    if (nativePids != null && nativePids.length == 1) {
+                        mBoostedPid = nativePids[0];
+                        disableCpusetBoost(nativePids[0]);
+                    }
+                }
+            }
+        }, TAG + ".<init>");
     }
 
     // TODO(b/35196900) We should pass the period in time units, rather
@@ -107,7 +116,9 @@ public class SchedulingPolicyService extends ISchedulingPolicyService.Stub {
 
     // Request to move media.codec process between SP_FOREGROUND and SP_TOP_APP.
     public int requestCpusetBoost(boolean enable, IBinder client) {
-        if (!isPermitted()) {
+        // Can only allow mediaserver to call this.
+        if (Binder.getCallingPid() != Process.myPid() &&
+                Binder.getCallingUid() != Process.MEDIA_UID) {
             return PackageManager.PERMISSION_DENIED;
         }
 
@@ -201,7 +212,6 @@ public class SchedulingPolicyService extends ISchedulingPolicyService.Stub {
 
         switch (Binder.getCallingUid()) {
         case Process.AUDIOSERVER_UID:  // fastcapture, fastmixer
-        case Process.MEDIA_UID:        // mediaserver
         case Process.CAMERASERVER_UID: // camera high frame rate recording
         case Process.BLUETOOTH_UID:    // Bluetooth audio playback
             return true;