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

Commit 272c7d32 authored by Tim Murray's avatar Tim Murray Committed by The Android Automerger
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 522b0248
Loading
Loading
Loading
Loading
+19 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ package android.os;
import android.net.LocalSocket;
import android.net.LocalSocket;
import android.net.LocalSocketAddress;
import android.net.LocalSocketAddress;
import android.system.Os;
import android.system.Os;
import android.system.OsConstants;
import android.util.Log;
import android.util.Log;
import com.android.internal.os.Zygote;
import com.android.internal.os.Zygote;
import dalvik.system.VMRuntime;
import dalvik.system.VMRuntime;
@@ -1250,4 +1251,22 @@ public class Process {
     * @hide
     * @hide
     */
     */
    public static final native void removeAllProcessGroups();
    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 Original line 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
    @Override
    public int setVrMode(IBinder token, boolean enabled, ComponentName packageName) {
    public int setVrMode(IBinder token, boolean enabled, ComponentName packageName) {
        if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_VR_MODE)) {
        if (!mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_VR_MODE)) {