Initial support for R8 based tracing of resource access.

This adds R class specific tracing to the enqueuer marking resource
reachable in the model when we read fields in the R class.

We build ir for the R classes in the analysis to extract the assigned
values of both integer fields and array values in stylable arrays.

This setup only works with non final fields in the R classes (outside
of testing) since we otherwise would not get the field reads.

Bug: b/287398085
Bug: b/310556986
Change-Id: I4553be74fc3856ee42fc2cf9f771ea98190a4b0e
diff --git a/src/resourceshrinker/java/com/android/build/shrinker/r8integration/LegacyResourceShrinker.java b/src/resourceshrinker/java/com/android/build/shrinker/r8integration/LegacyResourceShrinker.java
index b9b0629..ad7ddfb 100644
--- a/src/resourceshrinker/java/com/android/build/shrinker/r8integration/LegacyResourceShrinker.java
+++ b/src/resourceshrinker/java/com/android/build/shrinker/r8integration/LegacyResourceShrinker.java
@@ -123,6 +123,10 @@
       ResourceTable loadedResourceTable = ResourceTable.parseFrom(pathAndBytes.bytes);
       model.instantiateFromResourceTable(loadedResourceTable);
     }
+    return shrinkModel(model);
+  }
+
+  public ShrinkerResult shrinkModel(R8ResourceShrinkerModel model) throws IOException {
     for (Entry<String, byte[]> entry : dexInputs.entrySet()) {
       // The analysis needs an origin for the dex files, synthesize an easy recognizable one.
       Path inMemoryR8 = Paths.get("in_memory_r8_" + entry.getKey() + ".dex");
diff --git a/src/resourceshrinker/java/com/android/build/shrinker/r8integration/R8ResourceShrinkerState.java b/src/resourceshrinker/java/com/android/build/shrinker/r8integration/R8ResourceShrinkerState.java
index d8ac6a9..8273c96 100644
--- a/src/resourceshrinker/java/com/android/build/shrinker/r8integration/R8ResourceShrinkerState.java
+++ b/src/resourceshrinker/java/com/android/build/shrinker/r8integration/R8ResourceShrinkerState.java
@@ -19,6 +19,7 @@
 import java.util.List;
 
 public class R8ResourceShrinkerState {
+
   private R8ResourceShrinkerModel r8ResourceShrinkerModel;
 
   public List<String> trace(int id) {
@@ -32,6 +33,10 @@
     r8ResourceShrinkerModel.instantiateFromResourceTable(inputStream);
   }
 
+  public R8ResourceShrinkerModel getR8ResourceShrinkerModel() {
+    return r8ResourceShrinkerModel;
+  }
+
   public static class R8ResourceShrinkerModel extends ResourceShrinkerModel {
 
     public R8ResourceShrinkerModel(