Jared Duke 4514bdf1b7 Allow flag-guarded Java optimizations for services
Introduce a set of optional Java optimization and shrinking settings for
system server, based on the Soong variable added in aosp/1896612.
Opting in to optimizations can be achieved with either:
  * Env:
export SYSTEM_OPTIMIZE_JAVA=true
  * Make:
$(call add_soong_config_var_value,ANDROID,SYSTEM_OPTIMIZE_JAVA,true)

Note that the initial Proguard configuration is extremely conservative.
Follow-up work will refine the rules to both allow additional shrinking
while avoiding developer friction and overhead when adding services and
dynamically loaded jars.

As these optimiations can change the resulting stack traces, a parallel
effort is working to simplify retracing of stack traces for more
accurate debugging and diagnostics. Additional stabiliation and testing
will occur before any effort to enable these optimizations by default
for specific targets. Also note that there are no plans to enable
obfuscation for any of these targets.

Preliminary results:
  * Conservative keep rules (this CL w/ opt-in flag):
    * services.jar (19MB -> 15MB)
    * services.odex (52MB -> 54MB) (mostly from increased inlining)
  * Refined keep rules (follow-up CL):
    * services.jar (19MB -> 12MB)
    * services.odex (52MB -> 45MB)

Bug: 203088572
Test: SYSTEM_OPTIMIZE_JAVA=true m (validate services.jar/odex change)
Change-Id: I4130233310323611f63cd9bfcc0646080cf95875
2021-12-03 12:31:30 -08:00

11 lines
482 B
Plaintext

# TODO(b/196084106): Refine and optimize this configuration. Note that this
# configuration is only used when `SOONG_CONFIG_ANDROID_SYSTEM_OPTIMIZE_JAVA=true`.
-keep,allowoptimization,allowaccessmodification class ** {
*;
}
# Various classes subclassed in ethernet-service (avoid marking final).
-keep public class android.net.** { *; }
# Referenced via CarServiceHelperService in car-frameworks-service (avoid removing).
-keep public class com.android.server.utils.Slogf { *; }