Enable R8 shrinking of standalone system server jar service-connectivity

This change enables R8 shrinking, and R8 full mode of standalone system
server jar service-connectivity. Keep rules are specified based on the entries in
frameworks/base/services/java/com/android/server/SystemServer.java. Keep rules of classes extending SystemServer is inherited from "standalone-system-server-module-optimize-defaults", https://cs.android.com/android/platform/superproject/+/master:packages/modules/common/proguard/Android.bp, which is a set of common rules for standalone system server jar. Keep rules of proto is inherited from "proguard_basic_keeps", https://cs.android.com/android/platform/superproject/+/master:build/make/core/proguard_basic_keeps.flags, which is the common set of keep rules for all dex target.

The
size of service-connectivity will be reduced by 31% from 2094301B to 1426485B.

Test: Presubmit and MTS. Run MTS locally with command `mts-tradefed run` with `mts-tethering`, `mts-network`, `mts-cellbroadcast` on  Pixel 4 with sunfish-userdebug image.
Bug: 233746531
Change-Id: I291c9d880a1ffc7dc87f932f9d27ce3740b9dc36
This commit is contained in:
zhidou 2022-09-06 17:58:20 +00:00 committed by Zhi Dou
parent d748bf6b6b
commit b33a2638db
2 changed files with 9 additions and 15 deletions

View file

@ -223,6 +223,9 @@ java_defaults {
name: "service-connectivity-defaults",
sdk_version: "system_server_current",
min_sdk_version: "30",
defaults: [
"standalone-system-server-module-optimize-defaults",
],
// This library combines system server jars that have access to different bootclasspath jars.
// Lower SDK service jars must not depend on higher SDK jars as that would let them
// transitively depend on the wrong bootclasspath jars. Sources also cannot be added here as
@ -252,8 +255,6 @@ java_defaults {
"com.android.tethering",
],
optimize: {
enabled: true,
shrink: true,
proguard_flags_files: ["proguard.flags"],
},
lint: { strict_updatability_linting: true },

View file

@ -1,15 +1,8 @@
# Make sure proguard keeps all connectivity classes
# TODO: instead of keeping everything, consider listing only "entry points"
# (service loader, JNI registered methods, etc) and letting the optimizer do its job
-keep class android.net.** { *; }
-keep class !com.android.server.nearby.**,com.android.server.** { *; }
# Prevent proguard from stripping out any nearby-service and fast-pair-lite-protos fields.
-keep class com.android.server.nearby.NearbyService { *; }
# Keep JNI registered methods
-keepclasseswithmembers,includedescriptorclasses class * { native <methods>; }
# The lite proto runtime uses reflection to access fields based on the names in
# the schema, keep all the fields.
# This replicates the base proguard rule used by the build by default
# (proguard_basic_keeps.flags), but needs to be specified here because the
# com.google.protobuf package is jarjared to use a package prefix.
-keepclassmembers class * extends **.com.google.protobuf.MessageLite { <fields>; }
# Keep classes extending structured message.
-keepclassmembers public class * extends **.com.android.net.module.util.Struct {
*;
}