Fix GC of SharedStates. Accessible ContentIds should be prefixed with
SHARED_STATE_PREFIX.

PiperOrigin-RevId: 251470475
Change-Id: I9c906f93b9d7723b1d285011e392bd155627b2bc
diff --git a/src/main/java/com/google/android/libraries/feed/feedstore/internal/ContentGc.java b/src/main/java/com/google/android/libraries/feed/feedstore/internal/ContentGc.java
index 43b41f4..cc4aea1 100644
--- a/src/main/java/com/google/android/libraries/feed/feedstore/internal/ContentGc.java
+++ b/src/main/java/com/google/android/libraries/feed/feedstore/internal/ContentGc.java
@@ -76,6 +76,8 @@
     population.removeAll(getUploadableActionProperties(getUploadableActions()));
     if (keepSharedStates) {
       filterSharedStates(population);
+    } else {
+      population.removeAll(getAccessibleSharedStates(accessibleContent));
     }
 
     // Population now contains only un-accessible items
@@ -173,6 +175,18 @@
     return semanticPropertiesKeys;
   }
 
+  private Set<String> getAccessibleSharedStates(Set<String> accessibleContent) {
+    ElapsedTimeTracker tracker = timingUtils.getElapsedTimeTracker(TAG);
+    Set<String> sharedStateKeys = new HashSet<>();
+    for (String accessibleContentId : accessibleContent) {
+      String sharedStateKey = SHARED_STATE_PREFIX + accessibleContentId;
+      sharedStateKeys.add(sharedStateKey);
+    }
+    tracker.stop(
+        "", "getAccessibleSharedStates", "accessibleSharedStatesSize", sharedStateKeys.size());
+    return sharedStateKeys;
+  }
+
   private Set<String> getLocalActionSemanticProperties(Set<StreamLocalAction> actions) {
     ElapsedTimeTracker tracker = timingUtils.getElapsedTimeTracker(TAG);
     Set<String> semanticPropertiesKeys = new HashSet<>();
diff --git a/src/test/java/com/google/android/libraries/feed/feedstore/internal/ContentGcTest.java b/src/test/java/com/google/android/libraries/feed/feedstore/internal/ContentGcTest.java
index 791f717..f0a3949 100644
--- a/src/test/java/com/google/android/libraries/feed/feedstore/internal/ContentGcTest.java
+++ b/src/test/java/com/google/android/libraries/feed/feedstore/internal/ContentGcTest.java
@@ -369,7 +369,7 @@
     mockContentStorageWithContents(contentKeys);
     ContentGc contentGc =
         new ContentGc(
-            () -> ImmutableSet.of(SHARED_STATE_PREFIX + CONTENT_ID_1),
+            () -> ImmutableSet.of(CONTENT_ID_1),
             ImmutableSet.of(),
             ImmutableSet::of,
             ImmutableSet::of,