Merge "Ensure that buffering updates eventually hit 100% after we download everything." into gingerbread
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 3e0187d..f8e60ce 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -3338,7 +3338,8 @@
         setUpSelect();
         if (mNativeClass != 0 && nativeWordSelection(x, y)) {
             nativeSetExtendSelection();
-            getWebChromeClient().onSelectionStart(this);
+            WebChromeClient client = getWebChromeClient();
+            if (client != null) client.onSelectionStart(this);
             return true;
         }
         notifySelectDialogDismissed();
@@ -4126,7 +4127,8 @@
      */
     public void selectionDone() {
         if (mSelectingText) {
-            getWebChromeClient().onSelectionDone(this);
+            WebChromeClient client = getWebChromeClient();
+            if (client != null) client.onSelectionDone(this);
             invalidate(); // redraw without selection
             notifySelectDialogDismissed();
         }
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp
index 407d2e7..62a4495 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -506,7 +506,7 @@
 static void readLocale(char* language, char* region)
 {
     char propLang[PROPERTY_VALUE_MAX], propRegn[PROPERTY_VALUE_MAX];
-    
+
     property_get("persist.sys.language", propLang, "");
     property_get("persist.sys.country", propRegn, "");
     if (*propLang == 0 && *propRegn == 0) {
@@ -710,6 +710,33 @@
         LOGW("dalvik.vm.gc.overwritefree should be 'true' or 'false'");
     }
 
+    /* enable heap verification before each gc */
+    property_get("dalvik.vm.gc.preverify", propBuf, "false");
+    if (strcmp(propBuf, "true") == 0) {
+        opt.optionString = "-Xgc:preverify";
+        mOptions.add(opt);
+    } else if (strcmp(propBuf, "false") != 0) {
+        LOGW("dalvik.vm.gc.preverify should be 'true' or 'false'");
+    }
+
+    /* enable heap verification after each gc */
+    property_get("dalvik.vm.gc.postverify", propBuf, "false");
+    if (strcmp(propBuf, "true") == 0) {
+        opt.optionString = "-Xgc:postverify";
+        mOptions.add(opt);
+    } else if (strcmp(propBuf, "false") != 0) {
+        LOGW("dalvik.vm.gc.postverify should be 'true' or 'false'");
+    }
+
+    /* enable card table verification for partial gc */
+    property_get("dalvik.vm.gc.verifycardtable", propBuf, "false");
+    if (strcmp(propBuf, "true") == 0) {
+        opt.optionString = "-Xgc:verifycardtable";
+        mOptions.add(opt);
+    } else if (strcmp(propBuf, "false") != 0) {
+        LOGW("dalvik.vm.gc.verifycardtable should be 'true' or 'false'");
+    }
+
     /* enable debugging; set suspend=y to pause during VM init */
 #ifdef HAVE_ANDROID_OS
     /* use android ADB transport */
@@ -757,16 +784,6 @@
     }
 
 #if defined(WITH_JIT)
-    /* Minimal profile threshold to trigger JIT compilation */
-    char jitThresholdBuf[sizeof("-Xjitthreshold:") + PROPERTY_VALUE_MAX];
-    property_get("dalvik.vm.jit.threshold", propBuf, "");
-    if (strlen(propBuf) > 0) {
-        strcpy(jitThresholdBuf, "-Xjitthreshold:");
-        strcat(jitThresholdBuf, propBuf);
-        opt.optionString = jitThresholdBuf;
-        mOptions.add(opt);
-    }
-
     /* Force interpreter-only mode for selected opcodes. Eg "1-0a,3c,f1-ff" */
     char jitOpBuf[sizeof("-Xjitop:") + PROPERTY_VALUE_MAX];
     property_get("dalvik.vm.jit.op", propBuf, "");
@@ -777,16 +794,6 @@
         mOptions.add(opt);
     }
 
-    /*
-     * Reverse the polarity of dalvik.vm.jit.op and force interpreter-only
-     * for non-selected opcodes.
-     */
-    property_get("dalvik.vm.jit.includeop", propBuf, "");
-    if (strlen(propBuf) > 0) {
-        opt.optionString = "-Xincludeselectedop";
-        mOptions.add(opt);
-    }
-
     /* Force interpreter-only mode for selected methods */
     char jitMethodBuf[sizeof("-Xjitmethod:") + PROPERTY_VALUE_MAX];
     property_get("dalvik.vm.jit.method", propBuf, "");
@@ -796,37 +803,6 @@
         opt.optionString = jitMethodBuf;
         mOptions.add(opt);
     }
