2012年11月1日 星期四

[Android] Print log in Java libcore

Reference:
在Java核心库中打印log
android 在Java核心库libcore中打印log


Follow below steps to add log utility function in libcore/luni/src/main/java/java/text/SimpleDateFormat.java

Android version: 4.0.4
Affected files:
  1. libcore\luni\src\main\java\java\text\SimpleDateFormat.java
  2. libcore\luni\src\main\native\Register.cpp
  3. libcore\luni\src\main\native\sub.mk
Added file:
  1. libcore\luni\src\main\native\java_text_SimpleDateFormat.cpp

[Step 1]

Create libcore\luni\src\main\native\java_text_SimpleDateFormat.cpp 

 #define LOG_TAG "SimpleDateFormat"  
 #include "JNIHelp.h"  
 #include "JniConstants.h"  
 #include "JniException.h"  
 #include "ScopedPrimitiveArray.h"  
 #include "UniquePtr.h"  
 #include <stdlib.h>  
 #include <string.h>  
 static jint SimpleDateFormat_println_native(JNIEnv* env, jclass,  
     jint bufID, jint priority, jstring tagObj, jstring msgObj)  
 {  
   const char* tag = NULL;  
   const char* msg = NULL;  
   if (msgObj == NULL) {  
     jniThrowNullPointerException(env, "println needs a message");  
     return -1;  
   }  
   if (bufID < 0 || bufID >= LOG_ID_MAX) {  
     jniThrowNullPointerException(env, "bad bufID");  
     return -1;  
   }  
   if (tagObj != NULL)  
     tag = env->GetStringUTFChars(tagObj, NULL);  
   msg = env->GetStringUTFChars(msgObj, NULL);  
   int res = __android_log_buf_write(bufID, (android_LogPriority)priority, tag, msg);  
   if (tag != NULL)  
     env->ReleaseStringUTFChars(tagObj, tag);  
   env->ReleaseStringUTFChars(msgObj, msg);  
   return res;  
 }  
 static JNINativeMethod gMethods[] = {  
   NATIVE_METHOD(SimpleDateFormat, println_native, "(IILjava/lang/String;Ljava/lang/String;)I"),  
 };  
 int register_java_text_SimpleDateFormat(JNIEnv* env) {  
   return jniRegisterNativeMethods(env, "java/text/SimpleDateFormat", gMethods, NELEM(gMethods));  
 }  

[Step 2]

Add java_text_SimpleDateFormat.cpp into make file libcore\luni\src\main\native\sub.mk

 LOCAL_SRC_FILES := \  
      AsynchronousSocketCloseMonitor.cpp \  
      JniConstants.cpp \  
      JniException.cpp \  
      NetworkUtilities.cpp \  
      Register.cpp \  
      cbigint.cpp \  
      java_io_Console.cpp \  
      java_io_File.cpp \  
      java_io_ObjectStreamClass.cpp \  
      java_lang_Character.cpp \  
      java_lang_Math.cpp \  
      java_lang_ProcessManager.cpp \  
      java_lang_RealToString.cpp \  
      java_lang_StrictMath.cpp \  
      java_lang_StringToReal.cpp \  
      java_lang_System.cpp \  
      java_math_NativeBN.cpp \  
      java_nio_ByteOrder.cpp \  
      java_nio_charset_Charsets.cpp \  
      java_text_Bidi.cpp \  
      java_text_SimpleDateFormat.cpp \  
      java_util_regex_Matcher.cpp \  
      java_util_regex_Pattern.cpp \  
      java_util_zip_Adler32.cpp \  
      java_util_zip_CRC32.cpp \  
      java_util_zip_Deflater.cpp \  
      java_util_zip_Inflater.cpp \  
      libcore_icu_ICU.cpp \  
      libcore_icu_NativeBreakIterator.cpp \  
      libcore_icu_NativeCollation.cpp \  
      libcore_icu_NativeConverter.cpp \  
      libcore_icu_NativeDecimalFormat.cpp \  
      libcore_icu_NativeIDN.cpp \  
      libcore_icu_NativeNormalizer.cpp \  
      libcore_icu_NativePluralRules.cpp \  
      libcore_icu_TimeZones.cpp \  
      libcore_io_AsynchronousCloseMonitor.cpp \  
      libcore_io_Memory.cpp \  
      libcore_io_OsConstants.cpp \  
      libcore_io_Posix.cpp \  
      libcore_net_RawSocket.cpp \  
      org_apache_harmony_xml_ExpatParser.cpp \  
      org_apache_harmony_xnet_provider_jsse_NativeCrypto.cpp \  
      readlink.cpp \  
      realpath.cpp \  
      toStringArray.cpp \  
      valueOf.cpp  

[Step 3]

Register java_text_SimpleDateFormat(env) in libcore\luni\src\main\native\Register.cpp


 extern int register_java_nio_ByteOrder(JNIEnv* env);  
 extern int register_java_nio_charset_Charsets(JNIEnv* env);  
 extern int register_java_text_Bidi(JNIEnv* env);  
 extern int register_java_text_SimpleDateFormat(JNIEnv* env);  
 extern int register_java_util_regex_Matcher(JNIEnv* env);  
 extern int register_java_util_regex_Pattern(JNIEnv* env);  
 extern int register_java_util_zip_Adler32(JNIEnv* env);  


       register_java_nio_ByteOrder(env) != -1 &&  
       register_java_nio_charset_Charsets(env) != -1 &&  
       register_java_text_Bidi(env) != -1 &&  
       register_java_text_SimpleDateFormat(env) != -1 &&  
       register_java_util_regex_Matcher(env) != -1 &&  
       register_java_util_regex_Pattern(env) != -1 &&  
       register_java_util_zip_Adler32(env) != -1 &&  

