Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b89970e0 authored by Tim Murray's avatar Tim Murray
Browse files

Add isThreadInProcess.

Use this to make sure that the VR thread belongs to a given process when
it is assigned.

bug 28715706

Change-Id: I4e5b0d8493e69e443eb907f0a6f2a9482fb64bac
parent da68f061
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.os;
import android.net.LocalSocket;
import android.net.LocalSocketAddress;
import android.system.Os;
import android.system.OsConstants;
import android.util.Log;
import com.android.internal.os.Zygote;
import dalvik.system.VMRuntime;
@@ -1250,4 +1251,22 @@ public class Process {
     * @hide
     */
    public static final native void removeAllProcessGroups();

    /**
     * Check to see if a thread belongs to a given process. This may require
     * more permissions than apps generally have.
     * @return true if this thread belongs to a process
     * @hide
     */
    public static final boolean isThreadInProcess(int tid, int pid) {
        try {
            if (Os.access("/proc/" + tid + "/task/" + pid, OsConstants.F_OK)) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            return false;
        }
    }
}
+31 −0
Original line number Diff line number Diff line
@@ -12550,6 +12550,37 @@ public final class ActivityManagerService extends ActivityManagerNative
        }
    }
    @Override
    public void setRenderThread(int tid) {
        synchronized (this) {
            ProcessRecord proc;
            synchronized (mPidsSelfLocked) {
                int pid = Binder.getCallingPid();
                proc = mPidsSelfLocked.get(pid);
                if (proc != null && proc.renderThreadTid == 0 && tid > 0) {
                    // ensure the tid belongs to the process
                    if (Process.isThreadInProcess(pid, tid) == false) {
                        return;
                    }
                    proc.renderThreadTid = tid;
                    if (DEBUG_OOM_ADJ) {
                        Slog.d("UI_FIFO", "Set RenderThread tid " + tid + " for pid " + pid);
                    }
                    // promote to FIFO now
                    if (proc.curSchedGroup == ProcessList.SCHED_GROUP_TOP_APP) {
                        if (DEBUG_OOM_ADJ) Slog.d("UI_FIFO", "Promoting " + tid + "out of band");
                        Process.setThreadScheduler(proc.renderThreadTid,
                            Process.SCHED_FIFO | Process.SCHED_RESET_ON_FORK, 1);
                    }
                } else {
                    if (DEBUG_OOM_ADJ) {
                        Slog.d("UI_FIFO", "Didn't set thread from setRenderThreadForPid?");
                    }
                }
            }
        }
    }
    @Override
    public int setVrMode(IBinder token, boolean enabled, ComponentName packageName) {
        if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_VR_MODE)) {