-
-    /*
-     * Reverse the polarity of dalvik.vm.jit.method and force interpreter-only
-     * for non-selected methods.
-     */
-    property_get("dalvik.vm.jit.includemethod", propBuf, "");
-    if (strlen(propBuf) > 0) {
-        opt.optionString = "-Xincludeselectedmethod";
-        mOptions.add(opt);
-    }
-
-    /*
-     * Enable profile collection on JIT'ed code.
-     */
-    property_get("dalvik.vm.jit.profile", propBuf, "");
-    if (strlen(propBuf) > 0) {
-        opt.optionString = "-Xjitprofile";
-        mOptions.add(opt);
-    }
-
-    /*
-     * Disable optimizations by setting the corresponding bit to 1.
-     */
-    char jitOptBuf[sizeof("-Xjitdisableopt:") + PROPERTY_VALUE_MAX];
-    property_get("dalvik.vm.jit.disableopt", propBuf, "");
-    if (strlen(propBuf) > 0) {
-        strcpy(jitOptBuf, "-Xjitdisableopt:");
-        strcat(jitOptBuf, propBuf);
-        opt.optionString = jitOptBuf;
-        mOptions.add(opt);
-    }
 #endif
 
     if (executionMode == kEMIntPortable) {
diff --git a/include/media/stagefright/DataSource.h b/include/media/stagefright/DataSource.h
index 6f7dc38..9d2cff6 100644
--- a/include/media/stagefright/DataSource.h
+++ b/include/media/stagefright/DataSource.h
@@ -28,6 +28,7 @@
 
 namespace android {
 
+struct AMessage;
 class String8;
 
 class DataSource : public RefBase {
@@ -59,10 +60,14 @@
 
     ////////////////////////////////////////////////////////////////////////////
 
-    bool sniff(String8 *mimeType, float *confidence);
+    bool sniff(String8 *mimeType, float *confidence, sp<AMessage> *meta);
 
+    // The sniffer can optionally fill in "meta" with an AMessage containing
+    // a dictionary of values that helps the corresponding extractor initialize
+    // its state without duplicating effort already exerted by the sniffer.
     typedef bool (*SnifferFunc)(
-            const sp<DataSource> &source, String8 *mimeType, float *confidence);
+            const sp<DataSource> &source, String8 *mimeType,
+            float *confidence, sp<AMessage> *meta);
 
     static void RegisterSniffer(SnifferFunc func);
     static void RegisterDefaultSniffers();
diff --git a/media/libmedia/fixedfft.cpp b/media/libmedia/fixedfft.cpp
index 28eb05a..9cf05ba 100644
--- a/media/libmedia/fixedfft.cpp
+++ b/media/libmedia/fixedfft.cpp
@@ -26,7 +26,9 @@
 
 #include <stdio.h>
 #include <stdint.h>
+#ifdef __ARM_ARCH__
 #include <machine/cpu-features.h>
+#endif
 
 #define LOG_FFT_SIZE 10
 #define MAX_FFT_SIZE (1 << LOG_FFT_SIZE)
diff --git a/media/libstagefright/AMRExtractor.cpp b/media/libstagefright/AMRExtractor.cpp
index 70af2da..1b05528 100644
--- a/media/libstagefright/AMRExtractor.cpp
+++ b/media/libstagefright/AMRExtractor.cpp
@@ -87,7 +87,7 @@
       mInitCheck(NO_INIT) {
     String8 mimeType;
     float confidence;
-    if (!SniffAMR(mDataSource, &mimeType, &confidence)) {
+    if (!SniffAMR(mDataSource, &mimeType, &confidence, NULL)) {
         return;
     }
 
@@ -276,7 +276,8 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 bool SniffAMR(
-        const sp<DataSource> &source, String8 *mimeType, float *confidence) {
+        const sp<DataSource> &source, String8 *mimeType, float *confidence,
+        sp<AMessage> *) {
     char header[9];
 
     if (source->readAt(0, header, sizeof(header)) != sizeof(header)) {
diff --git a/media/libstagefright/DataSource.cpp b/media/libstagefright/DataSource.cpp
index 90a596c..49eac62 100644
--- a/media/libstagefright/DataSource.cpp
+++ b/media/libstagefright/DataSource.cpp
@@ -25,6 +25,7 @@
 
 #include "matroska/MatroskaExtractor.h"
 
+#include <media/stagefright/foundation/AMessage.h>
 #include <media/stagefright/DataSource.h>
 #include <media/stagefright/FileSource.h>
 #include <media/stagefright/MediaErrors.h>
@@ -56,19 +57,23 @@
 Mutex DataSource::gSnifferMutex;
 List<DataSource::SnifferFunc> DataSource::gSniffers;
 
-bool DataSource::sniff(String8 *mimeType, float *confidence) {
+bool DataSource::sniff(
+        String8 *mimeType, float *confidence, sp<AMessage> *meta) {
     *mimeType = "";
     *confidence = 0.0f;
+    meta->clear();
 
     Mutex::Autolock autoLock(gSnifferMutex);
     for (List<SnifferFunc>::iterator it = gSniffers.begin();
          it != gSniffers.end(); ++it) {
         String8 newMimeType;
         float newConfidence;
-        if ((*it)(this, &newMimeType, &newConfidence)) {
+        sp<AMessage> newMeta;
+        if ((*it)(this, &newMimeType, &newConfidence, &newMeta)) {
             if (newConfidence > *confidence) {
                 *mimeType = newMimeType;
                 *confidence = newConfidence;
+                *meta = newMeta;
             }
         }
     }
@@ -92,13 +97,13 @@
 
 // static
 void DataSource::RegisterDefaultSniffers() {
-    RegisterSniffer(SniffMP3);
     RegisterSniffer(SniffMPEG4);
-    RegisterSniffer(SniffAMR);
-    RegisterSniffer(SniffWAV);
-    RegisterSniffer(SniffOgg);
     RegisterSniffer(SniffMatroska);
+    RegisterSniffer(SniffOgg);
+    RegisterSniffer(SniffWAV);
+    RegisterSniffer(SniffAMR);
     RegisterSniffer(SniffMPEG2TS);
+    RegisterSniffer(SniffMP3);
 }
 
 // static
diff --git a/media/libstagefright/MP3Extractor.cpp b/media/libstagefright/MP3Extractor.cpp
index 4058fbc..2e36968 100644
--- a/media/libstagefright/MP3Extractor.cpp
+++ b/media/libstagefright/MP3Extractor.cpp
@@ -22,6 +22,7 @@
 
 #include "include/ID3.h"
 
+#include <media/stagefright/foundation/AMessage.h>
 #include <media/stagefright/DataSource.h>
 #include <media/stagefright/MediaBuffer.h>
 #include <media/stagefright/MediaBufferGroup.h>
@@ -456,15 +457,31 @@
     MP3Source &operator=(const MP3Source &);
 };
 
-MP3Extractor::MP3Extractor(const sp<DataSource> &source)
+MP3Extractor::MP3Extractor(
+        const sp<DataSource> &source, const sp<AMessage> &meta)
     : mDataSource(source),
       mFirstFramePos(-1),
       mFixedHeader(0),
       mByteNumber(0) {
     off_t pos = 0;
     uint32_t header;
-    bool success = Resync(mDataSource, 0, &pos, &header);
-    CHECK(success);
+    bool success;
+
+    int64_t meta_offset;
+    uint32_t meta_header;
+    if (meta != NULL
+            && meta->findInt64("offset", &meta_offset)
+            && meta->findInt32("header", (int32_t *)&meta_header)) {
+        // The sniffer has already done all the hard work for us, simply
+        // accept its judgement.
+        pos = (off_t)meta_offset;
+        header = meta_header;
+
+        success = true;
+    } else {
+        success = Resync(mDataSource, 0, &pos, &header);
+        CHECK(success);
+    }
 
     if (success) {
         mFirstFramePos = pos;
@@ -759,15 +776,20 @@
 }
 
 bool SniffMP3(
-        const sp<DataSource> &source, String8 *mimeType, float *confidence) {
+        const sp<DataSource> &source, String8 *mimeType,
+        float *confidence, sp<AMessage> *meta) {
     off_t pos = 0;
     uint32_t header;
     if (!Resync(source, 0, &pos, &header)) {
         return false;
     }
 
+    *meta = new AMessage;
+    (*meta)->setInt64("offset", pos);
+    (*meta)->setInt32("header", header);
+
     *mimeType = MEDIA_MIMETYPE_AUDIO_MPEG;
-    *confidence = 0.3f;
+    *confidence = 0.2f;
 
     return true;
 }
diff --git a/media/libstagefright/MPEG4Extractor.cpp b/media/libstagefright/MPEG4Extractor.cpp
index 12a1e6e..ba90407 100644
--- a/media/libstagefright/MPEG4Extractor.cpp
+++ b/media/libstagefright/MPEG4Extractor.cpp
@@ -1738,7 +1738,7 @@
         || !memcmp(header, "ftypM4A ", 8) || !memcmp(header, "ftypf4v ", 8)
         || !memcmp(header, "ftypkddi", 8) || !memcmp(header, "ftypM4VP", 8)) {
         *mimeType = MEDIA_MIMETYPE_CONTAINER_MPEG4;
-        *confidence = 0.1;
+        *confidence = 0.4;
 
         return true;
     }
@@ -1805,13 +1805,14 @@
     }
 
     *mimeType = MEDIA_MIMETYPE_CONTAINER_MPEG4;
-    *confidence = 0.3f;
+    *confidence = 0.4f;
 
     return true;
 }
 
 bool SniffMPEG4(
-        const sp<DataSource> &source, String8 *mimeType, float *confidence) {
+        const sp<DataSource> &source, String8 *mimeType, float *confidence,
+        sp<AMessage> *) {
     if (BetterSniffMPEG4(source, mimeType, confidence)) {
         return true;
     }
diff --git a/media/libstagefright/MediaExtractor.cpp b/media/libstagefright/MediaExtractor.cpp
index 56e6136..9bc94de 100644
--- a/media/libstagefright/MediaExtractor.cpp
+++ b/media/libstagefright/MediaExtractor.cpp
@@ -27,6 +27,7 @@
 
 #include "matroska/MatroskaExtractor.h"
 
+#include <media/stagefright/foundation/AMessage.h>
 #include <media/stagefright/DataSource.h>
 #include <media/stagefright/MediaDefs.h>
 #include <media/stagefright/MediaExtractor.h>
@@ -46,10 +47,12 @@
 // static
 sp<MediaExtractor> MediaExtractor::Create(
         const sp<DataSource> &source, const char *mime) {
+    sp<AMessage> meta;
+
     String8 tmp;
     if (mime == NULL) {
         float confidence;
-        if (!source->sniff(&tmp, &confidence)) {
+        if (!source->sniff(&tmp, &confidence, &meta)) {
             LOGV("FAILED to autodetect media content.");
 
             return NULL;
@@ -64,7 +67,7 @@
             || !strcasecmp(mime, "audio/mp4")) {
         return new MPEG4Extractor(source);
     } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_MPEG)) {
-        return new MP3Extractor(source);
+        return new MP3Extractor(source, meta);
     } else if (!strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AMR_NB)
             || !strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_AMR_WB)) {
         return new AMRExtractor(source);
diff --git a/media/libstagefright/OggExtractor.cpp b/media/libstagefright/OggExtractor.cpp
index 9630092..2c1311a 100644
--- a/media/libstagefright/OggExtractor.cpp
+++ b/media/libstagefright/OggExtractor.cpp
@@ -804,7 +804,8 @@
 }
 
 bool SniffOgg(
-        const sp<DataSource> &source, String8 *mimeType, float *confidence) {
+        const sp<DataSource> &source, String8 *mimeType, float *confidence,
+        sp<AMessage> *) {
     char tmp[4];
     if (source->readAt(0, tmp, 4) < 4 || memcmp(tmp, "OggS", 4)) {
         return false;
diff --git a/media/libstagefright/WAVExtractor.cpp b/media/libstagefright/WAVExtractor.cpp
index 8d820c0..57c1075 100644
--- a/media/libstagefright/WAVExtractor.cpp
+++ b/media/libstagefright/WAVExtractor.cpp
@@ -404,7 +404,8 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 bool SniffWAV(
-        const sp<DataSource> &source, String8 *mimeType, float *confidence) {
+        const sp<DataSource> &source, String8 *mimeType, float *confidence,
+        sp<AMessage> *) {
     char header[12];
     if (source->readAt(0, header, sizeof(header)) < (ssize_t)sizeof(header)) {
         return false;
diff --git a/media/libstagefright/include/AMRExtractor.h b/media/libstagefright/include/AMRExtractor.h
index db49fe4..1cdf36d 100644
--- a/media/libstagefright/include/AMRExtractor.h
+++ b/media/libstagefright/include/AMRExtractor.h
@@ -22,6 +22,7 @@
 
 namespace android {
 
+struct AMessage;
 class String8;
 
 class AMRExtractor : public MediaExtractor {
@@ -49,7 +50,8 @@
 };
 
 bool SniffAMR(
-        const sp<DataSource> &source, String8 *mimeType, float *confidence);
+        const sp<DataSource> &source, String8 *mimeType, float *confidence,
+        sp<AMessage> *);
 
 }  // namespace android
 
diff --git a/media/libstagefright/include/MP3Extractor.h b/media/libstagefright/include/MP3Extractor.h
index 3ce6df3..0e6ccde 100644
--- a/media/libstagefright/include/MP3Extractor.h
+++ b/media/libstagefright/include/MP3Extractor.h
@@ -22,13 +22,14 @@
 
 namespace android {
 
+struct AMessage;
 class DataSource;
 class String8;
 
 class MP3Extractor : public MediaExtractor {
 public:
     // Extractor assumes ownership of "source".
-    MP3Extractor(const sp<DataSource> &source);
+    MP3Extractor(const sp<DataSource> &source, const sp<AMessage> &meta);
 
     virtual size_t countTracks();
     virtual sp<MediaSource> getTrack(size_t index);
@@ -52,7 +53,8 @@
 };
 
 bool SniffMP3(
-        const sp<DataSource> &source, String8 *mimeType, float *confidence);
+        const sp<DataSource> &source, String8 *mimeType, float *confidence,
+        sp<AMessage> *meta);
 
 }  // namespace android
 
diff --git a/media/libstagefright/include/MPEG2TSExtractor.h b/media/libstagefright/include/MPEG2TSExtractor.h
index c96973b..1bf4cd1 100644
--- a/media/libstagefright/include/MPEG2TSExtractor.h
+++ b/media/libstagefright/include/MPEG2TSExtractor.h
@@ -9,6 +9,7 @@
 
 namespace android {
 
+struct AMessage;
 struct AnotherPacketSource;
 struct ATSParser;
 struct DataSource;
@@ -47,7 +48,8 @@
 };
 
 bool SniffMPEG2TS(
-        const sp<DataSource> &source, String8 *mimeType, float *confidence);
+        const sp<DataSource> &source, String8 *mimeType, float *confidence,
+        sp<AMessage> *);
 
 }  // namespace android
 
diff --git a/media/libstagefright/include/MPEG4Extractor.h b/media/libstagefright/include/MPEG4Extractor.h
index c8663d5..1c9cc7e 100644
--- a/media/libstagefright/include/MPEG4Extractor.h
+++ b/media/libstagefright/include/MPEG4Extractor.h
@@ -23,6 +23,7 @@
 
 namespace android {
 
+struct AMessage;
 class DataSource;
 class SampleTable;
 class String8;
@@ -75,7 +76,8 @@
 };
 
 bool SniffMPEG4(
-        const sp<DataSource> &source, String8 *mimeType, float *confidence);
+        const sp<DataSource> &source, String8 *mimeType, float *confidence,
+        sp<AMessage> *);
 
 }  // namespace android
 
diff --git a/media/libstagefright/include/OggExtractor.h b/media/libstagefright/include/OggExtractor.h
index 7066669..1eda025 100644
--- a/media/libstagefright/include/OggExtractor.h
+++ b/media/libstagefright/include/OggExtractor.h
@@ -22,6 +22,7 @@
 
 namespace android {
 
+struct AMessage;
 class DataSource;
 class String8;
 
@@ -53,7 +54,8 @@
 };
 
 bool SniffOgg(
-        const sp<DataSource> &source, String8 *mimeType, float *confidence);
+        const sp<DataSource> &source, String8 *mimeType, float *confidence,
+        sp<AMessage> *);
 
 }  // namespace android
 
diff --git a/media/libstagefright/include/WAVExtractor.h b/media/libstagefright/include/WAVExtractor.h
index 3e847b9..df6d3e7 100644
--- a/media/libstagefright/include/WAVExtractor.h
+++ b/media/libstagefright/include/WAVExtractor.h
@@ -22,6 +22,7 @@
 
 namespace android {
 
+struct AMessage;
 class DataSource;
 class String8;
 
@@ -58,7 +59,8 @@
 };
 
 bool SniffWAV(
-        const sp<DataSource> &source, String8 *mimeType, float *confidence);
+        const sp<DataSource> &source, String8 *mimeType, float *confidence,
+        sp<AMessage> *);
 
 }  // namespace android
 