[Step 4]

Declare native function in libcore\luni\src\main\java\java\text\SimpleDateFormat.java

   private static native int println_native(int bufID, int priority, String tag, String msg);   
   private static final String TAG = "SimpleDateFormat";  
   private static final int LOG_ID_MAIN = 0;   
   private static final int DEBUG = 3;   
   private static int Log(String tag, String msg) {   
     return println_native(LOG_ID_MAIN, DEBUG, tag, msg);   
   }  

[Step 5]

Finally, we can use Log(TAG, msg) in SimpleDataFormat.java!


 Log("SimpleDateFormat", "This is debug message");  

2011年5月17日 星期二

[OpenGL] OpenGL ES Conformance Tests (ESCTS)

OpenGL ES Adopters Overview

Adopters can download and run the conformance tests and if the implementaiton passes, they can advertise and promote the product as being compliant; using the OpenGL ES logos and trademarks under a royalty-free license.

Company listing on the Adopting Members with Conformant Products pages.

[Android] Compile module

Android 模組編譯(mm, mmm)

Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:

- croot: Changes directory to the top of the tree.
- m: Makes from the top of the tree.
- mm: Builds all of the modules in the current directory.
- mmm: Builds all of the modules in the supplied directories.

- cgrep: Greps on all local C/C++ files.
- hgrep: Greps on all local C/C++ header files.
- jgrep: Greps on all local Java files.
- mkgrep: Greps on all local make files.
- rcgrep: Greps on all local .rc files.
- resgrep: Greps on all local res/*.xml files.
- shgrep: Greps on all local .sh files.
- godir: Go to the directory containing a file.

We can use mm/mmm to compile modules, don't need to build the whole system.

[Android] StrictMode

New Gingerbread API: StrictMode

StrictMode is a new API in Gingerbread which primarily lets you set a policy on a thread declaring what you’re not allowed to do on that thread, and what the penalty is if you violate the policy. Implementation-wise, this policy is simply a thread-local integer bitmask.

By default everything is allowed and it won’t get in your way unless you want it to. The flags you can enable in the thread policy include:

detect disk writes
detect disk reads
detect network usage

on a violation: log
on a violation: crash
on a violation: dropbox
on a violation: show an annoying dialog

Watching StrictMode


If you’re using penaltyLog(), the default, just run adb logcat and watch the terminal output. Any violations will be logged to your console, slightly rate-limited for duplicate elimination.

If you want to get fancier, turn on penaltyDropbox() and they’ll be written to the DropBoxManager, where you can extract them later with

adb shell dumpsys dropbox data_app_strictmode --print

SystemServer Thread

When boot up, SystemServer Thread will enable StrictMode for debug purpose (if it is not a user build).
And any violations will be logged to dropbox.

2011年5月10日 星期二

[Android] Add an exchange gmail account

Gmail Exchange ActiveSync (EAS) configuration:


server address: m.google.com
domain: google
user name: Your full Gmail address (e.g. test@gmail.com)
password: Your Gmail password
TLS/SSL required: yes

Test Android version: 2.3.3 (Gingerbread)


Step 1. Settings -> Account & sync settings -> Press "Add account"


Step 2. Select account type "Corporate"


Step 3. Type email address & password then press "Next".


Step 4. Wait for retrieving account information.


Step 5. Modify server settings then press "Next"
(original)

(modified)


Step 6. Wait for checking incoming server settings


Step 7. Set account options.


Step 8. Set account name.



Note: Gmail EOS account can sync calendar and contact to your android phone.

2011年5月2日 星期一

[Patent] Samsung countersues Apple for patent violations

Relative articles:
Samsung countersues Apple for patent violations
Samsung files additional patent lawsuits against Apple in California
Samsung now countersuing Apple in four countries on three continents

What is seemingly unusual is that Samsung didn’t file the lawsuit in America, but instead filed lawsuits in Seoul, South Korea (5 patent infringements), Tokyo, Japan (2 patent infringements), and in Manheim, Germany (3 patent infringements).

The first seven patents are related to communications standards such as W-CDMA (UMTS) while the other three patents are user interface patents.

Patent lists:

U.S. Patent No. 7,675,941: Method and apparatus for transmitting/receiving packet data using pre-defined length indicator in a mobile communication system

U.S. Patent No. 7,362,867: Apparatus and method for generating scrambling code in UMTS mobile communication system

U.S. Patent No. 7,447,516: Method and apparatus for data transmission in a mobile telecommunication system supporting enhanced uplink service

U.S. Patent No. 7,200,792: Interleaving apparatus and method for symbol mapping in an HSDPA mobile communication system

U.S. Patent No. 7,386,001: Apparatus and method for channel coding and multiplexing in CDMA communication system

U.S. Patent No. 7,050,410: Apparatus and method for controlling a demultiplexer and a multiplexer used for rate matching in a mobile communication system

U.S. Patent No. 6,928,604: Turbo encoding/decoding device and method for processing frame data according to QOS

U.S. Patent No. 6,292,179: Software keyboard system using trace of stylus on a touch screen and method for recognizing key code using the same

U.S. Patent No. 7,009,626: Systems and methods for generating visual representations of graphical data and digital document processing

U.S. Patent No. 7,069,055: Mobile telephone capable of displaying world time and method for controlling the same