Add test to ensure no attributes are present after the last public one

This is to ensure we don't have resource collisions in future releases.

Bug:18263655
Change-Id: Ic808828729cd6dae7fe48527f1188776a99372cc
diff --git a/tests/tests/content/src/android/content/res/cts/PrivateAttributeTest.java b/tests/tests/content/src/android/content/res/cts/PrivateAttributeTest.java
new file mode 100644
index 0000000..35466be
--- /dev/null
+++ b/tests/tests/content/src/android/content/res/cts/PrivateAttributeTest.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2014 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.content.res.cts;
+
+import android.content.res.Resources;
+import android.test.AndroidTestCase;
+import android.util.TypedValue;
+
+/**
+ * Tests that private attributes are correctly placed in a separate type to
+ * prevent future releases from stomping over private attributes with new public ones.
+ */
+public class PrivateAttributeTest extends AndroidTestCase {
+
+    private static final int sLastPublicAttr = 0x010104d5;
+
+    public void testNoAttributesAfterLastPublicAttribute() throws Exception {
+        final Resources res = getContext().getResources();
+
+        final String lastPublicName;
+        try {
+            lastPublicName = res.getResourceEntryName(sLastPublicAttr);
+        } catch (Resources.NotFoundException e) {
+            throw new AssertionError("Last public resource was not found", e);
+        }
+
+        int currentAttr = sLastPublicAttr;
+        while (currentAttr < 0x0101ffff) {
+            currentAttr++;
+            try {
+                final String name = res.getResourceEntryName(currentAttr);
+                throw new AssertionError("Found attribute '" + name + "'"
+                        + " (0x" + Integer.toHexString(currentAttr) + ")"
+                        + " after last public framework attribute "
+                        + "'" + lastPublicName + "'"
+                        + " (0x" + Integer.toHexString(sLastPublicAttr) + ")");
+            } catch (Resources.NotFoundException e) {
+                // continue
+            }
+        }
+    }
+}