diff --git a/media/libstagefright/matroska/MatroskaExtractor.cpp b/media/libstagefright/matroska/MatroskaExtractor.cpp
index 71f6587..7c7d69e 100644
--- a/media/libstagefright/matroska/MatroskaExtractor.cpp
+++ b/media/libstagefright/matroska/MatroskaExtractor.cpp
@@ -579,7 +579,8 @@
 }
 
 bool SniffMatroska(
-        const sp<DataSource> &source, String8 *mimeType, float *confidence) {
+        const sp<DataSource> &source, String8 *mimeType, float *confidence,
+        sp<AMessage> *) {
     DataSourceReader reader(source);
     mkvparser::EBMLHeader ebmlHeader;
     long long pos;
diff --git a/media/libstagefright/matroska/MatroskaExtractor.h b/media/libstagefright/matroska/MatroskaExtractor.h
index 7471848..fa20b84 100644
--- a/media/libstagefright/matroska/MatroskaExtractor.h
+++ b/media/libstagefright/matroska/MatroskaExtractor.h
@@ -27,6 +27,7 @@
 
 namespace android {
 
+struct AMessage;
 class String8;
 
 struct DataSourceReader;
@@ -69,7 +70,8 @@
 };
 
 bool SniffMatroska(
-        const sp<DataSource> &source, String8 *mimeType, float *confidence);
+        const sp<DataSource> &source, String8 *mimeType, float *confidence,
+        sp<AMessage> *);
 
 }  // namespace android
 
