Remove libutils.so dependency from libRSDriver, libRSCpuRef, and most
parts of libRS_internal.

  NOTE: we're resolving dependencies to provide a model for vendors.
  For us, all this code is above the HAL, thus the dependencies
  are acceptable; whereas for vendors, their equivalent of this code is
  below the HAL, and so the dependencies are not acceptable.

  This CL resolves the libutils dependency by:
  - Implement the timings functions in android::renderscript namespace
  using NDK APIs, instead of using libutils counterparts.
  - Replace android::Vector and android::String8 by std::vector and
  std::string.
  - PROPERTY_VALUE_MAX is replaced as PROP_VALUE_MAX.

  This CL didn't resolve the libutils dependency of rsFont.cpp and
  rsDebugger.cpp in libRS_internal:
  The dependent functionality in rsDebugHelper.h is off by default, and
  only intended for use during development; and rsFont.cpp is part of
  graphics API which is not implemented below the HAL and is not used as
  a model by vendors.

  Additionally, this CL fixed the bug that mNodes was sorted in a
  decreasing order. Nodes in ScriptGroup should be executed in
  ascending order. The bad sort was only for support lib; so there was a
  previously-unknown bug in support lib implementation of ScriptGroup.

  Background:
  libutils contains a collection of things like Vector, String8,
  CallStack. It served the purpose similar to a STL library, when there
  was no stable STL implementation available in Android. And most
  importantly, it is not part of NDK.
  Support lib used to use our own implementations of android::Vector and
  android::String8, because it can only depend on NDK, similarly for the
  timing related functions.
  As part of the Treble requirements, native RS, including vendor version
  libRS_internal, libRSDriver, libRSCpuRef could only depend on NDK
  too. So we need to break the dependency on libutils. And since we now
  have reasonable support of STLs, we should use that instead.

Bug: 34396220
Test: mm, and all CTS tests pass on Bullhead;
      RsTest and RSTest_CompatLib (both native and compat path) also pass.
Change-Id: Ib9a37d16235c1dcd0f5bae3b95c374e394483c91
diff --git a/Android.mk b/Android.mk
index 3e5f593..6b53d4e 100644
--- a/Android.mk
+++ b/Android.mk
@@ -63,7 +63,7 @@
 
 
 LOCAL_SHARED_LIBRARIES += libRS_internal libRSCpuRef
-LOCAL_SHARED_LIBRARIES += liblog libutils libEGL libGLESv1_CM libGLESv2
+LOCAL_SHARED_LIBRARIES += liblog libEGL libGLESv1_CM libGLESv2
 LOCAL_SHARED_LIBRARIES += libui libgui libandroid
 
 LOCAL_SHARED_LIBRARIES += libbcinfo
diff --git a/cpu_ref/Android.mk b/cpu_ref/Android.mk
index 5d1b223..d50a77e 100644
--- a/cpu_ref/Android.mk
+++ b/cpu_ref/Android.mk
@@ -83,7 +83,7 @@
     rsCpuIntrinsics_x86.cpp
 endif
 
-LOCAL_SHARED_LIBRARIES += libRS_internal libc++ liblog libutils libz
+LOCAL_SHARED_LIBRARIES += libRS_internal libc++ liblog libz
 LOCAL_SHARED_LIBRARIES += libbcinfo libblas
 LOCAL_STATIC_LIBRARIES := libbnnmlowp
 
diff --git a/cpu_ref/rsCpuCore.h b/cpu_ref/rsCpuCore.h
index 8c5653f..59e6c4b 100644
--- a/cpu_ref/rsCpuCore.h
+++ b/cpu_ref/rsCpuCore.h
@@ -25,6 +25,8 @@
 #include "rsScriptC.h"
 #include "rsCpuCoreRuntime.h"
 
+#include <string>
+
 namespace android {
 namespace renderscript {
 
@@ -188,10 +190,10 @@
     }
 
     virtual void setBccPluginName(const char *name) {
-        mBccPluginName.setTo(name);
+        mBccPluginName.assign(name);
     }
     virtual const char *getBccPluginName() const {
-        return mBccPluginName.string();
+        return mBccPluginName.c_str();
     }
     bool getInKernel() override { return mInKernel; }
 
@@ -243,7 +245,7 @@
     ScriptTLSStruct mTlsStruct;
 
     RSSelectRTCallback mSelectRTCallback;
-    String8 mBccPluginName;
+    std::string mBccPluginName;
 
     // Specifies whether we should embed global variable information in the
     // code via special RS variables that can be examined later by the driver.
diff --git a/cpu_ref/rsCpuExecutable.cpp b/cpu_ref/rsCpuExecutable.cpp
index 426d89e..400a465 100644
--- a/cpu_ref/rsCpuExecutable.cpp
+++ b/cpu_ref/rsCpuExecutable.cpp
@@ -165,7 +165,7 @@
     return loaded;
 }
 
-String8 SharedLibraryUtils::getRandomString(size_t len) {
+std::string SharedLibraryUtils::getRandomString(size_t len) {
     char buf[len + 1];
     for (size_t i = 0; i < len; i++) {
         uint32_t r = arc4random() & 0xffff;
@@ -182,7 +182,7 @@
         }
     }
     buf[len] = '\0';
-    return String8(buf);
+    return std::string(buf);
 }
 
 void* SharedLibraryUtils::loadSOHelper(const char *origName, const char *cacheDir,
@@ -237,7 +237,7 @@
     newName.append("librs.");
     newName.append(resName);
     newName.append("#");
-    newName.append(getRandomString(6).string());  // 62^6 potential filename variants.
+    newName.append(getRandomString(6).c_str());  // 62^6 potential filename variants.
     newName.append(".so");
 
     int r = copyFile(newName.c_str(), origName);
diff --git a/cpu_ref/rsCpuExecutable.h b/cpu_ref/rsCpuExecutable.h
index 90d3759..ee58e37 100644
--- a/cpu_ref/rsCpuExecutable.h
+++ b/cpu_ref/rsCpuExecutable.h
@@ -17,10 +17,12 @@
 #ifndef ANDROID_RENDERSCRIPT_EXECUTABLE_H
 #define ANDROID_RENDERSCRIPT_EXECUTABLE_H
 
-#include <stdlib.h>
 
 #include "rsCpuScript.h"
 
+#include <stdlib.h>
+#include <string>
+
 namespace android {
 namespace renderscript {
 
@@ -47,7 +49,7 @@
                                    bool *alreadyLoaded = nullptr);
 
     // Create a len length string containing random characters from [A-Za-z0-9].
-    static String8 getRandomString(size_t len);
+    static std::string getRandomString(size_t len);
 
 private:
     // Attempt to load the shared library from origName, but then fall back to
diff --git a/cpu_ref/rsCpuScript.cpp b/cpu_ref/rsCpuScript.cpp
index 5bd2424..545e92f 100644
--- a/cpu_ref/rsCpuScript.cpp
+++ b/cpu_ref/rsCpuScript.cpp
@@ -58,7 +58,7 @@
 #ifndef RS_COMPATIBILITY_LIB
 
 static bool is_force_recompile() {
-  char buf[PROPERTY_VALUE_MAX];
+  char buf[PROP_VALUE_MAX];
 
   // Re-compile if floating point precision has been overridden.
   android::renderscript::property_get("debug.rs.precision", buf, "");
@@ -176,7 +176,7 @@
     if ((::strcmp(SYSLIBPATH, cacheDir) == 0) ||
         (::strcmp(SYSLIBPATH_VENDOR, cacheDir) == 0))
         return false;
-    char buf[PROPERTY_VALUE_MAX];
+    char buf[PROP_VALUE_MAX];
     android::renderscript::property_get("ro.debuggable", buf, "");
     return (buf[0] == '1');
 }
@@ -422,7 +422,7 @@
         }
     }
 
