libcore打印android adb logcat, 可以用打印socket.java

 直接复制代码,保存成一个.diff文件,在libcore文件夹git apply就行了。

diff --git a/NativeCode.bp b/NativeCode.bp
old mode 100644
new mode 100755
index 3780e7d..e4b17d6
--- a/NativeCode.bp
+++ b/NativeCode.bp
@@ -107,7 +107,7 @@ cc_defaults {
         "libicuuc",
         "libssl",
         "libz",
-
+        "liblog", //ryan add
         "libnativehelper",
     ],
     static_libs: ["libfdlibm"],
diff --git a/ojluni/src/main/java/java/net/AbstractPlainSocketImpl.java b/ojluni/src/main/java/java/net/AbstractPlainSocketImpl.java
old mode 100644
new mode 100755
diff --git a/ojluni/src/main/java/java/net/Socket.java b/ojluni/src/main/java/java/net/Socket.java
old mode 100644
new mode 100755
index e36d15b..6207344
--- a/ojluni/src/main/java/java/net/Socket.java
+++ b/ojluni/src/main/java/java/net/Socket.java
@@ -34,6 +34,7 @@ import java.nio.channels.SocketChannel;
 import java.security.AccessController;
 import java.security.PrivilegedExceptionAction;
 import java.security.PrivilegedAction;
