Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1a7211b4 authored by Jared Duke's avatar Jared Duke
Browse files

Keep members needed for downstream weak refs

Annotate several fields that are needed solely to keep alive downstream
weak refs. A more general solution is being pursued, but for now this
addresses some of the known issues when full optimization is enabled.

Test: FULL_SYSTEM_OPTIMIZE_JAVA=true m + check member preserved
Bug: 349245577
Flag: EXEMPT bugfix
Change-Id: I3683fd9909cd7881a907a26b8dcd564d1877df64
parent 37d1bca6
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.telephony.TelephonyManager;
import android.telephony.emergency.EmergencyNumber;
import android.util.Log;

import com.android.internal.annotations.KeepForWeakReference;
import com.android.internal.telephony.flags.Flags;

import java.util.concurrent.TimeUnit;
@@ -94,6 +95,7 @@ public class GpsNetInitiatedHandler {

    // The internal implementation of TelephonyManager uses WeakReference so we have to keep a
    // reference here.
    @KeepForWeakReference
    private final EmergencyCallListener mEmergencyCallListener = new EmergencyCallListener();

    private final EmergencyCallCallback mEmergencyCallCallback;
+7 −2
Original line number Diff line number Diff line
@@ -135,6 +135,7 @@ import android.util.proto.ProtoOutputStream;

import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.KeepForWeakReference;
import com.android.internal.camera.flags.Flags;
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.internal.os.BackgroundThread;
@@ -2006,8 +2007,12 @@ public final class SensorPrivacyService extends SystemService {
    }

    private class CallStateHelper {
        private OutgoingEmergencyStateCallback mEmergencyStateCallback;
        private CallStateCallback mCallStateCallback;
        // TelephonyCallback instances are only weakly referenced when registered, so we need
        // to ensure these fields are kept during optimization to preserve lifecycle semantics.
        @KeepForWeakReference
        private final OutgoingEmergencyStateCallback mEmergencyStateCallback;
        @KeepForWeakReference
        private final CallStateCallback mCallStateCallback;

        private boolean mIsInEmergencyCall;
        private boolean mMicUnmutedForEmergencyCall;
+3 −0
Original line number Diff line number Diff line
@@ -367,6 +367,7 @@ import android.window.WindowOnBackInvokedDispatcher;

import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.KeepForWeakReference;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.ResolverActivity;
import com.android.internal.content.ReferrerIntent;
@@ -938,6 +939,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A

    private RemoteCallbackList<IScreenCaptureObserver> mCaptureCallbacks;

    // Ensure the field is kept during optimization to preserve downstream weak refs.
    @KeepForWeakReference
    private final ColorDisplayService.ColorTransformController mColorTransformController =
            (matrix, translation) -> mWmService.mH.post(() -> {
                synchronized (mWmService.mGlobalLock) {