Remove deprecated code for pre-assigned resource IDs Pre-assigned resource IDs (i.e. <public id="0x7f123456"/>) are not supported by RPBB, and this code will never be needed for supporting pre-assigned IDs. The removed code provided this functionality: * reservation of IDs at compile time; this should not exist, since compile-time IDs are meaningless. * assert that reserved IDs match between (un)qualified values, i.e. values/ and values-es/. aapt2 ignores <public> tag in all qualified resource directories. * assert that reserved IDs are consistent w.r.t. types, e.g. all string IDs use type ID 0x02 or whatever. This is aapt2's responsibility, assuming that this is even desired (the underlying code in Android doesn't care). PiperOrigin-RevId: 285797220
diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceClassWriter.java b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceClassWriter.java index 4456f20..c2bd937 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceClassWriter.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceClassWriter.java
@@ -15,7 +15,6 @@ import com.android.resources.ResourceType; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Optional; import com.google.devtools.build.android.AndroidFrameworkAttrIdProvider.AttrLookupException; import com.google.devtools.build.android.resources.FieldInitializers; import com.google.devtools.build.android.resources.RClassGenerator; @@ -100,11 +99,6 @@ } @Override - public void acceptPublicResource(ResourceType type, String name, Optional<Integer> value) { - generator.addPublicResource(type, name, value); - } - - @Override public void acceptStyleableResource( DependencyInfo dependencyInfo, FullyQualifiedName key,
diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceSymbolSink.java b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceSymbolSink.java index bba4f32..0ceacf3 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidResourceSymbolSink.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidResourceSymbolSink.java
@@ -14,7 +14,6 @@ package com.google.devtools.build.android; import com.android.resources.ResourceType; -import com.google.common.base.Optional; import java.util.Map; /** Defines a sink for collecting data about resource symbols. */ @@ -29,13 +28,4 @@ DependencyInfo dependencyInfo, FullyQualifiedName key, Map<FullyQualifiedName, /*inlineable=*/ Boolean> attrs); - - /** - * Marks a resource as public. - * - * <p>This is orthogonal to the two methods above, and omits the 'DependencyInfo' parameter since - * a 'public' declaration must also have a matching definition (which triggers a call to one of - * the above methods). - */ - void acceptPublicResource(ResourceType type, String name, Optional<Integer> value); }
diff --git a/src/tools/android/java/com/google/devtools/build/android/PlaceholderIdFieldInitializerBuilder.java b/src/tools/android/java/com/google/devtools/build/android/PlaceholderIdFieldInitializerBuilder.java index f31e3a7..28ff6b5 100644 --- a/src/tools/android/java/com/google/devtools/build/android/PlaceholderIdFieldInitializerBuilder.java +++ b/src/tools/android/java/com/google/devtools/build/android/PlaceholderIdFieldInitializerBuilder.java
@@ -14,7 +14,6 @@ package com.google.devtools.build.android; import com.android.resources.ResourceType; -import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -37,7 +36,6 @@ import java.util.SortedMap; import java.util.TreeMap; import java.util.TreeSet; -import java.util.logging.Logger; /** * Generates {@link FieldInitializer}s placeholder unique ids. The real ids will be assigned when @@ -110,45 +108,8 @@ private static final int APP_PACKAGE_MASK = 0x7f000000; private static final int ATTR_TYPE_ID = 1; - private static final Logger logger = - Logger.getLogger(PlaceholderIdFieldInitializerBuilder.class.getName()); private static final String NORMALIZED_ANDROID_PREFIX = "android_"; - /** - * Assign any public ids to the given idBuilder. - * - * @param nameToId where to store the final name -> id mappings - * @param publicIds known public resources (can contain null values, if ID isn't reserved) - * @param typeId the type slot for the current resource type. - * @return the final set of assigned resource ids (includes those without apriori assignments). - */ - private static Set<Integer> assignPublicIds( - Map<String, Integer> nameToId, SortedMap<String, Optional<Integer>> publicIds, int typeId) { - LinkedHashMap<Integer, String> assignedIds = new LinkedHashMap<>(); - int prevId = getInitialIdForTypeId(typeId); - for (Map.Entry<String, Optional<Integer>> entry : publicIds.entrySet()) { - Optional<Integer> id = entry.getValue(); - if (id.isPresent()) { - prevId = id.get(); - } else { - prevId = nextFreeId(prevId + 1, assignedIds.keySet()); - } - String previousMapping = assignedIds.put(prevId, entry.getKey()); - if (previousMapping != null) { - logger.warning( - String.format( - "Multiple entry names declared for public entry identifier 0x%x (%s and %s)", - prevId, previousMapping, entry.getKey())); - } - nameToId.put(entry.getKey(), prevId); - } - return assignedIds.keySet(); - } - - private static int extractTypeId(int fullID) { - return (fullID & 0x00FF0000) >> 16; - } - private static int getInitialIdForTypeId(int typeId) { return APP_PACKAGE_MASK | (typeId << 16); } @@ -176,9 +137,6 @@ private final Map<ResourceType, SortedMap<String, DependencyInfo>> innerClasses = new EnumMap<>(ResourceType.class); - private final Map<ResourceType, SortedMap<String, Optional<Integer>>> publicIds = - new EnumMap<>(ResourceType.class); - private final Map<String, Map<String, /*inlineable=*/ Boolean>> styleableAttrs = new LinkedHashMap<>(); @@ -186,29 +144,6 @@ this.androidIdProvider = androidIdProvider; } - public void addPublicResource(ResourceType type, String name, Optional<Integer> value) { - SortedMap<String, Optional<Integer>> publicMappings = publicIds.get(type); - if (publicMappings == null) { - publicMappings = new TreeMap<>(); - publicIds.put(type, publicMappings); - } - Optional<Integer> oldValue = publicMappings.put(name, value); - // AAPT should issue an error, but do a bit of sanity checking here just in case. - if (oldValue != null && !oldValue.equals(value)) { - // Enforce a consistent ordering on the warning message. - Integer lower = oldValue.orNull(); - Integer higher = value.orNull(); - if (Ordering.natural().compare(oldValue.orNull(), value.orNull()) > 0) { - lower = higher; - higher = oldValue.orNull(); - } - logger.warning( - String.format( - "resource %s/%s has conflicting public identifiers (0x%x vs 0x%x)", - type, name, lower, higher)); - } - } - public void addSimpleResource(DependencyInfo dependencyInfo, ResourceType type, String name) { innerClasses .computeIfAbsent(type, t -> new TreeMap<>()) @@ -255,9 +190,6 @@ // After assigning public IDs, we count up monotonically, so we don't need to track additional // assignedIds to avoid collisions (use an ImmutableSet to ensure we don't add more). Set<Integer> assignedIds = ImmutableSet.of(); - if (publicIds.containsKey(ResourceType.ATTR)) { - assignedIds = assignPublicIds(attrToId, publicIds.get(ResourceType.ATTR), attrTypeId); - } Set<String> inlineAttrs = new LinkedHashSet<>(); Set<String> styleablesWithInlineAttrs = new TreeSet<>(); for (Map.Entry<String, Map<String, Boolean>> styleableAttrEntry : styleableAttrs.entrySet()) { @@ -291,65 +223,6 @@ return ImmutableMap.copyOf(attrToId); } - private Map<ResourceType, Integer> assignTypeIdsForPublic() { - Map<ResourceType, Integer> allocatedTypeIds = new EnumMap<>(ResourceType.class); - if (publicIds.isEmpty()) { - return allocatedTypeIds; - } - // Keep track of the reverse mapping from Int -> Type for validation. - Map<Integer, ResourceType> assignedIds = new LinkedHashMap<>(); - for (Map.Entry<ResourceType, SortedMap<String, Optional<Integer>>> publicTypeEntry : - publicIds.entrySet()) { - ResourceType currentType = publicTypeEntry.getKey(); - Integer reservedTypeSlot = null; - String previousResource = null; - for (Map.Entry<String, Optional<Integer>> publicEntry : - publicTypeEntry.getValue().entrySet()) { - Optional<Integer> reservedId = publicEntry.getValue(); - if (!reservedId.isPresent()) { - continue; - } - Integer typePortion = extractTypeId(reservedId.get()); - if (reservedTypeSlot == null) { - reservedTypeSlot = typePortion; - previousResource = publicEntry.getKey(); - } else { - if (!reservedTypeSlot.equals(typePortion)) { - logger.warning( - String.format( - "%s has conflicting type codes for its public identifiers (%s=%s vs %s=%s)", - currentType.getName(), - previousResource, - reservedTypeSlot, - publicEntry.getKey(), - typePortion)); - } - } - } - if (currentType == ResourceType.ATTR - && reservedTypeSlot != null - && !reservedTypeSlot.equals(ATTR_TYPE_ID)) { - logger.warning( - String.format( - "Cannot force ATTR to have type code other than 0x%02x (got 0x%02x from %s)", - ATTR_TYPE_ID, reservedTypeSlot, previousResource)); - } - if (reservedTypeSlot == null) { - logger.warning(String.format("Invalid public resource of type %s - ignoring", currentType)); - } else { - allocatedTypeIds.put(currentType, reservedTypeSlot); - ResourceType alreadyAssigned = assignedIds.put(reservedTypeSlot, currentType); - if (alreadyAssigned != null) { - logger.warning( - String.format( - "Multiple type names declared for public type identifier 0x%x (%s vs %s)", - reservedTypeSlot, alreadyAssigned, currentType)); - } - } - } - return allocatedTypeIds; - } - public FieldInitializers build() throws AttrLookupException { Map<ResourceType, Collection<FieldInitializer>> initializers = new EnumMap<>(ResourceType.class); @@ -366,7 +239,7 @@ fields = getAttrInitializers(attrAssignments, sortedFields); } else { int typeId = typeIdMap.get(type); - fields = getResourceInitializers(type, typeId, sortedFields); + fields = getResourceInitializers(typeId, sortedFields); } // The maximum number of Java fields is 2^16. // See the JVM reference "4.11. Limitations of the Java Virtual Machine." @@ -377,9 +250,7 @@ } private Map<ResourceType, Integer> chooseTypeIds() { - // Go through public entries. Those may have forced certain type assignments, so take those - // into account first. - Map<ResourceType, Integer> allocatedTypeIds = assignTypeIdsForPublic(); + Map<ResourceType, Integer> allocatedTypeIds = new EnumMap<>(ResourceType.class); Set<Integer> reservedTypeSlots = ImmutableSet.copyOf(allocatedTypeIds.values()); // ATTR always takes up slot #1, even if it isn't present. allocatedTypeIds.put(ResourceType.ATTR, ATTR_TYPE_ID); @@ -416,13 +287,10 @@ } private ImmutableList<FieldInitializer> getResourceInitializers( - ResourceType type, int typeId, SortedMap<String, DependencyInfo> sortedFields) { + int typeId, SortedMap<String, DependencyInfo> sortedFields) { ImmutableList.Builder<FieldInitializer> initList = ImmutableList.builder(); Map<String, Integer> publicNameToId = new LinkedHashMap<>(); Set<Integer> assignedIds = ImmutableSet.of(); - if (publicIds.containsKey(type)) { - assignedIds = assignPublicIds(publicNameToId, publicIds.get(type), typeId); - } int resourceIds = nextFreeId(getInitialIdForTypeId(typeId), assignedIds); for (Map.Entry<String, DependencyInfo> entry : sortedFields.entrySet()) { String field = entry.getKey();
diff --git a/src/tools/android/java/com/google/devtools/build/android/PlaceholderRTxtWriter.java b/src/tools/android/java/com/google/devtools/build/android/PlaceholderRTxtWriter.java index e66a2e6..7441633 100644 --- a/src/tools/android/java/com/google/devtools/build/android/PlaceholderRTxtWriter.java +++ b/src/tools/android/java/com/google/devtools/build/android/PlaceholderRTxtWriter.java
@@ -16,7 +16,6 @@ import static java.nio.charset.StandardCharsets.UTF_8; import com.android.resources.ResourceType; -import com.google.common.base.Optional; import java.io.BufferedWriter; import java.io.Flushable; import java.io.IOException; @@ -71,9 +70,6 @@ } @Override - public void acceptPublicResource(ResourceType type, String name, Optional<Integer> value) {} - - @Override public void flush() throws IOException { try (BufferedWriter writer = Files.newBufferedWriter(rTxtOut, UTF_8)) { for (Map.Entry<ResourceType, Set<String>> innerClass : innerClasses.entrySet()) {
diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/PublicXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/PublicXmlResourceValue.java index 00062cd..6de5158 100644 --- a/src/tools/android/java/com/google/devtools/build/android/xml/PublicXmlResourceValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/xml/PublicXmlResourceValue.java
@@ -92,11 +92,7 @@ @Override public void writeResourceToClass( - DependencyInfo dependencyInfo, FullyQualifiedName key, AndroidResourceSymbolSink sink) { - for (Map.Entry<ResourceType, Optional<Integer>> entry : typeToId.entrySet()) { - sink.acceptPublicResource(entry.getKey(), key.name(), entry.getValue()); - } - } + DependencyInfo dependencyInfo, FullyQualifiedName key, AndroidResourceSymbolSink sink) {} @Override public int hashCode() {