From 3027b4d017fa5e7ea57e882344256f8771f30c9e Mon Sep 17 00:00:00 2001 From: Jared Duke Date: Wed, 14 Dec 2022 12:30:14 -0800 Subject: [PATCH] Refine keep rules for Java classes w/ native methods The global keep rule for native methods allows stripping of such methods if they're unreferenced in Java. However, because system_server explicitly registers these methods from native code, stripping them in Java can cause runtime issues. As such, conservatively keep all such methods in system_server subpackages as long as the containing class is also kept or referenced. In practice, the difference is minimal, but this makes it easier to integrate optional debug pathways that have JNI interop. Bug: 246800015 Test: m services + inspect delta in services.jar Change-Id: Id1f9ab707edff9b1911cdde6bdd4bc24ebff7e49 --- services/proguard.flags | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/services/proguard.flags b/services/proguard.flags index eb5c7144c9672..4c2830e5c447d 100644 --- a/services/proguard.flags +++ b/services/proguard.flags @@ -72,6 +72,13 @@ -keep,allowoptimization,allowaccessmodification class com.android.server.wm.** implements com.android.server.wm.DisplayAreaPolicy$Provider # JNI keep rules +# The global keep rule for native methods allows stripping of such methods if they're unreferenced +# in Java. However, because system_server explicitly registers these methods from native code, +# stripping them in Java can cause runtime issues. As such, conservatively keep all such methods in +# system_server subpackages as long as the containing class is also kept or referenced. +-keepclassmembers class com.android.server.** { + native ; +} # TODO(b/210510433): Revisit and fix with @Keep, or consider auto-generating from # frameworks/base/services/core/jni/onload.cpp. -keep,allowoptimization,allowaccessmodification class com.android.server.broadcastradio.hal1.BroadcastRadioService { *; }