-    mBitcodeFilePath.setTo(bcFileName.c_str());
+    mBitcodeFilePath.assign(bcFileName.c_str());
 
 #else  // RS_COMPATIBILITY_LIB is defined
     const char *nativeLibDir = mCtx->getContext()->getNativeLibDir();
diff --git a/cpu_ref/rsCpuScript.h b/cpu_ref/rsCpuScript.h
index c6f9624..1814d5f 100644
--- a/cpu_ref/rsCpuScript.h
+++ b/cpu_ref/rsCpuScript.h
@@ -26,6 +26,8 @@
 
 #include "rsCpuCore.h"
 
+#include <string>
+
 namespace bcinfo {
     class MetadataExtractor;
 } // namespace bcinfo
@@ -130,14 +132,14 @@
 
 public:
     static const char* BCC_EXE_PATH;
-    const char* getBitcodeFilePath() const { return mBitcodeFilePath.string(); }
+    const char* getBitcodeFilePath() const { return mBitcodeFilePath.c_str(); }
 
 private:
     bool setUpMtlsDimensions(MTLaunchStructCommon *mtls,
                              const RsLaunchDimensions &baseDim,
                              const RsScriptCall *sc);
 
-    String8 mBitcodeFilePath;
+    std::string mBitcodeFilePath;
     uint32_t mBuildChecksum;
     bool mChecksumNeeded;
 };
diff --git a/cpu_ref/rsCpuScriptGroup.cpp b/cpu_ref/rsCpuScriptGroup.cpp
index f7a330a..cc2933c 100644
--- a/cpu_ref/rsCpuScriptGroup.cpp
+++ b/cpu_ref/rsCpuScriptGroup.cpp
@@ -19,6 +19,8 @@
 #include "rsScriptGroup.h"
 #include "rsCpuScriptGroup.h"
 
+#include <vector>
+
 namespace android {
 namespace renderscript {
 
@@ -124,11 +126,11 @@
 
 
 void CpuScriptGroupImpl::execute() {
-    Vector<Allocation *> ins;
-    Vector<bool> inExts;
-    Vector<Allocation *> outs;
-    Vector<bool> outExts;
-    Vector<const ScriptKernelID *> kernels;
+    std::vector<Allocation *> ins;
+    std::vector<uint8_t> inExts;
+    std::vector<Allocation *> outs;
+    std::vector<uint8_t> outExts;
+    std::vector<const ScriptKernelID *> kernels;
     bool fieldDep = false;
 
     for (size_t ct=0; ct < mSG->mNodes.size(); ct++) {
@@ -194,11 +196,11 @@
             rsAssert((k->mHasKernelOutput == (aout != nullptr)) &&
                      (k->mHasKernelInput == (ain != nullptr)));
 
-            ins.add(ain);
-            inExts.add(inExt);
-            outs.add(aout);
-            outExts.add(outExt);
-            kernels.add(k);
+            ins.push_back(ain);
+            inExts.push_back(inExt);
+            outs.push_back(aout);
+            outExts.push_back(outExt);
+            kernels.push_back(k);
         }
 
     }
@@ -237,9 +239,9 @@
         }
     } else {
         ScriptList sl;
-        sl.ins = ins.array();
-        sl.outs = outs.array();
-        sl.kernels = kernels.array();
+        sl.ins = ins.data();
+        sl.outs = outs.data();
+        sl.kernels = kernels.data();
         sl.count = kernels.size();
 
         uint32_t inLen;
@@ -254,25 +256,25 @@
             ains  = const_cast<const Allocation**>(&ins[0]);
         }
 
-        Vector<const void *> usrPtrs;
-        Vector<const void *> fnPtrs;
-        Vector<uint32_t> sigs;
+        std::vector<const void *> usrPtrs;
+        std::vector<const void *> fnPtrs;
+        std::vector<uint32_t> sigs;
         for (size_t ct=0; ct < kernels.size(); ct++) {
             Script *s = kernels[ct]->mScript;
             RsdCpuScriptImpl *si = (RsdCpuScriptImpl *)mCtx->lookupScript(s);
 
             si->forEachKernelSetup(kernels[ct]->mSlot, &mtls);
-            fnPtrs.add((void *)mtls.kernel);
-            usrPtrs.add(mtls.fep.usr);
-            sigs.add(mtls.fep.usrLen);
+            fnPtrs.push_back((void *)mtls.kernel);
+            usrPtrs.push_back(mtls.fep.usr);
+            sigs.push_back(mtls.fep.usrLen);
             si->preLaunch(kernels[ct]->mSlot, ains, inLen, outs[ct],
                           mtls.fep.usr, mtls.fep.usrLen, nullptr);
         }
-        sl.sigs = sigs.array();
-        sl.usrPtrs = usrPtrs.array();
-        sl.fnPtrs = fnPtrs.array();
-        sl.inExts = inExts.array();
-        sl.outExts = outExts.array();
+        sl.sigs = sigs.data();
+        sl.usrPtrs = usrPtrs.data();
+        sl.fnPtrs = fnPtrs.data();
+        sl.inExts = inExts.data();
+        sl.outExts = outExts.data();
 
         Script *s = kernels[0]->mScript;
         RsdCpuScriptImpl *si = (RsdCpuScriptImpl *)mCtx->lookupScript(s);
