Merge "[RenderScript] AutoPadding & Unpadding for Vec3 Elements during copyTo & copyFrom."
diff --git a/core/java/android/util/ArraySet.java b/core/java/android/util/ArraySet.java
index 423e48b..3214b22 100644
--- a/core/java/android/util/ArraySet.java
+++ b/core/java/android/util/ArraySet.java
@@ -468,6 +468,26 @@
     }
 
     /**
+     * Perform a {@link #remove(Object)} of all values in <var>array</var>
+     * @param array The array whose contents are to be removed.
+     */
+    public boolean removeAll(ArraySet<? extends E> array) {
+        // TODO: If array is sufficiently large, a marking approach might be beneficial. In a first
+        //       pass, use the property that the sets are sorted by hash to make this linear passes
+        //       (except for hash collisions, which means worst case still n*m), then do one
+        //       collection pass into a new array. This avoids binary searches and excessive memcpy.
+        final int N = array.mSize;
+
+        // Note: ArraySet does not make thread-safety guarantees. So instead of OR-ing together all
+        //       the single results, compare size before and after.
+        final int originalSize = mSize;
+        for (int i = 0; i < N; i++) {
+            remove(array.valueAt(i));
+        }
+        return originalSize != mSize;
+    }
+
+    /**
      * Return the number of items in this array map.
      */
     @Override
diff --git a/preloaded-classes b/preloaded-classes
index dee84f0..c8d8c5d 100644
--- a/preloaded-classes
+++ b/preloaded-classes
@@ -1172,6 +1172,7 @@
 android.telecom.InCallService
 android.telephony.PhoneNumberUtils
 android.telephony.Rlog
+android.telephony.SignalStrength
 android.telephony.SubscriptionManager
 android.telephony.TelephonyManager
 android.text.AndroidBidi
diff --git a/services/core/java/com/android/server/pm/KeySetManagerService.java b/services/core/java/com/android/server/pm/KeySetManagerService.java
index 4a8e318..1772856 100644
--- a/services/core/java/com/android/server/pm/KeySetManagerService.java
+++ b/services/core/java/com/android/server/pm/KeySetManagerService.java
@@ -415,9 +415,9 @@
         // Get the package's known keys and KeySets
         ArraySet<Long> deletableKeySets = getOriginalKeySetsByPackageNameLPr(packageName);
         ArraySet<Long> deletableKeys = new ArraySet<Long>();
