Merge "AArch64: Use long for pointers in view/input classes"
diff --git a/api/current.txt b/api/current.txt
index 2bd9c05..50337c0 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -17651,6 +17651,7 @@
     method public static void startMethodTracing(java.lang.String);
     method public static void startMethodTracing(java.lang.String, int);
     method public static void startMethodTracing(java.lang.String, int, int);
+    method public static void startMethodTracingSampling(java.lang.String, int, int);
     method public static void startNativeTracing();
     method public static deprecated void stopAllocCounting();
     method public static void stopMethodTracing();
diff --git a/core/java/android/app/SharedPreferencesImpl.java b/core/java/android/app/SharedPreferencesImpl.java
index 86fd7b9..a292ecb 100644
--- a/core/java/android/app/SharedPreferencesImpl.java
+++ b/core/java/android/app/SharedPreferencesImpl.java
@@ -421,13 +421,15 @@
                     for (Map.Entry<String, Object> e : mModified.entrySet()) {
                         String k = e.getKey();
                         Object v = e.getValue();
-                        if (v == this) {  // magic value for a removal mutation
+                        // "this" is the magic value for a removal mutation. In addition,
+                        // setting a value to "null" for a given key is specified to be
+                        // equivalent to calling remove on that key.
+                        if (v == this || v == null) {
                             if (!mMap.containsKey(k)) {
                                 continue;
                             }
                             mMap.remove(k);
                         } else {
-                            boolean isSame = false;
                             if (mMap.containsKey(k)) {
                                 Object existingValue = mMap.get(k);
                                 if (existingValue != null && existingValue.equals(v)) {
diff --git a/core/java/android/content/ContentProviderNative.java b/core/java/android/content/ContentProviderNative.java
index bcf0b63..39286d6 100644
--- a/core/java/android/content/ContentProviderNative.java
+++ b/core/java/android/content/ContentProviderNative.java
@@ -112,17 +112,24 @@
                     Cursor cursor = query(callingPkg, url, projection, selection, selectionArgs,
                             sortOrder, cancellationSignal);
                     if (cursor != null) {
+                        CursorToBulkCursorAdaptor adaptor = null;
+
                         try {
-                            CursorToBulkCursorAdaptor adaptor = new CursorToBulkCursorAdaptor(
-                                    cursor, observer, getProviderName());
-                            BulkCursorDescriptor d = adaptor.getBulkCursorDescriptor();
+                            adaptor = new CursorToBulkCursorAdaptor(cursor, observer,
+                                    getProviderName());
                             cursor = null;
 
+                            BulkCursorDescriptor d = adaptor.getBulkCursorDescriptor();
+                            adaptor = null;
+
                             reply.writeNoException();
                             reply.writeInt(1);
                             d.writeToParcel(reply, Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
                         } finally {
                             // Close cursor if an exception was thrown while constructing the adaptor.
+                            if (adaptor != null) {
+                                adaptor.close();
+                            }
                             if (cursor != null) {
                                 cursor.close();
                             }
diff --git a/core/java/android/content/res/AssetManager.java b/core/java/android/content/res/AssetManager.java
index fc9e486..48211b5 100644
--- a/core/java/android/content/res/AssetManager.java
+++ b/core/java/android/content/res/AssetManager.java
@@ -540,6 +540,12 @@
         public final int getAssetInt() {
             return mAsset;
         }
+        /**
+         * @hide
+         */
+        public final long getNativeAsset() {
+            return mAsset;
+        }
         private AssetInputStream(int asset)
         {
             mAsset = asset;
diff --git a/core/java/android/os/Debug.java b/core/java/android/os/Debug.java
index 974bf8d..2de1204 100644
--- a/core/java/android/os/Debug.java
+++ b/core/java/android/os/Debug.java
@@ -578,7 +578,7 @@
      * tracing.
      */
     public static void startMethodTracing() {
-        VMDebug.startMethodTracing(DEFAULT_TRACE_FILE_PATH, 0, 0);
+        VMDebug.startMethodTracing(DEFAULT_TRACE_FILE_PATH, 0, 0, false, 0);
     }
 
     /**
@@ -589,7 +589,7 @@
      * information about reading trace files.
      *
      * @param traceName Name for the trace log file to create.
-     * If no name argument is given, this value defaults to "/sdcard/dmtrace.trace".
+     * If {@code traceName} is null, this value defaults to "/sdcard/dmtrace.trace".
      * If the files already exist, they will be truncated.
      * If the trace file given does not end in ".trace", it will be appended for you.
      */
@@ -604,7 +604,7 @@
        href="{@docRoot}guide/developing/tools/traceview.html">Traceview: A Graphical Log Viewer</a> for
      * information about reading trace files.
      * @param traceName    Name for the trace log file to create.
-     * If no name argument is given, this value defaults to "/sdcard/dmtrace.trace".
+     * If {@code traceName} is null, this value defaults to "/sdcard/dmtrace.trace".
      * If the files already exist, they will be truncated.
      * If the trace file given does not end in ".trace", it will be appended for you.
      *
@@ -627,26 +627,54 @@
      * in relative terms (e.g. was run #1 faster than run #2).  The times
      * for native methods will not change, so don't try to use this to
      * compare the performance of interpreted and native implementations of the
-     * same method.  As an alternative, consider using "native" tracing
-     * in the emulator via {@link #startNativeTracing()}.
+     * same method.  As an alternative, consider using sampling-based method
+     * tracing via {@link #startMethodTracingSampling(String, int, int)} or
+     * "native" tracing in the emulator via {@link #startNativeTracing()}.
      * </p>
      *
      * @param traceName    Name for the trace log file to create.
-     * If no name argument is given, this value defaults to "/sdcard/dmtrace.trace".
+     * If {@code traceName} is null, this value defaults to "/sdcard/dmtrace.trace".
      * If the files already exist, they will be truncated.
      * If the trace file given does not end in ".trace", it will be appended for you.
      * @param bufferSize    The maximum amount of trace data we gather. If not given, it defaults to 8MB.
+     * @param flags    Flags to control method tracing. The only one that is currently defined is {@link #TRACE_COUNT_ALLOCS}.
      */
     public static void startMethodTracing(String traceName, int bufferSize,
         int flags) {
+        VMDebug.startMethodTracing(fixTraceName(traceName), bufferSize, flags, false, 0);
+    }
 
-        String pathName = traceName;
-        if (pathName.charAt(0) != '/')
-            pathName = DEFAULT_TRACE_PATH_PREFIX + pathName;
-        if (!pathName.endsWith(DEFAULT_TRACE_EXTENSION))
-            pathName = pathName + DEFAULT_TRACE_EXTENSION;
+    /**
+     * Start sampling-based method tracing, specifying the trace log file name,
+     * the buffer size, and the sampling interval. The trace files will be put
+     * under "/sdcard" unless an absolute path is given. See <a
+       href="{@docRoot}guide/developing/tools/traceview.html">Traceview: A Graphical Log Viewer</a>
+     * for information about reading trace files.
+     *
+     * @param traceName    Name for the trace log file to create.
+     * If {@code traceName} is null, this value defaults to "/sdcard/dmtrace.trace".
+     * If the files already exist, they will be truncated.
+     * If the trace file given does not end in ".trace", it will be appended for you.
+     * @param bufferSize    The maximum amount of trace data we gather. If not given, it defaults to 8MB.
+     * @param intervalUs    The amount of time between each sample in microseconds.
+     */
+    public static void startMethodTracingSampling(String traceName,
+        int bufferSize, int intervalUs) {
+        VMDebug.startMethodTracing(fixTraceName(traceName), bufferSize, 0, true, intervalUs);
+    }
 
-        VMDebug.startMethodTracing(pathName, bufferSize, flags);
+    /**
+     * Formats name of trace log file for method tracing.
+     */
+    private static String fixTraceName(String traceName) {
+        if (traceName == null)
+            traceName = DEFAULT_TRACE_FILE_PATH;
+        if (traceName.charAt(0) != '/')
+            traceName = DEFAULT_TRACE_PATH_PREFIX + traceName;
+        if (!traceName.endsWith(DEFAULT_TRACE_EXTENSION))
+            traceName = traceName + DEFAULT_TRACE_EXTENSION;
+
+        return traceName;
     }
 
     /**
@@ -660,7 +688,7 @@
      */
     public static void startMethodTracing(String traceName, FileDescriptor fd,
         int bufferSize, int flags) {
-        VMDebug.startMethodTracing(traceName, fd, bufferSize, flags);
+        VMDebug.startMethodTracing(traceName, fd, bufferSize, flags, false, 0);
     }
 
     /**
diff --git a/core/java/android/os/MemoryFile.java b/core/java/android/os/MemoryFile.java
index e8148f7..ee7a4c6 100644
--- a/core/java/android/os/MemoryFile.java
+++ b/core/java/android/os/MemoryFile.java
@@ -43,19 +43,19 @@
 
     private static native FileDescriptor native_open(String name, int length) throws IOException;
     // returns memory address for ashmem region
-    private static native int native_mmap(FileDescriptor fd, int length, int mode)
+    private static native long native_mmap(FileDescriptor fd, int length, int mode)
             throws IOException;
-    private static native void native_munmap(int addr, int length) throws IOException;
+    private static native void native_munmap(long addr, int length) throws IOException;
     private static native void native_close(FileDescriptor fd);
-    private static native int native_read(FileDescriptor fd, int address, byte[] buffer,
+    private static native int native_read(FileDescriptor fd, long address, byte[] buffer,
             int srcOffset, int destOffset, int count, boolean isUnpinned) throws IOException;
-    private static native void native_write(FileDescriptor fd, int address, byte[] buffer,
+    private static native void native_write(FileDescriptor fd, long address, byte[] buffer,
             int srcOffset, int destOffset, int count, boolean isUnpinned) throws IOException;
     private static native void native_pin(FileDescriptor fd, boolean pin) throws IOException;
     private static native int native_get_size(FileDescriptor fd) throws IOException;
 
     private FileDescriptor mFD;        // ashmem file descriptor
-    private int mAddress;   // address of ashmem memory
+    private long mAddress;   // address of ashmem memory
     private int mLength;    // total length of our ashmem region
     private boolean mAllowPurging = false;  // true if our ashmem region is unpinned
 
diff --git a/core/java/android/os/MessageQueue.java b/core/java/android/os/MessageQueue.java
index 799de5c..75f9813 100644
--- a/core/java/android/os/MessageQueue.java
+++ b/core/java/android/os/MessageQueue.java
@@ -35,7 +35,7 @@
     private final boolean mQuitAllowed;
 
     @SuppressWarnings("unused")
-    private int mPtr; // used by native code
+    private long mPtr; // used by native code
 
     Message mMessages;
     private final ArrayList<IdleHandler> mIdleHandlers = new ArrayList<IdleHandler>();
@@ -49,11 +49,11 @@
     // Barriers are indicated by messages with a null target whose arg1 field carries the token.
     private int mNextBarrierToken;
 
-    private native static int nativeInit();
-    private native static void nativeDestroy(int ptr);
-    private native static void nativePollOnce(int ptr, int timeoutMillis);
-    private native static void nativeWake(int ptr);
-    private native static boolean nativeIsIdling(int ptr);
+    private native static long nativeInit();
+    private native static void nativeDestroy(long ptr);
+    private native static void nativePollOnce(long ptr, int timeoutMillis);
+    private native static void nativeWake(long ptr);
+    private native static boolean nativeIsIdling(long ptr);
 
     /**
      * Callback interface for discovering when a thread is going to block
diff --git a/core/java/android/speech/srec/MicrophoneInputStream.java b/core/java/android/speech/srec/MicrophoneInputStream.java
index fab77a9..94db176 100644
--- a/core/java/android/speech/srec/MicrophoneInputStream.java
+++ b/core/java/android/speech/srec/MicrophoneInputStream.java
@@ -34,7 +34,7 @@
     }
     
     private final static String TAG = "MicrophoneInputStream";
-    private int mAudioRecord = 0;
+    private long mAudioRecord = 0;
     private byte[] mOneByte = new byte[1];
     
     /**
@@ -102,9 +102,9 @@
     //
     // AudioRecord JNI interface
     //
-    private static native int AudioRecordNew(int sampleRate, int fifoDepth);
-    private static native int AudioRecordStart(int audioRecord);
-    private static native int AudioRecordRead(int audioRecord, byte[] b, int offset, int length) throws IOException;
-    private static native void AudioRecordStop(int audioRecord) throws IOException;
-    private static native void AudioRecordDelete(int audioRecord) throws IOException;
+    private static native long AudioRecordNew(int sampleRate, int fifoDepth);
+    private static native int AudioRecordStart(long audioRecord);
+    private static native int AudioRecordRead(long audioRecord, byte[] b, int offset, int length) throws IOException;
+    private static native void AudioRecordStop(long audioRecord) throws IOException;
+    private static native void AudioRecordDelete(long audioRecord) throws IOException;
 }
diff --git a/core/java/android/speech/srec/Recognizer.java b/core/java/android/speech/srec/Recognizer.java
index db5d8fd..1396204 100644
--- a/core/java/android/speech/srec/Recognizer.java
+++ b/core/java/android/speech/srec/Recognizer.java
@@ -125,10 +125,10 @@
     public static final String KEY_MEANING = "meaning";
 
     // handle to SR_Vocabulary object
-    private int mVocabulary = 0;
+    private long mVocabulary = 0;
     
     // handle to SR_Recognizer object
-    private int mRecognizer = 0;
+    private long mRecognizer = 0;
     
     // Grammar currently associated with Recognizer via SR_GrammarSetupRecognizer
     private Grammar mActiveGrammar = null;
@@ -174,7 +174,7 @@
      * Represents a grammar loaded into the Recognizer.
      */
     public class Grammar {
-        private int mGrammar = 0;
+        private long mGrammar = 0;
 
         /**
          * Create a <code>Grammar</code> instance.
@@ -603,116 +603,116 @@
     //
     // SR_Recognizer methods
     //
-    private static native void SR_RecognizerStart(int recognizer);
-    private static native void SR_RecognizerStop(int recognizer);
-    private static native int SR_RecognizerCreate();
-    private static native void SR_RecognizerDestroy(int recognizer);
-    private static native void SR_RecognizerSetup(int recognizer);
-    private static native void SR_RecognizerUnsetup(int recognizer);
-    private static native boolean SR_RecognizerIsSetup(int recognizer);
-    private static native String SR_RecognizerGetParameter(int recognizer, String key);
-    private static native int SR_RecognizerGetSize_tParameter(int recognizer, String key);
-    private static native boolean SR_RecognizerGetBoolParameter(int recognizer, String key);
-    private static native void SR_RecognizerSetParameter(int recognizer, String key, String value);
-    private static native void SR_RecognizerSetSize_tParameter(int recognizer,
+    private static native void SR_RecognizerStart(long recognizer);
+    private static native void SR_RecognizerStop(long recognizer);
+    private static native long SR_RecognizerCreate();
+    private static native void SR_RecognizerDestroy(long recognizer);
+    private static native void SR_RecognizerSetup(long recognizer);
+    private static native void SR_RecognizerUnsetup(long recognizer);
+    private static native boolean SR_RecognizerIsSetup(long recognizer);
+    private static native String SR_RecognizerGetParameter(long recognizer, String key);
+    private static native int SR_RecognizerGetSize_tParameter(long recognizer, String key);
+    private static native boolean SR_RecognizerGetBoolParameter(long recognizer, String key);
+    private static native void SR_RecognizerSetParameter(long recognizer, String key, String value);
+    private static native void SR_RecognizerSetSize_tParameter(long recognizer,
             String key, int value);
-    private static native void SR_RecognizerSetBoolParameter(int recognizer, String key,
+    private static native void SR_RecognizerSetBoolParameter(long recognizer, String key,
             boolean value);
-    private static native void SR_RecognizerSetupRule(int recognizer, int grammar,
+    private static native void SR_RecognizerSetupRule(long recognizer, long grammar,
             String ruleName);
-    private static native boolean SR_RecognizerHasSetupRules(int recognizer);
-    private static native void SR_RecognizerActivateRule(int recognizer, int grammar,
+    private static native boolean SR_RecognizerHasSetupRules(long recognizer);
+    private static native void SR_RecognizerActivateRule(long recognizer, long grammar,
             String ruleName, int weight);
-    private static native void SR_RecognizerDeactivateRule(int recognizer, int grammar,
+    private static native void SR_RecognizerDeactivateRule(long recognizer, long grammar,
             String ruleName);
-    private static native void SR_RecognizerDeactivateAllRules(int recognizer);
-    private static native boolean SR_RecognizerIsActiveRule(int recognizer, int grammar,
+    private static native void SR_RecognizerDeactivateAllRules(long recognizer);
+    private static native boolean SR_RecognizerIsActiveRule(long recognizer, long grammar,
             String ruleName);
-    private static native boolean SR_RecognizerCheckGrammarConsistency(int recognizer,
-            int grammar);
-    private static native int SR_RecognizerPutAudio(int recognizer, byte[] buffer, int offset,
+    private static native boolean SR_RecognizerCheckGrammarConsistency(long recognizer,
+            long grammar);
+    private static native int SR_RecognizerPutAudio(long recognizer, byte[] buffer, int offset,
             int length, boolean isLast);
-    private static native int SR_RecognizerAdvance(int recognizer);
-    // private static native void SR_RecognizerLoadUtterance(int recognizer,
+    private static native int SR_RecognizerAdvance(long recognizer);
+    // private static native void SR_RecognizerLoadUtterance(long recognizer,
     //         const LCHAR* filename);
-    // private static native void SR_RecognizerLoadWaveFile(int recognizer,
+    // private static native void SR_RecognizerLoadWaveFile(long recognizer,
     //         const LCHAR* filename);
-    // private static native void SR_RecognizerSetLockFunction(int recognizer,
+    // private static native void SR_RecognizerSetLockFunction(long recognizer,
     //         SR_RecognizerLockFunction function, void* data);
-    private static native boolean SR_RecognizerIsSignalClipping(int recognizer);
-    private static native boolean SR_RecognizerIsSignalDCOffset(int recognizer);
-    private static native boolean SR_RecognizerIsSignalNoisy(int recognizer);
-    private static native boolean SR_RecognizerIsSignalTooQuiet(int recognizer);
-    private static native boolean SR_RecognizerIsSignalTooFewSamples(int recognizer);
-    private static native boolean SR_RecognizerIsSignalTooManySamples(int recognizer);
+    private static native boolean SR_RecognizerIsSignalClipping(long recognizer);
+    private static native boolean SR_RecognizerIsSignalDCOffset(long recognizer);
+    private static native boolean SR_RecognizerIsSignalNoisy(long recognizer);
+    private static native boolean SR_RecognizerIsSignalTooQuiet(long recognizer);
+    private static native boolean SR_RecognizerIsSignalTooFewSamples(long recognizer);
+    private static native boolean SR_RecognizerIsSignalTooManySamples(long recognizer);
     // private static native void SR_Recognizer_Change_Sample_Rate (size_t new_sample_rate);
     
     
     //
     // SR_AcousticState native methods
     //
-    private static native void SR_AcousticStateReset(int recognizer);
-    private static native void SR_AcousticStateSet(int recognizer, String state);
-    private static native String SR_AcousticStateGet(int recognizer);
+    private static native void SR_AcousticStateReset(long recognizer);
+    private static native void SR_AcousticStateSet(long recognizer, String state);
+    private static native String SR_AcousticStateGet(long recognizer);
 
 
     //
     // SR_Grammar native methods
     //
-    private static native void SR_GrammarCompile(int grammar);
-    private static native void SR_GrammarAddWordToSlot(int grammar, String slot,
+    private static native void SR_GrammarCompile(long grammar);
+    private static native void SR_GrammarAddWordToSlot(long grammar, String slot,
             String word, String pronunciation, int weight, String tag);
-    private static native void SR_GrammarResetAllSlots(int grammar);
-    // private static native void SR_GrammarAddNametagToSlot(int grammar, String slot,
+    private static native void SR_GrammarResetAllSlots(long grammar);
+    // private static native void SR_GrammarAddNametagToSlot(long grammar, String slot,
     // const struct SR_Nametag_t* nametag, int weight, String tag);
-    private static native void SR_GrammarSetupVocabulary(int grammar, int vocabulary);
-    // private static native void SR_GrammarSetupModels(int grammar, SR_AcousticModels* models);
-    private static native void SR_GrammarSetupRecognizer(int grammar, int recognizer);
-    private static native void SR_GrammarUnsetupRecognizer(int grammar);
-    // private static native void SR_GrammarGetModels(int grammar,SR_AcousticModels** models);
-    private static native int SR_GrammarCreate();
-    private static native void SR_GrammarDestroy(int grammar);
-    private static native int SR_GrammarLoad(String filename);
-    private static native void SR_GrammarSave(int grammar, String filename);
-    // private static native void SR_GrammarSetDispatchFunction(int grammar,
+    private static native void SR_GrammarSetupVocabulary(long grammar, long vocabulary);
+    // private static native void SR_GrammarSetupModels(long grammar, SR_AcousticModels* models);
+    private static native void SR_GrammarSetupRecognizer(long grammar, long recognizer);
+    private static native void SR_GrammarUnsetupRecognizer(long grammar);
+    // private static native void SR_GrammarGetModels(long grammar,SR_AcousticModels** models);
+    private static native long SR_GrammarCreate();
+    private static native void SR_GrammarDestroy(long grammar);
+    private static native long SR_GrammarLoad(String filename);
+    private static native void SR_GrammarSave(long grammar, String filename);
+    // private static native void SR_GrammarSetDispatchFunction(long grammar,
     //         const LCHAR* name, void* userData, SR_GrammarDispatchFunction function);
-    // private static native void SR_GrammarSetParameter(int grammar, const
+    // private static native void SR_GrammarSetParameter(long grammar, const
     //         LCHAR* key, void* value);
-    // private static native void SR_GrammarSetSize_tParameter(int grammar,
+    // private static native void SR_GrammarSetSize_tParameter(long grammar,
     //         const LCHAR* key, size_t value);
-    // private static native void SR_GrammarGetParameter(int grammar, const
+    // private static native void SR_GrammarGetParameter(long grammar, const
     //         LCHAR* key, void** value);
-    // private static native void SR_GrammarGetSize_tParameter(int grammar,
+    // private static native void SR_GrammarGetSize_tParameter(long grammar,
     //         const LCHAR* key, size_t* value);
-    // private static native void SR_GrammarCheckParse(int grammar, const LCHAR*
+    // private static native void SR_GrammarCheckParse(long grammar, const LCHAR*
     //         transcription, SR_SemanticResult** result, size_t* resultCount);
-    private static native void SR_GrammarAllowOnly(int grammar, String transcription);
-    private static native void SR_GrammarAllowAll(int grammar);
+    private static native void SR_GrammarAllowOnly(long grammar, String transcription);
+    private static native void SR_GrammarAllowAll(long grammar);
 
 
     //
     // SR_Vocabulary native methods
     //
     // private static native int SR_VocabularyCreate();
-    private static native int SR_VocabularyLoad();
+    private static native long SR_VocabularyLoad();
     // private static native void SR_VocabularySave(SR_Vocabulary* self,
     //         const LCHAR* filename);
     // private static native void SR_VocabularyAddWord(SR_Vocabulary* self,
     //         const LCHAR* word);
     // private static native void SR_VocabularyGetLanguage(SR_Vocabulary* self,
     //         ESR_Locale* locale);
-    private static native void SR_VocabularyDestroy(int vocabulary);
-    private static native String SR_VocabularyGetPronunciation(int vocabulary, String word);
+    private static native void SR_VocabularyDestroy(long vocabulary);
+    private static native String SR_VocabularyGetPronunciation(long vocabulary, String word);
 
 
     //
     // SR_RecognizerResult native methods
     //
-    private static native byte[] SR_RecognizerResultGetWaveform(int recognizer);
-    private static native int SR_RecognizerResultGetSize(int recognizer);
-    private static native int SR_RecognizerResultGetKeyCount(int recognizer, int nbest);
-    private static native String[] SR_RecognizerResultGetKeyList(int recognizer, int nbest);
-    private static native String SR_RecognizerResultGetValue(int recognizer,
+    private static native byte[] SR_RecognizerResultGetWaveform(long recognizer);
+    private static native int SR_RecognizerResultGetSize(long recognizer);
+    private static native int SR_RecognizerResultGetKeyCount(long recognizer, int nbest);
+    private static native String[] SR_RecognizerResultGetKeyList(long recognizer, int nbest);
+    private static native String SR_RecognizerResultGetValue(long recognizer,
             int nbest, String key);
-    // private static native void SR_RecognizerResultGetLocale(int recognizer, ESR_Locale* locale);
+    // private static native void SR_RecognizerResultGetLocale(long recognizer, ESR_Locale* locale);
 }
diff --git a/core/java/android/view/KeyCharacterMap.java b/core/java/android/view/KeyCharacterMap.java
index 9e5f25a..55dd6bb 100644
--- a/core/java/android/view/KeyCharacterMap.java
+++ b/core/java/android/view/KeyCharacterMap.java
@@ -282,20 +282,20 @@
         }
     };
 
-    private int mPtr;
+    private long mPtr;
 
-    private static native int nativeReadFromParcel(Parcel in);
-    private static native void nativeWriteToParcel(int ptr, Parcel out);
-    private static native void nativeDispose(int ptr);
+    private static native long nativeReadFromParcel(Parcel in);
+    private static native void nativeWriteToParcel(long ptr, Parcel out);
+    private static native void nativeDispose(long ptr);
 
-    private static native char nativeGetCharacter(int ptr, int keyCode, int metaState);
-    private static native boolean nativeGetFallbackAction(int ptr, int keyCode, int metaState,
+    private static native char nativeGetCharacter(long ptr, int keyCode, int metaState);
+    private static native boolean nativeGetFallbackAction(long ptr, int keyCode, int metaState,
             FallbackAction outFallbackAction);
-    private static native char nativeGetNumber(int ptr, int keyCode);
-    private static native char nativeGetMatch(int ptr, int keyCode, char[] chars, int metaState);
-    private static native char nativeGetDisplayLabel(int ptr, int keyCode);
-    private static native int nativeGetKeyboardType(int ptr);
-    private static native KeyEvent[] nativeGetEvents(int ptr, char[] chars);
+    private static native char nativeGetNumber(long ptr, int keyCode);
+    private static native char nativeGetMatch(long ptr, int keyCode, char[] chars, int metaState);
+    private static native char nativeGetDisplayLabel(long ptr, int keyCode);
+    private static native int nativeGetKeyboardType(long ptr);
+    private static native KeyEvent[] nativeGetEvents(long ptr, char[] chars);
 
     private KeyCharacterMap(Parcel in) {
         if (in == null) {
@@ -308,7 +308,7 @@
     }
 
     // Called from native
-    private KeyCharacterMap(int ptr) {
+    private KeyCharacterMap(long ptr) {
         mPtr = ptr;
     }
 
diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java
index db577f3..ddce3ce 100644
--- a/core/java/android/view/MotionEvent.java
+++ b/core/java/android/view/MotionEvent.java
@@ -1311,63 +1311,63 @@
     }
 
     // Pointer to the native MotionEvent object that contains the actual data.
-    private int mNativePtr;
+    private long mNativePtr;
 
     private MotionEvent mNext;
 
-    private static native int nativeInitialize(int nativePtr,
+    private static native long nativeInitialize(long nativePtr,
             int deviceId, int source, int action, int flags, int edgeFlags,
             int metaState, int buttonState,
             float xOffset, float yOffset, float xPrecision, float yPrecision,
             long downTimeNanos, long eventTimeNanos,
             int pointerCount, PointerProperties[] pointerIds, PointerCoords[] pointerCoords);
-    private static native int nativeCopy(int destNativePtr, int sourceNativePtr,
+    private static native long nativeCopy(long destNativePtr, long sourceNativePtr,
             boolean keepHistory);
-    private static native void nativeDispose(int nativePtr);
-    private static native void nativeAddBatch(int nativePtr, long eventTimeNanos,
+    private static native void nativeDispose(long nativePtr);
+    private static native void nativeAddBatch(long nativePtr, long eventTimeNanos,
             PointerCoords[] pointerCoords, int metaState);
 
-    private static native int nativeGetDeviceId(int nativePtr);
-    private static native int nativeGetSource(int nativePtr);
-    private static native int nativeSetSource(int nativePtr, int source);
-    private static native int nativeGetAction(int nativePtr);
-    private static native void nativeSetAction(int nativePtr, int action);
-    private static native boolean nativeIsTouchEvent(int nativePtr);
-    private static native int nativeGetFlags(int nativePtr);
-    private static native void nativeSetFlags(int nativePtr, int flags);
-    private static native int nativeGetEdgeFlags(int nativePtr);
-    private static native void nativeSetEdgeFlags(int nativePtr, int action);
-    private static native int nativeGetMetaState(int nativePtr);
-    private static native int nativeGetButtonState(int nativePtr);
-    private static native void nativeOffsetLocation(int nativePtr, float deltaX, float deltaY);
-    private static native float nativeGetXOffset(int nativePtr);
-    private static native float nativeGetYOffset(int nativePtr);
-    private static native float nativeGetXPrecision(int nativePtr);
-    private static native float nativeGetYPrecision(int nativePtr);
-    private static native long nativeGetDownTimeNanos(int nativePtr);
-    private static native void nativeSetDownTimeNanos(int nativePtr, long downTime);
+    private static native int nativeGetDeviceId(long nativePtr);
+    private static native int nativeGetSource(long nativePtr);
+    private static native int nativeSetSource(long nativePtr, int source);
+    private static native int nativeGetAction(long nativePtr);
+    private static native void nativeSetAction(long nativePtr, int action);
+    private static native boolean nativeIsTouchEvent(long nativePtr);
+    private static native int nativeGetFlags(long nativePtr);
+    private static native void nativeSetFlags(long nativePtr, int flags);
+    private static native int nativeGetEdgeFlags(long nativePtr);
+    private static native void nativeSetEdgeFlags(long nativePtr, int action);
+    private static native int nativeGetMetaState(long nativePtr);
+    private static native int nativeGetButtonState(long nativePtr);
+    private static native void nativeOffsetLocation(long nativePtr, float deltaX, float deltaY);
+    private static native float nativeGetXOffset(long nativePtr);
+    private static native float nativeGetYOffset(long nativePtr);
+    private static native float nativeGetXPrecision(long nativePtr);
+    private static native float nativeGetYPrecision(long nativePtr);
+    private static native long nativeGetDownTimeNanos(long nativePtr);
+    private static native void nativeSetDownTimeNanos(long nativePtr, long downTime);
 
-    private static native int nativeGetPointerCount(int nativePtr);
-    private static native int nativeGetPointerId(int nativePtr, int pointerIndex);
-    private static native int nativeGetToolType(int nativePtr, int pointerIndex);
-    private static native int nativeFindPointerIndex(int nativePtr, int pointerId);
+    private static native int nativeGetPointerCount(long nativePtr);
+    private static native int nativeGetPointerId(long nativePtr, int pointerIndex);
+    private static native int nativeGetToolType(long nativePtr, int pointerIndex);
+    private static native int nativeFindPointerIndex(long nativePtr, int pointerId);
 
-    private static native int nativeGetHistorySize(int nativePtr);
-    private static native long nativeGetEventTimeNanos(int nativePtr, int historyPos);
-    private static native float nativeGetRawAxisValue(int nativePtr,
+    private static native int nativeGetHistorySize(long nativePtr);
+    private static native long nativeGetEventTimeNanos(long nativePtr, int historyPos);
+    private static native float nativeGetRawAxisValue(long nativePtr,
             int axis, int pointerIndex, int historyPos);
-    private static native float nativeGetAxisValue(int nativePtr,
+    private static native float nativeGetAxisValue(long nativePtr,
             int axis, int pointerIndex, int historyPos);
-    private static native void nativeGetPointerCoords(int nativePtr,
+    private static native void nativeGetPointerCoords(long nativePtr,
             int pointerIndex, int historyPos, PointerCoords outPointerCoords);
-    private static native void nativeGetPointerProperties(int nativePtr,
+    private static native void nativeGetPointerProperties(long nativePtr,
             int pointerIndex, PointerProperties outPointerProperties);
 
-    private static native void nativeScale(int nativePtr, float scale);
-    private static native void nativeTransform(int nativePtr, Matrix matrix);
+    private static native void nativeScale(long nativePtr, float scale);
+    private static native void nativeTransform(long nativePtr, Matrix matrix);
 
-    private static native int nativeReadFromParcel(int nativePtr, Parcel parcel);
-    private static native void nativeWriteToParcel(int nativePtr, Parcel parcel);
+    private static native long nativeReadFromParcel(long nativePtr, Parcel parcel);
+    private static native void nativeWriteToParcel(long nativePtr, Parcel parcel);
 
     private MotionEvent() {
     }
diff --git a/core/java/android/view/VelocityTracker.java b/core/java/android/view/VelocityTracker.java
index eb81f72..22b5cca 100644
--- a/core/java/android/view/VelocityTracker.java
+++ b/core/java/android/view/VelocityTracker.java
@@ -34,17 +34,17 @@
 
     private static final int ACTIVE_POINTER_ID = -1;
 
-    private int mPtr;
+    private long mPtr;
     private final String mStrategy;
 
-    private static native int nativeInitialize(String strategy);
-    private static native void nativeDispose(int ptr);
-    private static native void nativeClear(int ptr);
-    private static native void nativeAddMovement(int ptr, MotionEvent event);
-    private static native void nativeComputeCurrentVelocity(int ptr, int units, float maxVelocity);
-    private static native float nativeGetXVelocity(int ptr, int id);
-    private static native float nativeGetYVelocity(int ptr, int id);
-    private static native boolean nativeGetEstimator(int ptr, int id, Estimator outEstimator);
+    private static native long nativeInitialize(String strategy);
+    private static native void nativeDispose(long ptr);
+    private static native void nativeClear(long ptr);
+    private static native void nativeAddMovement(long ptr, MotionEvent event);
+    private static native void nativeComputeCurrentVelocity(long ptr, int units, float maxVelocity);
+    private static native float nativeGetXVelocity(long ptr, int id);
+    private static native float nativeGetYVelocity(long ptr, int id);
+    private static native boolean nativeGetEstimator(long ptr, int id, Estimator outEstimator);
 
     /**
      * Retrieve a new VelocityTracker object to watch the velocity of a
diff --git a/core/java/android/widget/CursorTreeAdapter.java b/core/java/android/widget/CursorTreeAdapter.java
old mode 100644
new mode 100755
index 44d1656..405e45a
--- a/core/java/android/widget/CursorTreeAdapter.java
+++ b/core/java/android/widget/CursorTreeAdapter.java
@@ -497,7 +497,7 @@
 
             @Override
             public void onChange(boolean selfChange) {
-                if (mAutoRequery && mCursor != null) {
+                if (mAutoRequery && mCursor != null && !mCursor.isClosed()) {
                     if (false) Log.v("Cursor", "Auto requerying " + mCursor +
                             " due to update");
                     mDataValid = mCursor.requery();
diff --git a/core/jni/android/graphics/BitmapRegionDecoder.cpp b/core/jni/android/graphics/BitmapRegionDecoder.cpp
index ee47ac4..e7d2422 100644
--- a/core/jni/android/graphics/BitmapRegionDecoder.cpp
+++ b/core/jni/android/graphics/BitmapRegionDecoder.cpp
@@ -102,7 +102,7 @@
 }
 
 static jobject nativeNewInstanceFromByteArray(JNIEnv* env, jobject, jbyteArray byteArray,
-                                     int offset, int length, jboolean isShareable) {
+                                     jint offset, jint length, jboolean isShareable) {
     /*  If isShareable we could decide to just wrap the java array and
         share it, but that means adding a globalref to the java array object
         For now we just always copy the array's data if isShareable.
@@ -151,7 +151,7 @@
 }
 
 static jobject nativeNewInstanceFromAsset(JNIEnv* env, jobject clazz,
-                                 jint native_asset, // Asset
+                                 jlong native_asset, // Asset
                                  jboolean isShareable) {
     Asset* asset = reinterpret_cast<Asset*>(native_asset);
     SkAutoTUnref<SkMemoryStream> stream(CopyAssetToStream(asset));
@@ -170,8 +170,9 @@
  * purgeable not supported
  * reportSizeToVM not supported
  */
-static jobject nativeDecodeRegion(JNIEnv* env, jobject, SkBitmapRegionDecoder *brd,
-                                int start_x, int start_y, int width, int height, jobject options) {
+static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle,
+                                jint start_x, jint start_y, jint width, jint height, jobject options) {
+    SkBitmapRegionDecoder *brd = reinterpret_cast<SkBitmapRegionDecoder*>(brdHandle);
     jobject tileBitmap = NULL;
     SkImageDecoder *decoder = brd->getDecoder();
     int sampleSize = 1;
@@ -256,15 +257,18 @@
     return GraphicsJNI::createBitmap(env, bitmap, buff, bitmapCreateFlags, NULL, NULL, -1);
 }
 
-static int nativeGetHeight(JNIEnv* env, jobject, SkBitmapRegionDecoder *brd) {
-    return brd->getHeight();
+static jint nativeGetHeight(JNIEnv* env, jobject, jlong brdHandle) {
+    SkBitmapRegionDecoder *brd = reinterpret_cast<SkBitmapRegionDecoder*>(brdHandle);
+    return static_cast<jint>(brd->getHeight());
 }
 
-static int nativeGetWidth(JNIEnv* env, jobject, SkBitmapRegionDecoder *brd) {
-    return brd->getWidth();
+static jint nativeGetWidth(JNIEnv* env, jobject, jlong brdHandle) {
+    SkBitmapRegionDecoder *brd = reinterpret_cast<SkBitmapRegionDecoder*>(brdHandle);
+    return static_cast<jint>(brd->getWidth());
 }
 
-static void nativeClean(JNIEnv* env, jobject, SkBitmapRegionDecoder *brd) {
+static void nativeClean(JNIEnv* env, jobject, jlong brdHandle) {
+    SkBitmapRegionDecoder *brd = reinterpret_cast<SkBitmapRegionDecoder*>(brdHandle);
     delete brd;
 }
 
@@ -274,14 +278,14 @@
 
 static JNINativeMethod gBitmapRegionDecoderMethods[] = {
     {   "nativeDecodeRegion",
-        "(IIIIILandroid/graphics/BitmapFactory$Options;)Landroid/graphics/Bitmap;",
+        "(JIIIILandroid/graphics/BitmapFactory$Options;)Landroid/graphics/Bitmap;",
         (void*)nativeDecodeRegion},
 
-    {   "nativeGetHeight", "(I)I", (void*)nativeGetHeight},
+    {   "nativeGetHeight", "(J)I", (void*)nativeGetHeight},
 
-    {   "nativeGetWidth", "(I)I", (void*)nativeGetWidth},
+    {   "nativeGetWidth", "(J)I", (void*)nativeGetWidth},
 
-    {   "nativeClean", "(I)V", (void*)nativeClean},
+    {   "nativeClean", "(J)V", (void*)nativeClean},
 
     {   "nativeNewInstance",
         "([BIIZ)Landroid/graphics/BitmapRegionDecoder;",
@@ -299,7 +303,7 @@
     },
 
     {   "nativeNewInstance",
-        "(IZ)Landroid/graphics/BitmapRegionDecoder;",
+        "(JZ)Landroid/graphics/BitmapRegionDecoder;",
         (void*)nativeNewInstanceFromAsset
     },
 };
diff --git a/core/jni/android/graphics/Graphics.cpp b/core/jni/android/graphics/Graphics.cpp
index 38a9ba3..a10e158 100644
--- a/core/jni/android/graphics/Graphics.cpp
+++ b/core/jni/android/graphics/Graphics.cpp
@@ -392,7 +392,7 @@
 
     jobject obj = env->NewObject(gBitmapRegionDecoder_class,
             gBitmapRegionDecoder_constructorMethodID,
-            static_cast<jint>(reinterpret_cast<uintptr_t>(bitmap)));
+            reinterpret_cast<jlong>(bitmap));
     hasException(env); // For the side effect of logging.
     return obj;
 }
@@ -651,7 +651,7 @@
     gBitmap_reinitMethodID = env->GetMethodID(gBitmap_class, "reinit", "(IIZ)V");
     gBitmap_getAllocationByteCountMethodID = env->GetMethodID(gBitmap_class, "getAllocationByteCount", "()I");
     gBitmapRegionDecoder_class = make_globalref(env, "android/graphics/BitmapRegionDecoder");
-    gBitmapRegionDecoder_constructorMethodID = env->GetMethodID(gBitmapRegionDecoder_class, "<init>", "(I)V");
+    gBitmapRegionDecoder_constructorMethodID = env->GetMethodID(gBitmapRegionDecoder_class, "<init>", "(J)V");
 
     gBitmapConfig_class = make_globalref(env, "android/graphics/Bitmap$Config");
     gBitmapConfig_nativeInstanceID = getFieldIDCheck(env, gBitmapConfig_class,
diff --git a/core/jni/android/graphics/Movie.cpp b/core/jni/android/graphics/Movie.cpp
index feb2dec..0040b6f 100644
--- a/core/jni/android/graphics/Movie.cpp
+++ b/core/jni/android/graphics/Movie.cpp
@@ -27,43 +27,43 @@
         return NULL;
     }
     return env->NewObject(gMovie_class, gMovie_constructorMethodID,
-            static_cast<jint>(reinterpret_cast<uintptr_t>(moov)));
+            static_cast<jlong>(reinterpret_cast<uintptr_t>(moov)));
 }
 
 static SkMovie* J2Movie(JNIEnv* env, jobject movie) {
     SkASSERT(env);
     SkASSERT(movie);
     SkASSERT(env->IsInstanceOf(movie, gMovie_class));
-    SkMovie* m = (SkMovie*)env->GetIntField(movie, gMovie_nativeInstanceID);
+    SkMovie* m = (SkMovie*)env->GetLongField(movie, gMovie_nativeInstanceID);
     SkASSERT(m);
     return m;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 
-static int movie_width(JNIEnv* env, jobject movie) {
+static jint movie_width(JNIEnv* env, jobject movie) {
     NPE_CHECK_RETURN_ZERO(env, movie);
-    return J2Movie(env, movie)->width();
+    return static_cast<jint>(J2Movie(env, movie)->width());
 }
 
-static int movie_height(JNIEnv* env, jobject movie) {
+static jint movie_height(JNIEnv* env, jobject movie) {
     NPE_CHECK_RETURN_ZERO(env, movie);
-    return J2Movie(env, movie)->height();
+    return static_cast<jint>(J2Movie(env, movie)->height());
 }
 
 static jboolean movie_isOpaque(JNIEnv* env, jobject movie) {
     NPE_CHECK_RETURN_ZERO(env, movie);
-    return J2Movie(env, movie)->isOpaque();
+    return J2Movie(env, movie)->isOpaque() ? JNI_TRUE : JNI_FALSE;
 }
 
-static int movie_duration(JNIEnv* env, jobject movie) {
+static jint movie_duration(JNIEnv* env, jobject movie) {
     NPE_CHECK_RETURN_ZERO(env, movie);
-    return J2Movie(env, movie)->duration();
+    return static_cast<jint>(J2Movie(env, movie)->duration());
 }
 
-static jboolean movie_setTime(JNIEnv* env, jobject movie, int ms) {
+static jboolean movie_setTime(JNIEnv* env, jobject movie, jint ms) {
     NPE_CHECK_RETURN_ZERO(env, movie);
-    return J2Movie(env, movie)->setTime(ms);
+    return J2Movie(env, movie)->setTime(ms) ? JNI_TRUE : JNI_FALSE;
 }
 
 static void movie_draw(JNIEnv* env, jobject movie, jobject canvas,
@@ -82,7 +82,7 @@
     c->drawBitmap(b, sx, sy, p);
 }
 
-static jobject movie_decodeAsset(JNIEnv* env, jobject clazz, jint native_asset) {
+static jobject movie_decodeAsset(JNIEnv* env, jobject clazz, jlong native_asset) {
     android::Asset* asset = reinterpret_cast<android::Asset*>(native_asset);
     if (asset == NULL) return NULL;
     SkAutoTUnref<SkStreamRewindable> stream (new android::AssetStreamAdaptor(asset));
@@ -115,7 +115,7 @@
 
 static jobject movie_decodeByteArray(JNIEnv* env, jobject clazz,
                                      jbyteArray byteArray,
-                                     int offset, int length) {
+                                     jint offset, jint length) {
 
     NPE_CHECK_RETURN_ZERO(env, byteArray);
 
@@ -130,7 +130,8 @@
     return create_jmovie(env, moov);
 }
 
-static void movie_destructor(JNIEnv* env, jobject, SkMovie* movie) {
+static void movie_destructor(JNIEnv* env, jobject, jlong movieHandle) {
+    SkMovie* movie = (SkMovie*) movieHandle;
     delete movie;
 }
 
@@ -146,11 +147,11 @@
     {   "setTime",  "(I)Z", (void*)movie_setTime  },
     {   "draw",     "(Landroid/graphics/Canvas;FFLandroid/graphics/Paint;)V",
                             (void*)movie_draw  },
-    { "nativeDecodeAsset", "(I)Landroid/graphics/Movie;",
+    { "nativeDecodeAsset", "(J)Landroid/graphics/Movie;",
                             (void*)movie_decodeAsset },
     { "nativeDecodeStream", "(Ljava/io/InputStream;)Landroid/graphics/Movie;",
                             (void*)movie_decodeStream },
-    { "nativeDestructor","(I)V", (void*)movie_destructor },
+    { "nativeDestructor","(J)V", (void*)movie_destructor },
     { "decodeByteArray", "([BII)Landroid/graphics/Movie;",
                             (void*)movie_decodeByteArray },
 };
@@ -165,10 +166,10 @@
     RETURN_ERR_IF_NULL(gMovie_class);
     gMovie_class = (jclass)env->NewGlobalRef(gMovie_class);
 
-    gMovie_constructorMethodID = env->GetMethodID(gMovie_class, "<init>", "(I)V");
+    gMovie_constructorMethodID = env->GetMethodID(gMovie_class, "<init>", "(J)V");
     RETURN_ERR_IF_NULL(gMovie_constructorMethodID);
 
-    gMovie_nativeInstanceID = env->GetFieldID(gMovie_class, "mNativeMovie", "I");
+    gMovie_nativeInstanceID = env->GetFieldID(gMovie_class, "mNativeMovie", "J");
     RETURN_ERR_IF_NULL(gMovie_nativeInstanceID);
 
     return android::AndroidRuntime::registerNativeMethods(env, kClassPathName,
diff --git a/core/jni/android/graphics/PathMeasure.cpp b/core/jni/android/graphics/PathMeasure.cpp
index 51a3f3a..8478a02 100644
--- a/core/jni/android/graphics/PathMeasure.cpp
+++ b/core/jni/android/graphics/PathMeasure.cpp
@@ -52,11 +52,24 @@
 class SkPathMeasureGlue {
 public:
 
-    static PathMeasurePair* create(JNIEnv* env, jobject clazz, const SkPath* path, jboolean forceClosed) {
-        return path ? new PathMeasurePair(*path, forceClosed) : new PathMeasurePair;
+    static jlong create(JNIEnv* env, jobject clazz, jlong pathHandle,
+                        jboolean forceClosedHandle) {
+        const SkPath* path = reinterpret_cast<SkPath*>(pathHandle);
+        bool forceClosed = (forceClosedHandle == JNI_TRUE);
+        PathMeasurePair* pair;
+        if(path)
+            pair = new PathMeasurePair(*path, forceClosed);
+        else
+            pair = new PathMeasurePair;
+        return reinterpret_cast<jlong>(pair);
     }
- 
-    static void setPath(JNIEnv* env, jobject clazz, PathMeasurePair* pair, const SkPath* path, jboolean forceClosed) {
+
+    static void setPath(JNIEnv* env, jobject clazz, jlong pairHandle,
+                        jlong pathHandle, jboolean forceClosedHandle) {
+        PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
+        const SkPath* path = reinterpret_cast<SkPath*>(pathHandle);
+        bool forceClosed = (forceClosedHandle == JNI_TRUE);
+
         if (NULL == path) {
             pair->fPath.reset();
         } else {
@@ -64,11 +77,12 @@
         }
         pair->fMeasure.setPath(&pair->fPath, forceClosed);
     }
- 
-    static jfloat getLength(JNIEnv* env, jobject clazz, PathMeasurePair* pair) {
-        return SkScalarToFloat(pair->fMeasure.getLength());
+
+    static jfloat getLength(JNIEnv* env, jobject clazz, jlong pairHandle) {
+        PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
+        return static_cast<jfloat>(SkScalarToFloat(pair->fMeasure.getLength()));
     }
- 
+
     static void convertTwoElemFloatArray(JNIEnv* env, jfloatArray array, const SkScalar src[2]) {
         AutoJavaFloatArray autoArray(env, array, 2);
         jfloat* ptr = autoArray.ptr();
@@ -76,13 +90,14 @@
         ptr[1] = SkScalarToFloat(src[1]);
     }
 
-    static jboolean getPosTan(JNIEnv* env, jobject clazz, PathMeasurePair* pair, jfloat dist, jfloatArray pos, jfloatArray tan) {
+    static jboolean getPosTan(JNIEnv* env, jobject clazz, jlong pairHandle, jfloat dist, jfloatArray pos, jfloatArray tan) {
+        PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
         SkScalar    tmpPos[2], tmpTan[2];
         SkScalar*   posPtr = pos ? tmpPos : NULL;
         SkScalar*   tanPtr = tan ? tmpTan : NULL;
         
         if (!pair->fMeasure.getPosTan(SkFloatToScalar(dist), (SkPoint*)posPtr, (SkVector*)tanPtr)) {
-            return false;
+            return JNI_FALSE;
         }
     
         if (pos) {
@@ -91,42 +106,53 @@
         if (tan) {
             convertTwoElemFloatArray(env, tan, tmpTan);
         }
-        return true;
+        return JNI_TRUE;
     }
- 
-    static jboolean getMatrix(JNIEnv* env, jobject clazz, PathMeasurePair* pair, jfloat dist,
-                          SkMatrix* matrix, int flags) {
-        return pair->fMeasure.getMatrix(SkFloatToScalar(dist), matrix, (SkPathMeasure::MatrixFlags)flags);
+
+    static jboolean getMatrix(JNIEnv* env, jobject clazz, jlong pairHandle, jfloat dist,
+                          jlong matrixHandle, jint flags) {
+        PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
+        SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
+        bool result = pair->fMeasure.getMatrix(SkFloatToScalar(dist), matrix, (SkPathMeasure::MatrixFlags)flags);
+        return result ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean getSegment(JNIEnv* env, jobject clazz, PathMeasurePair* pair, jfloat startF,
-                               jfloat stopF, SkPath* dst, jboolean startWithMoveTo) {
-        return pair->fMeasure.getSegment(SkFloatToScalar(startF), SkFloatToScalar(stopF), dst, startWithMoveTo);
+
+    static jboolean getSegment(JNIEnv* env, jobject clazz, jlong pairHandle, jfloat startF,
+                               jfloat stopF, jlong dstHandle, jboolean startWithMoveTo) {
+        PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
+        SkPath* dst = reinterpret_cast<SkPath*>(dstHandle);
+        bool result = pair->fMeasure.getSegment(SkFloatToScalar(startF), SkFloatToScalar(stopF), dst, startWithMoveTo);
+        return result ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean isClosed(JNIEnv* env, jobject clazz, PathMeasurePair* pair) {
-        return pair->fMeasure.isClosed();
+
+    static jboolean isClosed(JNIEnv* env, jobject clazz, jlong pairHandle) {
+        PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
+        bool result = pair->fMeasure.isClosed();
+        return result ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static jboolean nextContour(JNIEnv* env, jobject clazz, PathMeasurePair* pair) {
-        return pair->fMeasure.nextContour();
+
+    static jboolean nextContour(JNIEnv* env, jobject clazz, jlong pairHandle) {
+        PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
+        bool result = pair->fMeasure.nextContour();
+        return result ? JNI_TRUE : JNI_FALSE;
     }
- 
-    static void destroy(JNIEnv* env, jobject clazz, PathMeasurePair* pair) {
+
+    static void destroy(JNIEnv* env, jobject clazz, jlong pairHandle) {
+        PathMeasurePair* pair = reinterpret_cast<PathMeasurePair*>(pairHandle);
         delete pair;
     } 
 };
 
 static JNINativeMethod methods[] = {
-    {"native_create",       "(IZ)I",        (void*) SkPathMeasureGlue::create      },
-    {"native_setPath",      "(IIZ)V",       (void*) SkPathMeasureGlue::setPath     },
-    {"native_getLength",    "(I)F",         (void*) SkPathMeasureGlue::getLength   },
-    {"native_getPosTan",    "(IF[F[F)Z",    (void*) SkPathMeasureGlue::getPosTan   },
-    {"native_getMatrix",    "(IFII)Z",      (void*) SkPathMeasureGlue::getMatrix   },
-    {"native_getSegment",   "(IFFIZ)Z",     (void*) SkPathMeasureGlue::getSegment  },
-    {"native_isClosed",     "(I)Z",         (void*) SkPathMeasureGlue::isClosed    },
-    {"native_nextContour",  "(I)Z",         (void*) SkPathMeasureGlue::nextContour },
-    {"native_destroy",      "(I)V",         (void*) SkPathMeasureGlue::destroy     }
+    {"native_create",       "(JZ)J",        (void*) SkPathMeasureGlue::create      },
+    {"native_setPath",      "(JJZ)V",       (void*) SkPathMeasureGlue::setPath     },
+    {"native_getLength",    "(J)F",         (void*) SkPathMeasureGlue::getLength   },
+    {"native_getPosTan",    "(JF[F[F)Z",    (void*) SkPathMeasureGlue::getPosTan   },
+    {"native_getMatrix",    "(JFJI)Z",      (void*) SkPathMeasureGlue::getMatrix   },
+    {"native_getSegment",   "(JFFJZ)Z",     (void*) SkPathMeasureGlue::getSegment  },
+    {"native_isClosed",     "(J)Z",         (void*) SkPathMeasureGlue::isClosed    },
+    {"native_nextContour",  "(J)Z",         (void*) SkPathMeasureGlue::nextContour },
+    {"native_destroy",      "(J)V",         (void*) SkPathMeasureGlue::destroy     }
 };
 
 int register_android_graphics_PathMeasure(JNIEnv* env) {
diff --git a/core/jni/android/graphics/YuvToJpegEncoder.cpp b/core/jni/android/graphics/YuvToJpegEncoder.cpp
index f386905..799782d 100644
--- a/core/jni/android/graphics/YuvToJpegEncoder.cpp
+++ b/core/jni/android/graphics/YuvToJpegEncoder.cpp
@@ -217,8 +217,8 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 static jboolean YuvImage_compressToJpeg(JNIEnv* env, jobject, jbyteArray inYuv,
-        int format, int width, int height, jintArray offsets,
-        jintArray strides, int jpegQuality, jobject jstream,
+        jint format, jint width, jint height, jintArray offsets,
+        jintArray strides, jint jpegQuality, jobject jstream,
         jbyteArray jstorage) {
     jbyte* yuv = env->GetByteArrayElements(inYuv, NULL);
     SkWStream* strm = CreateJavaOutputStreamAdaptor(env, jstream, jstorage);
@@ -227,7 +227,7 @@
     jint* imgStrides = env->GetIntArrayElements(strides, NULL);
     YuvToJpegEncoder* encoder = YuvToJpegEncoder::create(format, imgStrides);
     if (encoder == NULL) {
-        return false;
+        return JNI_FALSE;
     }
     encoder->encode(strm, yuv, width, height, imgOffsets, jpegQuality);
 
@@ -235,7 +235,7 @@
     env->ReleaseByteArrayElements(inYuv, yuv, 0);
     env->ReleaseIntArrayElements(offsets, imgOffsets, 0);
     env->ReleaseIntArrayElements(strides, imgStrides, 0);
-    return true;
+    return JNI_TRUE;
 }
 ///////////////////////////////////////////////////////////////////////////////
 
diff --git a/core/jni/android_media_AudioRecord.cpp b/core/jni/android_media_AudioRecord.cpp
index 1c43cc5..b22668b 100644
--- a/core/jni/android_media_AudioRecord.cpp
+++ b/core/jni/android_media_AudioRecord.cpp
@@ -136,7 +136,7 @@
 {
     Mutex::Autolock l(sLock);
     AudioRecord* const ar =
-            (AudioRecord*)env->GetIntField(thiz, javaAudioRecordFields.nativeRecorderInJavaObj);
+            (AudioRecord*)env->GetLongField(thiz, javaAudioRecordFields.nativeRecorderInJavaObj);
     return sp<AudioRecord>(ar);
 }
 
@@ -144,19 +144,19 @@
 {
     Mutex::Autolock l(sLock);
     sp<AudioRecord> old =
-            (AudioRecord*)env->GetIntField(thiz, javaAudioRecordFields.nativeRecorderInJavaObj);
+            (AudioRecord*)env->GetLongField(thiz, javaAudioRecordFields.nativeRecorderInJavaObj);
     if (ar.get()) {
         ar->incStrong((void*)setAudioRecord);
     }
     if (old != 0) {
         old->decStrong((void*)setAudioRecord);
     }
-    env->SetIntField(thiz, javaAudioRecordFields.nativeRecorderInJavaObj, (int)ar.get());
+    env->SetLongField(thiz, javaAudioRecordFields.nativeRecorderInJavaObj, (jlong)ar.get());
     return old;
 }
 
 // ----------------------------------------------------------------------------
-static int
+static jint
 android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject weak_this,
         jint source, jint sampleRateInHertz, jint channelMask,
                 // Java channel masks map directly to the native definition
@@ -168,7 +168,7 @@
 
     if (!audio_is_input_channel(channelMask)) {
         ALOGE("Error creating AudioRecord: channel mask %#x is not valid.", channelMask);
-        return AUDIORECORD_ERROR_SETUP_INVALIDCHANNELMASK;
+        return (jint) AUDIORECORD_ERROR_SETUP_INVALIDCHANNELMASK;
     }
     uint32_t nbChannels = popcount(channelMask);
 
@@ -176,7 +176,7 @@
     if ((audioFormat != ENCODING_PCM_16BIT)
         && (audioFormat != ENCODING_PCM_8BIT)) {
         ALOGE("Error creating AudioRecord: unsupported audio format.");
-        return AUDIORECORD_ERROR_SETUP_INVALIDFORMAT;
+        return (jint) AUDIORECORD_ERROR_SETUP_INVALIDFORMAT;
     }
 
     int bytesPerSample = audioFormat == ENCODING_PCM_16BIT ? 2 : 1;
@@ -185,31 +185,31 @@
 
     if (buffSizeInBytes == 0) {
          ALOGE("Error creating AudioRecord: frameCount is 0.");
-        return AUDIORECORD_ERROR_SETUP_ZEROFRAMECOUNT;
+        return (jint) AUDIORECORD_ERROR_SETUP_ZEROFRAMECOUNT;
     }
     int frameSize = nbChannels * bytesPerSample;
     size_t frameCount = buffSizeInBytes / frameSize;
 
     if ((uint32_t(source) >= AUDIO_SOURCE_CNT) && (uint32_t(source) != AUDIO_SOURCE_HOTWORD)) {
         ALOGE("Error creating AudioRecord: unknown source.");
-        return AUDIORECORD_ERROR_SETUP_INVALIDSOURCE;
+        return (jint) AUDIORECORD_ERROR_SETUP_INVALIDSOURCE;
     }
 
     jclass clazz = env->GetObjectClass(thiz);
     if (clazz == NULL) {
         ALOGE("Can't find %s when setting up callback.", kClassPathName);
-        return AUDIORECORD_ERROR_SETUP_NATIVEINITFAILED;
+        return (jint) AUDIORECORD_ERROR_SETUP_NATIVEINITFAILED;
     }
 
     if (jSession == NULL) {
         ALOGE("Error creating AudioRecord: invalid session ID pointer");
-        return AUDIORECORD_ERROR;
+        return (jint) AUDIORECORD_ERROR;
     }
 
     jint* nSession = (jint *) env->GetPrimitiveArrayCritical(jSession, NULL);
     if (nSession == NULL) {
         ALOGE("Error creating AudioRecord: Error retrieving session id pointer");
-        return AUDIORECORD_ERROR;
+        return (jint) AUDIORECORD_ERROR;
     }
     int sessionId = nSession[0];
     env->ReleasePrimitiveArrayCritical(jSession, nSession, 0);
@@ -262,33 +262,33 @@
 
     // save our newly created callback information in the "nativeCallbackCookie" field
     // of the Java object (in mNativeCallbackCookie) so we can free the memory in finalize()
-    env->SetIntField(thiz, javaAudioRecordFields.nativeCallbackCookie, (int)lpCallbackData);
+    env->SetLongField(thiz, javaAudioRecordFields.nativeCallbackCookie, (jlong)lpCallbackData);
 
-    return AUDIORECORD_SUCCESS;
+    return (jint) AUDIORECORD_SUCCESS;
 
     // failure:
 native_init_failure:
     env->DeleteGlobalRef(lpCallbackData->audioRecord_class);
     env->DeleteGlobalRef(lpCallbackData->audioRecord_ref);
     delete lpCallbackData;
-    env->SetIntField(thiz, javaAudioRecordFields.nativeCallbackCookie, 0);
+    env->SetLongField(thiz, javaAudioRecordFields.nativeCallbackCookie, 0);
 
-    return AUDIORECORD_ERROR_SETUP_NATIVEINITFAILED;
+    return (jint) AUDIORECORD_ERROR_SETUP_NATIVEINITFAILED;
 }
 
 
 
 // ----------------------------------------------------------------------------
-static int
+static jint
 android_media_AudioRecord_start(JNIEnv *env, jobject thiz, jint event, jint triggerSession)
 {
     sp<AudioRecord> lpRecorder = getAudioRecord(env, thiz);
     if (lpRecorder == NULL ) {
         jniThrowException(env, "java/lang/IllegalStateException", NULL);
-        return AUDIORECORD_ERROR;
+        return (jint) AUDIORECORD_ERROR;
     }
 
-    return android_media_translateRecorderErrorCode(
+    return (jint) android_media_translateRecorderErrorCode(
             lpRecorder->start((AudioSystem::sync_event_t)event, triggerSession));
 }
 
@@ -319,12 +319,12 @@
     ALOGV("About to delete lpRecorder: %x\n", (int)lpRecorder.get());
     lpRecorder->stop();
 
-    audiorecord_callback_cookie *lpCookie = (audiorecord_callback_cookie *)env->GetIntField(
+    audiorecord_callback_cookie *lpCookie = (audiorecord_callback_cookie *)env->GetLongField(
         thiz, javaAudioRecordFields.nativeCallbackCookie);
 
     // reset the native resources in the Java object so any attempt to access
     // them after a call to release fails.
-    env->SetIntField(thiz, javaAudioRecordFields.nativeCallbackCookie, 0);
+    env->SetLongField(thiz, javaAudioRecordFields.nativeCallbackCookie, 0);
 
     // delete the callback information
     if (lpCookie) {
@@ -585,7 +585,7 @@
     //    mNativeRecorderInJavaObj
     javaAudioRecordFields.nativeRecorderInJavaObj =
         env->GetFieldID(audioRecordClass,
-                        JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME, "I");
+                        JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME, "J");
     if (javaAudioRecordFields.nativeRecorderInJavaObj == NULL) {
         ALOGE("Can't find AudioRecord.%s", JAVA_NATIVERECORDERINJAVAOBJ_FIELD_NAME);
         return -1;
@@ -593,7 +593,7 @@
     //     mNativeCallbackCookie
     javaAudioRecordFields.nativeCallbackCookie = env->GetFieldID(
             audioRecordClass,
-            JAVA_NATIVECALLBACKINFO_FIELD_NAME, "I");
+            JAVA_NATIVECALLBACKINFO_FIELD_NAME, "J");
     if (javaAudioRecordFields.nativeCallbackCookie == NULL) {
         ALOGE("Can't find AudioRecord.%s", JAVA_NATIVECALLBACKINFO_FIELD_NAME);
         return -1;
diff --git a/core/jni/android_media_AudioSystem.cpp b/core/jni/android_media_AudioSystem.cpp
index 7d99464..a19d111 100644
--- a/core/jni/android_media_AudioSystem.cpp
+++ b/core/jni/android_media_AudioSystem.cpp
@@ -52,10 +52,10 @@
     return kAudioStatusError;
 }
 
-static int
+static jint
 android_media_AudioSystem_muteMicrophone(JNIEnv *env, jobject thiz, jboolean on)
 {
-    return check_AudioSystem_Command(AudioSystem::muteMicrophone(on));
+    return (jint) check_AudioSystem_Command(AudioSystem::muteMicrophone(on));
 }
 
 static jboolean
@@ -91,7 +91,7 @@
     return state;
 }
 
-static int
+static jint
 android_media_AudioSystem_setParameters(JNIEnv *env, jobject thiz, jstring keyValuePairs)
 {
     const jchar* c_keyValuePairs = env->GetStringCritical(keyValuePairs, 0);
@@ -101,7 +101,7 @@
         env->ReleaseStringCritical(keyValuePairs, c_keyValuePairs);
     }
     int status = check_AudioSystem_Command(AudioSystem::setParameters(0, c_keyValuePairs8));
-    return status;
+    return (jint) status;
 }
 
 static jstring
@@ -131,7 +131,7 @@
                               check_AudioSystem_Command(err));
 }
 
-static int
+static jint
 android_media_AudioSystem_setDeviceConnectionState(JNIEnv *env, jobject thiz, jint device, jint state, jstring device_address)
 {
     const char *c_address = env->GetStringUTFChars(device_address, NULL);
@@ -139,60 +139,60 @@
                                           static_cast <audio_policy_dev_state_t>(state),
                                           c_address));
     env->ReleaseStringUTFChars(device_address, c_address);
-    return status;
+    return (jint) status;
 }
 
-static int
+static jint
 android_media_AudioSystem_getDeviceConnectionState(JNIEnv *env, jobject thiz, jint device, jstring device_address)
 {
     const char *c_address = env->GetStringUTFChars(device_address, NULL);
     int state = static_cast <int>(AudioSystem::getDeviceConnectionState(static_cast <audio_devices_t>(device),
                                           c_address));
     env->ReleaseStringUTFChars(device_address, c_address);
-    return state;
+    return (jint) state;
 }
 
-static int
+static jint
 android_media_AudioSystem_setPhoneState(JNIEnv *env, jobject thiz, jint state)
 {
-    return check_AudioSystem_Command(AudioSystem::setPhoneState((audio_mode_t) state));
+    return (jint) check_AudioSystem_Command(AudioSystem::setPhoneState((audio_mode_t) state));
 }
 
-static int
+static jint
 android_media_AudioSystem_setForceUse(JNIEnv *env, jobject thiz, jint usage, jint config)
 {
-    return check_AudioSystem_Command(AudioSystem::setForceUse(static_cast <audio_policy_force_use_t>(usage),
+    return (jint) check_AudioSystem_Command(AudioSystem::setForceUse(static_cast <audio_policy_force_use_t>(usage),
                                                            static_cast <audio_policy_forced_cfg_t>(config)));
 }
 
-static int
+static jint
 android_media_AudioSystem_getForceUse(JNIEnv *env, jobject thiz, jint usage)
 {
-    return static_cast <int>(AudioSystem::getForceUse(static_cast <audio_policy_force_use_t>(usage)));
+    return static_cast <jint>(AudioSystem::getForceUse(static_cast <audio_policy_force_use_t>(usage)));
 }
 
-static int
+static jint
 android_media_AudioSystem_initStreamVolume(JNIEnv *env, jobject thiz, jint stream, jint indexMin, jint indexMax)
 {
-    return check_AudioSystem_Command(AudioSystem::initStreamVolume(static_cast <audio_stream_type_t>(stream),
+    return (jint) check_AudioSystem_Command(AudioSystem::initStreamVolume(static_cast <audio_stream_type_t>(stream),
                                                                    indexMin,
                                                                    indexMax));
 }
 
-static int
+static jint
 android_media_AudioSystem_setStreamVolumeIndex(JNIEnv *env,
                                                jobject thiz,
                                                jint stream,
                                                jint index,
                                                jint device)
 {
-    return check_AudioSystem_Command(
+    return (jint) check_AudioSystem_Command(
             AudioSystem::setStreamVolumeIndex(static_cast <audio_stream_type_t>(stream),
                                               index,
                                               (audio_devices_t)device));
 }
 
-static int
+static jint
 android_media_AudioSystem_getStreamVolumeIndex(JNIEnv *env,
                                                jobject thiz,
                                                jint stream,
@@ -205,13 +205,13 @@
             != NO_ERROR) {
         index = -1;
     }
-    return index;
+    return (jint) index;
 }
 
-static int
+static jint
 android_media_AudioSystem_setMasterVolume(JNIEnv *env, jobject thiz, jfloat value)
 {
-    return check_AudioSystem_Command(AudioSystem::setMasterVolume(value));
+    return (jint) check_AudioSystem_Command(AudioSystem::setMasterVolume(value));
 }
 
 static jfloat
@@ -224,10 +224,10 @@
     return value;
 }
 
-static int
+static jint
 android_media_AudioSystem_setMasterMute(JNIEnv *env, jobject thiz, jboolean mute)
 {
-    return check_AudioSystem_Command(AudioSystem::setMasterMute(mute));
+    return (jint) check_AudioSystem_Command(AudioSystem::setMasterMute(mute));
 }
 
 static jfloat
@@ -275,10 +275,10 @@
     return (jint) AudioSystem::setLowRamDevice((bool) isLowRamDevice);
 }
 
-static int
+static jint
 android_media_AudioSystem_checkAudioFlinger(JNIEnv *env, jobject clazz)
 {
-    return check_AudioSystem_Command(AudioSystem::checkAudioFlinger());
+    return (jint) check_AudioSystem_Command(AudioSystem::checkAudioFlinger());
 }
 
 // ----------------------------------------------------------------------------
diff --git a/core/jni/android_media_AudioTrack.cpp b/core/jni/android_media_AudioTrack.cpp
index 225bf06..dc8d9d8 100644
--- a/core/jni/android_media_AudioTrack.cpp
+++ b/core/jni/android_media_AudioTrack.cpp
@@ -174,7 +174,7 @@
 {
     Mutex::Autolock l(sLock);
     AudioTrack* const at =
-            (AudioTrack*)env->GetIntField(thiz, javaAudioTrackFields.nativeTrackInJavaObj);
+            (AudioTrack*)env->GetLongField(thiz, javaAudioTrackFields.nativeTrackInJavaObj);
     return sp<AudioTrack>(at);
 }
 
@@ -182,19 +182,19 @@
 {
     Mutex::Autolock l(sLock);
     sp<AudioTrack> old =
-            (AudioTrack*)env->GetIntField(thiz, javaAudioTrackFields.nativeTrackInJavaObj);
+            (AudioTrack*)env->GetLongField(thiz, javaAudioTrackFields.nativeTrackInJavaObj);
     if (at.get()) {
         at->incStrong((void*)setAudioTrack);
     }
     if (old != 0) {
         old->decStrong((void*)setAudioTrack);
     }
-    env->SetIntField(thiz, javaAudioTrackFields.nativeTrackInJavaObj, (int)at.get());
+    env->SetLongField(thiz, javaAudioTrackFields.nativeTrackInJavaObj, (jlong)at.get());
     return old;
 }
 
 // ----------------------------------------------------------------------------
-static int
+static jint
 android_media_AudioTrack_native_setup(JNIEnv *env, jobject thiz, jobject weak_this,
         jint streamType, jint sampleRateInHertz, jint javaChannelMask,
         jint audioFormat, jint buffSizeInBytes, jint memoryMode, jintArray jSession)
@@ -206,11 +206,11 @@
 
     if (AudioSystem::getOutputFrameCount(&afFrameCount, (audio_stream_type_t) streamType) != NO_ERROR) {
         ALOGE("Error creating AudioTrack: Could not get AudioSystem frame count.");
-        return AUDIOTRACK_ERROR_SETUP_AUDIOSYSTEM;
+        return (jint) AUDIOTRACK_ERROR_SETUP_AUDIOSYSTEM;
     }
     if (AudioSystem::getOutputSamplingRate(&afSampleRate, (audio_stream_type_t) streamType) != NO_ERROR) {
         ALOGE("Error creating AudioTrack: Could not get AudioSystem sampling rate.");
-        return AUDIOTRACK_ERROR_SETUP_AUDIOSYSTEM;
+        return (jint) AUDIOTRACK_ERROR_SETUP_AUDIOSYSTEM;
     }
 
     // Java channel masks don't map directly to the native definition, but it's a simple shift
@@ -219,7 +219,7 @@
 
     if (!audio_is_output_channel(nativeChannelMask)) {
         ALOGE("Error creating AudioTrack: invalid channel mask %#x.", javaChannelMask);
-        return AUDIOTRACK_ERROR_SETUP_INVALIDCHANNELMASK;
+        return (jint) AUDIOTRACK_ERROR_SETUP_INVALIDCHANNELMASK;
     }
 
     int nbChannels = popcount(nativeChannelMask);
@@ -239,7 +239,7 @@
         break;
     default:
         ALOGE("Error creating AudioTrack: unknown stream type.");
-        return AUDIOTRACK_ERROR_SETUP_INVALIDSTREAMTYPE;
+        return (jint) AUDIOTRACK_ERROR_SETUP_INVALIDSTREAMTYPE;
     }
 
     // check the format.
@@ -247,7 +247,7 @@
     if ((audioFormat != ENCODING_PCM_16BIT) && (audioFormat != ENCODING_PCM_8BIT)) {
 
         ALOGE("Error creating AudioTrack: unsupported audio format.");
-        return AUDIOTRACK_ERROR_SETUP_INVALIDFORMAT;
+        return (jint) AUDIOTRACK_ERROR_SETUP_INVALIDFORMAT;
     }
 
     // for the moment 8bitPCM in MODE_STATIC is not supported natively in the AudioTrack C++ class
@@ -272,18 +272,18 @@
     jclass clazz = env->GetObjectClass(thiz);
     if (clazz == NULL) {
         ALOGE("Can't find %s when setting up callback.", kClassPathName);
-        return AUDIOTRACK_ERROR_SETUP_NATIVEINITFAILED;
+        return (jint) AUDIOTRACK_ERROR_SETUP_NATIVEINITFAILED;
     }
 
     if (jSession == NULL) {
         ALOGE("Error creating AudioTrack: invalid session ID pointer");
-        return AUDIOTRACK_ERROR;
+        return (jint) AUDIOTRACK_ERROR;
     }
 
     jint* nSession = (jint *) env->GetPrimitiveArrayCritical(jSession, NULL);
     if (nSession == NULL) {
         ALOGE("Error creating AudioTrack: Error retrieving session id pointer");
-        return AUDIOTRACK_ERROR;
+        return (jint) AUDIOTRACK_ERROR;
     }
     int sessionId = nSession[0];
     env->ReleasePrimitiveArrayCritical(jSession, nSession, 0);
@@ -370,10 +370,10 @@
     setAudioTrack(env, thiz, lpTrack);
 
     // save the JNI resources so we can free them later
-    //ALOGV("storing lpJniStorage: %x\n", (int)lpJniStorage);
-    env->SetIntField(thiz, javaAudioTrackFields.jniData, (int)lpJniStorage);
+    //ALOGV("storing lpJniStorage: %x\n", (long)lpJniStorage);
+    env->SetLongField(thiz, javaAudioTrackFields.jniData, (jlong)lpJniStorage);
 
-    return AUDIOTRACK_SUCCESS;
+    return (jint) AUDIOTRACK_SUCCESS;
 
     // failures:
 native_init_failure:
@@ -383,9 +383,9 @@
     env->DeleteGlobalRef(lpJniStorage->mCallbackData.audioTrack_class);
     env->DeleteGlobalRef(lpJniStorage->mCallbackData.audioTrack_ref);
     delete lpJniStorage;
-    env->SetIntField(thiz, javaAudioTrackFields.jniData, 0);
+    env->SetLongField(thiz, javaAudioTrackFields.jniData, 0);
 
-    return AUDIOTRACK_ERROR_SETUP_NATIVEINITFAILED;
+    return (jint) AUDIOTRACK_ERROR_SETUP_NATIVEINITFAILED;
 }
 
 
@@ -474,11 +474,11 @@
     lpTrack->stop();
 
     // delete the JNI data
-    AudioTrackJniStorage* pJniStorage = (AudioTrackJniStorage *)env->GetIntField(
+    AudioTrackJniStorage* pJniStorage = (AudioTrackJniStorage *)env->GetLongField(
         thiz, javaAudioTrackFields.jniData);
     // reset the native resources in the Java object so any attempt to access
     // them after a call to release fails.
-    env->SetIntField(thiz, javaAudioTrackFields.jniData, 0);
+    env->SetLongField(thiz, javaAudioTrackFields.jniData, 0);
 
     if (pJniStorage) {
         Mutex::Autolock l(sLock);
@@ -955,7 +955,7 @@
     //      nativeTrackInJavaObj
     javaAudioTrackFields.nativeTrackInJavaObj = env->GetFieldID(
             audioTrackClass,
-            JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME, "I");
+            JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME, "J");
     if (javaAudioTrackFields.nativeTrackInJavaObj == NULL) {
         ALOGE("Can't find AudioTrack.%s", JAVA_NATIVETRACKINJAVAOBJ_FIELD_NAME);
         return -1;
@@ -963,7 +963,7 @@
     //      jniData;
     javaAudioTrackFields.jniData = env->GetFieldID(
             audioTrackClass,
-            JAVA_JNIDATA_FIELD_NAME, "I");
+            JAVA_JNIDATA_FIELD_NAME, "J");
     if (javaAudioTrackFields.jniData == NULL) {
         ALOGE("Can't find AudioTrack.%s", JAVA_JNIDATA_FIELD_NAME);
         return -1;
diff --git a/core/jni/android_media_JetPlayer.cpp b/core/jni/android_media_JetPlayer.cpp
index 5795aba..69f5711 100644
--- a/core/jni/android_media_JetPlayer.cpp
+++ b/core/jni/android_media_JetPlayer.cpp
@@ -87,12 +87,12 @@
     if (result==EAS_SUCCESS) {
         // save our newly created C++ JetPlayer in the "nativePlayerInJavaObj" field
         // of the Java object (in mNativePlayerInJavaObj)
-        env->SetIntField(thiz, javaJetPlayerFields.nativePlayerInJavaObj, (int)lpJet);
+        env->SetLongField(thiz, javaJetPlayerFields.nativePlayerInJavaObj, (jlong)lpJet);
         return JNI_TRUE;
     } else {
         ALOGE("android_media_JetPlayer_setup(): initialization failed with EAS error code %d", (int)result);
         delete lpJet;
-        env->SetIntField(weak_this, javaJetPlayerFields.nativePlayerInJavaObj, 0);
+        env->SetLongField(weak_this, javaJetPlayerFields.nativePlayerInJavaObj, 0);
         return JNI_FALSE;
     }
 }
@@ -103,7 +103,7 @@
 android_media_JetPlayer_finalize(JNIEnv *env, jobject thiz)
 {
     ALOGV("android_media_JetPlayer_finalize(): entering.");
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet != NULL) {
         lpJet->release();
@@ -119,7 +119,7 @@
 android_media_JetPlayer_release(JNIEnv *env, jobject thiz)
 {
     android_media_JetPlayer_finalize(env, thiz);
-    env->SetIntField(thiz, javaJetPlayerFields.nativePlayerInJavaObj, 0);
+    env->SetLongField(thiz, javaJetPlayerFields.nativePlayerInJavaObj, 0);
     ALOGV("android_media_JetPlayer_release() done");
 }
 
@@ -128,7 +128,7 @@
 static jboolean
 android_media_JetPlayer_loadFromFile(JNIEnv *env, jobject thiz, jstring path)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -165,7 +165,7 @@
 android_media_JetPlayer_loadFromFileD(JNIEnv *env, jobject thiz,
     jobject fileDescriptor, jlong offset, jlong length)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -195,7 +195,7 @@
 static jboolean
 android_media_JetPlayer_closeFile(JNIEnv *env, jobject thiz)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -217,7 +217,7 @@
 static jboolean
 android_media_JetPlayer_play(JNIEnv *env, jobject thiz)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -241,7 +241,7 @@
 static jboolean
 android_media_JetPlayer_pause(JNIEnv *env, jobject thiz)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -271,7 +271,7 @@
         jint segmentNum, jint libNum, jint repeatCount, jint transpose, jint muteFlags,
         jbyte userID)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -298,7 +298,7 @@
         jint segmentNum, jint libNum, jint repeatCount, jint transpose, jbooleanArray muteArray,
         jbyte userID)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -344,7 +344,7 @@
 android_media_JetPlayer_setMuteFlags(JNIEnv *env, jobject thiz,
          jint muteFlags /*unsigned?*/, jboolean bSync)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -369,7 +369,7 @@
 android_media_JetPlayer_setMuteArray(JNIEnv *env, jobject thiz,
         jbooleanArray muteArray, jboolean bSync)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -415,7 +415,7 @@
 android_media_JetPlayer_setMuteFlag(JNIEnv *env, jobject thiz,
          jint trackId, jboolean muteFlag, jboolean bSync)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -441,7 +441,7 @@
 static jboolean
 android_media_JetPlayer_triggerClip(JNIEnv *env, jobject thiz, jint clipId)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -466,7 +466,7 @@
 static jboolean
 android_media_JetPlayer_clearQueue(JNIEnv *env, jobject thiz)
 {
-    JetPlayer *lpJet = (JetPlayer *)env->GetIntField(
+    JetPlayer *lpJet = (JetPlayer *)env->GetLongField(
         thiz, javaJetPlayerFields.nativePlayerInJavaObj);
     if (lpJet == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException",
@@ -533,7 +533,7 @@
     // Get the mNativePlayerInJavaObj variable field
     javaJetPlayerFields.nativePlayerInJavaObj = env->GetFieldID(
             jetPlayerClass,
-            JAVA_NATIVEJETPLAYERINJAVAOBJ_FIELD_NAME, "I");
+            JAVA_NATIVEJETPLAYERINJAVAOBJ_FIELD_NAME, "J");
     if (javaJetPlayerFields.nativePlayerInJavaObj == NULL) {
         ALOGE("Can't find JetPlayer.%s", JAVA_NATIVEJETPLAYERINJAVAOBJ_FIELD_NAME);
         return -1;
diff --git a/core/jni/android_media_RemoteDisplay.cpp b/core/jni/android_media_RemoteDisplay.cpp
index 463be5e..1cd3fbb 100644
--- a/core/jni/android_media_RemoteDisplay.cpp
+++ b/core/jni/android_media_RemoteDisplay.cpp
@@ -134,7 +134,7 @@
 
 // ----------------------------------------------------------------------------
 
-static jint nativeListen(JNIEnv* env, jobject remoteDisplayObj, jstring ifaceStr) {
+static jlong nativeListen(JNIEnv* env, jobject remoteDisplayObj, jstring ifaceStr) {
     ScopedUtfChars iface(env, ifaceStr);
 
     sp<IServiceManager> sm = defaultServiceManager();
@@ -155,20 +155,20 @@
     }
 
     NativeRemoteDisplay* wrapper = new NativeRemoteDisplay(display, client);
-    return reinterpret_cast<jint>(wrapper);
+    return reinterpret_cast<jlong>(wrapper);
 }
 
-static void nativePause(JNIEnv* env, jobject remoteDisplayObj, jint ptr) {
+static void nativePause(JNIEnv* env, jobject remoteDisplayObj, jlong ptr) {
     NativeRemoteDisplay* wrapper = reinterpret_cast<NativeRemoteDisplay*>(ptr);
     wrapper->pause();
 }
 
-static void nativeResume(JNIEnv* env, jobject remoteDisplayObj, jint ptr) {
+static void nativeResume(JNIEnv* env, jobject remoteDisplayObj, jlong ptr) {
     NativeRemoteDisplay* wrapper = reinterpret_cast<NativeRemoteDisplay*>(ptr);
     wrapper->resume();
 }
 
-static void nativeDispose(JNIEnv* env, jobject remoteDisplayObj, jint ptr) {
+static void nativeDispose(JNIEnv* env, jobject remoteDisplayObj, jlong ptr) {
     NativeRemoteDisplay* wrapper = reinterpret_cast<NativeRemoteDisplay*>(ptr);
     delete wrapper;
 }
@@ -176,13 +176,13 @@
 // ----------------------------------------------------------------------------
 
 static JNINativeMethod gMethods[] = {
-    {"nativeListen", "(Ljava/lang/String;)I",
+    {"nativeListen", "(Ljava/lang/String;)J",
             (void*)nativeListen },
-    {"nativeDispose", "(I)V",
+    {"nativeDispose", "(J)V",
             (void*)nativeDispose },
-    {"nativePause", "(I)V",
+    {"nativePause", "(J)V",
             (void*)nativePause },
-    {"nativeResume", "(I)V",
+    {"nativeResume", "(J)V",
             (void*)nativeResume },
 };
 
diff --git a/core/jni/android_media_ToneGenerator.cpp b/core/jni/android_media_ToneGenerator.cpp
index 76e42bc..ca00709 100644
--- a/core/jni/android_media_ToneGenerator.cpp
+++ b/core/jni/android_media_ToneGenerator.cpp
@@ -39,9 +39,9 @@
 static fields_t fields;
 
 static jboolean android_media_ToneGenerator_startTone(JNIEnv *env, jobject thiz, jint toneType, jint durationMs) {
-    ALOGV("android_media_ToneGenerator_startTone: %x", (int)thiz);
+    ALOGV("android_media_ToneGenerator_startTone: %p", thiz);
 
-    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetIntField(thiz,
+    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetLongField(thiz,
             fields.context);
     if (lpToneGen == NULL) {
         jniThrowRuntimeException(env, "Method called after release()");
@@ -52,12 +52,12 @@
 }
 
 static void android_media_ToneGenerator_stopTone(JNIEnv *env, jobject thiz) {
-    ALOGV("android_media_ToneGenerator_stopTone: %x", (int)thiz);
+    ALOGV("android_media_ToneGenerator_stopTone: %p", thiz);
 
-    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetIntField(thiz,
+    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetLongField(thiz,
             fields.context);
 
-    ALOGV("ToneGenerator lpToneGen: %x", (unsigned int)lpToneGen);
+    ALOGV("ToneGenerator lpToneGen: %p", lpToneGen);
     if (lpToneGen == NULL) {
         jniThrowRuntimeException(env, "Method called after release()");
         return;
@@ -66,7 +66,7 @@
 }
 
 static jint android_media_ToneGenerator_getAudioSessionId(JNIEnv *env, jobject thiz) {
-    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetIntField(thiz,
+    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetLongField(thiz,
             fields.context);
     if (lpToneGen == NULL) {
         jniThrowRuntimeException(env, "Method called after release()");
@@ -76,11 +76,11 @@
 }
 
 static void android_media_ToneGenerator_release(JNIEnv *env, jobject thiz) {
-    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetIntField(thiz,
+    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetLongField(thiz,
             fields.context);
-    ALOGV("android_media_ToneGenerator_release lpToneGen: %x", (int)lpToneGen);
+    ALOGV("android_media_ToneGenerator_release lpToneGen: %p", lpToneGen);
 
-    env->SetIntField(thiz, fields.context, 0);
+    env->SetLongField(thiz, fields.context, 0);
 
     delete lpToneGen;
 }
@@ -89,11 +89,11 @@
         jint streamType, jint volume) {
     ToneGenerator *lpToneGen = new ToneGenerator((audio_stream_type_t) streamType, AudioSystem::linearToLog(volume), true);
 
-    env->SetIntField(thiz, fields.context, 0);
+    env->SetLongField(thiz, fields.context, 0);
 
-    ALOGV("android_media_ToneGenerator_native_setup jobject: %x", (int)thiz);
+    ALOGV("android_media_ToneGenerator_native_setup jobject: %p", thiz);
 
-    ALOGV("ToneGenerator lpToneGen: %x", (unsigned int)lpToneGen);
+    ALOGV("ToneGenerator lpToneGen: %p", lpToneGen);
 
     if (!lpToneGen->isInited()) {
         ALOGE("ToneGenerator init failed");
@@ -103,16 +103,16 @@
     }
 
     // Stow our new C++ ToneGenerator in an opaque field in the Java object.
-    env->SetIntField(thiz, fields.context, (int)lpToneGen);
+    env->SetLongField(thiz, fields.context, (jlong)lpToneGen);
 
-    ALOGV("ToneGenerator fields.context: %x", env->GetIntField(thiz, fields.context));
+    ALOGV("ToneGenerator fields.context: %p", (void*) env->GetLongField(thiz, fields.context));
 }
 
 static void android_media_ToneGenerator_native_finalize(JNIEnv *env,
         jobject thiz) {
-    ALOGV("android_media_ToneGenerator_native_finalize jobject: %x", (int)thiz);
+    ALOGV("android_media_ToneGenerator_native_finalize jobject: %p", thiz);
 
-    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetIntField(thiz,
+    ToneGenerator *lpToneGen = (ToneGenerator *)env->GetLongField(thiz,
             fields.context);
 
     if (lpToneGen != NULL) {
@@ -142,12 +142,12 @@
         return -1;
     }
 
-    fields.context = env->GetFieldID(clazz, "mNativeContext", "I");
+    fields.context = env->GetFieldID(clazz, "mNativeContext", "J");
     if (fields.context == NULL) {
         ALOGE("Can't find ToneGenerator.mNativeContext");
         return -1;
     }
-    ALOGV("register_android_media_ToneGenerator ToneGenerator fields.context: %x", (unsigned int)fields.context);
+    ALOGV("register_android_media_ToneGenerator ToneGenerator fields.context: %p", fields.context);
 
     return AndroidRuntime::registerNativeMethods(env,
             "android/media/ToneGenerator", gMethods, NELEM(gMethods));
diff --git a/core/jni/android_os_MemoryFile.cpp b/core/jni/android_os_MemoryFile.cpp
index 7134191..88a3738 100644
--- a/core/jni/android_os_MemoryFile.cpp
+++ b/core/jni/android_os_MemoryFile.cpp
@@ -43,17 +43,17 @@
     return jniCreateFileDescriptor(env, result);
 }
 
-static jint android_os_MemoryFile_mmap(JNIEnv* env, jobject clazz, jobject fileDescriptor,
+static jlong android_os_MemoryFile_mmap(JNIEnv* env, jobject clazz, jobject fileDescriptor,
         jint length, jint prot)
 {
     int fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
-    jint result = (jint)mmap(NULL, length, prot, MAP_SHARED, fd, 0);
+    jlong result = (jlong)mmap(NULL, length, prot, MAP_SHARED, fd, 0);
     if (!result)
         jniThrowException(env, "java/io/IOException", "mmap failed");
     return result;
 }
 
-static void android_os_MemoryFile_munmap(JNIEnv* env, jobject clazz, jint addr, jint length)
+static void android_os_MemoryFile_munmap(JNIEnv* env, jobject clazz, jlong addr, jint length)
 {
     int result = munmap((void *)addr, length);
     if (result < 0)
@@ -70,7 +70,7 @@
 }
 
 static jint android_os_MemoryFile_read(JNIEnv* env, jobject clazz,
-        jobject fileDescriptor, jint address, jbyteArray buffer, jint srcOffset, jint destOffset,
+        jobject fileDescriptor, jlong address, jbyteArray buffer, jint srcOffset, jint destOffset,
         jint count, jboolean unpinned)
 {
     int fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
@@ -89,7 +89,7 @@
 }
 
 static jint android_os_MemoryFile_write(JNIEnv* env, jobject clazz,
-        jobject fileDescriptor, jint address, jbyteArray buffer, jint srcOffset, jint destOffset,
+        jobject fileDescriptor, jlong address, jbyteArray buffer, jint srcOffset, jint destOffset,
         jint count, jboolean unpinned)
 {
     int fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
@@ -138,11 +138,11 @@
 
 static const JNINativeMethod methods[] = {
     {"native_open",  "(Ljava/lang/String;I)Ljava/io/FileDescriptor;", (void*)android_os_MemoryFile_open},
-    {"native_mmap",  "(Ljava/io/FileDescriptor;II)I", (void*)android_os_MemoryFile_mmap},
-    {"native_munmap", "(II)V", (void*)android_os_MemoryFile_munmap},
+    {"native_mmap",  "(Ljava/io/FileDescriptor;II)J", (void*)android_os_MemoryFile_mmap},
+    {"native_munmap", "(JI)V", (void*)android_os_MemoryFile_munmap},
     {"native_close", "(Ljava/io/FileDescriptor;)V", (void*)android_os_MemoryFile_close},
-    {"native_read",  "(Ljava/io/FileDescriptor;I[BIIIZ)I", (void*)android_os_MemoryFile_read},
-    {"native_write", "(Ljava/io/FileDescriptor;I[BIIIZ)V", (void*)android_os_MemoryFile_write},
+    {"native_read",  "(Ljava/io/FileDescriptor;J[BIIIZ)I", (void*)android_os_MemoryFile_read},
+    {"native_write", "(Ljava/io/FileDescriptor;J[BIIIZ)V", (void*)android_os_MemoryFile_write},
     {"native_pin",   "(Ljava/io/FileDescriptor;Z)V", (void*)android_os_MemoryFile_pin},
     {"native_get_size", "(Ljava/io/FileDescriptor;)I",
             (void*)android_os_MemoryFile_get_size}
diff --git a/core/jni/android_os_MessageQueue.cpp b/core/jni/android_os_MessageQueue.cpp
index c9c3720..a8ed895 100644
--- a/core/jni/android_os_MessageQueue.cpp
+++ b/core/jni/android_os_MessageQueue.cpp
@@ -110,11 +110,11 @@
 // ----------------------------------------------------------------------------
 
 sp<MessageQueue> android_os_MessageQueue_getMessageQueue(JNIEnv* env, jobject messageQueueObj) {
-    jint intPtr = env->GetIntField(messageQueueObj, gMessageQueueClassInfo.mPtr);
-    return reinterpret_cast<NativeMessageQueue*>(intPtr);
+    jlong ptr = env->GetLongField(messageQueueObj, gMessageQueueClassInfo.mPtr);
+    return reinterpret_cast<NativeMessageQueue*>(ptr);
 }
 
-static jint android_os_MessageQueue_nativeInit(JNIEnv* env, jclass clazz) {
+static jlong android_os_MessageQueue_nativeInit(JNIEnv* env, jclass clazz) {
     NativeMessageQueue* nativeMessageQueue = new NativeMessageQueue();
     if (!nativeMessageQueue) {
         jniThrowRuntimeException(env, "Unable to allocate native queue");
@@ -122,26 +122,26 @@
     }
 
     nativeMessageQueue->incStrong(env);
-    return reinterpret_cast<jint>(nativeMessageQueue);
+    return reinterpret_cast<jlong>(nativeMessageQueue);
 }
 
-static void android_os_MessageQueue_nativeDestroy(JNIEnv* env, jclass clazz, jint ptr) {
+static void android_os_MessageQueue_nativeDestroy(JNIEnv* env, jclass clazz, jlong ptr) {
     NativeMessageQueue* nativeMessageQueue = reinterpret_cast<NativeMessageQueue*>(ptr);
     nativeMessageQueue->decStrong(env);
 }
 
 static void android_os_MessageQueue_nativePollOnce(JNIEnv* env, jclass clazz,
-        jint ptr, jint timeoutMillis) {
+        jlong ptr, jint timeoutMillis) {
     NativeMessageQueue* nativeMessageQueue = reinterpret_cast<NativeMessageQueue*>(ptr);
     nativeMessageQueue->pollOnce(env, timeoutMillis);
 }
 
-static void android_os_MessageQueue_nativeWake(JNIEnv* env, jclass clazz, jint ptr) {
+static void android_os_MessageQueue_nativeWake(JNIEnv* env, jclass clazz, jlong ptr) {
     NativeMessageQueue* nativeMessageQueue = reinterpret_cast<NativeMessageQueue*>(ptr);
     return nativeMessageQueue->wake();
 }
 
-static jboolean android_os_MessageQueue_nativeIsIdling(JNIEnv* env, jclass clazz, jint ptr) {
+static jboolean android_os_MessageQueue_nativeIsIdling(JNIEnv* env, jclass clazz, jlong ptr) {
     NativeMessageQueue* nativeMessageQueue = reinterpret_cast<NativeMessageQueue*>(ptr);
     return nativeMessageQueue->getLooper()->isIdling();
 }
@@ -150,11 +150,11 @@
 
 static JNINativeMethod gMessageQueueMethods[] = {
     /* name, signature, funcPtr */
-    { "nativeInit", "()I", (void*)android_os_MessageQueue_nativeInit },
-    { "nativeDestroy", "(I)V", (void*)android_os_MessageQueue_nativeDestroy },
-    { "nativePollOnce", "(II)V", (void*)android_os_MessageQueue_nativePollOnce },
-    { "nativeWake", "(I)V", (void*)android_os_MessageQueue_nativeWake },
-    { "nativeIsIdling", "(I)Z", (void*)android_os_MessageQueue_nativeIsIdling }
+    { "nativeInit", "()J", (void*)android_os_MessageQueue_nativeInit },
+    { "nativeDestroy", "(J)V", (void*)android_os_MessageQueue_nativeDestroy },
+    { "nativePollOnce", "(JI)V", (void*)android_os_MessageQueue_nativePollOnce },
+    { "nativeWake", "(J)V", (void*)android_os_MessageQueue_nativeWake },
+    { "nativeIsIdling", "(J)Z", (void*)android_os_MessageQueue_nativeIsIdling }
 };
 
 #define FIND_CLASS(var, className) \
@@ -174,7 +174,7 @@
     FIND_CLASS(clazz, "android/os/MessageQueue");
 
     GET_FIELD_ID(gMessageQueueClassInfo.mPtr, clazz,
-            "mPtr", "I");
+            "mPtr", "J");
     
     return 0;
 }
diff --git a/core/jni/android_view_KeyCharacterMap.cpp b/core/jni/android_view_KeyCharacterMap.cpp
index ffe2dea..62d5129 100644
--- a/core/jni/android_view_KeyCharacterMap.cpp
+++ b/core/jni/android_view_KeyCharacterMap.cpp
@@ -75,10 +75,10 @@
     }
 
     return env->NewObject(gKeyCharacterMapClassInfo.clazz, gKeyCharacterMapClassInfo.ctor,
-            reinterpret_cast<jint>(map));
+            reinterpret_cast<jlong>(map));
 }
 
-static jint nativeReadFromParcel(JNIEnv *env, jobject clazz, jobject parcelObj) {
+static jlong nativeReadFromParcel(JNIEnv *env, jobject clazz, jobject parcelObj) {
     Parcel* parcel = parcelForJavaObject(env, parcelObj);
     if (!parcel) {
         return 0;
@@ -95,10 +95,10 @@
     }
 
     NativeKeyCharacterMap* map = new NativeKeyCharacterMap(deviceId, kcm);
-    return reinterpret_cast<jint>(map);
+    return reinterpret_cast<jlong>(map);
 }
 
-static void nativeWriteToParcel(JNIEnv* env, jobject clazz, jint ptr, jobject parcelObj) {
+static void nativeWriteToParcel(JNIEnv* env, jobject clazz, jlong ptr, jobject parcelObj) {
     NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
     Parcel* parcel = parcelForJavaObject(env, parcelObj);
     if (parcel) {
@@ -107,18 +107,18 @@
     }
 }
 
-static void nativeDispose(JNIEnv *env, jobject clazz, jint ptr) {
+static void nativeDispose(JNIEnv *env, jobject clazz, jlong ptr) {
     NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
     delete map;
 }
 
-static jchar nativeGetCharacter(JNIEnv *env, jobject clazz, jint ptr,
+static jchar nativeGetCharacter(JNIEnv *env, jobject clazz, jlong ptr,
         jint keyCode, jint metaState) {
     NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
     return map->getMap()->getCharacter(keyCode, metaState);
 }
 
-static jboolean nativeGetFallbackAction(JNIEnv *env, jobject clazz, jint ptr, jint keyCode,
+static jboolean nativeGetFallbackAction(JNIEnv *env, jobject clazz, jlong ptr, jint keyCode,
         jint metaState, jobject fallbackActionObj) {
     NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
     KeyCharacterMap::FallbackAction fallbackAction;
@@ -133,12 +133,12 @@
     return result;
 }
 
-static jchar nativeGetNumber(JNIEnv *env, jobject clazz, jint ptr, jint keyCode) {
+static jchar nativeGetNumber(JNIEnv *env, jobject clazz, jlong ptr, jint keyCode) {
     NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
     return map->getMap()->getNumber(keyCode);
 }
 
-static jchar nativeGetMatch(JNIEnv *env, jobject clazz, jint ptr, jint keyCode,
+static jchar nativeGetMatch(JNIEnv *env, jobject clazz, jlong ptr, jint keyCode,
         jcharArray charsArray, jint metaState) {
     NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
 
@@ -154,17 +154,17 @@
     return result;
 }
 
-static jchar nativeGetDisplayLabel(JNIEnv *env, jobject clazz, jint ptr, jint keyCode) {
+static jchar nativeGetDisplayLabel(JNIEnv *env, jobject clazz, jlong ptr, jint keyCode) {
     NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
     return map->getMap()->getDisplayLabel(keyCode);
 }
 
-static jint nativeGetKeyboardType(JNIEnv *env, jobject clazz, jint ptr) {
+static jint nativeGetKeyboardType(JNIEnv *env, jobject clazz, jlong ptr) {
     NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
     return map->getMap()->getKeyboardType();
 }
 
-static jobjectArray nativeGetEvents(JNIEnv *env, jobject clazz, jint ptr,
+static jobjectArray nativeGetEvents(JNIEnv *env, jobject clazz, jlong ptr,
         jcharArray charsArray) {
     NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr);
 
@@ -199,25 +199,25 @@
 
 static JNINativeMethod g_methods[] = {
     /* name, signature, funcPtr */
-    { "nativeReadFromParcel", "(Landroid/os/Parcel;)I",
+    { "nativeReadFromParcel", "(Landroid/os/Parcel;)J",
             (void*)nativeReadFromParcel },
-    { "nativeWriteToParcel", "(ILandroid/os/Parcel;)V",
+    { "nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
             (void*)nativeWriteToParcel },
-    { "nativeDispose", "(I)V",
+    { "nativeDispose", "(J)V",
             (void*)nativeDispose },
-    { "nativeGetCharacter", "(III)C",
+    { "nativeGetCharacter", "(JII)C",
             (void*)nativeGetCharacter },
-    { "nativeGetFallbackAction", "(IIILandroid/view/KeyCharacterMap$FallbackAction;)Z",
+    { "nativeGetFallbackAction", "(JIILandroid/view/KeyCharacterMap$FallbackAction;)Z",
             (void*)nativeGetFallbackAction },
-    { "nativeGetNumber", "(II)C",
+    { "nativeGetNumber", "(JI)C",
             (void*)nativeGetNumber },
-    { "nativeGetMatch", "(II[CI)C",
+    { "nativeGetMatch", "(JI[CI)C",
             (void*)nativeGetMatch },
-    { "nativeGetDisplayLabel", "(II)C",
+    { "nativeGetDisplayLabel", "(JI)C",
             (void*)nativeGetDisplayLabel },
-    { "nativeGetKeyboardType", "(I)I",
+    { "nativeGetKeyboardType", "(J)I",
             (void*)nativeGetKeyboardType },
-    { "nativeGetEvents", "(I[C)[Landroid/view/KeyEvent;",
+    { "nativeGetEvents", "(J[C)[Landroid/view/KeyEvent;",
             (void*)nativeGetEvents },
 };
 
@@ -239,7 +239,7 @@
     gKeyCharacterMapClassInfo.clazz = jclass(env->NewGlobalRef(gKeyCharacterMapClassInfo.clazz));
 
     GET_METHOD_ID(gKeyCharacterMapClassInfo.ctor, gKeyCharacterMapClassInfo.clazz,
-            "<init>", "(I)V");
+            "<init>", "(J)V");
 
     FIND_CLASS(gKeyEventClassInfo.clazz, "android/view/KeyEvent");
     gKeyEventClassInfo.clazz = jclass(env->NewGlobalRef(gKeyEventClassInfo.clazz));
diff --git a/core/jni/android_view_MotionEvent.cpp b/core/jni/android_view_MotionEvent.cpp
index f1b90e1..76e145b 100644
--- a/core/jni/android_view_MotionEvent.cpp
+++ b/core/jni/android_view_MotionEvent.cpp
@@ -67,13 +67,13 @@
         return NULL;
     }
     return reinterpret_cast<MotionEvent*>(
-            env->GetIntField(eventObj, gMotionEventClassInfo.mNativePtr));
+            env->GetLongField(eventObj, gMotionEventClassInfo.mNativePtr));
 }
 
 static void android_view_MotionEvent_setNativePtr(JNIEnv* env, jobject eventObj,
         MotionEvent* event) {
-    env->SetIntField(eventObj, gMotionEventClassInfo.mNativePtr,
-            reinterpret_cast<int>(event));
+    env->SetLongField(eventObj, gMotionEventClassInfo.mNativePtr,
+            reinterpret_cast<jlong>(event));
 }
 
 jobject android_view_MotionEvent_obtainAsCopy(JNIEnv* env, const MotionEvent* event) {
@@ -334,8 +334,8 @@
 
 // ----------------------------------------------------------------------------
 
-static jint android_view_MotionEvent_nativeInitialize(JNIEnv* env, jclass clazz,
-        jint nativePtr,
+static jlong android_view_MotionEvent_nativeInitialize(JNIEnv* env, jclass clazz,
+        jlong nativePtr,
         jint deviceId, jint source, jint action, jint flags, jint edgeFlags,
         jint metaState, jint buttonState,
         jfloat xOffset, jfloat yOffset, jfloat xPrecision, jfloat yPrecision,
@@ -377,7 +377,7 @@
             xOffset, yOffset, xPrecision, yPrecision,
             downTimeNanos, eventTimeNanos, pointerCount, pointerProperties, rawPointerCoords);
 
-    return reinterpret_cast<jint>(event);
+    return reinterpret_cast<jlong>(event);
 
 Error:
     if (!nativePtr) {
@@ -386,25 +386,25 @@
     return 0;
 }
 
-static jint android_view_MotionEvent_nativeCopy(JNIEnv* env, jclass clazz,
-        jint destNativePtr, jint sourceNativePtr, jboolean keepHistory) {
+static jlong android_view_MotionEvent_nativeCopy(JNIEnv* env, jclass clazz,
+        jlong destNativePtr, jlong sourceNativePtr, jboolean keepHistory) {
     MotionEvent* destEvent = reinterpret_cast<MotionEvent*>(destNativePtr);
     if (!destEvent) {
         destEvent = new MotionEvent();
     }
     MotionEvent* sourceEvent = reinterpret_cast<MotionEvent*>(sourceNativePtr);
     destEvent->copyFrom(sourceEvent, keepHistory);
-    return reinterpret_cast<jint>(destEvent);
+    return reinterpret_cast<jlong>(destEvent);
 }
 
 static void android_view_MotionEvent_nativeDispose(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     delete event;
 }
 
 static void android_view_MotionEvent_nativeAddBatch(JNIEnv* env, jclass clazz,
-        jint nativePtr, jlong eventTimeNanos, jobjectArray pointerCoordsObjArray,
+        jlong nativePtr, jlong eventTimeNanos, jobjectArray pointerCoordsObjArray,
         jint metaState) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     size_t pointerCount = event->getPointerCount();
@@ -430,127 +430,127 @@
 }
 
 static jint android_view_MotionEvent_nativeGetDeviceId(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getDeviceId();
 }
 
 static jint android_view_MotionEvent_nativeGetSource(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getSource();
 }
 
 static void android_view_MotionEvent_nativeSetSource(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint source) {
+        jlong nativePtr, jint source) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     event->setSource(source);
 }
 
 static jint android_view_MotionEvent_nativeGetAction(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getAction();
 }
 
 static void android_view_MotionEvent_nativeSetAction(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint action) {
+        jlong nativePtr, jint action) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     event->setAction(action);
 }
 
 static jboolean android_view_MotionEvent_nativeIsTouchEvent(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->isTouchEvent();
 }
 
 static jint android_view_MotionEvent_nativeGetFlags(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getFlags();
 }
 
 static void android_view_MotionEvent_nativeSetFlags(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint flags) {
+        jlong nativePtr, jint flags) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     event->setFlags(flags);
 }
 
 static jint android_view_MotionEvent_nativeGetEdgeFlags(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getEdgeFlags();
 }
 
 static void android_view_MotionEvent_nativeSetEdgeFlags(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint edgeFlags) {
+        jlong nativePtr, jint edgeFlags) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     event->setEdgeFlags(edgeFlags);
 }
 
 static jint android_view_MotionEvent_nativeGetMetaState(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getMetaState();
 }
 
 static jint android_view_MotionEvent_nativeGetButtonState(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getButtonState();
 }
 
 static void android_view_MotionEvent_nativeOffsetLocation(JNIEnv* env, jclass clazz,
-        jint nativePtr, jfloat deltaX, jfloat deltaY) {
+        jlong nativePtr, jfloat deltaX, jfloat deltaY) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->offsetLocation(deltaX, deltaY);
 }
 
 static jfloat android_view_MotionEvent_nativeGetXOffset(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getXOffset();
 }
 
 static jfloat android_view_MotionEvent_nativeGetYOffset(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getYOffset();
 }
 
 static jfloat android_view_MotionEvent_nativeGetXPrecision(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getXPrecision();
 }
 
 static jfloat android_view_MotionEvent_nativeGetYPrecision(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getYPrecision();
 }
 
 static jlong android_view_MotionEvent_nativeGetDownTimeNanos(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return event->getDownTime();
 }
 
 static void android_view_MotionEvent_nativeSetDownTimeNanos(JNIEnv* env, jclass clazz,
-        jint nativePtr, jlong downTimeNanos) {
+        jlong nativePtr, jlong downTimeNanos) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     event->setDownTime(downTimeNanos);
 }
 
 static jint android_view_MotionEvent_nativeGetPointerCount(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return jint(event->getPointerCount());
 }
 
 static jint android_view_MotionEvent_nativeGetPointerId(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint pointerIndex) {
+        jlong nativePtr, jint pointerIndex) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     size_t pointerCount = event->getPointerCount();
     if (!validatePointerIndex(env, pointerIndex, pointerCount)) {
@@ -560,7 +560,7 @@
 }
 
 static jint android_view_MotionEvent_nativeGetToolType(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint pointerIndex) {
+        jlong nativePtr, jint pointerIndex) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     size_t pointerCount = event->getPointerCount();
     if (!validatePointerIndex(env, pointerIndex, pointerCount)) {
@@ -570,19 +570,19 @@
 }
 
 static jint android_view_MotionEvent_nativeFindPointerIndex(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint pointerId) {
+        jlong nativePtr, jint pointerId) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return jint(event->findPointerIndex(pointerId));
 }
 
 static jint android_view_MotionEvent_nativeGetHistorySize(JNIEnv* env, jclass clazz,
-        jint nativePtr) {
+        jlong nativePtr) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     return jint(event->getHistorySize());
 }
 
 static jlong android_view_MotionEvent_nativeGetEventTimeNanos(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint historyPos) {
+        jlong nativePtr, jint historyPos) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     if (historyPos == HISTORY_CURRENT) {
         return event->getEventTime();
@@ -596,7 +596,7 @@
 }
 
 static jfloat android_view_MotionEvent_nativeGetRawAxisValue(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint axis, jint pointerIndex, jint historyPos) {
+        jlong nativePtr, jint axis, jint pointerIndex, jint historyPos) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     size_t pointerCount = event->getPointerCount();
     if (!validatePointerIndex(env, pointerIndex, pointerCount)) {
@@ -615,7 +615,7 @@
 }
 
 static jfloat android_view_MotionEvent_nativeGetAxisValue(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint axis, jint pointerIndex, jint historyPos) {
+        jlong nativePtr, jint axis, jint pointerIndex, jint historyPos) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     size_t pointerCount = event->getPointerCount();
     if (!validatePointerIndex(env, pointerIndex, pointerCount)) {
@@ -634,7 +634,7 @@
 }
 
 static void android_view_MotionEvent_nativeGetPointerCoords(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint pointerIndex, jint historyPos, jobject outPointerCoordsObj) {
+        jlong nativePtr, jint pointerIndex, jint historyPos, jobject outPointerCoordsObj) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     size_t pointerCount = event->getPointerCount();
     if (!validatePointerIndex(env, pointerIndex, pointerCount)
@@ -657,7 +657,7 @@
 }
 
 static void android_view_MotionEvent_nativeGetPointerProperties(JNIEnv* env, jclass clazz,
-        jint nativePtr, jint pointerIndex, jobject outPointerPropertiesObj) {
+        jlong nativePtr, jint pointerIndex, jobject outPointerPropertiesObj) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     size_t pointerCount = event->getPointerCount();
     if (!validatePointerIndex(env, pointerIndex, pointerCount)
@@ -670,13 +670,13 @@
 }
 
 static void android_view_MotionEvent_nativeScale(JNIEnv* env, jclass clazz,
-        jint nativePtr, jfloat scale) {
+        jlong nativePtr, jfloat scale) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     event->scale(scale);
 }
 
 static void android_view_MotionEvent_nativeTransform(JNIEnv* env, jclass clazz,
-        jint nativePtr, jobject matrixObj) {
+        jlong nativePtr, jobject matrixObj) {
     SkMatrix* matrix = android_graphics_Matrix_getSkMatrix(env, matrixObj);
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
 
@@ -693,8 +693,8 @@
     event->transform(m);
 }
 
-static jint android_view_MotionEvent_nativeReadFromParcel(JNIEnv* env, jclass clazz,
-        jint nativePtr, jobject parcelObj) {
+static jlong android_view_MotionEvent_nativeReadFromParcel(JNIEnv* env, jclass clazz,
+        jlong nativePtr, jobject parcelObj) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     if (!event) {
         event = new MotionEvent();
@@ -710,11 +710,11 @@
         jniThrowRuntimeException(env, "Failed to read MotionEvent parcel.");
         return 0;
     }
-    return reinterpret_cast<jint>(event);
+    return reinterpret_cast<jlong>(event);
 }
 
 static void android_view_MotionEvent_nativeWriteToParcel(JNIEnv* env, jclass clazz,
-        jint nativePtr, jobject parcelObj) {
+        jlong nativePtr, jobject parcelObj) {
     MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
     Parcel* parcel = parcelForJavaObject(env, parcelObj);
 
@@ -729,116 +729,116 @@
 static JNINativeMethod gMotionEventMethods[] = {
     /* name, signature, funcPtr */
     { "nativeInitialize",
-            "(IIIIIIIIFFFFJJI[Landroid/view/MotionEvent$PointerProperties;"
-                    "[Landroid/view/MotionEvent$PointerCoords;)I",
+            "(JIIIIIIIFFFFJJI[Landroid/view/MotionEvent$PointerProperties;"
+                    "[Landroid/view/MotionEvent$PointerCoords;)J",
             (void*)android_view_MotionEvent_nativeInitialize },
     { "nativeCopy",
-            "(IIZ)I",
+            "(JJZ)J",
             (void*)android_view_MotionEvent_nativeCopy },
     { "nativeDispose",
-            "(I)V",
+            "(J)V",
             (void*)android_view_MotionEvent_nativeDispose },
     { "nativeAddBatch",
-            "(IJ[Landroid/view/MotionEvent$PointerCoords;I)V",
+            "(JJ[Landroid/view/MotionEvent$PointerCoords;I)V",
             (void*)android_view_MotionEvent_nativeAddBatch },
     { "nativeGetDeviceId",
-            "(I)I",
+            "(J)I",
             (void*)android_view_MotionEvent_nativeGetDeviceId },
     { "nativeGetSource",
-            "(I)I",
+            "(J)I",
             (void*)android_view_MotionEvent_nativeGetSource },
     { "nativeSetSource",
-            "(II)I",
+            "(JI)I",
             (void*)android_view_MotionEvent_nativeSetSource },
     { "nativeGetAction",
-            "(I)I",
+            "(J)I",
             (void*)android_view_MotionEvent_nativeGetAction },
     { "nativeSetAction",
-            "(II)V",
+            "(JI)V",
             (void*)android_view_MotionEvent_nativeSetAction },
     { "nativeIsTouchEvent",
-            "(I)Z",
+            "(J)Z",
             (void*)android_view_MotionEvent_nativeIsTouchEvent },
     { "nativeGetFlags",
-            "(I)I",
+            "(J)I",
             (void*)android_view_MotionEvent_nativeGetFlags },
     { "nativeSetFlags",
-            "(II)V",
+            "(JI)V",
             (void*)android_view_MotionEvent_nativeSetFlags },
     { "nativeGetEdgeFlags",
-            "(I)I",
+            "(J)I",
             (void*)android_view_MotionEvent_nativeGetEdgeFlags },
     { "nativeSetEdgeFlags",
-            "(II)V",
+            "(JI)V",
             (void*)android_view_MotionEvent_nativeSetEdgeFlags },
     { "nativeGetMetaState",
-            "(I)I",
+            "(J)I",
             (void*)android_view_MotionEvent_nativeGetMetaState },
     { "nativeGetButtonState",
-            "(I)I",
+            "(J)I",
             (void*)android_view_MotionEvent_nativeGetButtonState },
     { "nativeOffsetLocation",
-            "(IFF)V",
+            "(JFF)V",
             (void*)android_view_MotionEvent_nativeOffsetLocation },
     { "nativeGetXOffset",
-            "(I)F",
+            "(J)F",
             (void*)android_view_MotionEvent_nativeGetXOffset },
     { "nativeGetYOffset",
-            "(I)F",
+            "(J)F",
             (void*)android_view_MotionEvent_nativeGetYOffset },
     { "nativeGetXPrecision",
-            "(I)F",
+            "(J)F",
             (void*)android_view_MotionEvent_nativeGetXPrecision },
     { "nativeGetYPrecision",
-            "(I)F",
+            "(J)F",
             (void*)android_view_MotionEvent_nativeGetYPrecision },
     { "nativeGetDownTimeNanos",
-            "(I)J",
+            "(J)J",
             (void*)android_view_MotionEvent_nativeGetDownTimeNanos },
     { "nativeSetDownTimeNanos",
-            "(IJ)V",
+            "(JJ)V",
             (void*)android_view_MotionEvent_nativeSetDownTimeNanos },
     { "nativeGetPointerCount",
-            "(I)I",
+            "(J)I",
             (void*)android_view_MotionEvent_nativeGetPointerCount },
     { "nativeGetPointerId",
-            "(II)I",
+            "(JI)I",
             (void*)android_view_MotionEvent_nativeGetPointerId },
     { "nativeGetToolType",
-            "(II)I",
+            "(JI)I",
             (void*)android_view_MotionEvent_nativeGetToolType },
     { "nativeFindPointerIndex",
-            "(II)I",
+            "(JI)I",
             (void*)android_view_MotionEvent_nativeFindPointerIndex },
     { "nativeGetHistorySize",
-            "(I)I",
+            "(J)I",
             (void*)android_view_MotionEvent_nativeGetHistorySize },
     { "nativeGetEventTimeNanos",
-            "(II)J",
+            "(JI)J",
             (void*)android_view_MotionEvent_nativeGetEventTimeNanos },
     { "nativeGetRawAxisValue",
-            "(IIII)F",
+            "(JIII)F",
             (void*)android_view_MotionEvent_nativeGetRawAxisValue },
     { "nativeGetAxisValue",
-            "(IIII)F",
+            "(JIII)F",
             (void*)android_view_MotionEvent_nativeGetAxisValue },
     { "nativeGetPointerCoords",
-            "(IIILandroid/view/MotionEvent$PointerCoords;)V",
+            "(JIILandroid/view/MotionEvent$PointerCoords;)V",
             (void*)android_view_MotionEvent_nativeGetPointerCoords },
     { "nativeGetPointerProperties",
-            "(IILandroid/view/MotionEvent$PointerProperties;)V",
+            "(JILandroid/view/MotionEvent$PointerProperties;)V",
             (void*)android_view_MotionEvent_nativeGetPointerProperties },
     { "nativeScale",
-            "(IF)V",
+            "(JF)V",
             (void*)android_view_MotionEvent_nativeScale },
     { "nativeTransform",
-            "(ILandroid/graphics/Matrix;)V",
+            "(JLandroid/graphics/Matrix;)V",
             (void*)android_view_MotionEvent_nativeTransform },
     { "nativeReadFromParcel",
-            "(ILandroid/os/Parcel;)I",
+            "(JLandroid/os/Parcel;)J",
             (void*)android_view_MotionEvent_nativeReadFromParcel },
     { "nativeWriteToParcel",
-            "(ILandroid/os/Parcel;)V",
+            "(JLandroid/os/Parcel;)V",
             (void*)android_view_MotionEvent_nativeWriteToParcel },
 };
 
@@ -871,7 +871,7 @@
     GET_METHOD_ID(gMotionEventClassInfo.recycle, gMotionEventClassInfo.clazz,
             "recycle", "()V");
     GET_FIELD_ID(gMotionEventClassInfo.mNativePtr, gMotionEventClassInfo.clazz,
-            "mNativePtr", "I");
+            "mNativePtr", "J");
 
     jclass clazz;
     FIND_CLASS(clazz, "android/view/MotionEvent$PointerCoords");
diff --git a/core/jni/android_view_VelocityTracker.cpp b/core/jni/android_view_VelocityTracker.cpp
index 90ba2ba..1e36932 100644
--- a/core/jni/android_view_VelocityTracker.cpp
+++ b/core/jni/android_view_VelocityTracker.cpp
@@ -138,26 +138,26 @@
 
 // --- JNI Methods ---
 
-static jint android_view_VelocityTracker_nativeInitialize(JNIEnv* env, jclass clazz,
+static jlong android_view_VelocityTracker_nativeInitialize(JNIEnv* env, jclass clazz,
         jstring strategyStr) {
     if (strategyStr) {
         ScopedUtfChars strategy(env, strategyStr);
-        return reinterpret_cast<jint>(new VelocityTrackerState(strategy.c_str()));
+        return reinterpret_cast<jlong>(new VelocityTrackerState(strategy.c_str()));
     }
-    return reinterpret_cast<jint>(new VelocityTrackerState(NULL));
+    return reinterpret_cast<jlong>(new VelocityTrackerState(NULL));
 }
 
-static void android_view_VelocityTracker_nativeDispose(JNIEnv* env, jclass clazz, jint ptr) {
+static void android_view_VelocityTracker_nativeDispose(JNIEnv* env, jclass clazz, jlong ptr) {
     VelocityTrackerState* state = reinterpret_cast<VelocityTrackerState*>(ptr);
     delete state;
 }
 
-static void android_view_VelocityTracker_nativeClear(JNIEnv* env, jclass clazz, jint ptr) {
+static void android_view_VelocityTracker_nativeClear(JNIEnv* env, jclass clazz, jlong ptr) {
     VelocityTrackerState* state = reinterpret_cast<VelocityTrackerState*>(ptr);
     state->clear();
 }
 
-static void android_view_VelocityTracker_nativeAddMovement(JNIEnv* env, jclass clazz, jint ptr,
+static void android_view_VelocityTracker_nativeAddMovement(JNIEnv* env, jclass clazz, jlong ptr,
         jobject eventObj) {
     const MotionEvent* event = android_view_MotionEvent_getNativePtr(env, eventObj);
     if (!event) {
@@ -170,13 +170,13 @@
 }
 
 static void android_view_VelocityTracker_nativeComputeCurrentVelocity(JNIEnv* env, jclass clazz,
-        jint ptr, jint units, jfloat maxVelocity) {
+        jlong ptr, jint units, jfloat maxVelocity) {
     VelocityTrackerState* state = reinterpret_cast<VelocityTrackerState*>(ptr);
     state->computeCurrentVelocity(units, maxVelocity);
 }
 
 static jfloat android_view_VelocityTracker_nativeGetXVelocity(JNIEnv* env, jclass clazz,
-        jint ptr, jint id) {
+        jlong ptr, jint id) {
     VelocityTrackerState* state = reinterpret_cast<VelocityTrackerState*>(ptr);
     float vx;
     state->getVelocity(id, &vx, NULL);
@@ -184,7 +184,7 @@
 }
 
 static jfloat android_view_VelocityTracker_nativeGetYVelocity(JNIEnv* env, jclass clazz,
-        jint ptr, jint id) {
+        jlong ptr, jint id) {
     VelocityTrackerState* state = reinterpret_cast<VelocityTrackerState*>(ptr);
     float vy;
     state->getVelocity(id, NULL, &vy);
@@ -192,7 +192,7 @@
 }
 
 static jboolean android_view_VelocityTracker_nativeGetEstimator(JNIEnv* env, jclass clazz,
-        jint ptr, jint id, jobject outEstimatorObj) {
+        jlong ptr, jint id, jobject outEstimatorObj) {
     VelocityTrackerState* state = reinterpret_cast<VelocityTrackerState*>(ptr);
     VelocityTracker::Estimator estimator;
     bool result = state->getEstimator(id, &estimator);
@@ -217,28 +217,28 @@
 static JNINativeMethod gVelocityTrackerMethods[] = {
     /* name, signature, funcPtr */
     { "nativeInitialize",
-            "(Ljava/lang/String;)I",
+            "(Ljava/lang/String;)J",
             (void*)android_view_VelocityTracker_nativeInitialize },
     { "nativeDispose",
-            "(I)V",
+            "(J)V",
             (void*)android_view_VelocityTracker_nativeDispose },
     { "nativeClear",
-            "(I)V",
+            "(J)V",
             (void*)android_view_VelocityTracker_nativeClear },
     { "nativeAddMovement",
-            "(ILandroid/view/MotionEvent;)V",
+            "(JLandroid/view/MotionEvent;)V",
             (void*)android_view_VelocityTracker_nativeAddMovement },
     { "nativeComputeCurrentVelocity",
-            "(IIF)V",
+            "(JIF)V",
             (void*)android_view_VelocityTracker_nativeComputeCurrentVelocity },
     { "nativeGetXVelocity",
-            "(II)F",
+            "(JI)F",
             (void*)android_view_VelocityTracker_nativeGetXVelocity },
     { "nativeGetYVelocity",
-            "(II)F",
+            "(JI)F",
             (void*)android_view_VelocityTracker_nativeGetYVelocity },
     { "nativeGetEstimator",
-            "(IILandroid/view/VelocityTracker$Estimator;)Z",
+            "(JILandroid/view/VelocityTracker$Estimator;)Z",
             (void*)android_view_VelocityTracker_nativeGetEstimator },
 };
 
diff --git a/graphics/java/android/graphics/BitmapRegionDecoder.java b/graphics/java/android/graphics/BitmapRegionDecoder.java
index 3a99977..e689b08 100644
--- a/graphics/java/android/graphics/BitmapRegionDecoder.java
+++ b/graphics/java/android/graphics/BitmapRegionDecoder.java
@@ -33,7 +33,7 @@
  *
  */
 public final class BitmapRegionDecoder {
-    private int mNativeBitmapRegionDecoder;
+    private long mNativeBitmapRegionDecoder;
     private boolean mRecycled;
     // ensures that the native decoder object exists and that only one decode can
     // occur at a time.
@@ -114,7 +114,7 @@
             boolean isShareable) throws IOException {
         if (is instanceof AssetManager.AssetInputStream) {
             return nativeNewInstance(
-                    ((AssetManager.AssetInputStream) is).getAssetInt(),
+                    ((AssetManager.AssetInputStream) is).getNativeAsset(),
                     isShareable);
         } else {
             // pass some temp storage down to the native code. 1024 is made up,
@@ -165,7 +165,7 @@
 
         This can be called from JNI code.
     */
-    private BitmapRegionDecoder(int decoder) {
+    private BitmapRegionDecoder(long decoder) {
         mNativeBitmapRegionDecoder = decoder;
         mRecycled = false;
     }
@@ -254,12 +254,12 @@
         }
     }
 
-    private static native Bitmap nativeDecodeRegion(int lbm,
+    private static native Bitmap nativeDecodeRegion(long lbm,
             int start_x, int start_y, int width, int height,
             BitmapFactory.Options options);
-    private static native int nativeGetWidth(int lbm);
-    private static native int nativeGetHeight(int lbm);
-    private static native void nativeClean(int lbm);
+    private static native int nativeGetWidth(long lbm);
+    private static native int nativeGetHeight(long lbm);
+    private static native void nativeClean(long lbm);
 
     private static native BitmapRegionDecoder nativeNewInstance(
             byte[] data, int offset, int length, boolean isShareable);
@@ -268,5 +268,5 @@
     private static native BitmapRegionDecoder nativeNewInstance(
             InputStream is, byte[] storage, boolean isShareable);
     private static native BitmapRegionDecoder nativeNewInstance(
-            int asset, boolean isShareable);
+            long asset, boolean isShareable);
 }
diff --git a/graphics/java/android/graphics/Movie.java b/graphics/java/android/graphics/Movie.java
index 9419faf..b0a4553 100644
--- a/graphics/java/android/graphics/Movie.java
+++ b/graphics/java/android/graphics/Movie.java
@@ -21,9 +21,9 @@
 import java.io.FileInputStream;
 
 public class Movie {
-    private final int mNativeMovie;
+    private final long mNativeMovie;
 
-    private Movie(int nativeMovie) {
+    private Movie(long nativeMovie) {
         if (nativeMovie == 0) {
             throw new RuntimeException("native movie creation failed");
         }
@@ -48,19 +48,19 @@
             return null;
         }
         if (is instanceof AssetManager.AssetInputStream) {
-            final int asset = ((AssetManager.AssetInputStream) is).getAssetInt();
+            final long asset = ((AssetManager.AssetInputStream) is).getNativeAsset();
             return nativeDecodeAsset(asset);
         }
 
         return nativeDecodeStream(is);
     }
 
-    private static native Movie nativeDecodeAsset(int asset);
+    private static native Movie nativeDecodeAsset(long asset);
     private static native Movie nativeDecodeStream(InputStream is);
     public static native Movie decodeByteArray(byte[] data, int offset,
                                                int length);
 
-    private static native void nativeDestructor(int nativeMovie);
+    private static native void nativeDestructor(long nativeMovie);
 
     public static Movie decodeFile(String pathName) {
         InputStream is;
diff --git a/graphics/java/android/graphics/PathMeasure.java b/graphics/java/android/graphics/PathMeasure.java
index 7062824..e56716f 100644
--- a/graphics/java/android/graphics/PathMeasure.java
+++ b/graphics/java/android/graphics/PathMeasure.java
@@ -138,16 +138,16 @@
         native_destroy(native_instance);
     }
 
-    private static native int native_create(int native_path, boolean forceClosed);
-    private static native void native_setPath(int native_instance, int native_path, boolean forceClosed);
-    private static native float native_getLength(int native_instance);
-    private static native boolean native_getPosTan(int native_instance, float distance, float pos[], float tan[]);
-    private static native boolean native_getMatrix(int native_instance, float distance, int native_matrix, int flags);
-    private static native boolean native_getSegment(int native_instance, float startD, float stopD, int native_path, boolean startWithMoveTo);
-    private static native boolean native_isClosed(int native_instance);
-    private static native boolean native_nextContour(int native_instance);
-    private static native void native_destroy(int native_instance);
+    private static native long native_create(long native_path, boolean forceClosed);
+    private static native void native_setPath(long native_instance, long native_path, boolean forceClosed);
+    private static native float native_getLength(long native_instance);
+    private static native boolean native_getPosTan(long native_instance, float distance, float pos[], float tan[]);
+    private static native boolean native_getMatrix(long native_instance, float distance, long native_matrix, int flags);
+    private static native boolean native_getSegment(long native_instance, float startD, float stopD, long native_path, boolean startWithMoveTo);
+    private static native boolean native_isClosed(long native_instance);
+    private static native boolean native_nextContour(long native_instance);
+    private static native void native_destroy(long native_instance);
 
-    /* package */private final int native_instance;
+    /* package */private final long native_instance;
 }
 
diff --git a/media/java/android/media/AudioRecord.java b/media/java/android/media/AudioRecord.java
index f49ef2e..461b52f 100644
--- a/media/java/android/media/AudioRecord.java
+++ b/media/java/android/media/AudioRecord.java
@@ -107,13 +107,13 @@
      * Accessed by native methods: provides access to C++ AudioRecord object
      */
     @SuppressWarnings("unused")
-    private int mNativeRecorderInJavaObj;
+    private long mNativeRecorderInJavaObj;
 
     /**
      * Accessed by native methods: provides access to the callback data.
      */
     @SuppressWarnings("unused")
-    private int mNativeCallbackCookie;
+    private long mNativeCallbackCookie;
 
 
     //---------------------------------------------------------
diff --git a/media/java/android/media/AudioTrack.java b/media/java/android/media/AudioTrack.java
index 78a37c5..01a6fc2 100644
--- a/media/java/android/media/AudioTrack.java
+++ b/media/java/android/media/AudioTrack.java
@@ -221,13 +221,13 @@
      * Accessed by native methods: provides access to C++ AudioTrack object.
      */
     @SuppressWarnings("unused")
-    private int mNativeTrackInJavaObj;
+    private long mNativeTrackInJavaObj;
     /**
      * Accessed by native methods: provides access to the JNI data (i.e. resources used by
      * the native AudioTrack object, but not stored in it).
      */
     @SuppressWarnings("unused")
-    private int mJniData;
+    private long mJniData;
 
 
     //--------------------------------------------------------------------------
diff --git a/media/java/android/media/FaceDetector.java b/media/java/android/media/FaceDetector.java
index cf900ce..61991e3 100644
--- a/media/java/android/media/FaceDetector.java
+++ b/media/java/android/media/FaceDetector.java
@@ -191,9 +191,9 @@
     native private void fft_get_face(Face face, int i);
     native private void fft_destroy();
 
-    private int     mFD;
-    private int     mSDK;
-    private int     mDCR;
+    private long    mFD;
+    private long    mSDK;
+    private long    mDCR;
     private int     mWidth;
     private int     mHeight;
     private int     mMaxFaces;    
diff --git a/media/java/android/media/JetPlayer.java b/media/java/android/media/JetPlayer.java
index 06cda34..bd91fc5 100644
--- a/media/java/android/media/JetPlayer.java
+++ b/media/java/android/media/JetPlayer.java
@@ -127,7 +127,7 @@
      * Accessed by native methods: provides access to C++ JetPlayer object 
      */
     @SuppressWarnings("unused")
-    private int mNativePlayerInJavaObj;
+    private long mNativePlayerInJavaObj;
 
     
     //--------------------------------------------
diff --git a/media/java/android/media/MediaCodec.java b/media/java/android/media/MediaCodec.java
index 5175830..ddf88df 100644
--- a/media/java/android/media/MediaCodec.java
+++ b/media/java/android/media/MediaCodec.java
@@ -644,5 +644,5 @@
         native_init();
     }
 
-    private int mNativeContext;
+    private long mNativeContext;
 }
diff --git a/media/java/android/media/MediaCrypto.java b/media/java/android/media/MediaCrypto.java
index 40a1326..c7c3fc2 100644
--- a/media/java/android/media/MediaCrypto.java
+++ b/media/java/android/media/MediaCrypto.java
@@ -88,5 +88,5 @@
         native_init();
     }
 
-    private int mNativeContext;
+    private long mNativeContext;
 }
diff --git a/media/java/android/media/MediaExtractor.java b/media/java/android/media/MediaExtractor.java
index e558c07..c3e5035 100644
--- a/media/java/android/media/MediaExtractor.java
+++ b/media/java/android/media/MediaExtractor.java
@@ -352,5 +352,5 @@
         native_init();
     }
 
-    private int mNativeContext;
+    private long mNativeContext;
 }
diff --git a/media/java/android/media/MediaMetadataRetriever.java b/media/java/android/media/MediaMetadataRetriever.java
index 9014453..db27d09 100644
--- a/media/java/android/media/MediaMetadataRetriever.java
+++ b/media/java/android/media/MediaMetadataRetriever.java
@@ -42,7 +42,7 @@
 
     // The field below is accessed by native methods
     @SuppressWarnings("unused")
-    private int mNativeContext;
+    private long mNativeContext;
  
     private static final int EMBEDDED_PICTURE_TYPE_ANY = 0xFFFF;
 
diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java
index 706258a..b34cea8 100644
--- a/media/java/android/media/MediaPlayer.java
+++ b/media/java/android/media/MediaPlayer.java
@@ -572,8 +572,8 @@
     // macro invocation in IMediaPlayer.cpp
     private final static String IMEDIA_PLAYER = "android.media.IMediaPlayer";
 
-    private int mNativeContext; // accessed by native methods
-    private int mNativeSurfaceTexture;  // accessed by native methods
+    private long mNativeContext; // accessed by native methods
+    private long mNativeSurfaceTexture;  // accessed by native methods
     private int mListenerContext; // accessed by native methods
     private SurfaceHolder mSurfaceHolder;
     private EventHandler mEventHandler;
diff --git a/media/java/android/media/MediaRecorder.java b/media/java/android/media/MediaRecorder.java
index 8dcbd6b..5a9d577 100644
--- a/media/java/android/media/MediaRecorder.java
+++ b/media/java/android/media/MediaRecorder.java
@@ -81,7 +81,7 @@
 
     // The two fields below are accessed by native methods
     @SuppressWarnings("unused")
-    private int mNativeContext;
+    private long mNativeContext;
 
     @SuppressWarnings("unused")
     private Surface mSurface;
diff --git a/media/java/android/media/MediaScanner.java b/media/java/android/media/MediaScanner.java
index de3041e..53835e2 100644
--- a/media/java/android/media/MediaScanner.java
+++ b/media/java/android/media/MediaScanner.java
@@ -301,7 +301,7 @@
         // 148 and up don't seem to have been defined yet.
     };
 
-    private int mNativeContext;
+    private long mNativeContext;
     private Context mContext;
     private String mPackageName;
     private IContentProvider mMediaProvider;
diff --git a/media/java/android/media/RemoteDisplay.java b/media/java/android/media/RemoteDisplay.java
index 7afce1a..4e937a5 100644
--- a/media/java/android/media/RemoteDisplay.java
+++ b/media/java/android/media/RemoteDisplay.java
@@ -38,12 +38,12 @@
     private final Listener mListener;
     private final Handler mHandler;
 
-    private int mPtr;
+    private long mPtr;
 
-    private native int nativeListen(String iface);
-    private native void nativeDispose(int ptr);
-    private native void nativePause(int ptr);
-    private native void nativeResume(int ptr);
+    private native long nativeListen(String iface);
+    private native void nativeDispose(long ptr);
+    private native void nativePause(long ptr);
+    private native void nativeResume(long ptr);
 
     private RemoteDisplay(Listener listener, Handler handler) {
         mListener = listener;
diff --git a/media/java/android/media/SoundPool.java b/media/java/android/media/SoundPool.java
index 06af5de..fbfc574 100644
--- a/media/java/android/media/SoundPool.java
+++ b/media/java/android/media/SoundPool.java
@@ -443,7 +443,7 @@
         private final static String TAG = "SoundPool";
         private final static boolean DEBUG = false;
 
-        private int mNativeContext; // accessed by native methods
+        private long mNativeContext; // accessed by native methods
 
         private EventHandler mEventHandler;
         private SoundPool.OnLoadCompleteListener mOnLoadCompleteListener;
diff --git a/media/java/android/media/ToneGenerator.java b/media/java/android/media/ToneGenerator.java
index 5592105..713f147 100644
--- a/media/java/android/media/ToneGenerator.java
+++ b/media/java/android/media/ToneGenerator.java
@@ -887,5 +887,5 @@
     protected void finalize() { native_finalize(); }
 
     @SuppressWarnings("unused")
-    private int mNativeContext; // accessed by native methods
+    private long mNativeContext; // accessed by native methods
 }
diff --git a/media/jni/android_media_MediaCodec.cpp b/media/jni/android_media_MediaCodec.cpp
index b8d437c..221ea57 100644
--- a/media/jni/android_media_MediaCodec.cpp
+++ b/media/jni/android_media_MediaCodec.cpp
@@ -328,20 +328,20 @@
 
 static sp<JMediaCodec> setMediaCodec(
         JNIEnv *env, jobject thiz, const sp<JMediaCodec> &codec) {
-    sp<JMediaCodec> old = (JMediaCodec *)env->GetIntField(thiz, gFields.context);
+    sp<JMediaCodec> old = (JMediaCodec *)env->GetLongField(thiz, gFields.context);
     if (codec != NULL) {
         codec->incStrong(thiz);
     }
     if (old != NULL) {
         old->decStrong(thiz);
     }
-    env->SetIntField(thiz, gFields.context, (int)codec.get());
+    env->SetLongField(thiz, gFields.context, (jlong)codec.get());
 
     return old;
 }
 
 static sp<JMediaCodec> getMediaCodec(JNIEnv *env, jobject thiz) {
-    return (JMediaCodec *)env->GetIntField(thiz, gFields.context);
+    return (JMediaCodec *)env->GetLongField(thiz, gFields.context);
 }
 
 static void android_media_MediaCodec_release(JNIEnv *env, jobject thiz) {
@@ -710,7 +710,7 @@
     status_t err = codec->dequeueInputBuffer(&index, timeoutUs);
 
     if (err == OK) {
-        return index;
+        return (jint) index;
     }
 
     return throwExceptionAsNecessary(env, err);
@@ -732,7 +732,7 @@
             env, bufferInfo, &index, timeoutUs);
 
     if (err == OK) {
-        return index;
+        return (jint) index;
     }
 
     return throwExceptionAsNecessary(env, err);
@@ -885,7 +885,7 @@
             env, env->FindClass("android/media/MediaCodec"));
     CHECK(clazz.get() != NULL);
 
-    gFields.context = env->GetFieldID(clazz.get(), "mNativeContext", "I");
+    gFields.context = env->GetFieldID(clazz.get(), "mNativeContext", "J");
     CHECK(gFields.context != NULL);
 
     clazz.reset(env->FindClass("android/media/MediaCodec$CryptoInfo"));
diff --git a/media/jni/android_media_MediaCrypto.cpp b/media/jni/android_media_MediaCrypto.cpp
index d0f56ea..a6f8dcd 100644
--- a/media/jni/android_media_MediaCrypto.cpp
+++ b/media/jni/android_media_MediaCrypto.cpp
@@ -38,7 +38,7 @@
 static fields_t gFields;
 
 static sp<JCrypto> getCrypto(JNIEnv *env, jobject thiz) {
-    return (JCrypto *)env->GetIntField(thiz, gFields.context);
+    return (JCrypto *)env->GetLongField(thiz, gFields.context);
 }
 
 JCrypto::JCrypto(
@@ -146,14 +146,14 @@
 
 static sp<JCrypto> setCrypto(
         JNIEnv *env, jobject thiz, const sp<JCrypto> &crypto) {
-    sp<JCrypto> old = (JCrypto *)env->GetIntField(thiz, gFields.context);
+    sp<JCrypto> old = (JCrypto *)env->GetLongField(thiz, gFields.context);
     if (crypto != NULL) {
         crypto->incStrong(thiz);
     }
     if (old != NULL) {
         old->decStrong(thiz);
     }
-    env->SetIntField(thiz, gFields.context, (int)crypto.get());
+    env->SetLongField(thiz, gFields.context, (jlong)crypto.get());
 
     return old;
 }
@@ -166,7 +166,7 @@
     jclass clazz = env->FindClass("android/media/MediaCrypto");
     CHECK(clazz != NULL);
 
-    gFields.context = env->GetFieldID(clazz, "mNativeContext", "I");
+    gFields.context = env->GetFieldID(clazz, "mNativeContext", "J");
     CHECK(gFields.context != NULL);
 }
 
@@ -232,7 +232,7 @@
                 env,
                 "java/lang/IllegalArgumentException",
                 NULL);
-        return false;
+        return JNI_FALSE;
     }
 
     jboolean isCopy;
@@ -243,27 +243,27 @@
     env->ReleaseByteArrayElements(uuidObj, uuid, 0);
     uuid = NULL;
 
-    return result;
+    return result ? JNI_TRUE : JNI_FALSE;
 }
 
 static jboolean android_media_MediaCrypto_requiresSecureDecoderComponent(
         JNIEnv *env, jobject thiz, jstring mimeObj) {
     if (mimeObj == NULL) {
         jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
-        return false;
+        return JNI_FALSE;
     }
 
     sp<JCrypto> crypto = getCrypto(env, thiz);
 
     if (crypto == NULL) {
         jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
-        return false;
+        return JNI_FALSE;
     }
 
     const char *mime = env->GetStringUTFChars(mimeObj, NULL);
 
     if (mime == NULL) {
-        return false;
+        return JNI_FALSE;
     }
 
     bool result = crypto->requiresSecureDecoderComponent(mime);
@@ -271,7 +271,7 @@
     env->ReleaseStringUTFChars(mimeObj, mime);
     mime = NULL;
 
-    return result;
+    return result ? JNI_TRUE : JNI_FALSE;
 }
 
 static JNINativeMethod gMethods[] = {
diff --git a/media/jni/android_media_MediaDrm.cpp b/media/jni/android_media_MediaDrm.cpp
index eb7d51c..052d97d 100644
--- a/media/jni/android_media_MediaDrm.cpp
+++ b/media/jni/android_media_MediaDrm.cpp
@@ -186,6 +186,7 @@
             nativeParcel->setData(obj->data(), obj->dataSize());
             env->CallStaticVoidMethod(mClass, gFields.post_event, mObject,
                     jeventType, extra, jParcel);
+            env->DeleteLocalRef(jParcel);
         }
     }
 
diff --git a/media/jni/android_media_MediaExtractor.cpp b/media/jni/android_media_MediaExtractor.cpp
index 1ac45d4..705de88 100644
--- a/media/jni/android_media_MediaExtractor.cpp
+++ b/media/jni/android_media_MediaExtractor.cpp
@@ -88,7 +88,7 @@
         env->GetByteArrayRegion(byteArrayObj, 0, size, (jbyte*) buffer);
         env->DeleteLocalRef(byteArrayObj);
         if (env->ExceptionCheck()) {
-            ALOGW("Exception occurred while reading %d at %lld", size, offset);
+            ALOGW("Exception occurred while reading %zu at %lld", size, offset);
             LOGW_EX(env);
             env->ExceptionClear();
             return -1;
@@ -198,7 +198,7 @@
 
     void *dst = env->GetDirectBufferAddress(byteBuf);
 
-    jlong dstSize;
+    size_t dstSize;
     jbyteArray byteArray = NULL;
 
     if (dst == NULL) {
@@ -219,9 +219,9 @@
         jboolean isCopy;
         dst = env->GetByteArrayElements(byteArray, &isCopy);
 
-        dstSize = env->GetArrayLength(byteArray);
+        dstSize = (size_t) env->GetArrayLength(byteArray);
     } else {
-        dstSize = env->GetDirectBufferCapacity(byteBuf);
+        dstSize = (size_t) env->GetDirectBufferCapacity(byteBuf);
     }
 
     if (dstSize < offset) {
@@ -299,7 +299,7 @@
 static sp<JMediaExtractor> setMediaExtractor(
         JNIEnv *env, jobject thiz, const sp<JMediaExtractor> &extractor) {
     sp<JMediaExtractor> old =
-        (JMediaExtractor *)env->GetIntField(thiz, gFields.context);
+        (JMediaExtractor *)env->GetLongField(thiz, gFields.context);
 
     if (extractor != NULL) {
         extractor->incStrong(thiz);
@@ -307,13 +307,13 @@
     if (old != NULL) {
         old->decStrong(thiz);
     }
-    env->SetIntField(thiz, gFields.context, (int)extractor.get());
+    env->SetLongField(thiz, gFields.context, (jlong)extractor.get());
 
     return old;
 }
 
 static sp<JMediaExtractor> getMediaExtractor(JNIEnv *env, jobject thiz) {
-    return (JMediaExtractor *)env->GetIntField(thiz, gFields.context);
+    return (JMediaExtractor *)env->GetLongField(thiz, gFields.context);
 }
 
 static void android_media_MediaExtractor_release(JNIEnv *env, jobject thiz) {
@@ -329,7 +329,7 @@
         return -1;
     }
 
-    return extractor->countTracks();
+    return (jint) extractor->countTracks();
 }
 
 static jobject android_media_MediaExtractor_getTrackFormatNative(
@@ -430,19 +430,19 @@
 
     if (extractor == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException", NULL);
-        return false;
+        return JNI_FALSE;
     }
 
     status_t err = extractor->advance();
 
     if (err == ERROR_END_OF_STREAM) {
-        return false;
+        return JNI_FALSE;
     } else if (err != OK) {
         jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
-        return false;
+        return JNI_FALSE;
     }
 
-    return true;
+    return JNI_TRUE;
 }
 
 static jint android_media_MediaExtractor_readSampleData(
@@ -461,10 +461,10 @@
         return -1;
     } else if (err != OK) {
         jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
-        return false;
+        return -1;
     }
 
-    return sampleSize;
+    return (jint) sampleSize;
 }
 
 static jint android_media_MediaExtractor_getSampleTrackIndex(
@@ -483,10 +483,10 @@
         return -1;
     } else if (err != OK) {
         jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
-        return false;
+        return -1;
     }
 
-    return trackIndex;
+    return (jint) trackIndex;
 }
 
 static jlong android_media_MediaExtractor_getSampleTime(
@@ -505,10 +505,10 @@
         return -1ll;
     } else if (err != OK) {
         jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
-        return false;
+        return -1ll;
     }
 
-    return sampleTimeUs;
+    return (jlong) sampleTimeUs;
 }
 
 static jint android_media_MediaExtractor_getSampleFlags(
@@ -517,20 +517,20 @@
 
     if (extractor == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException", NULL);
-        return -1ll;
+        return -1;
     }
 
     uint32_t sampleFlags;
     status_t err = extractor->getSampleFlags(&sampleFlags);
 
     if (err == ERROR_END_OF_STREAM) {
-        return -1ll;
+        return -1;
     } else if (err != OK) {
         jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
-        return false;
+        return -1;
     }
 
-    return sampleFlags;
+    return (jint) sampleFlags;
 }
 
 static jboolean android_media_MediaExtractor_getSampleCryptoInfo(
@@ -539,27 +539,27 @@
 
     if (extractor == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException", NULL);
-        return -1ll;
+        return JNI_FALSE;
     }
 
     sp<MetaData> meta;
     status_t err = extractor->getSampleMeta(&meta);
 
     if (err != OK) {
-        return false;
+        return JNI_FALSE;
     }
 
     uint32_t type;
     const void *data;
     size_t size;
     if (!meta->findData(kKeyEncryptedSizes, &type, &data, &size)) {
-        return false;
+        return JNI_FALSE;
     }
 
     size_t numSubSamples = size / sizeof(size_t);
 
     if (numSubSamples == 0) {
-        return false;
+        return JNI_FALSE;
     }
 
     jintArray numBytesOfEncryptedDataObj = env->NewIntArray(numSubSamples);
@@ -576,7 +576,7 @@
     if (meta->findData(kKeyPlainSizes, &type, &data, &size)) {
         if (size != encSize) {
             // The two must be of the same length.
-            return false;
+            return JNI_FALSE;
         }
 
         numBytesOfPlainDataObj = env->NewIntArray(numSubSamples);
@@ -593,7 +593,7 @@
     if (meta->findData(kKeyCryptoKey, &type, &data, &size)) {
         if (size != 16) {
             // Keys must be 16 bytes in length.
-            return false;
+            return JNI_FALSE;
         }
 
         keyObj = env->NewByteArray(size);
@@ -608,7 +608,7 @@
     if (meta->findData(kKeyCryptoIV, &type, &data, &size)) {
         if (size != 16) {
             // IVs must be 16 bytes in length.
-            return false;
+            return JNI_FALSE;
         }
 
         ivObj = env->NewByteArray(size);
@@ -634,14 +634,14 @@
             ivObj,
             mode);
 
-    return true;
+    return JNI_TRUE;
 }
 
 static void android_media_MediaExtractor_native_init(JNIEnv *env) {
     jclass clazz = env->FindClass("android/media/MediaExtractor");
     CHECK(clazz != NULL);
 
-    gFields.context = env->GetFieldID(clazz, "mNativeContext", "I");
+    gFields.context = env->GetFieldID(clazz, "mNativeContext", "J");
     CHECK(gFields.context != NULL);
 
     clazz = env->FindClass("android/media/MediaCodec$CryptoInfo");
@@ -770,7 +770,7 @@
         return -1ll;
     }
 
-    return cachedDurationUs;
+    return (jlong) cachedDurationUs;
 }
 
 static jboolean android_media_MediaExtractor_hasCacheReachedEOS(
@@ -779,16 +779,16 @@
 
     if (extractor == NULL) {
         jniThrowException(env, "java/lang/IllegalStateException", NULL);
-        return true;
+        return JNI_TRUE;
     }
 
     int64_t cachedDurationUs;
     bool eos;
     if (!extractor->getCachedDuration(&cachedDurationUs, &eos)) {
-        return true;
+        return JNI_TRUE;
     }
 
-    return eos;
+    return eos ? JNI_TRUE : JNI_FALSE;
 }
 
 static void android_media_MediaExtractor_native_finalize(
diff --git a/media/jni/android_media_MediaMetadataRetriever.cpp b/media/jni/android_media_MediaMetadataRetriever.cpp
index 297dadf..fe69819 100644
--- a/media/jni/android_media_MediaMetadataRetriever.cpp
+++ b/media/jni/android_media_MediaMetadataRetriever.cpp
@@ -67,15 +67,15 @@
 static MediaMetadataRetriever* getRetriever(JNIEnv* env, jobject thiz)
 {
     // No lock is needed, since it is called internally by other methods that are protected
-    MediaMetadataRetriever* retriever = (MediaMetadataRetriever*) env->GetIntField(thiz, fields.context);
+    MediaMetadataRetriever* retriever = (MediaMetadataRetriever*) env->GetLongField(thiz, fields.context);
     return retriever;
 }
 
-static void setRetriever(JNIEnv* env, jobject thiz, int retriever)
+static void setRetriever(JNIEnv* env, jobject thiz, MediaMetadataRetriever* retriever)
 {
     // No lock is needed, since it is called internally by other methods that are protected
-    MediaMetadataRetriever *old = (MediaMetadataRetriever*) env->GetIntField(thiz, fields.context);
-    env->SetIntField(thiz, fields.context, retriever);
+    MediaMetadataRetriever *old = (MediaMetadataRetriever*) env->GetLongField(thiz, fields.context);
+    env->SetLongField(thiz, fields.context, (jlong) retriever);
 }
 
 static void
@@ -146,10 +146,10 @@
     int fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
     if (offset < 0 || length < 0 || fd < 0) {
         if (offset < 0) {
-            ALOGE("negative offset (%lld)", offset);
+            ALOGE("negative offset (%lld)", (long long)offset);
         }
         if (length < 0) {
-            ALOGE("negative length (%lld)", length);
+            ALOGE("negative length (%lld)", (long long)length);
         }
         if (fd < 0) {
             ALOGE("invalid file descriptor");
@@ -359,7 +359,7 @@
     Mutex::Autolock lock(sLock);
     MediaMetadataRetriever* retriever = getRetriever(env, thiz);
     delete retriever;
-    setRetriever(env, thiz, 0);
+    setRetriever(env, thiz, (MediaMetadataRetriever*) 0);
 }
 
 static void android_media_MediaMetadataRetriever_native_finalize(JNIEnv *env, jobject thiz)
@@ -379,7 +379,7 @@
         return;
     }
 
-    fields.context = env->GetFieldID(clazz, "mNativeContext", "I");
+    fields.context = env->GetFieldID(clazz, "mNativeContext", "J");
     if (fields.context == NULL) {
         return;
     }
@@ -435,7 +435,7 @@
         jniThrowException(env, "java/lang/RuntimeException", "Out of memory");
         return;
     }
-    setRetriever(env, thiz, (int)retriever);
+    setRetriever(env, thiz, retriever);
 }
 
 // JNI mapping between Java methods and native methods
diff --git a/media/jni/android_media_MediaPlayer.cpp b/media/jni/android_media_MediaPlayer.cpp
index 4be9cd6..9d0d5a6 100644
--- a/media/jni/android_media_MediaPlayer.cpp
+++ b/media/jni/android_media_MediaPlayer.cpp
@@ -133,21 +133,21 @@
 static sp<MediaPlayer> getMediaPlayer(JNIEnv* env, jobject thiz)
 {
     Mutex::Autolock l(sLock);
-    MediaPlayer* const p = (MediaPlayer*)env->GetIntField(thiz, fields.context);
+    MediaPlayer* const p = (MediaPlayer*)env->GetLongField(thiz, fields.context);
     return sp<MediaPlayer>(p);
 }
 
 static sp<MediaPlayer> setMediaPlayer(JNIEnv* env, jobject thiz, const sp<MediaPlayer>& player)
 {
     Mutex::Autolock l(sLock);
-    sp<MediaPlayer> old = (MediaPlayer*)env->GetIntField(thiz, fields.context);
+    sp<MediaPlayer> old = (MediaPlayer*)env->GetLongField(thiz, fields.context);
     if (player.get()) {
         player->incStrong((void*)setMediaPlayer);
     }
     if (old != 0) {
         old->decStrong((void*)setMediaPlayer);
     }
-    env->SetIntField(thiz, fields.context, (int)player.get());
+    env->SetLongField(thiz, fields.context, (jlong)player.get());
     return old;
 }
 
@@ -244,7 +244,7 @@
 
 static sp<IGraphicBufferProducer>
 getVideoSurfaceTexture(JNIEnv* env, jobject thiz) {
-    IGraphicBufferProducer * const p = (IGraphicBufferProducer*)env->GetIntField(thiz, fields.surface_texture);
+    IGraphicBufferProducer * const p = (IGraphicBufferProducer*)env->GetLongField(thiz, fields.surface_texture);
     return sp<IGraphicBufferProducer>(p);
 }
 
@@ -293,7 +293,7 @@
         }
     }
 
-    env->SetIntField(thiz, fields.surface_texture, (int)new_st.get());
+    env->SetLongField(thiz, fields.surface_texture, (jlong)new_st.get());
 
     // This will fail if the media player has not been initialized yet. This
     // can be the case if setDisplay() on MediaPlayer.java has been called
@@ -384,7 +384,7 @@
     sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
     if (mp == NULL ) {
         jniThrowException(env, "java/lang/IllegalStateException", NULL);
-        return false;
+        return JNI_FALSE;
     }
     const jboolean is_playing = mp->isPlaying();
 
@@ -393,7 +393,7 @@
 }
 
 static void
-android_media_MediaPlayer_seekTo(JNIEnv *env, jobject thiz, int msec)
+android_media_MediaPlayer_seekTo(JNIEnv *env, jobject thiz, jint msec)
 {
     sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
     if (mp == NULL ) {
@@ -404,7 +404,7 @@
     process_media_player_call( env, thiz, mp->seekTo(msec), NULL, NULL );
 }
 
-static int
+static jint
 android_media_MediaPlayer_getVideoWidth(JNIEnv *env, jobject thiz)
 {
     sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
@@ -418,10 +418,10 @@
         w = 0;
     }
     ALOGV("getVideoWidth: %d", w);
-    return w;
+    return (jint) w;
 }
 
-static int
+static jint
 android_media_MediaPlayer_getVideoHeight(JNIEnv *env, jobject thiz)
 {
     sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
@@ -435,11 +435,11 @@
         h = 0;
     }
     ALOGV("getVideoHeight: %d", h);
-    return h;
+    return (jint) h;
 }
 
 
-static int
+static jint
 android_media_MediaPlayer_getCurrentPosition(JNIEnv *env, jobject thiz)
 {
     sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
@@ -450,10 +450,10 @@
     int msec;
     process_media_player_call( env, thiz, mp->getCurrentPosition(&msec), NULL, NULL );
     ALOGV("getCurrentPosition: %d (msec)", msec);
-    return msec;
+    return (jint) msec;
 }
 
-static int
+static jint
 android_media_MediaPlayer_getDuration(JNIEnv *env, jobject thiz)
 {
     sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
@@ -464,7 +464,7 @@
     int msec;
     process_media_player_call( env, thiz, mp->getDuration(&msec), NULL, NULL );
     ALOGV("getDuration: %d (msec)", msec);
-    return msec;
+    return (jint) msec;
 }
 
 static void
@@ -480,7 +480,7 @@
 }
 
 static void
-android_media_MediaPlayer_setAudioStreamType(JNIEnv *env, jobject thiz, int streamtype)
+android_media_MediaPlayer_setAudioStreamType(JNIEnv *env, jobject thiz, jint streamtype)
 {
     ALOGV("setAudioStreamType: %d", streamtype);
     sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
@@ -510,21 +510,21 @@
     sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
     if (mp == NULL ) {
         jniThrowException(env, "java/lang/IllegalStateException", NULL);
-        return false;
+        return JNI_FALSE;
     }
-    return mp->isLooping();
+    return mp->isLooping() ? JNI_TRUE : JNI_FALSE;
 }
 
 static void
-android_media_MediaPlayer_setVolume(JNIEnv *env, jobject thiz, float leftVolume, float rightVolume)
+android_media_MediaPlayer_setVolume(JNIEnv *env, jobject thiz, jfloat leftVolume, jfloat rightVolume)
 {
-    ALOGV("setVolume: left %f  right %f", leftVolume, rightVolume);
+    ALOGV("setVolume: left %f  right %f", (float) leftVolume, (float) rightVolume);
     sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
     if (mp == NULL ) {
         jniThrowException(env, "java/lang/IllegalStateException", NULL);
         return;
     }
-    process_media_player_call( env, thiz, mp->setVolume(leftVolume, rightVolume), NULL, NULL );
+    process_media_player_call( env, thiz, mp->setVolume((float) leftVolume, (float) rightVolume), NULL, NULL );
 }
 
 // Sends the request and reply parcels to the media player via the
@@ -544,7 +544,7 @@
 
     // Don't use process_media_player_call which use the async loop to
     // report errors, instead returns the status.
-    return media_player->invoke(*request, reply);
+    return (jint) media_player->invoke(*request, reply);
 }
 
 // Sends the new filter to the client.
@@ -564,7 +564,7 @@
         return UNKNOWN_ERROR;
     }
 
-    return media_player->setMetadataFilter(*filter);
+    return (jint) media_player->setMetadataFilter(*filter);
 }
 
 static jboolean
@@ -574,14 +574,14 @@
     sp<MediaPlayer> media_player = getMediaPlayer(env, thiz);
     if (media_player == NULL ) {
         jniThrowException(env, "java/lang/IllegalStateException", NULL);
-        return false;
+        return JNI_FALSE;
     }
 
     Parcel *metadata = parcelForJavaObject(env, reply);
 
     if (metadata == NULL ) {
         jniThrowException(env, "java/lang/RuntimeException", "Reply parcel is null");
-        return false;
+        return JNI_FALSE;
     }
 
     metadata->freeData();
@@ -589,7 +589,11 @@
     // metadata. Note however that the parcel actually starts with the
     // return code so you should not rewind the parcel using
     // setDataPosition(0).
-    return media_player->getMetadata(update_only, apply_filter, metadata) == OK;
+    if (media_player->getMetadata(update_only, apply_filter, metadata) == OK) {
+        return JNI_TRUE;
+    } else {
+        return JNI_FALSE;
+    }
 }
 
 // This function gets some field IDs, which in turn causes class initialization.
@@ -605,7 +609,7 @@
         return;
     }
 
-    fields.context = env->GetFieldID(clazz, "mNativeContext", "I");
+    fields.context = env->GetFieldID(clazz, "mNativeContext", "J");
     if (fields.context == NULL) {
         return;
     }
@@ -616,7 +620,7 @@
         return;
     }
 
-    fields.surface_texture = env->GetFieldID(clazz, "mNativeSurfaceTexture", "I");
+    fields.surface_texture = env->GetFieldID(clazz, "mNativeSurfaceTexture", "J");
     if (fields.surface_texture == NULL) {
         return;
     }
@@ -696,7 +700,7 @@
         return 0;
     }
 
-    return mp->getAudioSessionId();
+    return (jint) mp->getAudioSessionId();
 }
 
 static void
@@ -733,7 +737,7 @@
 
     Parcel *reply = parcelForJavaObject(env, java_reply);
 
-    return service->pullBatteryData(reply);
+    return (jint) service->pullBatteryData(reply);
 }
 
 static jint
@@ -772,7 +776,7 @@
         jniThrowException(env, "java/lang/IllegalStateException", NULL);
     }
 
-    return ret;
+    return (jint) ret;
 }
 
 static void
@@ -826,16 +830,19 @@
         jstring exclusionListObj = (jstring)env->CallObjectMethod(
                 proxyProps, fields.proxyConfigGetExclusionList);
 
-        const char *exclusionList =
-            env->GetStringUTFChars(exclusionListObj, NULL);
-
         if (host != NULL && exclusionListObj != NULL) {
-            thisplayer->updateProxyConfig(host, port, exclusionList);
-        }
+            const char *exclusionList = env->GetStringUTFChars(exclusionListObj, NULL);
 
-        if (exclusionList != NULL) {
-            env->ReleaseStringUTFChars(exclusionListObj, exclusionList);
-            exclusionList = NULL;
+            if (exclusionList != NULL) {
+                thisplayer->updateProxyConfig(host, port, exclusionList);
+
+                env->ReleaseStringUTFChars(exclusionListObj, exclusionList);
+                exclusionList = NULL;
+            } else {
+                thisplayer->updateProxyConfig(host, port, "");
+            }
+        } else if (host != NULL) {
+            thisplayer->updateProxyConfig(host, port, "");
         }
 
         if (host != NULL) {
diff --git a/media/jni/android_media_MediaProfiles.cpp b/media/jni/android_media_MediaProfiles.cpp
index 3fbb8ba..48a9132 100644
--- a/media/jni/android_media_MediaProfiles.cpp
+++ b/media/jni/android_media_MediaProfiles.cpp
@@ -48,7 +48,7 @@
 android_media_MediaProfiles_native_get_num_file_formats(JNIEnv *env, jobject thiz)
 {
     ALOGV("native_get_num_file_formats");
-    return sProfiles->getOutputFileFormats().size();
+    return (jint) sProfiles->getOutputFileFormats().size();
 }
 
 static jint
@@ -119,7 +119,7 @@
 android_media_MediaProfiles_native_get_num_audio_encoders(JNIEnv *env, jobject thiz)
 {
     ALOGV("native_get_num_audio_encoders");
-    return sProfiles->getAudioEncoders().size();
+    return (jint) sProfiles->getAudioEncoders().size();
 }
 
 static jobject
@@ -223,18 +223,18 @@
 {
     ALOGV("native_has_camcorder_profile: %d %d", id, quality);
     if (!isCamcorderQualityKnown(quality)) {
-        return false;
+        return JNI_FALSE;
     }
 
     camcorder_quality q = static_cast<camcorder_quality>(quality);
-    return sProfiles->hasCamcorderProfile(id, q);
+    return sProfiles->hasCamcorderProfile(id, q) ? JNI_TRUE : JNI_FALSE;
 }
 
 static jint
 android_media_MediaProfiles_native_get_num_video_decoders(JNIEnv *env, jobject thiz)
 {
     ALOGV("native_get_num_video_decoders");
-    return sProfiles->getVideoDecoders().size();
+    return (jint) sProfiles->getVideoDecoders().size();
 }
 
 static jint
@@ -255,7 +255,7 @@
 android_media_MediaProfiles_native_get_num_audio_decoders(JNIEnv *env, jobject thiz)
 {
     ALOGV("native_get_num_audio_decoders");
-    return sProfiles->getAudioDecoders().size();
+    return (jint) sProfiles->getAudioDecoders().size();
 }
 
 static jint
@@ -276,7 +276,7 @@
 android_media_MediaProfiles_native_get_num_image_encoding_quality_levels(JNIEnv *env, jobject thiz, jint cameraId)
 {
     ALOGV("native_get_num_image_encoding_quality_levels");
-    return sProfiles->getImageEncodingQualityLevels(cameraId).size();
+    return (jint) sProfiles->getImageEncodingQualityLevels(cameraId).size();
 }
 
 static jint
@@ -284,7 +284,7 @@
 {
     ALOGV("native_get_image_encoding_quality_level");
     Vector<int> levels = sProfiles->getImageEncodingQualityLevels(cameraId);
-    if (index < 0 || index >= levels.size()) {
+    if (index < 0 || index >= (jint) levels.size()) {
         jniThrowException(env, "java/lang/IllegalArgumentException", "out of array boundary");
         return -1;
     }
diff --git a/media/jni/android_media_MediaRecorder.cpp b/media/jni/android_media_MediaRecorder.cpp
index 9888591..0cfd2ff 100644
--- a/media/jni/android_media_MediaRecorder.cpp
+++ b/media/jni/android_media_MediaRecorder.cpp
@@ -128,21 +128,21 @@
 static sp<MediaRecorder> getMediaRecorder(JNIEnv* env, jobject thiz)
 {
     Mutex::Autolock l(sLock);
-    MediaRecorder* const p = (MediaRecorder*)env->GetIntField(thiz, fields.context);
+    MediaRecorder* const p = (MediaRecorder*)env->GetLongField(thiz, fields.context);
     return sp<MediaRecorder>(p);
 }
 
 static sp<MediaRecorder> setMediaRecorder(JNIEnv* env, jobject thiz, const sp<MediaRecorder>& recorder)
 {
     Mutex::Autolock l(sLock);
-    sp<MediaRecorder> old = (MediaRecorder*)env->GetIntField(thiz, fields.context);
+    sp<MediaRecorder> old = (MediaRecorder*)env->GetLongField(thiz, fields.context);
     if (recorder.get()) {
         recorder->incStrong(thiz);
     }
     if (old != 0) {
         old->decStrong(thiz);
     }
-    env->SetIntField(thiz, fields.context, (int)recorder.get());
+    env->SetLongField(thiz, fields.context, (jlong)recorder.get());
     return old;
 }
 
@@ -334,14 +334,14 @@
     process_media_recorder_call(env, mr->prepare(), "java/io/IOException", "prepare failed.");
 }
 
-static int
+static jint
 android_media_MediaRecorder_native_getMaxAmplitude(JNIEnv *env, jobject thiz)
 {
     ALOGV("getMaxAmplitude");
     sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
     int result = 0;
     process_media_recorder_call(env, mr->getMaxAmplitude(&result), "java/lang/RuntimeException", "getMaxAmplitude failed.");
-    return result;
+    return (jint) result;
 }
 
 static void
@@ -392,7 +392,7 @@
         return;
     }
 
-    fields.context = env->GetFieldID(clazz, "mNativeContext", "I");
+    fields.context = env->GetFieldID(clazz, "mNativeContext", "J");
     if (fields.context == NULL) {
         return;
     }
diff --git a/media/jni/android_media_MediaScanner.cpp b/media/jni/android_media_MediaScanner.cpp
index 4e3d14e..84028b7 100644
--- a/media/jni/android_media_MediaScanner.cpp
+++ b/media/jni/android_media_MediaScanner.cpp
@@ -226,12 +226,12 @@
 
 static MediaScanner *getNativeScanner_l(JNIEnv* env, jobject thiz)
 {
-    return (MediaScanner *) env->GetIntField(thiz, fields.context);
+    return (MediaScanner *) env->GetLongField(thiz, fields.context);
 }
 
 static void setNativeScanner_l(JNIEnv* env, jobject thiz, MediaScanner *s)
 {
-    env->SetIntField(thiz, fields.context, (int)s);
+    env->SetLongField(thiz, fields.context, (jlong)s);
 }
 
 static void
@@ -381,7 +381,7 @@
         return;
     }
 
-    fields.context = env->GetFieldID(clazz, "mNativeContext", "I");
+    fields.context = env->GetFieldID(clazz, "mNativeContext", "J");
     if (fields.context == NULL) {
         return;
     }
@@ -398,7 +398,7 @@
         return;
     }
 
-    env->SetIntField(thiz, fields.context, (int)mp);
+    env->SetLongField(thiz, fields.context, (jlong)mp);
 }
 
 static void
diff --git a/media/jni/soundpool/android_media_SoundPool_SoundPoolImpl.cpp b/media/jni/soundpool/android_media_SoundPool_SoundPoolImpl.cpp
index 2604850..9cc55ab 100644
--- a/media/jni/soundpool/android_media_SoundPool_SoundPoolImpl.cpp
+++ b/media/jni/soundpool/android_media_SoundPool_SoundPoolImpl.cpp
@@ -34,11 +34,11 @@
 } fields;
 
 static inline SoundPool* MusterSoundPool(JNIEnv *env, jobject thiz) {
-    return (SoundPool*)env->GetIntField(thiz, fields.mNativeContext);
+    return (SoundPool*)env->GetLongField(thiz, fields.mNativeContext);
 }
 
 // ----------------------------------------------------------------------------
-static int
+static jint
 android_media_SoundPool_SoundPoolImpl_load_URL(JNIEnv *env, jobject thiz, jstring path, jint priority)
 {
     ALOGV("android_media_SoundPool_SoundPoolImpl_load_URL");
@@ -50,29 +50,29 @@
     const char* s = env->GetStringUTFChars(path, NULL);
     int id = ap->load(s, priority);
     env->ReleaseStringUTFChars(path, s);
-    return id;
+    return (jint) id;
 }
 
-static int
+static jint
 android_media_SoundPool_SoundPoolImpl_load_FD(JNIEnv *env, jobject thiz, jobject fileDescriptor,
         jlong offset, jlong length, jint priority)
 {
     ALOGV("android_media_SoundPool_SoundPoolImpl_load_FD");
     SoundPool *ap = MusterSoundPool(env, thiz);
     if (ap == NULL) return 0;
-    return ap->load(jniGetFDFromFileDescriptor(env, fileDescriptor),
+    return (jint) ap->load(jniGetFDFromFileDescriptor(env, fileDescriptor),
             int64_t(offset), int64_t(length), int(priority));
 }
 
-static bool
+static jboolean
 android_media_SoundPool_SoundPoolImpl_unload(JNIEnv *env, jobject thiz, jint sampleID) {
     ALOGV("android_media_SoundPool_SoundPoolImpl_unload\n");
     SoundPool *ap = MusterSoundPool(env, thiz);
-    if (ap == NULL) return 0;
-    return ap->unload(sampleID);
+    if (ap == NULL) return JNI_FALSE;
+    return ap->unload(sampleID) ? JNI_TRUE : JNI_FALSE;
 }
 
-static int
+static jint
 android_media_SoundPool_SoundPoolImpl_play(JNIEnv *env, jobject thiz, jint sampleID,
         jfloat leftVolume, jfloat rightVolume, jint priority, jint loop,
         jfloat rate)
@@ -80,7 +80,7 @@
     ALOGV("android_media_SoundPool_SoundPoolImpl_play\n");
     SoundPool *ap = MusterSoundPool(env, thiz);
     if (ap == NULL) return 0;
-    return ap->play(sampleID, leftVolume, rightVolume, priority, loop, rate);
+    return (jint) ap->play(sampleID, leftVolume, rightVolume, priority, loop, rate);
 }
 
 static void
@@ -130,22 +130,22 @@
 
 static void
 android_media_SoundPool_SoundPoolImpl_setVolume(JNIEnv *env, jobject thiz, jint channelID,
-        float leftVolume, float rightVolume)
+        jfloat leftVolume, jfloat rightVolume)
 {
     ALOGV("android_media_SoundPool_SoundPoolImpl_setVolume");
     SoundPool *ap = MusterSoundPool(env, thiz);
     if (ap == NULL) return;
-    ap->setVolume(channelID, leftVolume, rightVolume);
+    ap->setVolume(channelID, (float) leftVolume, (float) rightVolume);
 }
 
 static void
 android_media_SoundPool_SoundPoolImpl_setPriority(JNIEnv *env, jobject thiz, jint channelID,
-        int priority)
+        jint priority)
 {
     ALOGV("android_media_SoundPool_SoundPoolImpl_setPriority");
     SoundPool *ap = MusterSoundPool(env, thiz);
     if (ap == NULL) return;
-    ap->setPriority(channelID, priority);
+    ap->setPriority(channelID, (int) priority);
 }
 
 static void
@@ -160,12 +160,12 @@
 
 static void
 android_media_SoundPool_SoundPoolImpl_setRate(JNIEnv *env, jobject thiz, jint channelID,
-        float rate)
+       jfloat rate)
 {
     ALOGV("android_media_SoundPool_SoundPoolImpl_setRate");
     SoundPool *ap = MusterSoundPool(env, thiz);
     if (ap == NULL) return;
-    ap->setRate(channelID, rate);
+    ap->setRate(channelID, (float) rate);
 }
 
 static void android_media_callback(SoundPoolEvent event, SoundPool* soundPool, void* user)
@@ -185,7 +185,7 @@
     }
 
     // save pointer to SoundPool C++ object in opaque field in Java object
-    env->SetIntField(thiz, fields.mNativeContext, (int)ap);
+    env->SetLongField(thiz, fields.mNativeContext, (jlong) ap);
 
     // set callback with weak reference
     jobject globalWeakRef = env->NewGlobalRef(weakRef);
@@ -208,7 +208,7 @@
 
         // clear callback and native context
         ap->setCallback(NULL, NULL);
-        env->SetIntField(thiz, fields.mNativeContext, 0);
+        env->SetLongField(thiz, fields.mNativeContext, 0);
         delete ap;
     }
 }
@@ -299,7 +299,7 @@
         goto bail;
     }
 
-    fields.mNativeContext = env->GetFieldID(clazz, "mNativeContext", "I");
+    fields.mNativeContext = env->GetFieldID(clazz, "mNativeContext", "J");
     if (fields.mNativeContext == NULL) {
         ALOGE("Can't find SoundPoolImpl.mNativeContext");
         goto bail;
diff --git a/media/mca/filterfw/jni/jni_gl_environment.cpp b/media/mca/filterfw/jni/jni_gl_environment.cpp
index 9abf191..6da7b7c 100644
--- a/media/mca/filterfw/jni/jni_gl_environment.cpp
+++ b/media/mca/filterfw/jni/jni_gl_environment.cpp
@@ -119,12 +119,12 @@
         return NULL;
     }
 
-    jfieldID context = env->GetFieldID(clazz, "mNativeContext", "I");
+    jfieldID context = env->GetFieldID(clazz, "mNativeContext", "J");
     if (context == NULL) {
         return NULL;
     }
 
-    MediaRecorder* const p = (MediaRecorder*)env->GetIntField(jmediarecorder, context);
+    MediaRecorder* const p = (MediaRecorder*)env->GetLongField(jmediarecorder, context);
     env->DeleteLocalRef(clazz);
     return sp<MediaRecorder>(p);
 }
diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java
index e60231a..0d535cc 100644
--- a/services/java/com/android/server/MountService.java
+++ b/services/java/com/android/server/MountService.java
@@ -1411,7 +1411,7 @@
     public void unregisterListener(IMountServiceListener listener) {
         synchronized (mListeners) {
             for(MountServiceBinderListener bl : mListeners) {
-                if (bl.mListener == listener) {
+                if (bl.mListener.asBinder() == listener.asBinder()) {
                     mListeners.remove(mListeners.indexOf(bl));
                     listener.asBinder().unlinkToDeath(bl, 0);
                     return;
diff --git a/services/java/com/android/server/am/ActivityStack.java b/services/java/com/android/server/am/ActivityStack.java
old mode 100644
new mode 100755
index 37f4cd7..e9c78a7
--- a/services/java/com/android/server/am/ActivityStack.java
+++ b/services/java/com/android/server/am/ActivityStack.java
@@ -1144,7 +1144,7 @@
                     } else if (isActivityOverHome(r)) {
                         if (DEBUG_VISBILITY) Slog.v(TAG, "Showing home: at " + r);
                         showHomeBehindStack = true;
-                        behindFullscreen = !isHomeStack();
+                        behindFullscreen = !isHomeStack() && r.frontOfTask && task.mOnTopOfHome;
                     }
                 } else {
                     if (DEBUG_VISBILITY) Slog.v(
diff --git a/telephony/java/android/telephony/CellSignalStrengthCdma.java b/telephony/java/android/telephony/CellSignalStrengthCdma.java
index c945094..46d09f6 100644
--- a/telephony/java/android/telephony/CellSignalStrengthCdma.java
+++ b/telephony/java/android/telephony/CellSignalStrengthCdma.java
@@ -21,7 +21,7 @@
 import android.telephony.Rlog;
 
 /**
- * LTE signal strength related information.
+ * Signal strength related information.
  */
 public final class CellSignalStrengthCdma extends CellSignalStrength implements Parcelable {
 
@@ -136,7 +136,7 @@
     }
 
     /**
-     * Get the LTE signal level as an asu value between 0..97, 99 is unknown
+     * Get the signal level as an asu value between 0..97, 99 is unknown
      * Asu is calculated based on 3GPP RSRP. Refer to 3GPP 27.007 (Ver 10.3.0) Sec 8.69
      */
     @Override