diff --git a/cpu_ref/rsCpuScriptGroup.h b/cpu_ref/rsCpuScriptGroup.h
index a749ea4..7e1386d 100644
--- a/cpu_ref/rsCpuScriptGroup.h
+++ b/cpu_ref/rsCpuScriptGroup.h
@@ -41,9 +41,9 @@
     struct ScriptList {
         size_t count;
         Allocation *const* ins;
-        bool const* inExts;
+        uint8_t const* inExts;
         Allocation *const* outs;
-        bool const* outExts;
+        uint8_t const* outExts;
         const void *const* usrPtrs;
         size_t const *usrSizes;
         uint32_t const *sigs;
diff --git a/cpu_ref/rsCpuScriptGroup2.cpp b/cpu_ref/rsCpuScriptGroup2.cpp
index 9d9929a..a8b72c4 100644
--- a/cpu_ref/rsCpuScriptGroup2.cpp
+++ b/cpu_ref/rsCpuScriptGroup2.cpp
@@ -483,7 +483,7 @@
 
             cloneName.append(resName);
             cloneName.append("#");
-            cloneName.append(SharedLibraryUtils::getRandomString(6).string());
+            cloneName.append(SharedLibraryUtils::getRandomString(6).c_str());
 
             // The last element in arguments is the output filename.
             arguments.pop_back();
diff --git a/driver/rsdMeshObj.cpp b/driver/rsdMeshObj.cpp
index 205acb6..1571725 100644
--- a/driver/rsdMeshObj.cpp
+++ b/driver/rsdMeshObj.cpp
@@ -26,7 +26,8 @@
 #include "rsdMeshObj.h"
 #include "rsdGL.h"
 
-using android::String8;
+#include <string>
+
 using android::renderscript::Allocation;
 using android::renderscript::Context;
 using android::renderscript::Element;
@@ -115,9 +116,9 @@
             mAttribs[userNum].type = rsdTypeToGLType(f->mHal.state.dataType);
             mAttribs[userNum].normalized = f->mHal.state.dataType != RS_TYPE_FLOAT_32;
             mAttribs[userNum].stride = stride;
-            String8 tmp(RS_SHADER_ATTR);
+            std::string tmp(RS_SHADER_ATTR);
             tmp.append(elem->mHal.state.fieldNames[fieldI]);
-            mAttribs[userNum].name = tmp.string();
+            mAttribs[userNum].name = tmp;
 
             // Remember which allocation this attribute came from
             mAttribAllocationIndex[userNum] = ct;
diff --git a/driver/rsdShader.cpp b/driver/rsdShader.cpp
index 6d66141..6d35cd2 100644
--- a/driver/rsdShader.cpp
+++ b/driver/rsdShader.cpp
@@ -26,7 +26,6 @@
 #include "rsdShader.h"
 #include "rsdShaderCache.h"
 
-using android::String8;
 using android::renderscript::Allocation;
 using android::renderscript::Context;
 using android::renderscript::Element;
@@ -46,13 +45,13 @@
     init(textureNames, textureNamesCount, textureNamesLength);
 
     for(size_t i=0; i < textureNamesCount; i++) {
-        mTextureNames.push(String8(textureNames[i], textureNamesLength[i]));
+        mTextureNames.push_back(std::string(textureNames[i], textureNamesLength[i]));
     }
 }
 
 RsdShader::~RsdShader() {
     for (uint32_t i = 0; i < mStateBasedShaders.size(); i ++) {
-        StateBasedKey *state = mStateBasedShaders.itemAt(i);
+        StateBasedKey *state = mStateBasedShaders.at(i);
         if (state->mShaderID) {
             glDeleteShader(state->mShaderID);
         }
@@ -81,7 +80,7 @@
     RsdShader::StateBasedKey *returnKey = nullptr;
 
     for (uint32_t i = 0; i < mStateBasedShaders.size(); i ++) {
-        returnKey = mStateBasedShaders.itemAt(i);
+        returnKey = mStateBasedShaders.at(i);
 
         for (uint32_t ct = 0; ct < mRSProgram->mHal.state.texturesCount; ct ++) {
             uint32_t texType = 0;
@@ -113,7 +112,7 @@
     // We have not created a shader for this particular state yet
     state = new StateBasedKey(mTextureCount);
     mCurrentState = state;
-    mStateBasedShaders.add(state);
+    mStateBasedShaders.push_back(state);
     createShader();
     loadShader(rsc);
     return mCurrentState->mShaderID;
diff --git a/driver/rsdShader.h b/driver/rsdShader.h
index 1b5c010..b52fe92 100644
--- a/driver/rsdShader.h
+++ b/driver/rsdShader.h
@@ -18,6 +18,7 @@
 #define ANDROID_RSD_SHADER_H
 
 #include <string>
+#include <vector>
 
 // ---------------------------------------------------------------------------
 namespace android {
@@ -49,7 +50,7 @@
     // Add ability to get all ID's to clean up the cached program objects
     uint32_t getStateBasedIDCount() const { return mStateBasedShaders.size(); }
     uint32_t getStateBasedID(uint32_t index) const {
-        return mStateBasedShaders.itemAt(index)->mShaderID;
+        return mStateBasedShaders.at(index)->mShaderID;
     }
 
     uint32_t getAttribCount() const {return mAttribCount;}
@@ -116,9 +117,9 @@
     std::string *mUniformNames;
     uint32_t *mUniformArraySizes;
 
-    android::Vector<android::String8> mTextureNames;
+    std::vector<std::string> mTextureNames;
 
-    android::Vector<StateBasedKey*> mStateBasedShaders;
+    std::vector<StateBasedKey*> mStateBasedShaders;
 
     int32_t mTextureUniformIndexStart;
 
diff --git a/driver/rsdShaderCache.cpp b/driver/rsdShaderCache.cpp
index 3b82641..f62bb63 100644
--- a/driver/rsdShaderCache.cpp
+++ b/driver/rsdShaderCache.cpp
@@ -24,11 +24,10 @@
 #include <GLES/gl.h>
 #include <GLES2/gl2.h>
 
-using android::String8;
 using android::renderscript::Context;
 
 RsdShaderCache::RsdShaderCache() {
-    mEntries.setCapacity(16);
+    mEntries.resize(16);
     mVertexDirty = true;
     mFragmentDirty = true;
 }
@@ -138,7 +137,7 @@
     ProgramEntry *e = new ProgramEntry(vtx->getAttribCount(),
                                        vtx->getUniformCount(),
                                        frag->getUniformCount());
-    mEntries.push(e);
+    mEntries.push_back(e);
     mCurrent = e;
     e->vtx = vID;
     e->frag = fID;
@@ -236,7 +235,7 @@
     return true;
 }
 
-int32_t RsdShaderCache::vtxAttribSlot(const String8 &attrName) const {
+int32_t RsdShaderCache::vtxAttribSlot(const std::string &attrName) const {
     for (uint32_t ct=0; ct < mCurrent->vtxAttrCount; ct++) {
         if (attrName == mCurrent->vtxAttrs[ct].name) {
             return mCurrent->vtxAttrs[ct].slot;
@@ -255,7 +254,7 @@
                 glDeleteProgram(mEntries[ct]->program);
 
                 delete mEntries[ct];
-                mEntries.removeAt(ct);
+                mEntries.erase(mEntries.begin() + ct);
                 numEntries = (int32_t)mEntries.size();
                 ct --;
             }
@@ -273,7 +272,7 @@
                 glDeleteProgram(mEntries[ct]->program);
 
                 delete mEntries[ct];
-                mEntries.removeAt(ct);
+                mEntries.erase(mEntries.begin() + ct);
                 numEntries = (int32_t)mEntries.size();
                 ct --;
             }
diff --git a/driver/rsdShaderCache.h b/driver/rsdShaderCache.h
index 7e78f81..9e6c17c 100644
--- a/driver/rsdShaderCache.h
+++ b/driver/rsdShaderCache.h
@@ -17,6 +17,9 @@
 #ifndef ANDROID_RSD_SHADER_CACHE_H
 #define ANDROID_RSD_SHADER_CACHE_H
 
+#include <string>
+#include <vector>
+
 namespace android {
 namespace renderscript {
 
@@ -52,7 +55,7 @@
 
     void cleanupAll();
 
-    int32_t vtxAttribSlot(const android::String8 &attrName) const;
+    int32_t vtxAttribSlot(const std::string &attrName) const;
     int32_t vtxUniformSlot(uint32_t a) const {return mCurrent->vtxUniforms[a].slot;}
     uint32_t vtxUniformSize(uint32_t a) const {return mCurrent->vtxUniforms[a].arraySize;}
     int32_t fragUniformSlot(uint32_t a) const {return mCurrent->fragUniforms[a].slot;}
@@ -137,7 +140,7 @@
         UniformData *fragUniforms;
         bool *fragUniformIsSTO;
     };
-    android::Vector<ProgramEntry*> mEntries;
+    std::vector<ProgramEntry*> mEntries;
     ProgramEntry *mCurrent;
 
     bool hasArrayUniforms(RsdShader *vtx, RsdShader *frag);
diff --git a/driver/rsdVertexArray.cpp b/driver/rsdVertexArray.cpp
index 1efe3b0..987639e 100644
--- a/driver/rsdVertexArray.cpp
+++ b/driver/rsdVertexArray.cpp
@@ -47,7 +47,7 @@
     stride = 0;
     ptr = nullptr;
     normalized = false;
-    name.setTo("");
+    name.assign("");
 }
 
 void RsdVertexArray::Attrib::set(uint32_t type, uint32_t size, uint32_t stride,
@@ -59,7 +59,7 @@
     this->offset = offset;
     this->normalized = normalized;
     this->stride = stride;
-    this->name.setTo(name);
+    this->name.assign(name);
 }
 
 void RsdVertexArray::logAttrib(uint32_t idx, uint32_t slot) const {
@@ -68,7 +68,7 @@
     }
     ALOGV("va %i: slot=%i name=%s buf=%i ptr=%p size=%i  type=0x%x  stride=0x%x  norm=%i  offset=0x%p",
           idx, slot,
-          mAttribs[idx].name.string(),
+          mAttribs[idx].name.c_str(),
           mAttribs[idx].buffer,
           mAttribs[idx].ptr,
           mAttribs[idx].size,
diff --git a/driver/rsdVertexArray.h b/driver/rsdVertexArray.h
index 34a4663..618647a 100644
--- a/driver/rsdVertexArray.h
+++ b/driver/rsdVertexArray.h
@@ -19,6 +19,8 @@
 
 #include "rsUtils.h"
 
+#include <string>
+
 namespace android {
 namespace renderscript {
 
@@ -39,7 +41,7 @@
         uint32_t size;
         uint32_t stride;
         bool normalized;
-        android::String8 name;
+        std::string name;
 
         Attrib();
         void clear();
diff --git a/rsAllocation.cpp b/rsAllocation.cpp
index 59944bf..a210435 100644
--- a/rsAllocation.cpp
+++ b/rsAllocation.cpp
@@ -336,13 +336,13 @@
 }
 
 void Allocation::addProgramToDirty(const Program *p) {
-    mToDirtyList.push(p);
+    mToDirtyList.push_back(p);
 }
 
 void Allocation::removeProgramToDirty(const Program *p) {
     for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
         if (mToDirtyList[ct] == p) {
-            mToDirtyList.removeAt(ct);
+            mToDirtyList.erase(mToDirtyList.begin() + ct);
             return;
         }
     }
diff --git a/rsAllocation.h b/rsAllocation.h
index 60f17a3..78be2fc 100644
--- a/rsAllocation.h
+++ b/rsAllocation.h
@@ -26,6 +26,8 @@
 struct ANativeWindowBuffer;
 #endif
 
+#include <vector>
+
 // ---------------------------------------------------------------------------
 namespace android {
 
@@ -212,7 +214,7 @@
     bool hasSameDims(const Allocation *Other) const;
 
 protected:
-    Vector<const Program *> mToDirtyList;
+    std::vector<const Program *> mToDirtyList;
     ObjectBaseRef<const Type> mType;
     void setType(const Type *t) {
         mType.set(t);
diff --git a/rsContext.cpp b/rsContext.cpp
index fabfa6b..51a8ca9 100644
--- a/rsContext.cpp
+++ b/rsContext.cpp
@@ -202,7 +202,7 @@
 
 static uint32_t getProp(const char *str) {
 #ifdef __ANDROID__
-    char buf[PROPERTY_VALUE_MAX];
+    char buf[PROP_VALUE_MAX];
     property_get(str, buf, "0");
     return atoi(buf);
 #else
@@ -692,13 +692,13 @@
 void Context::assignName(ObjectBase *obj, const char *name, uint32_t len) {
     rsAssert(!obj->getName());
     obj->setName(name, len);
-    mNames.add(obj);
+    mNames.push_back(obj);
 }
 
 void Context::removeName(ObjectBase *obj) {
     for (size_t ct=0; ct < mNames.size(); ct++) {
         if (obj == mNames[ct]) {
-            mNames.removeAt(ct);
+            mNames.erase(mNames.begin() + ct);
             return;
         }
     }
diff --git a/rsContext.h b/rsContext.h
index 9385d4b..b600018 100644
--- a/rsContext.h
+++ b/rsContext.h
@@ -40,6 +40,8 @@
 
 #endif
 
+#include <vector>
+
 // ---------------------------------------------------------------------------
 namespace android {
 
@@ -352,7 +354,7 @@
     // allocate, copy, or free any memory here.
     const char* mDriverName;
 
-    Vector<ObjectBase *> mNames;
+    std::vector<ObjectBase *> mNames;
 
     uint64_t mTimers[_RS_TIMER_TOTAL];
     Timers mTimerActive;
diff --git a/rsCppUtils.cpp b/rsCppUtils.cpp
index cf7fe40..333f3a1 100644
--- a/rsCppUtils.cpp
+++ b/rsCppUtils.cpp
@@ -20,8 +20,6 @@
 #include <string>
 #include <unistd.h>
 
-#include <sys/system_properties.h>
-
 #ifndef RS_COMPATIBILITY_LIB
 #include <sys/wait.h>
 #endif
diff --git a/rsCppUtils.h b/rsCppUtils.h
index 6932bab..73416c5 100644
--- a/rsCppUtils.h
+++ b/rsCppUtils.h
@@ -17,27 +17,19 @@
 #ifndef ANDROID_RS_CPP_UTILS_H
 #define ANDROID_RS_CPP_UTILS_H
 
-#ifndef RS_COMPATIBILITY_LIB
-#include <utils/Log.h>
-#include <utils/String8.h>
-#include <utils/Vector.h>
-#endif
-
 #include <stdint.h>
 #include <stdlib.h>
 #include <pthread.h>
 #include <time.h>
 #include <math.h>
 
-#ifdef RS_COMPATIBILITY_LIB
-#define ATRACE_TAG
-#define ATRACE_CALL(...)
-
-#include <android/log.h>
 #include <string>
 #include <vector>
 #include <algorithm>
 
+#include <android/log.h>
+#include <sys/system_properties.h>
+
 #ifndef ALOGE
 #define ALOGE(...) \
     __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__);
@@ -61,95 +53,9 @@
 #define OS_PATH_SEPARATOR '/'
 #endif
 
+
 namespace android {
-
-    // server has no Vector or String8 classes; implement on top of STL
-    class String8: public std::string {
-    public:
-    explicit String8(const char *ptr) : std::string(ptr) {
-
-        }
-    String8(const char *ptr, size_t len) : std::string(ptr, len) {
-
-        }
-    String8() : std::string() {
-
-        }
-
-        const char* string() const {
-            return this->c_str();
-        }
-
-        void setTo(const char* str, ssize_t len) {
-            this->assign(str, len);
-        }
-        void setTo(const char* str) {
-            this->assign(str);
-        }
-        String8 getPathDir(void) const {
-            const char* cp;
-            const char*const str = this->c_str();
-
-            cp = strrchr(str, OS_PATH_SEPARATOR);
-            if (cp == NULL)
-                return String8("");
-            else
-                return String8(str, cp - str);
-        }
-    };
-
-    template <class T> class Vector: public std::vector<T> {
-    public:
-        void push(T obj) {
-            this->push_back(obj);
-        }
-        void removeAt(uint32_t index) {
-            this->erase(this->begin() + index);
-        }
-        ssize_t add(const T& obj) {
-            this->push_back(obj);
-            return this->size() - 1;
-        }
-        void setCapacity(ssize_t capacity) {
-            this->resize(capacity);
-        }
-
-        T* editArray() {
-            return (T*)(this->begin());
-        }
-
-        const T* array() {
-            return this->data();
-        }
-
-    };
-
-    template<> class Vector<bool>: public std::vector<char> {
-    public:
-        void push(bool obj) {
-            this->push_back(obj);
-        }
-        void removeAt(uint32_t index) {
-            this->erase(this->begin() + index);
-        }
-        ssize_t add(const bool& obj) {
-            this->push_back(obj);
-            return this->size() - 1;
-        }
-        void setCapacity(ssize_t capacity) {
-            this->resize(capacity);
-        }
-
-        bool* editArray() {
-            return (bool*)(&*this->begin());
-        }
-
-        const bool* array() {
-            return (const bool*)(&*this->begin());
-        }
-    };
-
-} // namespace android
+namespace renderscript {
 
 typedef int64_t nsecs_t;  // nano-seconds
 
@@ -187,14 +93,6 @@
     return secs/1000000;
 }
 
-#endif // RS_COMPATIBILITY_LIB
-
-namespace android {
-namespace renderscript {
-
-const char * rsuCopyString(const char *name);
-const char * rsuCopyString(const char *name, size_t len);
-
 #if 1
 #define rsAssert(v) do {if(!(v)) ALOGE("rsAssert failed: %s, in %s at %i", #v, __FILE__, __LINE__);} while (0)
 #else
@@ -288,6 +186,8 @@
     return (r >> 2) | ((g >> 2) << 8) | ((b >> 2) << 16) | ((a >> 2) << 24);
 }
 
+const char * rsuCopyString(const char *name);
+const char * rsuCopyString(const char *name, size_t len);
 const char* rsuJoinStrings(int n, const char* const* strs);
 
 #ifndef RS_COMPATIBILITY_LIB
@@ -298,10 +198,6 @@
 bool rsuExecuteCommand(const char *exe, int nArgs, const char * const *args);
 #endif
 
-// from cutils/properties.h
-#define PROPERTY_KEY_MAX 32
-#define PROPERTY_VALUE_MAX 92
-
 int property_get(const char *key, char *value, const char *default_value);
 
 } // namespace renderscript
diff --git a/rsDebugHelper.h b/rsDebugHelper.h
index 93b4d1e..2356e0e 100644
--- a/rsDebugHelper.h
+++ b/rsDebugHelper.h
@@ -38,8 +38,7 @@
 
     void dump() {
 #ifndef RS_COMPATIBILITY_LIB
-        String8 s = mStack.toString();
-        ALOGV("%s", s.string());
+        ALOGV("%s", mStack.toString().string());
         //mStack.dump();
 #endif
     }
diff --git a/rsDevice.cpp b/rsDevice.cpp
index 7944fa3..07cf0e8 100644
--- a/rsDevice.cpp
+++ b/rsDevice.cpp
@@ -28,13 +28,13 @@
 }
 
 void Device::addContext(Context *rsc) {
-    mContexts.push(rsc);
+    mContexts.push_back(rsc);
 }
 
 void Device::removeContext(Context *rsc) {
     for (size_t idx=0; idx < mContexts.size(); idx++) {
         if (mContexts[idx] == rsc) {
-            mContexts.removeAt(idx);
+            mContexts.erase(mContexts.begin() + idx);
             break;
         }
     }
diff --git a/rsDevice.h b/rsDevice.h
index be5d94f..cddf9ba 100644
--- a/rsDevice.h
+++ b/rsDevice.h
@@ -19,6 +19,8 @@
 
 #include "rsUtils.h"
 
+#include <vector>
+
 // ---------------------------------------------------------------------------
 namespace android {
 namespace renderscript {
@@ -36,7 +38,7 @@
     bool mForceSW;
 
 protected:
-    Vector<Context *> mContexts;
+    std::vector<Context *> mContexts;
 };
 
 } // namespace renderscript
diff --git a/rsElement.cpp b/rsElement.cpp
index f8c1bfa..6b23f81 100644
--- a/rsElement.cpp
+++ b/rsElement.cpp
@@ -41,9 +41,10 @@
 }
 
 void Element::preDestroy() const {
-    for (uint32_t ct = 0; ct < mRSC->mStateElement.mElements.size(); ct++) {
-        if (mRSC->mStateElement.mElements[ct] == this) {
-            mRSC->mStateElement.mElements.removeAt(ct);
+    auto& elements = mRSC->mStateElement.mElements;
+    for (uint32_t ct = 0; ct < elements.size(); ct++) {
+        if (elements[ct] == this) {
+            elements.erase(elements.begin() + ct);
             break;
         }
     }
@@ -265,7 +266,7 @@
 
 
     ObjectBase::asyncLock();
-    rsc->mStateElement.mElements.push(e);
+    rsc->mStateElement.mElements.push_back(e);
     ObjectBase::asyncUnlock();
 
     return returnRef;
@@ -340,7 +341,7 @@
     e->compute();
 
     ObjectBase::asyncLock();
-    rsc->mStateElement.mElements.push(e);
+    rsc->mStateElement.mElements.push_back(e);
     ObjectBase::asyncUnlock();
 
     return returnRef;
diff --git a/rsElement.h b/rsElement.h
index cc1b5e4..ef87487 100644
--- a/rsElement.h
+++ b/rsElement.h
@@ -22,6 +22,8 @@
 #include "rsInternalDefines.h"
 #include "rsObjectBase.h"
 
+#include <vector>
+
 // ---------------------------------------------------------------------------
 namespace android {
 namespace renderscript {
@@ -170,7 +172,7 @@
     ~ElementState();
 
     // Cache of all existing elements.
-    Vector<Element *> mElements;
+    std::vector<Element *> mElements;
 };
 
 
diff --git a/rsFileA3D.cpp b/rsFileA3D.cpp
index 4107f6f..b09c52e 100644
--- a/rsFileA3D.cpp
+++ b/rsFileA3D.cpp
@@ -77,7 +77,7 @@
             entry->mLength = headerStream->loadU32();
         }
         entry->mRsObj = nullptr;
-        mIndex.push(entry);
+        mIndex.push_back(entry);
     }
 }
 
@@ -371,7 +371,7 @@
     indexEntry->mType = obj->getClassId();
     indexEntry->mOffset = mWriteStream->getPos();
     indexEntry->mRsObj = obj;
-    mWriteIndex.push(indexEntry);
+    mWriteIndex.push_back(indexEntry);
     obj->serialize(con, mWriteStream);
     indexEntry->mLength = mWriteStream->getPos() - indexEntry->mOffset;
     mWriteStream->align(4);
diff --git a/rsFileA3D.h b/rsFileA3D.h
index dde2c9a..3334159 100644
--- a/rsFileA3D.h
+++ b/rsFileA3D.h
@@ -21,6 +21,7 @@
 
 #include "rsStream.h"
 #include <stdio.h>
+#include <vector>
 
 #define A3D_MAGIC_KEY "Android3D_ff"
 
@@ -87,10 +88,10 @@
     uint64_t mDataSize;
 
     OStream *mWriteStream;
-    Vector<A3DIndexEntry*> mWriteIndex;
+    std::vector<A3DIndexEntry*> mWriteIndex;
 
     IStream *mReadStream;
-    Vector<A3DIndexEntry*> mIndex;
+    std::vector<A3DIndexEntry*> mIndex;
 };
 
 
diff --git a/rsFont.cpp b/rsFont.cpp
index a69cb16..b3c6c17 100644
--- a/rsFont.cpp
+++ b/rsFont.cpp
@@ -73,9 +73,10 @@
 }
 
 void Font::preDestroy() const {
-    for (uint32_t ct = 0; ct < mRSC->mStateFont.mActiveFonts.size(); ct++) {
-        if (mRSC->mStateFont.mActiveFonts[ct] == this) {
-            mRSC->mStateFont.mActiveFonts.removeAt(ct);
+    auto& activeFonts = mRSC->mStateFont.mActiveFonts;
+    for (uint32_t ct = 0; ct < activeFonts.size(); ct++) {
+        if (activeFonts[ct] == this) {
+            activeFonts.erase(activeFonts.begin() + ct);
             break;
         }
     }
@@ -293,7 +294,7 @@
 Font * Font::create(Context *rsc, const char *name, float fontSize, uint32_t dpi,
                     const void *data, uint32_t dataLen) {
     rsc->mStateFont.checkInit();
-    Vector<Font*> &activeFonts = rsc->mStateFont.mActiveFonts;
+    auto& activeFonts = rsc->mStateFont.mActiveFonts;
 
     for (uint32_t i = 0; i < activeFonts.size(); i ++) {
         Font *ithFont = activeFonts[i];
@@ -305,7 +306,7 @@
     Font *newFont = new Font(rsc);
     bool isInitialized = newFont->init(name, fontSize, dpi, data, dataLen);
     if (isInitialized) {
-        activeFonts.push(newFont);
+        activeFonts.push_back(newFont);
         rsc->mStateFont.precacheLatin(newFont);
         return newFont;
     }
@@ -342,7 +343,7 @@
 
 #ifdef __ANDROID__
     // Get the renderer properties
-    char property[PROPERTY_VALUE_MAX];
+    char property[PROP_VALUE_MAX];
 
     // Get the gamma
     if (property_get(PROPERTY_TEXT_GAMMA, property, nullptr) > 0) {
@@ -557,19 +558,19 @@
 
     // Split up our cache texture into lines of certain widths
     int32_t nextLine = 0;
-    mCacheLines.push(new CacheTextureLine(16, texType->getDimX(), nextLine, 0));
-    nextLine += mCacheLines.top()->mMaxHeight;
-    mCacheLines.push(new CacheTextureLine(24, texType->getDimX(), nextLine, 0));
-    nextLine += mCacheLines.top()->mMaxHeight;
-    mCacheLines.push(new CacheTextureLine(24, texType->getDimX(), nextLine, 0));
-    nextLine += mCacheLines.top()->mMaxHeight;
-    mCacheLines.push(new CacheTextureLine(32, texType->getDimX(), nextLine, 0));
-    nextLine += mCacheLines.top()->mMaxHeight;
-    mCacheLines.push(new CacheTextureLine(32, texType->getDimX(), nextLine, 0));
-    nextLine += mCacheLines.top()->mMaxHeight;
-    mCacheLines.push(new CacheTextureLine(40, texType->getDimX(), nextLine, 0));
-    nextLine += mCacheLines.top()->mMaxHeight;
-    mCacheLines.push(new CacheTextureLine(texType->getDimY() - nextLine, texType->getDimX(), nextLine, 0));
+    mCacheLines.push_back(new CacheTextureLine(16, texType->getDimX(), nextLine, 0));
+    nextLine += mCacheLines.back()->mMaxHeight;
+    mCacheLines.push_back(new CacheTextureLine(24, texType->getDimX(), nextLine, 0));
+    nextLine += mCacheLines.back()->mMaxHeight;
+    mCacheLines.push_back(new CacheTextureLine(24, texType->getDimX(), nextLine, 0));
+    nextLine += mCacheLines.back()->mMaxHeight;
+    mCacheLines.push_back(new CacheTextureLine(32, texType->getDimX(), nextLine, 0));
+    nextLine += mCacheLines.back()->mMaxHeight;
+    mCacheLines.push_back(new CacheTextureLine(32, texType->getDimX(), nextLine, 0));
+    nextLine += mCacheLines.back()->mMaxHeight;
+    mCacheLines.push_back(new CacheTextureLine(40, texType->getDimX(), nextLine, 0));
+    nextLine += mCacheLines.back()->mMaxHeight;
+    mCacheLines.push_back(new CacheTextureLine(texType->getDimY() - nextLine, texType->getDimX(), nextLine, 0));
 }
 
 // Avoid having to reallocate memory and render quad by quad
diff --git a/rsFont.h b/rsFont.h
index 84223e6..d08c6f2 100644
--- a/rsFont.h
+++ b/rsFont.h
@@ -18,7 +18,6 @@
 #define ANDROID_RS_FONT_H
 
 #include "rsStream.h"
-#include <utils/Vector.h>
 #include <utils/KeyedVector.h>
 
 struct FT_LibraryRec_;
@@ -178,7 +177,7 @@
         bool fitBitmap(FT_Bitmap_ *bitmap, uint32_t *retOriginX, uint32_t *retOriginY);
     };
 
-    Vector<CacheTextureLine*> mCacheLines;
+    std::vector<CacheTextureLine*> mCacheLines;
     uint32_t getRemainingCacheCapacity();
 
     void precacheLatin(Font *font);
@@ -203,7 +202,7 @@
     FT_LibraryRec_ *mLibrary;
     FT_LibraryRec_ *getLib();
 #endif //ANDROID_RS_SERIALIZE
-    Vector<Font*> mActiveFonts;
+    std::vector<Font*> mActiveFonts;
 
     // Render state for the font
     ObjectBaseRef<Allocation> mFontShaderFConstant;
diff --git a/rsProgramFragment.h b/rsProgramFragment.h
index 61cce91..f35b8b9 100644
--- a/rsProgramFragment.h
+++ b/rsProgramFragment.h
@@ -55,7 +55,7 @@
     void deinit(Context *rsc);
 
     ObjectBaseRef<ProgramFragment> mDefault;
-    Vector<ProgramFragment *> mPrograms;
+    std::vector<ProgramFragment *> mPrograms;
 
     ObjectBaseRef<ProgramFragment> mLast;
 };
diff --git a/rsProgramRaster.cpp b/rsProgramRaster.cpp
index 772c182..203ecbd 100644
--- a/rsProgramRaster.cpp
+++ b/rsProgramRaster.cpp
@@ -30,9 +30,10 @@
 }
 
 void ProgramRaster::preDestroy() const {
-    for (uint32_t ct = 0; ct < mRSC->mStateRaster.mRasterPrograms.size(); ct++) {
-        if (mRSC->mStateRaster.mRasterPrograms[ct] == this) {
-            mRSC->mStateRaster.mRasterPrograms.removeAt(ct);
+    auto& rasterPrograms = mRSC->mStateRaster.mRasterPrograms;
+    for (uint32_t ct = 0; ct < rasterPrograms.size(); ct++) {
+        if (rasterPrograms[ct] == this) {
+            rasterPrograms.erase(rasterPrograms.begin() + ct);
             break;
         }
     }
@@ -93,7 +94,7 @@
     returnRef.set(pr);
 
     ObjectBase::asyncLock();
-    rsc->mStateRaster.mRasterPrograms.push(pr);
+    rsc->mStateRaster.mRasterPrograms.push_back(pr);
     ObjectBase::asyncUnlock();
 
     return returnRef;
diff --git a/rsProgramRaster.h b/rsProgramRaster.h
index a0ec1db..b9244a9 100644
--- a/rsProgramRaster.h
+++ b/rsProgramRaster.h
@@ -19,6 +19,8 @@
 
 #include "rsProgramBase.h"
 
+#include <vector>
+
 // ---------------------------------------------------------------------------
 namespace android {
 namespace renderscript {
@@ -75,7 +77,7 @@
     ObjectBaseRef<ProgramRaster> mLast;
 
     // Cache of all existing raster programs.
-    Vector<ProgramRaster *> mRasterPrograms;
+    std::vector<ProgramRaster *> mRasterPrograms;
 };
 
 
diff --git a/rsProgramStore.cpp b/rsProgramStore.cpp
index 79cc149..1051d92 100644
--- a/rsProgramStore.cpp
+++ b/rsProgramStore.cpp
@@ -41,9 +41,10 @@
 }
 
 void ProgramStore::preDestroy() const {
-    for (uint32_t ct = 0; ct < mRSC->mStateFragmentStore.mStorePrograms.size(); ct++) {
-        if (mRSC->mStateFragmentStore.mStorePrograms[ct] == this) {
-            mRSC->mStateFragmentStore.mStorePrograms.removeAt(ct);
+    auto& storePrograms = mRSC->mStateFragmentStore.mStorePrograms;
+    for (uint32_t ct = 0; ct < storePrograms.size(); ct++) {
+        if (storePrograms[ct] == this) {
+            storePrograms.erase(storePrograms.begin() + ct);
             break;
         }
     }
@@ -117,7 +118,7 @@
     pfs->init();
 
     ObjectBase::asyncLock();
-    rsc->mStateFragmentStore.mStorePrograms.push(pfs);
+    rsc->mStateFragmentStore.mStorePrograms.push_back(pfs);
     ObjectBase::asyncUnlock();
 
     return returnRef;
diff --git a/rsProgramStore.h b/rsProgramStore.h
index b9463ec..eab00c1 100644
--- a/rsProgramStore.h
+++ b/rsProgramStore.h
@@ -20,6 +20,8 @@
 #include "rsProgramBase.h"
 #include "rsStream.h"
 
+#include <vector>
+
 // ---------------------------------------------------------------------------
 namespace android {
 namespace renderscript {
@@ -92,7 +94,7 @@
     ObjectBaseRef<ProgramStore> mLast;
 
     // Cache of all existing store programs.
-    Vector<ProgramStore *> mStorePrograms;
+    std::vector<ProgramStore *> mStorePrograms;
 };
 
 } // namespace renderscript
diff --git a/rsSampler.cpp b/rsSampler.cpp
index 25abfb9..cd90a32 100644
--- a/rsSampler.cpp
+++ b/rsSampler.cpp
@@ -48,9 +48,10 @@
 }
 
 void Sampler::preDestroy() const {
-    for (uint32_t ct = 0; ct < mRSC->mStateSampler.mAllSamplers.size(); ct++) {
-        if (mRSC->mStateSampler.mAllSamplers[ct] == this) {
-            mRSC->mStateSampler.mAllSamplers.removeAt(ct);
+    auto& allSamplers = mRSC->mStateSampler.mAllSamplers;
+    for (uint32_t ct = 0; ct < allSamplers.size(); ct++) {
+        if (allSamplers[ct] == this) {
+            allSamplers.erase(allSamplers.begin() + ct);
             break;
         }
     }
@@ -112,7 +113,7 @@
 #endif
 
     ObjectBase::asyncLock();
-    rsc->mStateSampler.mAllSamplers.push(s);
+    rsc->mStateSampler.mAllSamplers.push_back(s);
     ObjectBase::asyncUnlock();
 
     return returnRef;
diff --git a/rsSampler.h b/rsSampler.h
index 8af83f1..ab085d3 100644
--- a/rsSampler.h
+++ b/rsSampler.h
@@ -19,6 +19,8 @@
 
 #include "rsAllocation.h"
 
+#include <vector>
+
 // ---------------------------------------------------------------------------
 namespace android {
 namespace renderscript {
@@ -96,7 +98,7 @@
         }
     }
     // Cache of all existing raster programs.
-    Vector<Sampler *> mAllSamplers;
+    std::vector<Sampler *> mAllSamplers;
 };
 
 } // namespace renderscript
diff --git a/rsScriptC_LibGL.cpp b/rsScriptC_LibGL.cpp
index 8678097..7608b06 100644
--- a/rsScriptC_LibGL.cpp
+++ b/rsScriptC_LibGL.cpp
@@ -22,7 +22,6 @@
 #include "rsMesh.h"
 #include "rsgApiStructs.h"
 
-#include "utils/Timers.h"
 #include "driver/rsdVertexArray.h"
 #include "driver/rsdShaderCache.h"
 #include "driver/rsdCore.h"
diff --git a/rsScriptGroup.cpp b/rsScriptGroup.cpp
index 9ebec09..2efc5a9 100644
--- a/rsScriptGroup.cpp
+++ b/rsScriptGroup.cpp
@@ -94,26 +94,13 @@
     return ret;
 }
 
-#ifndef RS_COMPATIBILITY_LIB
-static int CompareNodeForSort(ScriptGroup::Node *const* lhs,
-                              ScriptGroup::Node *const* rhs) {
-    if (lhs[0]->mOrder > rhs[0]->mOrder) {
-        return 1;
-    }
-    return 0;
-}
-#else
 class NodeCompare {
 public:
     bool operator() (const ScriptGroup::Node* lhs,
                      const ScriptGroup::Node* rhs) {
-        if (lhs->mOrder > rhs->mOrder) {
-            return true;
-        }
-        return false;
+        return (lhs->mOrder < rhs->mOrder);
     }
 };
-#endif
 
 bool ScriptGroup::calcOrder() {
     // Make nodes
@@ -125,9 +112,9 @@
         //ALOGE("    n = %p", n);
         if (n == NULL) {
             n = new Node(k->mScript);
-            mNodes.add(n);
+            mNodes.push_back(n);
         }
-        n->mKernels.add(k);
+        n->mKernels.push_back(k);
     }
 
     // add links
@@ -137,17 +124,17 @@
         //ALOGE("link  %i %p", (int)ct, l);
         Node *n = findNode(l->mSource->mScript);
         //ALOGE("link n %p", n);
-        n->mOutputs.add(l);
+        n->mOutputs.push_back(l);
 
         if (l->mDstKernel.get()) {
             //ALOGE("l->mDstKernel.get() %p", l->mDstKernel.get());
             n = findNode(l->mDstKernel->mScript);
             //ALOGE("  n1 %p", n);
-            n->mInputs.add(l);
+            n->mInputs.push_back(l);
         } else {
             n = findNode(l->mDstField->mScript);
             //ALOGE("  n2 %p", n);
-            n->mInputs.add(l);
+            n->mInputs.push_back(l);
         }
     }
 
@@ -178,7 +165,7 @@
             }
             if (!found) {
                 //ALOGE("add io out %p", k);
-                mOutputs.add(new IO(k));
+                mOutputs.push_back(new IO(k));
             }
         }
 
@@ -192,18 +179,13 @@
             }
             if (!found) {
                 //ALOGE("add io in %p", k);
-                mInputs.add(new IO(k));
+                mInputs.push_back(new IO(k));
             }
         }
     }
 
-    // sort
-#ifndef RS_COMPATIBILITY_LIB
-    mNodes.sort(&CompareNodeForSort);
-#else
+    // Sort mNodes in the increasing order.
     std::sort(mNodes.begin(), mNodes.end(), NodeCompare());
-#endif
-
     return ret;
 }
 
@@ -226,7 +208,7 @@
 
     sg->mKernels.reserve(kernelCount);
     for (size_t ct=0; ct < kernelCount; ct++) {
-        sg->mKernels.add(kernels[ct]);
+        sg->mKernels.push_back(kernels[ct]);
     }
 
     sg->mLinks.reserve(linkCount);
@@ -236,7 +218,7 @@
         l->mSource = src[ct];
         l->mDstField = dstF[ct];
         l->mDstKernel = dstK[ct];
-        sg->mLinks.add(l);
+        sg->mLinks.push_back(l);
     }
 
     sg->calcOrder();
diff --git a/rsScriptGroup.h b/rsScriptGroup.h
index a3801df..76c2a60 100644
--- a/rsScriptGroup.h
+++ b/rsScriptGroup.h
@@ -41,7 +41,7 @@
     virtual SG_API_Version getApiVersion() const { return SG_V1; }
     virtual void execute(Context *rsc);
 
-    Vector<ObjectBaseRef<ScriptKernelID> > mKernels;
+    std::vector<ObjectBaseRef<ScriptKernelID> > mKernels;
 
     class Link {
     public:
@@ -58,9 +58,9 @@
     public:
         explicit Node(Script *);
 
-        Vector<const ScriptKernelID *> mKernels;
-        Vector<Link *> mOutputs;
-        Vector<Link *> mInputs;
+        std::vector<const ScriptKernelID *> mKernels;
+        std::vector<Link *> mOutputs;
+        std::vector<Link *> mInputs;
         bool mSeen;
         int mOrder;
         Script *mScript;
@@ -74,10 +74,10 @@
         ObjectBaseRef<Allocation> mAlloc;
     };
 
-    Vector<Link *> mLinks;
-    Vector<Node *> mNodes;
-    Vector<IO *> mInputs;
-    Vector<IO *> mOutputs;
+    std::vector<Link *> mLinks;
+    std::vector<Node *> mNodes;
+    std::vector<IO *> mInputs;
+    std::vector<IO *> mOutputs;
 
     static ScriptGroup * create(Context *rsc,
                            ScriptKernelID ** kernels, size_t kernelsSize,
diff --git a/rsType.cpp b/rsType.cpp
index 8242597..36143f2 100644
--- a/rsType.cpp
+++ b/rsType.cpp
@@ -31,9 +31,10 @@
 }
 
 void Type::preDestroy() const {
-    for (uint32_t ct = 0; ct < mRSC->mStateType.mTypes.size(); ct++) {
-        if (mRSC->mStateType.mTypes[ct] == this) {
-            mRSC->mStateType.mTypes.removeAt(ct);
+    auto& types = mRSC->mStateType.mTypes;
+    for (uint32_t ct = 0; ct < types.size(); ct++) {
+        if (types[ct] == this) {
+            types.erase(types.begin() + ct);
             break;
         }
     }
@@ -283,7 +284,7 @@
     nt->compute();
 
     ObjectBase::asyncLock();
-    stc->mTypes.push(nt);
+    stc->mTypes.push_back(nt);
     ObjectBase::asyncUnlock();
 
     return returnRef;
diff --git a/rsType.h b/rsType.h
index 07c04ed..c907869 100644
--- a/rsType.h
+++ b/rsType.h
@@ -19,6 +19,8 @@
 
 #include "rsElement.h"
 
+#include <vector>
+
 // ---------------------------------------------------------------------------
 namespace android {
 namespace renderscript {
@@ -161,7 +163,7 @@
     ~TypeState();
 
     // Cache of all existing types.
-    Vector<Type *> mTypes;
+    std::vector<Type *> mTypes;
 };