-        ArraySet<Long> knownKeys = null;
-        for (Long ks : deletableKeySets) {
-            knownKeys = mKeySetMapping.get(ks);
+        final int origDksSize = deletableKeySets.size();
+        for (int i = 0; i < origDksSize; i++) {
+            ArraySet<Long> knownKeys = mKeySetMapping.get(deletableKeySets.valueAt(i));
             if (knownKeys != null) {
                 deletableKeys.addAll(knownKeys);
             }
@@ -430,9 +430,9 @@
             }
             ArraySet<Long> knownKeySets = getOriginalKeySetsByPackageNameLPr(pkgName);
             deletableKeySets.removeAll(knownKeySets);
-            knownKeys = new ArraySet<Long>();
-            for (Long ks : knownKeySets) {
-                knownKeys = mKeySetMapping.get(ks);
+            final int kksSize = knownKeySets.size();
+            for (int i = 0; i < kksSize; i++) {
+                ArraySet<Long> knownKeys = mKeySetMapping.get(knownKeySets.valueAt(i));
                 if (knownKeys != null) {
                     deletableKeys.removeAll(knownKeys);
                 }
@@ -441,18 +441,22 @@
 
         // The remaining keys and KeySets are not relied on by any other
         // application and so can be safely deleted.
-        for (Long ks : deletableKeySets) {
+        final int dksSize = deletableKeySets.size();
+        for (int i = 0; i < dksSize; i++) {
+            Long ks = deletableKeySets.valueAt(i);
             mKeySets.delete(ks);
             mKeySetMapping.delete(ks);
         }
-        for (Long keyId : deletableKeys) {
-            mPublicKeys.delete(keyId);
+        final int dkSize = deletableKeys.size();
+        for (int i = 0; i < dkSize; i++) {
+            mPublicKeys.delete(deletableKeys.valueAt(i));
         }
 
         // Now remove the deleted KeySets from each package's signingKeySets
         for (String pkgName : mPackages.keySet()) {
             PackageSetting p = mPackages.get(pkgName);
-            for (Long ks : deletableKeySets) {
+            for (int i = 0; i < dksSize; i++) {
+                Long ks = deletableKeySets.valueAt(i);
                 p.keySetData.removeSigningKeySet(ks);
             }
         }
diff --git a/tools/aapt/Images.cpp b/tools/aapt/Images.cpp
index 5ab177b..063b4e6 100644
--- a/tools/aapt/Images.cpp
+++ b/tools/aapt/Images.cpp
@@ -481,8 +481,9 @@
 
     // assuming the image is a round rect, compute the radius by marching
     // diagonally from the top left corner towards the center
-    image->outlineAlpha = max(max_alpha_over_row(image->rows[innerMidY], innerStartX, innerEndX),
-            max_alpha_over_col(image->rows, innerMidX, innerStartY, innerStartY));
+    image->outlineAlpha = std::max(
+        max_alpha_over_row(image->rows[innerMidY], innerStartX, innerEndX),
+        max_alpha_over_col(image->rows, innerMidX, innerStartY, innerStartY));
 
     int diagonalInset = 0;
     find_max_opacity(image->rows, innerStartX, innerStartY, innerMidX, innerMidY, 1, 1,
diff --git a/tools/aapt/ResourceTable.cpp b/tools/aapt/ResourceTable.cpp
index 0ec1aeb..9861be2 100644
--- a/tools/aapt/ResourceTable.cpp
+++ b/tools/aapt/ResourceTable.cpp
@@ -1802,7 +1802,7 @@
         }
 
         const ResTable& featureTable = featureAssetManager.getResources(false);
-        mTypeIdOffset = max(mTypeIdOffset,
+        mTypeIdOffset = std::max(mTypeIdOffset,
                 findLargestTypeIdForPackage(featureTable, mAssetsPackage)); 
     }
 
@@ -2667,20 +2667,16 @@
     const String8 defaultLocale;
 
     // For all strings...
-    for (map<String16, map<String8, SourcePos> >::iterator nameIter = mLocalizations.begin();
-         nameIter != mLocalizations.end();
-         nameIter++) {
-        const map<String8, SourcePos>& configSrcMap = nameIter->second;
+    for (const auto& nameIter : mLocalizations) {
+        const std::map<String8, SourcePos>& configSrcMap = nameIter.second;
 
         // Look for strings with no default localization
         if (configSrcMap.count(defaultLocale) == 0) {
             SourcePos().warning("string '%s' has no default translation.",
-                    String8(nameIter->first).string());
+                    String8(nameIter.first).string());
             if (mBundle->getVerbose()) {
-                for (map<String8, SourcePos>::const_iterator locales = configSrcMap.begin();
-                    locales != configSrcMap.end();
-                    locales++) {
-                    locales->second.printf("locale %s found", locales->first.string());
+                for (const auto& locale : configSrcMap) {
+                    locale.second.printf("locale %s found", locale.first.string());
                 }
             }
             // !!! TODO: throw an error here in some circumstances
@@ -2691,8 +2687,8 @@
             const char* allConfigs = mBundle->getConfigurations().string();
             const char* start = allConfigs;
             const char* comma;
-            
-            set<String8> missingConfigs;
+
+            std::set<String8> missingConfigs;
             AaptLocaleValue locale;
             do {
                 String8 config;
@@ -2726,13 +2722,11 @@
 
             if (!missingConfigs.empty()) {
                 String8 configStr;
-                for (set<String8>::iterator iter = missingConfigs.begin();
-                     iter != missingConfigs.end();
-                     iter++) {
-                    configStr.appendFormat(" %s", iter->string());
+                for (const auto& iter : missingConfigs) {
+                    configStr.appendFormat(" %s", iter.string());
                 }
                 SourcePos().warning("string '%s' is missing %u required localizations:%s",
-                        String8(nameIter->first).string(),
+                        String8(nameIter.first).string(),
                         (unsigned int)missingConfigs.size(),
                         configStr.string());
             }
diff --git a/tools/aapt/ResourceTable.h b/tools/aapt/ResourceTable.h
index eac5dd3..a939dd3 100644
--- a/tools/aapt/ResourceTable.h
+++ b/tools/aapt/ResourceTable.h
@@ -16,8 +16,6 @@
 #include <queue>
 #include <set>
 
-using namespace std;
-
 class XMLNode;
 class ResourceTable;
 
@@ -28,7 +26,7 @@
     XML_COMPILE_STRIP_WHITESPACE = 1<<3,
     XML_COMPILE_STRIP_RAW_VALUES = 1<<4,
     XML_COMPILE_UTF8 = 1<<5,
-    
+
     XML_COMPILE_STANDARD_RESOURCE =
             XML_COMPILE_STRIP_COMMENTS | XML_COMPILE_ASSIGN_ATTRIBUTE_IDS
             | XML_COMPILE_STRIP_WHITESPACE | XML_COMPILE_STRIP_RAW_VALUES
@@ -115,7 +113,7 @@
      * and would mess up iteration order for the existing
      * resources.
      */
-    queue<CompileResourceWorkItem>& getWorkQueue() {
+    std::queue<CompileResourceWorkItem>& getWorkQueue() {
         return mWorkQueue;
     }
 
@@ -577,10 +575,10 @@
     size_t mNumLocal;
     SourcePos mCurrentXmlPos;
     Bundle* mBundle;
-    
+
     // key = string resource name, value = set of locales in which that name is defined
-    map<String16, map<String8, SourcePos> > mLocalizations;
-    queue<CompileResourceWorkItem> mWorkQueue;
+    std::map<String16, std::map<String8, SourcePos>> mLocalizations;
+    std::queue<CompileResourceWorkItem> mWorkQueue;
 };
 
 #endif