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

Commit 406ec156 authored by Jeff Hao's avatar Jeff Hao Committed by Elliott Hughes
Browse files

Replace native Process getpid/getuid with calls to libcore equivalents.

The Process natives were getting called were getting called while
handling a jdwp packet before the vm had a chance to register them.

(cherry-pick of 5bce6a308fc8a3c1e449cf905b8b6e8ace4ef3e2.)

Change-Id: Ia2b4f79b11e427283a712b2d0c52948f394640bf
parent f2d643cf
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -97,7 +97,9 @@ public class DdmHandleHello extends ChunkHandler {
    }

    /*
     * Handle introductory packet.
     * Handle introductory packet. This is called during JNI_CreateJavaVM
     * before frameworks native methods are registered, so be careful not
     * to call any APIs that depend on frameworks native code.
     */
    private Chunk handleHELO(Chunk request) {
        if (false)
+8 −2
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;

import libcore.io.Libcore;

/*package*/ class ZygoteStartFailedEx extends Exception {
    /**
     * Something prevented the zygote process startup from happening normally
@@ -647,7 +649,9 @@ public class Process {
     * Returns the identifier of this process, which can be used with
     * {@link #killProcess} and {@link #sendSignal}.
     */
    public static final native int myPid();
    public static final int myPid() {
        return Libcore.os.getpid();
    }

    /**
     * Returns the identifier of the calling thread, which be used with
@@ -661,7 +665,9 @@ public class Process {
     * app-specific sandbox.  It is different from {@link #myUserHandle} in that
     * a uid identifies a specific app sandbox in a specific user.
     */
    public static final native int myUid();
    public static final int myUid() {
        return Libcore.os.getuid();
    }

    /**
     * Returns this process's user handle.  This is the
+0 −12
Original line number Diff line number Diff line
@@ -94,16 +94,6 @@ static void signalExceptionForGroupError(JNIEnv* env, int err)
    }
}

jint android_os_Process_myPid(JNIEnv* env, jobject clazz)
{
    return getpid();
}

jint android_os_Process_myUid(JNIEnv* env, jobject clazz)
{
    return getuid();
}

jint android_os_Process_myTid(JNIEnv* env, jobject clazz)
{
    return androidGetTid();
@@ -989,9 +979,7 @@ jintArray android_os_Process_getPidsForCommands(JNIEnv* env, jobject clazz,
}

static const JNINativeMethod methods[] = {
    {"myPid",       "()I", (void*)android_os_Process_myPid},
    {"myTid",       "()I", (void*)android_os_Process_myTid},
    {"myUid",       "()I", (void*)android_os_Process_myUid},
    {"getUidForName",       "(Ljava/lang/String;)I", (void*)android_os_Process_getUidForName},
    {"getGidForName",       "(Ljava/lang/String;)I", (void*)android_os_Process_getGidForName},
    {"setThreadPriority",   "(II)V", (void*)android_os_Process_setThreadPriority},