First pass at flagged resources

This gets the main parts of resource flagging in place and the basic use
case of flagging with an xml attribute working.

Test: Automated
Bug: 329436914
Flag: EXEMPT Aconfig not supported on host tools
Change-Id: Id2b5ba450d05da00a922e98ca204b6e5aa6c6c24
diff --git a/tools/aapt2/ResourceTable.h b/tools/aapt2/ResourceTable.h
index 61e399c..9530c17 100644
--- a/tools/aapt2/ResourceTable.h
+++ b/tools/aapt2/ResourceTable.h
@@ -104,6 +104,8 @@
   // The actual Value.
   std::unique_ptr<Value> value;
 
+  FlagStatus flag_status;
+
   ResourceConfigValue(const android::ConfigDescription& config, android::StringPiece product)
       : config(config), product(product) {
   }
@@ -269,6 +271,7 @@
   std::optional<AllowNew> allow_new;
   std::optional<StagedId> staged_id;
   bool allow_mangled = false;
+  FlagStatus flag_status;
 };
 
 struct NewResourceBuilder {
@@ -282,6 +285,7 @@
   NewResourceBuilder& SetAllowNew(AllowNew allow_new);
   NewResourceBuilder& SetStagedId(StagedId id);
   NewResourceBuilder& SetAllowMangled(bool allow_mangled);
+  NewResourceBuilder& SetFlagStatus(FlagStatus flag_status);
   NewResource Build();
 
  private:
@@ -330,7 +334,8 @@
 
   std::unique_ptr<ResourceTable> Clone() const;
 
-  // When a collision of resources occurs, this method decides which value to keep.
+  // When a collision of resources occurs, these methods decide which value to keep.
+  static CollisionResult ResolveFlagCollision(FlagStatus existing, FlagStatus incoming);
   static CollisionResult ResolveValueCollision(Value* existing, Value* incoming);
 
   // The string pool used by this resource table. Values that reference strings must use