From 1b05e74010108cdc7a5669bf4089788530a662cc Mon Sep 17 00:00:00 2001 From: Jared Duke Date: Fri, 6 Jan 2023 21:53:58 +0000 Subject: [PATCH] Ensure weakly referenced callback fields are kept Under certain conditions, R8 can optimize away write-only fields. However, this isn't safe if the fields are implicitly used as strong references that keep alive downstream weak references. Add a keep rule to handle this for various callback field types. Follow-up work will explore more general ways of avoiding undesirable optimizations for similiar cases. Change-Id: I5d21fad848eda7580fa150d03fd838d0b87b96a0 Test: m SystemUI + `dexdump SystemUI.apk | grep mCurrentUserTracker` Bug: 264686688,234609147 --- packages/SystemUI/proguard.flags | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/SystemUI/proguard.flags b/packages/SystemUI/proguard.flags index f96644fbd6673..030eaa660c9f1 100644 --- a/packages/SystemUI/proguard.flags +++ b/packages/SystemUI/proguard.flags @@ -16,6 +16,18 @@ public (); } +# Needed to ensure callback field references are kept in their respective +# owning classes when the downstream callback registrars only store weak refs. +# TODO(b/264686688): Handle these cases with more targeted annotations. +-keepclassmembers,allowaccessmodification class com.android.systemui.**, com.android.keyguard.** { + private com.android.keyguard.KeyguardUpdateMonitorCallback *; + private com.android.systemui.privacy.PrivacyItemController$Callback *; + private com.android.systemui.settings.UserTracker$Callback *; + private com.android.systemui.statusbar.phone.StatusBarWindowCallback *; + private com.android.systemui.util.service.Observer$Callback *; + private com.android.systemui.util.service.ObservableServiceConnection$Callback *; +} + -keepclasseswithmembers class * { public (android.content.Context, android.util.AttributeSet); }