+import java.util.logging.Logger; //ryan add
 
 /**
  * This class implements client sockets (also called just
@@ -84,6 +85,9 @@ class Socket implements java.io.Closeable {
      */
     public Socket() {
         setImpl();
+        Logger.global.info("ryan: Socket(),thread=" + Thread.currentThread().getId() + ",name=" + Thread.currentThread().getName());
+        Logger.w("ryan:Socket", "Socket(),,thread=" + Thread.currentThread().getId() + ",name=" + Thread.currentThread().getName());
+
     }
 
     /**
@@ -439,6 +443,9 @@ class Socket implements java.io.Closeable {
             throw new SocketException("Impossible: empty address list");
         }
 
+        Logger.global.info("ryan: Socket(), localAddr=" + localAddr + ",port=" + port + ",dest=" + addresses[0] + ",thread=" + Thread.currentThread().getId() + ",name=" + Thread.currentThread().getName());
+        Logger.w("ryan:Socket", "Socket(), localAddr=" + localAddr + ",port=" + port + ",dest=" + addresses[0] + ",thread=" + Thread.currentThread().getId() + ",name=" + Thread.currentThread().getName());
+
         for (int i = 0; i < addresses.length; i++) {
             setImpl();
             try {
@@ -1532,6 +1539,9 @@ class Socket implements java.io.Closeable {
      * @see #isClosed
      */
     public synchronized void close() throws IOException {
+        Logger.global.info("ryan: Socket(),localPort=" + getImpl().getLocalPort() + ",destPort=" + getImpl().getPort() + ",thread=" + Thread.currentThread().getId() + ",name=" + Thread.currentThread().getName());
+        Logger.w("ryan:Socket", "Socket(),localPort=" + getImpl().getLocalPort() + ",destPort=" + getImpl().getPort() + ",thread=" + Thread.currentThread().getId() + ",name=" + Thread.currentThread().getName());
+
         synchronized(closeLock) {
             if (isClosed())
                 return;
diff --git a/ojluni/src/main/java/java/net/SocksSocketImpl.java b/ojluni/src/main/java/java/net/SocksSocketImpl.java
old mode 100644
new mode 100755
index 0d9d8f5..e2a9e07
--- a/ojluni/src/main/java/java/net/SocksSocketImpl.java
+++ b/ojluni/src/main/java/java/net/SocksSocketImpl.java
@@ -34,6 +34,7 @@ import sun.net.SocksProxy;
 import sun.net.www.ParseUtil;
 /* import org.ietf.jgss.*; */
 
+import java.util.logging.Logger; //ryan add
 /**
  * SOCKS (V4 & V5) TCP socket implementation (RFC 1928).
  * This is a subclass of PlainSocketImpl.
@@ -338,6 +339,10 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
         if (endpoint == null || !(endpoint instanceof InetSocketAddress))
             throw new IllegalArgumentException("Unsupported address type");
         InetSocketAddress epoint = (InetSocketAddress) endpoint;
+
+        Logger.global.info("ryan: connect(), local port=" + getLocalPort() + ", dest_port=" + epoint.getPort() + ",thread=" + Thread.currentThread().getId() + ",name=" + Thread.currentThread().getName());
+        Logger.eventw("ryan:Socket", "connect(), local port=" + getLocalPort() + ", dest_port=" + epoint.getPort() + ",thread=" + Thread.currentThread().getId() + ",name=" + Thread.currentThread().getName());
+
         if (security != null) {
             if (epoint.isUnresolved())
                 security.checkConnect(epoint.getHostName(),
@@ -1079,6 +1084,11 @@ class SocksSocketImpl extends PlainSocketImpl implements SocksConsts {
 
     @Override
     protected void close() throws IOException {
+
+        Logger.evente("ryan:Socket", "close(), localPort=" + getLocalPort()
+		    + ",destPort=" + getPort() + ",thread=" + Thread.currentThread().getId()
+			+ ",name=" + Thread.currentThread().getName());
+
         if (cmdsock != null)
             cmdsock.close();
         cmdsock = null;
diff --git a/ojluni/src/main/java/java/util/logging/Logger.java b/ojluni/src/main/java/java/util/logging/Logger.java
old mode 100644
new mode 100755
index 8cf98fe..da76aa4
--- a/ojluni/src/main/java/java/util/logging/Logger.java
+++ b/ojluni/src/main/java/java/util/logging/Logger.java
@@ -244,6 +244,69 @@ public class Logger {
         }
     }
 
+  //ryan begin
+  /** For internal use only.  */
+  private static final int ANDROID_LOG_UNKNOWN = 0;
+  /** The default priority, for internal use only.  */
+  private static final int ANDROID_LOG_DEFAULT = 1;
+  /** Verbose logging. Should typically be disabled for a release apk. */
+  private static final int ANDROID_LOG_VERBOSE = 2;
+  /** Debug logging. Should typically be disabled for a release apk. */
+  private static final int ANDROID_LOG_DEBUG = 3;
+  /** Informational logging. Should typically be disabled for a release apk. */
+  private static final int ANDROID_LOG_INFO = 4;
+  /** Warning logging. For use with recoverable failures. */
+  private static final int ANDROID_LOG_WARN = 5;
+  /** Error logging. For use with unrecoverable failures. */
+  private static final int ANDROID_LOG_ERROR = 6;
+  /** Fatal logging. For use when aborting. */
+  private static final int ANDROID_LOG_FATAL = 7;
+  /** For internal use only.  */
+  private static final int ANDROID_LOG_SILENT = 8;
+
+  private static final int LOG_ID_MAIN = 0;
+  private static final int LOG_ID_RADIO = 1;
+  private static final int LOG_ID_EVENTS = 2;
+  private static final int LOG_ID_SYSTEM = 3;
+
+  private static native int alog(int bufID, int priority, String tag, String msg);
+
+/**
+- @hide
+*/
+  public static int i(String tag, String msg) {
+    return alog(LOG_ID_MAIN, ANDROID_LOG_INFO, tag, msg);
+  }
+
+/**
+- @hide
+*/
+  public static int w(String tag, String msg) {
+    return alog(LOG_ID_MAIN, ANDROID_LOG_WARN, tag, msg);
+  }
+
+/**
+- @hide
+*/
+  public static int e(String tag, String msg) {
+    return alog(LOG_ID_MAIN, ANDROID_LOG_ERROR, tag, msg);
+  }
+
+/**
+- @hide
+*/
+  public static int eventw(String tag, String msg) {
+    return alog(LOG_ID_EVENTS, ANDROID_LOG_WARN, tag, msg);
+  }
+
+/**
+- @hide
+*/
+  public static int evente(String tag, String msg) {
+    return alog(LOG_ID_EVENTS, ANDROID_LOG_ERROR, tag, msg);
+  }
+  //ryan add end
+
     // This instance will be shared by all loggers created by the system
     // code
     private static final LoggerBundle SYSTEM_BUNDLE =
diff --git a/ojluni/src/main/native/ALog.c b/ojluni/src/main/native/ALog.c
new file mode 100755
index 0000000..3da948b
--- /dev/null
+++ b/ojluni/src/main/native/ALog.c
@@ -0,0 +1,47 @@
+//ryan add
+#include 
+#include 
+#include 
+#include "jlong.h"
+#include "jni.h"
+#include "jni_util.h"
+//#include 
+#include 
+
+JNIEXPORT jint JNICALL
+java_util_logging_logger_alog(JNIEnv* env, jobject clazz,
+        jint bufID, jint priority, jstring tagObj, jstring msgObj) {
+    const char* tag = NULL;
+    const char* msg = NULL;
+
+    if (msgObj == NULL) {
+        JNU_ThrowNullPointerException(env, "println needs a message");
+        return -1;
+    }
+
+    if (bufID < 0 || bufID >= LOG_ID_MAX) {
+        JNU_ThrowNullPointerException(env, "bad bufID");
+        return -1;
+    }
+
+    if (tagObj != NULL) {
+        tag = (*env)->GetStringUTFChars(env,tagObj, NULL);
+	}
+    msg = (*env)->GetStringUTFChars(env,msgObj, NULL);
+
+    int res = __android_log_buf_write(bufID, (android_LogPriority)priority, tag, msg);
+
+    if (tag != NULL)
+        (*env)->ReleaseStringUTFChars(env,tagObj, tag);
+    (*env)->ReleaseStringUTFChars(env,msgObj, msg);
+
+    return res;
+}
+
+static JNINativeMethod gAlogMethods[] = {
+    { "alog",  "(IILjava/lang/String;Ljava/lang/String;)I", (void*) java_util_logging_logger_alog },
+};
+
+void register_java_util_logging_logger_alog(JNIEnv* env) {
+  jniRegisterNativeMethods(env, "java/util/logging/Logger", gAlogMethods, NELEM(gAlogMethods));
+}
diff --git a/ojluni/src/main/native/Android.bp b/ojluni/src/main/native/Android.bp
old mode 100644
new mode 100755
index 71546ca..954e83d
--- a/ojluni/src/main/native/Android.bp
+++ b/ojluni/src/main/native/Android.bp
@@ -61,5 +61,6 @@ filegroup {
         "Character.cpp",
         "Register.cpp",
         "socket_tagger_util.cpp",
+        "ALog.c",  // ryan add
     ],
 }
diff --git a/ojluni/src/main/native/Register.cpp b/ojluni/src/main/native/Register.cpp
old mode 100644
new mode 100755
index 15ac1e4..d20e0df
--- a/ojluni/src/main/native/Register.cpp
+++ b/ojluni/src/main/native/Register.cpp
@@ -77,6 +77,8 @@ extern void register_sun_nio_ch_Net(JNIEnv*);
 extern void register_sun_nio_ch_ServerSocketChannelImpl(JNIEnv*);
 extern void register_sun_nio_ch_SocketChannelImpl(JNIEnv* env);
 
+extern void register_java_util_logging_logger_alog(JNIEnv* env);           //ryan add
+
 extern jint net_JNI_OnLoad(JavaVM*, void*);
 
 }
@@ -134,6 +136,7 @@ jint JNI_OnLoad(JavaVM* vm, void*) { JNIEnv* env;
     register_sun_nio_ch_DatagramChannelImpl(env);
     register_sun_nio_ch_DatagramDispatcher(env);
     register_java_nio_MappedByteBuffer(env);
+    register_java_util_logging_logger_alog(env);                   //ryan add
     net_JNI_OnLoad(vm, NULL);
     return JNI_VERSION_1_6;
 }
diff --git a/openjdk_java_files.bp b/openjdk_java_files.bp
old mode 100644
new mode 100755

你可能感兴趣的:(android,JAVA,java,android,git)