diff --git a/media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp b/media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp
index b287c95..56ca375 100644
--- a/media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp
+++ b/media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp
@@ -174,7 +174,8 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 bool SniffMPEG2TS(
-        const sp<DataSource> &source, String8 *mimeType, float *confidence) {
+        const sp<DataSource> &source, String8 *mimeType, float *confidence,
+        sp<AMessage> *) {
 #if 0
     char header;
     if (source->readAt(0, &header, 1) != 1 || header != 0x47) {
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 6f3c66d..03d7a02 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -196,12 +196,16 @@
     } else {
 slowpath:
         GGLSurface t;
-        status_t res = buffer->lock(&t, GRALLOC_USAGE_SW_READ_OFTEN);
-        LOGE_IF(res, "error %d (%s) locking buffer %p",
-                res, strerror(res), buffer.get());
-        if (res == NO_ERROR) {
-            mBufferManager.loadTexture(dirty, t);
-            buffer->unlock();
+        if (buffer->usage & GRALLOC_USAGE_SW_READ_MASK) {
+            status_t res = buffer->lock(&t, GRALLOC_USAGE_SW_READ_OFTEN);
+            LOGE_IF(res, "error %d (%s) locking buffer %p",
+                    res, strerror(res), buffer.get());
+            if (res == NO_ERROR) {
+                mBufferManager.loadTexture(dirty, t);
+                buffer->unlock();
+            }
+        } else {
+            // we can't do anything
         }
     }
 }
diff --git a/tests/CoreTests/android/core/JavaPerformanceTests.java b/tests/CoreTests/android/core/JavaPerformanceTests.java
index fbe70cc..95075ea 100644
--- a/tests/CoreTests/android/core/JavaPerformanceTests.java
+++ b/tests/CoreTests/android/core/JavaPerformanceTests.java
@@ -23,7 +23,6 @@
 
     public static String[] children() {
         return new String[] {
-                StringTest.class.getName(),
                 HashMapPerformanceTest.class.getName(),
                 ArrayListPerformanceTest.class.getName(),
                 TreeMapPerformanceTest.class.getName(),
diff --git a/tests/CoreTests/android/core/StringTest.java b/tests/CoreTests/android/core/StringTest.java
deleted file mode 100644
index 128531c..0000000
--- a/tests/CoreTests/android/core/StringTest.java
+++ /dev/null
@@ -1,951 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.core;
-
-import java.util.Locale;
-
-import android.test.PerformanceTestBase;
-import android.test.PerformanceTestCase;
-
-public class StringTest extends PerformanceTestBase {
-    public static final int ITERATIONS = 1000;
-    public static final String STATIC_STRING_01 = "Hello Android";
-    public static final String STATIC_STRING_02 =
-            "Remember, today is the tomorrow you worried about yesterday";
-    public static final char[] STATIC_CHAR_ARRAY =
-            {'N', 'A', 'N', 'D', 'R', 'O', 'I', 'D'};
-    public static StringBuffer STATIC_SBUF = new StringBuffer(STATIC_STRING_02);
-
-    @Override
-    public int startPerformance(PerformanceTestCase.Intermediates intermediates) {
-        intermediates.setInternalIterations(ITERATIONS);
-        return 0;
-    }
-
-    /** Create an empty String object* */
-
-    public void testStringCreate() {
-        String rString;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            rString = new String();
-            rString = new String();
-            rString = new String();
-            rString = new String();
-            rString = new String();
-            rString = new String();
-            rString = new String();
-            rString = new String();
-            rString = new String();
-            rString = new String();
-        }
-    }
-
-    /** Create an initialised String object* */
-
-    public void testStringCreate1() {
-        String rString, str = STATIC_STRING_01;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            rString = new String(str);
-            rString = new String(str);
-            rString = new String(str);
-            rString = new String(str);
-            rString = new String(str);
-            rString = new String(str);
-            rString = new String(str);
-            rString = new String(str);
-            rString = new String(str);
-            rString = new String(str); // 10
-        }
-    }
-
-    /** equals() with for loop* */
-    public void testStringEquals() {
-        String mString = new String(STATIC_STRING_01);
-        String str = STATIC_STRING_01;
-        boolean result;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            result = mString.equals(str);
-            result = mString.equals(str);
-            result = mString.equals(str);
-            result = mString.equals(str);
-            result = mString.equals(str);
-            result = mString.equals(str);
-            result = mString.equals(str);
-            result = mString.equals(str);
-            result = mString.equals(str);
-            result = mString.equals(str);
-        }
-    }
-
-    /**
-     * ContentEquals- Comparing the content of a String with that of a String
-     * Buffer*
-     */
-
-    public void testStringContentEquals() {
-        StringBuffer sBuf = new StringBuffer(STATIC_STRING_01);
-        String str = STATIC_STRING_01;
-        boolean result;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            result = str.contentEquals(sBuf);
-            result = str.contentEquals(sBuf);
-            result = str.contentEquals(sBuf);
-            result = str.contentEquals(sBuf);
-            result = str.contentEquals(sBuf);
-            result = str.contentEquals(sBuf);
-            result = str.contentEquals(sBuf);
-            result = str.contentEquals(sBuf);
-            result = str.contentEquals(sBuf);
-            result = str.contentEquals(sBuf);
-        }
-    }
-
-    /** Compare string objects lexicographically using compareTo() with for loop* */
-
-    public void testStringCompareTo() {
-        String str1 = new String(STATIC_STRING_01);
-        String str2 = STATIC_STRING_01;
-        int result;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            result = str1.compareTo(str2);
-            result = str1.compareTo(str2);
-            result = str1.compareTo(str2);
-            result = str1.compareTo(str2);
-            result = str1.compareTo(str2);
-            result = str1.compareTo(str2);
-            result = str1.compareTo(str2);
-            result = str1.compareTo(str2);
-            result = str1.compareTo(str2);
-            result = str1.compareTo(str2);
-        }
-
-    }
-
-    /** Compare string objects using compareToIgnorecase() with for loop* */
-
-    public void testStringCompareToIgnoreCase() {
-        String mString = new String(STATIC_STRING_01);
-        String str2 = STATIC_STRING_01;
-        int result;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            result = mString.compareToIgnoreCase(str2);
-            result = mString.compareToIgnoreCase(str2);
-            result = mString.compareToIgnoreCase(str2);
-            result = mString.compareToIgnoreCase(str2);
-            result = mString.compareToIgnoreCase(str2);
-            result = mString.compareToIgnoreCase(str2);
-            result = mString.compareToIgnoreCase(str2);
-            result = mString.compareToIgnoreCase(str2);
-            result = mString.compareToIgnoreCase(str2);
-            result = mString.compareToIgnoreCase(str2);
-        }
-    }
-
-    /** startsWith * */
-
-    public void testStringstartsWith() {
-        boolean result;
-        String str1 = STATIC_STRING_02, str2 = "Rem";
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            result = str1.startsWith(str2);
-            result = str1.startsWith(str2);
-            result = str1.startsWith(str2);
-            result = str1.startsWith(str2);
-            result = str1.startsWith(str2);
-            result = str1.startsWith(str2);
-            result = str1.startsWith(str2);
-            result = str1.startsWith(str2);
-            result = str1.startsWith(str2);
-            result = str1.startsWith(str2);
-        }
-    }
-
-    /** startsWith(String seq, int begin) * */
-
-    public void testStringstartsWith1() {
-        String str1 = STATIC_STRING_02, str2 = "tom";
-        int pos = 10;
-        boolean result;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            result = str1.startsWith(str2, pos);
-            result = str1.startsWith(str2, pos);
-            result = str1.startsWith(str2, pos);
-            result = str1.startsWith(str2, pos);
-            result = str1.startsWith(str2, pos);
-            result = str1.startsWith(str2, pos);
-            result = str1.startsWith(str2, pos);
-            result = str1.startsWith(str2, pos);
-            result = str1.startsWith(str2, pos);
-            result = str1.startsWith(str2, pos);
-        }
-    }
-
-    /** endsWith * */
-
-    public void testStringendsWith() {
-        String str = STATIC_STRING_02, str1 = "day";
-        boolean result;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            result = str.endsWith(str1);
-            result = str.endsWith(str1);
-            result = str.endsWith(str1);
-            result = str.endsWith(str1);
-            result = str.endsWith(str1);
-            result = str.endsWith(str1);
-            result = str.endsWith(str1);
-            result = str.endsWith(str1);
-            result = str.endsWith(str1);
-            result = str.endsWith(str1);
-        }
-    }
-
-    /**
-     * indexOf to determine whether a string contains a substring
-     */
-    public void testStringindexOf() {
-        boolean result;
-        String str = STATIC_STRING_02, str1 = "tomo";
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            result = str.indexOf(str1) > 0;
-            result = str.indexOf(str1) > 0;
-            result = str.indexOf(str1) > 0;
-            result = str.indexOf(str1) > 0;
-            result = str.indexOf(str1) > 0;
-            result = str.indexOf(str1) > 0;
-            result = str.indexOf(str1) > 0;
-            result = str.indexOf(str1) > 0;
-            result = str.indexOf(str1) > 0;
-            result = str.indexOf(str1) > 0;
-        }
-    }
-
-    /** indexOf()* */
-
-    public void testStringindexOf1() {
-        int index;
-        String str = STATIC_STRING_02;
-        char c = 't';
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            index = str.indexOf(c);
-            index = str.indexOf(c);
-            index = str.indexOf(c);
-            index = str.indexOf(c);
-            index = str.indexOf(c);
-            index = str.indexOf(c);
-            index = str.indexOf(c);
-            index = str.indexOf(c);
-            index = str.indexOf(c);
-            index = str.indexOf(c);
-        }
-
-    }
-
-    /** indexOf(char c, int start)* */
-    public void testStringindexOf2() {
-        int index, pos = 12;
-        String str = STATIC_STRING_02, str1 = "tom";
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            index = str.indexOf(str1, pos);
-            index = str.indexOf(str1, pos);
-            index = str.indexOf(str1, pos);
-            index = str.indexOf(str1, pos);
-            index = str.indexOf(str1, pos);
-            index = str.indexOf(str1, pos);
-            index = str.indexOf(str1, pos);
-            index = str.indexOf(str1, pos);
-            index = str.indexOf(str1, pos);
-            index = str.indexOf(str1, pos);
-        }
-    }
-
-    /** lastIndexOf()* */
-
-    public void testStringlastIndexOf() {
-        int index;
-        char c = 't';
-        String str = STATIC_STRING_02;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            index = str.lastIndexOf(c);
-            index = str.lastIndexOf(c);
-            index = str.lastIndexOf(c);
-            index = str.lastIndexOf(c);
-            index = str.lastIndexOf(c);
-            index = str.lastIndexOf(c);
-            index = str.lastIndexOf(c);
-            index = str.lastIndexOf(c);
-            index = str.lastIndexOf(c);
-            index = str.lastIndexOf(c);
-        }
-    }
-
-    /** lastIndexOf()* */
-
-    public void testStringlastIndexOf1() {
-        int index, pos = 36;
-        String str = STATIC_STRING_02, str1 = "tom";
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            index = str.lastIndexOf(str1, pos);
-            index = str.lastIndexOf(str1, pos);
-            index = str.lastIndexOf(str1, pos);
-            index = str.lastIndexOf(str1, pos);
-            index = str.lastIndexOf(str1, pos);
-            index = str.lastIndexOf(str1, pos);
-            index = str.lastIndexOf(str1, pos);
-            index = str.lastIndexOf(str1, pos);
-            index = str.lastIndexOf(str1, pos);
-            index = str.lastIndexOf(str1, pos);
-        }
-    }
-
-    /**
-     * contains() to determine whether a string contains a substring
-     */
-
-    public void testStringcontains() {
-        boolean result;
-        String str = STATIC_STRING_02, str1 = "tomo";
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            result = str.contains(str1);
-            result = str.contains(str1);
-            result = str.contains(str1);
-            result = str.contains(str1);
-            result = str.contains(str1);
-            result = str.contains(str1);
-            result = str.contains(str1);
-            result = str.contains(str1);
-            result = str.contains(str1);
-            result = str.contains(str1);
-        }
-    }
-
-    /** substring(int start) */
-
-    public void testStringsubstring() {
-        String rString;
-        String str = STATIC_STRING_02;
-        int index = 10;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            rString = str.substring(index);
-            rString = str.substring(index);
-            rString = str.substring(index);
-            rString = str.substring(index);
-            rString = str.substring(index);
-            rString = str.substring(index);
-            rString = str.substring(index);
-            rString = str.substring(index);
-            rString = str.substring(index);
-            rString = str.substring(index);
-        }
-    }
-
-    /** substring(int start, int end) in a for loop* */
-
-    public void testStringsubstring1() {
-        String rString;
-        String str = STATIC_STRING_02;
-        int start = 10, end = 48;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            rString = str.substring(start, end);
-            rString = str.substring(start, end);
-            rString = str.substring(start, end);
-            rString = str.substring(start, end);
-            rString = str.substring(start, end);
-            rString = str.substring(start, end);
-            rString = str.substring(start, end);
-            rString = str.substring(start, end);
-            rString = str.substring(start, end);
-            rString = str.substring(start, end);
-        }
-    }
-
-    /**
-     * valueOf(char[] cArray) String representation of a character array
-     */
-    public void testStringvalueOf() {
-        String rString;
-        char[] cArray = STATIC_CHAR_ARRAY;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            rString = String.valueOf(cArray);
-            rString = String.valueOf(cArray);
-            rString = String.valueOf(cArray);
-            rString = String.valueOf(cArray);
-            rString = String.valueOf(cArray);
-            rString = String.valueOf(cArray);
-            rString = String.valueOf(cArray);
-            rString = String.valueOf(cArray);
-            rString = String.valueOf(cArray);
-            rString = String.valueOf(cArray);
-        }
-    }
-
-    /** valueOf(char[] cArray, int offset, int count)* */
-
-    public void testStringvalueOf1() {
-        String rString;
-        char[] cArray = STATIC_CHAR_ARRAY;
-        int start = 1, end = 7;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            rString = String.valueOf(cArray, start, end);
-            rString = String.valueOf(cArray, start, end);
-            rString = String.valueOf(cArray, start, end);
-            rString = String.valueOf(cArray, start, end);
-            rString = String.valueOf(cArray, start, end);
-            rString = String.valueOf(cArray, start, end);
-            rString = String.valueOf(cArray, start, end);
-            rString = String.valueOf(cArray, start, end);
-            rString = String.valueOf(cArray, start, end);
-            rString = String.valueOf(cArray, start, end);
-        }
-    }
-
-    /** Convert a string to a char Array* */
-
-    public void testStringtoCharArray() {
-        char[] cArray;
-        String str = STATIC_STRING_02;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            cArray = str.toCharArray();
-            cArray = str.toCharArray();
-            cArray = str.toCharArray();
-            cArray = str.toCharArray();
-            cArray = str.toCharArray();
-            cArray = str.toCharArray();
-            cArray = str.toCharArray();
-            cArray = str.toCharArray();
-            cArray = str.toCharArray();
-            cArray = str.toCharArray();
-        }
-    }
-
-    /** length()* */
-
-    public void testStringlength() {
-        int len;
-        String str = STATIC_STRING_02;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            len = str.length();
-            len = str.length();
-            len = str.length();
-            len = str.length();
-            len = str.length();
-            len = str.length();
-            len = str.length();
-            len = str.length();
-            len = str.length();
-            len = str.length();
-        }
-    }
-
-    /** hashcode()* */
-
-    public void testStringhashCode() {
-        int index;
-        String str = STATIC_STRING_02;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            index = str.hashCode();
-            index = str.hashCode();
-            index = str.hashCode();
-            index = str.hashCode();
-            index = str.hashCode();
-            index = str.hashCode();
-            index = str.hashCode();
-            index = str.hashCode();
-            index = str.hashCode();
-            index = str.hashCode();
-        }
-    }
-
-    /** replace()* */
-
-    public void testStringreplace() {
-        String rString;
-        String str = STATIC_STRING_02;
-        char c1 = ' ', c2 = ' ';
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            rString = str.replace(c1, c2);
-            rString = str.replace(c1, c2);
-            rString = str.replace(c1, c2);
-            rString = str.replace(c1, c2);
-            rString = str.replace(c1, c2);
-            rString = str.replace(c1, c2);
-            rString = str.replace(c1, c2);
-            rString = str.replace(c1, c2);
-            rString = str.replace(c1, c2);
-            rString = str.replace(c1, c2);
-        }
-    }
-
-    public void testStringreplaceAll() {
-        String rString;
-        String str = STATIC_STRING_02, str1 = " ", str2 = "/";
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            rString = str.replaceAll(str1, str2);
-            rString = str.replaceAll(str1, str2);
-            rString = str.replaceAll(str1, str2);
-            rString = str.replaceAll(str1, str2);
-            rString = str.replaceAll(str1, str2);
-            rString = str.replaceAll(str1, str2);
-            rString = str.replaceAll(str1, str2);
-            rString = str.replaceAll(str1, str2);
-            rString = str.replaceAll(str1, str2);
-            rString = str.replaceAll(str1, str2);
-        }
-    }
-
-    /** Convert a StringBuffer to a String* */
-
-    public void testStringtoString() {
-        StringBuffer sBuf = new StringBuffer(STATIC_STRING_02);
-
-        String rString;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            rString = sBuf.toString();
-            rString = sBuf.toString();
-            rString = sBuf.toString();
-            rString = sBuf.toString();
-            rString = sBuf.toString();
-            rString = sBuf.toString();
-            rString = sBuf.toString();
-            rString = sBuf.toString();
-            rString = sBuf.toString();
-            rString = sBuf.toString();
-        }
-    }
-
-    /** Split a string into an array of strings* */
-
-    public void testStringsplit() {
-        String[] strings;
-        String str1 = STATIC_STRING_02, str = " ";
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            strings = str1.split(str);
-            strings = str1.split(str);
-            strings = str1.split(str);
-            strings = str1.split(str);
-            strings = str1.split(str);
-            strings = str1.split(str);
-            strings = str1.split(str);
-            strings = str1.split(str);
-            strings = str1.split(str);
-            strings = str1.split(str);
-
-        }
-    }
-
-    /** Split a string into an array of strings* */
-
-    public void testStringsplit1() {
-        String str = STATIC_STRING_02, str1 = " ";
-        String[] strings;
-        int pos = 8;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            strings = str.split(str1, pos);
-            strings = str.split(str1, pos);
-            strings = str.split(str1, pos);
-            strings = str.split(str1, pos);
-            strings = str.split(str1, pos);
-            strings = str.split(str1, pos);
-            strings = str.split(str1, pos);
-            strings = str.split(str1, pos);
-            strings = str.split(str1, pos);
-            strings = str.split(str1, pos);
-        }
-    }
-
-    public void testStringgetBytes() {
-        byte[] bytes;
-        String str = STATIC_STRING_02;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            bytes = str.getBytes();
-            bytes = str.getBytes();
-            bytes = str.getBytes();
-            bytes = str.getBytes();
-            bytes = str.getBytes();
-            bytes = str.getBytes();
-            bytes = str.getBytes();
-            bytes = str.getBytes();
-            bytes = str.getBytes();
-            bytes = str.getBytes();
-        }
-    }
-
-    /** copyValueOf(char[] data) * */
-
-    public void testStringcopyValueOf() {
-        String rString;
-        char[] cArray = STATIC_CHAR_ARRAY;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            rString = String.copyValueOf(cArray);
-            rString = String.copyValueOf(cArray);
-            rString = String.copyValueOf(cArray);
-            rString = String.copyValueOf(cArray);
-            rString = String.copyValueOf(cArray);
-            rString = String.copyValueOf(cArray);
-            rString = String.copyValueOf(cArray);
-            rString = String.copyValueOf(cArray);
-            rString = String.copyValueOf(cArray);
-            rString = String.copyValueOf(cArray);
-        }
-    }
-
-    /** copyValueOf(char[] data, int index, int count)* */
-
-    public void testStringcopyValueOf1() {
-        String rString;
-        int start = 1, end = 7;
-        char[] cArray = STATIC_CHAR_ARRAY;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            rString = String.copyValueOf(cArray, start, end);
-            rString = String.copyValueOf(cArray, start, end);
-            rString = String.copyValueOf(cArray, start, end);
-            rString = String.copyValueOf(cArray, start, end);
-            rString = String.copyValueOf(cArray, start, end);
-            rString = String.copyValueOf(cArray, start, end);
-            rString = String.copyValueOf(cArray, start, end);
-            rString = String.copyValueOf(cArray, start, end);
-            rString = String.copyValueOf(cArray, start, end);
-            rString = String.copyValueOf(cArray, start, end);
-        }
-    }
-
-    /** trim()* */
-
-    public void testStringtrim() {
-        String mString =
-                new String(
-                        "                            HELLO ANDROID                                                ");
-        String rString;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            rString = mString.trim();
-            rString = mString.trim();
-            rString = mString.trim();
-            rString = mString.trim();
-            rString = mString.trim();
-            rString = mString.trim();
-            rString = mString.trim();
-            rString = mString.trim();
-            rString = mString.trim();
-            rString = mString.trim();
-        }
-    }
-
-    /** getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)* */
-
-    public void testStringgetChars() {
-        char[] cArray = STATIC_CHAR_ARRAY;
-        String str = STATIC_STRING_01;
-        int value1 = 7, value2 = 12, value3 = 1;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            str.getChars(value1, value2, cArray, value3);
-            str.getChars(value1, value2, cArray, value3);
-            str.getChars(value1, value2, cArray, value3);
-            str.getChars(value1, value2, cArray, value3);
-            str.getChars(value1, value2, cArray, value3);
-            str.getChars(value1, value2, cArray, value3);
-            str.getChars(value1, value2, cArray, value3);
-            str.getChars(value1, value2, cArray, value3);
-            str.getChars(value1, value2, cArray, value3);
-            str.getChars(value1, value2, cArray, value3);
-        }
-    }
-
-    /** toUpperCase()* */
-
-    public void testStringtoUpperCase() {
-        String rString, str = STATIC_STRING_02;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            rString = str.toUpperCase();
-            rString = str.toUpperCase();
-            rString = str.toUpperCase();
-            rString = str.toUpperCase();
-            rString = str.toUpperCase();
-            rString = str.toUpperCase();
-            rString = str.toUpperCase();
-            rString = str.toUpperCase();
-            rString = str.toUpperCase();
-            rString = str.toUpperCase();
-        }
-    }
-
-    /** toUpperCase() with locale* */
-
-    public void testStringtoUpperCase1() {
-        Locale locale = new Locale("tr");
-        String str = STATIC_STRING_02;
-        String rString;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            rString = str.toUpperCase(locale);
-            rString = str.toUpperCase(locale);
-            rString = str.toUpperCase(locale);
-            rString = str.toUpperCase(locale);
-            rString = str.toUpperCase(locale);
-            rString = str.toUpperCase(locale);
-            rString = str.toUpperCase(locale);
-            rString = str.toUpperCase(locale);
-            rString = str.toUpperCase(locale);
-            rString = str.toUpperCase(locale);
-        }
-    }
-
-    /** toLowerCase* */
-
-    public void StringtoLowerCase() {
-        String rString, str = STATIC_STRING_02;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            rString = str.toLowerCase();
-            rString = str.toLowerCase();
-            rString = str.toLowerCase();
-            rString = str.toLowerCase();
-            rString = str.toLowerCase();
-            rString = str.toLowerCase();
-            rString = str.toLowerCase();
-            rString = str.toLowerCase();
-            rString = str.toLowerCase();
-            rString = str.toLowerCase();
-        }
-    }
-
-    /** toLowerCase with locale* */
-
-    public void testStringtoLowerCase1() {
-        Locale locale = new Locale("tr");
-        String rString, str = STATIC_STRING_02;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            rString = str.toLowerCase(locale);
-            rString = str.toLowerCase(locale);
-            rString = str.toLowerCase(locale);
-            rString = str.toLowerCase(locale);
-            rString = str.toLowerCase(locale);
-            rString = str.toLowerCase(locale);
-            rString = str.toLowerCase(locale);
-            rString = str.toLowerCase(locale);
-            rString = str.toLowerCase(locale);
-            rString = str.toLowerCase(locale);
-        }
-    }
-
-    /** charAt()* */
-
-    public void testStringcharAt() {
-        String str = STATIC_STRING_02;
-        int index, pos = 21;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            index = str.charAt(pos);
-            index = str.charAt(pos);
-            index = str.charAt(pos);
-            index = str.charAt(pos);
-            index = str.charAt(pos);
-            index = str.charAt(pos);
-            index = str.charAt(pos);
-            index = str.charAt(pos);
-            index = str.charAt(pos);
-            index = str.charAt(pos);
-        }
-    }
-
-    public void testStringConcat() {
-        String mString, str1 = STATIC_STRING_01, str2 = STATIC_STRING_02;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            mString = str1.concat(str2);
-            mString = str1.concat(str2);
-            mString = str1.concat(str2);
-            mString = str1.concat(str2);
-            mString = str1.concat(str2);
-            mString = str1.concat(str2);
-            mString = str1.concat(str2);
-            mString = str1.concat(str2);
-            mString = str1.concat(str2);
-            mString = str1.concat(str2);
-        }
-    }
-
-    public void testStringBufferAppend() {
-        StringBuffer sBuf = new StringBuffer(" ");
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            sBuf.append(i);
-            sBuf.append(i);
-            sBuf.append(i);
-            sBuf.append(i);
-            sBuf.append(i);
-            sBuf.append(i);
-            sBuf.append(i);
-            sBuf.append(i);
-            sBuf.append(i);
-            sBuf.append(i);
-        }
-    }
-
-    public void testStringBufferInsert() {
-        StringBuffer sBuf = new StringBuffer(" ");
-        int index = sBuf.length();
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            sBuf.insert(index, i);
-            sBuf.insert(index, i);
-            sBuf.insert(index, i);
-            sBuf.insert(index, i);
-            sBuf.insert(index, i);
-            sBuf.insert(index, i);
-            sBuf.insert(index, i);
-            sBuf.insert(index, i);
-            sBuf.insert(index, i);
-            sBuf.insert(index, i);
-        }
-    }
-
-    public void testStringBufferReverse() {
-        StringBuffer sBuf = STATIC_SBUF;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            sBuf.reverse();
-            sBuf.reverse();
-            sBuf.reverse();
-            sBuf.reverse();
-            sBuf.reverse();
-            sBuf.reverse();
-            sBuf.reverse();
-            sBuf.reverse();
-            sBuf.reverse();
-            sBuf.reverse();
-        }
-    }
-
-    public void testStringBufferSubstring() {
-        StringBuffer sBuf = STATIC_SBUF;
-        String rString;
-        int index = 0;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            rString = sBuf.substring(index);
-            rString = sBuf.substring(index);
-            rString = sBuf.substring(index);
-            rString = sBuf.substring(index);
-            rString = sBuf.substring(index);
-            rString = sBuf.substring(index);
-            rString = sBuf.substring(index);
-            rString = sBuf.substring(index);
-            rString = sBuf.substring(index);
-            rString = sBuf.substring(index);
-        }
-    }
-
-    public void testStringBufferSubstring1() {
-        StringBuffer sBuf = STATIC_SBUF;
-        String rString;
-        int start = 5, end = 25;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            rString = sBuf.substring(start, end);
-            rString = sBuf.substring(start, end);
-            rString = sBuf.substring(start, end);
-            rString = sBuf.substring(start, end);
-            rString = sBuf.substring(start, end);
-            rString = sBuf.substring(start, end);
-            rString = sBuf.substring(start, end);
-            rString = sBuf.substring(start, end);
-            rString = sBuf.substring(start, end);
-            rString = sBuf.substring(start, end);
-        }
-    }
-
-    public void testStringBufferReplace() {
-        StringBuffer sBuf = STATIC_SBUF;
-        int start = 3, end = 6;
-        String str = "ind";
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            sBuf.replace(start, end, str);
-            sBuf.replace(start, end, str);
-            sBuf.replace(start, end, str);
-            sBuf.replace(start, end, str);
-            sBuf.replace(start, end, str);
-            sBuf.replace(start, end, str);
-            sBuf.replace(start, end, str);
-            sBuf.replace(start, end, str);
-            sBuf.replace(start, end, str);
-            sBuf.replace(start, end, str);
-        }
-    }
-
-    public void testStringBufferIndexOf() {
-        StringBuffer sBuf = STATIC_SBUF;
-        String str = "t";
-        int index;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            index = sBuf.indexOf(str);
-            index = sBuf.indexOf(str);
-            index = sBuf.indexOf(str);
-            index = sBuf.indexOf(str);
-            index = sBuf.indexOf(str);
-            index = sBuf.indexOf(str);
-            index = sBuf.indexOf(str);
-            index = sBuf.indexOf(str);
-            index = sBuf.indexOf(str);
-            index = sBuf.indexOf(str);
-        }
-    }
-
-    public void testStringBufferIndexOf1() {
-        StringBuffer sBuf = STATIC_SBUF;
-        String str = "tom";
-        int index, pos = 12;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            index = sBuf.indexOf(str, pos);
-            index = sBuf.indexOf(str, pos);
-            index = sBuf.indexOf(str, pos);
-            index = sBuf.indexOf(str, pos);
-            index = sBuf.indexOf(str, pos);
-            index = sBuf.indexOf(str, pos);
-            index = sBuf.indexOf(str, pos);
-            index = sBuf.indexOf(str, pos);
-            index = sBuf.indexOf(str, pos);
-            index = sBuf.indexOf(str, pos);
-        }
-
-    }
-
-    public void testStringBufferLastIndexOf() {
-        StringBuffer sBuf = STATIC_SBUF;
-        String str = "t";
-        int index;
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            index = sBuf.lastIndexOf(str);
-            index = sBuf.lastIndexOf(str);
-            index = sBuf.lastIndexOf(str);
-            index = sBuf.lastIndexOf(str);
-            index = sBuf.lastIndexOf(str);
-            index = sBuf.lastIndexOf(str);
-            index = sBuf.lastIndexOf(str);
-            index = sBuf.lastIndexOf(str);
-            index = sBuf.lastIndexOf(str);
-            index = sBuf.lastIndexOf(str);
-        }
-    }
-
-    public void testStringBufferLastIndexOf1() {
-        StringBuffer sBuf = STATIC_SBUF;
-        int index, pos = 36;
-        String str = "tom";
-        for (int i = ITERATIONS - 1; i >= 0; i--) {
-            index = sBuf.lastIndexOf(str, pos);
-            index = sBuf.lastIndexOf(str, pos);
-            index = sBuf.lastIndexOf(str, pos);
-            index = sBuf.lastIndexOf(str, pos);
-            index = sBuf.lastIndexOf(str, pos);
-            index = sBuf.lastIndexOf(str, pos);
-            index = sBuf.lastIndexOf(str, pos);
-            index = sBuf.lastIndexOf(str, pos);
-            index = sBuf.lastIndexOf(str, pos);
-            index = sBuf.lastIndexOf(str, pos);
-        }
-    }
-}
diff --git a/tools/aapt/Android.mk b/tools/aapt/Android.mk
index b339a2c..094b7db 100644
--- a/tools/aapt/Android.mk
+++ b/tools/aapt/Android.mk
@@ -41,7 +41,7 @@
 	libpng
 
 ifeq ($(HOST_OS),linux)
-LOCAL_LDLIBS += -lrt
+LOCAL_LDLIBS += -lrt -lpthread
 endif
 
 # Statically link libz for MinGW (Win SDK under Linux),
diff --git a/tools/localize/Android.mk b/tools/localize/Android.mk
index ab79f8d..f284e86 100644
--- a/tools/localize/Android.mk
+++ b/tools/localize/Android.mk
@@ -34,7 +34,7 @@
 	libcutils
     
 ifeq ($(HOST_OS),linux)
-LOCAL_LDLIBS += -lrt
+LOCAL_LDLIBS += -lrt -lpthread
 endif