Add android.gsi.* keep rules to system server

These classes are statically linked both into the bootclasspath and
system server. Add an associated keep rule to avoid optimizing such
classes in system server, avoiding runtime issues where the class
signatures and APIs may differ from those in the framework, which take
precedence.

Also group related rules for similar bootclasspath conflicts in a single
section of the proguard config. A follow-up change will enable warnings
for such collisions, and also make it harder to introduce new violations
(by way of StrictPackagesJavaTest).

Bug: 222468116
Bug: 349245577
Test: atest CtsStrictJavaPackagesTestCases
Test: FULL_SYSTEM_OPTIMIZE_JAVA=true atest CtsStrictJavaPackagesTestCases
Test: FULL_SYSTEM_OPTIMIZE_JAVA=true + presubmit
Flag: EXEMPT bugfix
Change-Id: I017b360d3e4d62be2a07abd13340abb772d9cbbb
diff --git a/services/proguard.flags b/services/proguard.flags
index f84eff7..21d0488 100644
--- a/services/proguard.flags
+++ b/services/proguard.flags
@@ -57,9 +57,6 @@
 -keep public class com.android.server.utils.Slogf { *; }
 
 # Referenced in wear-service
-# HIDL interfaces
--keep public class android.hidl.base.** { *; }
--keep public class android.hidl.manager.** { *; }
 -keep public class com.android.server.wm.WindowManagerInternal { *; }
 
 # JNI keep rules
@@ -112,8 +109,16 @@
 -keep,allowoptimization,allowaccessmodification class com.android.server.SystemService { *; }
 -keep,allowoptimization,allowaccessmodification class com.android.server.SystemService$TargetUser { *; }
 -keep,allowoptimization,allowaccessmodification class com.android.server.usage.StorageStatsManagerLocal { *; }
--keep,allowoptimization,allowaccessmodification class com.android.internal.util.** { *; }
--keep,allowoptimization,allowaccessmodification class android.os.** { *; }
+
+# Prevent optimizations of any statically linked code that may shadow code in
+# the bootclasspath. See also StrictJavaPackagesTest for details on exceptions.
+# TODO(b/222468116): Resolve such collisions in the build system.
+-keep public class android.gsi.** { *; }
+-keep public class android.hidl.base.** { *; }
+-keep public class android.hidl.manager.** { *; }
+-keep public class android.os.** { *; }
+-keep public class com.android.internal.util.** { *; }
+-keep public class com.android.modules.utils.build.** { *; }
 
 # CoverageService guards optional jacoco class references with a runtime guard, so we can safely
 # suppress build-time warnings.