Merge "AArch64: Use long for pointers in media 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/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/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/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/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