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

Commit 46e71943 authored by Jared Duke's avatar Jared Duke
Browse files

Clean up KeepForWeakReference usage

We now rely on the WeaklyReferencedCallback annotation to automatically
preserve fields that are needed to keep callback type instances that are
weakly referenced when registered.

The affected members should be identically preserved with this change.

Bug: 349245577
Test: FULL_SYSTEM_OPTIMIZE_JAVA=true m services
Flag: EXEMPT refactor
Change-Id: Iff7e56d3537c4fdf8d5baff196e87ea315b60b88
parent 228ccb46
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.util.Log;
import android.util.Slog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.WeaklyReferencedCallback;
import com.android.internal.os.BackgroundThread;

import java.lang.ref.WeakReference;
@@ -46,6 +47,7 @@ import java.util.concurrent.Executor;
 * Helper class for monitoring the state of packages: adding, removing,
 * updating, and disappearing and reappearing on the SD card.
 */
@WeaklyReferencedCallback
public abstract class PackageMonitor extends android.content.BroadcastReceiver {
    static final String TAG = "PackageMonitor";

+0 −3
Original line number Diff line number Diff line
@@ -49,7 +49,6 @@ import android.view.RoundedCorners;
import android.view.SurfaceControl;

import com.android.internal.R;
import com.android.internal.annotations.KeepForWeakReference;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.display.BrightnessSynchronizer;
import com.android.internal.util.function.pooled.PooledLambda;
@@ -1468,9 +1467,7 @@ final class LocalDisplayAdapter extends DisplayAdapter {
    }

    public static class Injector {
        // Ensure the callback is kept to preserve native weak reference lifecycle semantics.
        @SuppressWarnings("unused")
        @KeepForWeakReference
        private ProxyDisplayEventReceiver mReceiver;
        public void setDisplayEventListenerLocked(Looper looper, DisplayEventListener listener) {
            mReceiver = new ProxyDisplayEventReceiver(looper, listener);
+0 −2
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@ import android.util.AtomicFile;
import android.util.Slog;
import android.util.Xml;

import com.android.internal.annotations.KeepForWeakReference;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.content.PackageMonitor;
import com.android.internal.util.FrameworkStatsLog;
@@ -101,7 +100,6 @@ public class LocaleManagerService extends SystemService {

    private LocaleManagerBackupHelper mBackupHelper;

    @KeepForWeakReference
    private final PackageMonitor mPackageMonitor;

    private final Object mWriteLock = new Object();
+0 −2
Original line number Diff line number Diff line
@@ -81,7 +81,6 @@ import android.util.Slog;
import android.util.SparseArray;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.KeepForWeakReference;
import com.android.internal.content.PackageMonitor;
import com.android.internal.content.om.OverlayConfig;
import com.android.internal.util.ArrayUtils;
@@ -263,7 +262,6 @@ public final class OverlayManagerService extends SystemService {

    private final OverlayActorEnforcer mActorEnforcer;

    @KeepForWeakReference
    private final PackageMonitor mPackageMonitor = new OverlayManagerPackageMonitor();

    private int mPrevStartedUserId = -1;
+0 −5
Original line number Diff line number Diff line
@@ -131,7 +131,6 @@ 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;
@@ -2008,11 +2007,7 @@ public final class SensorPrivacyService extends SystemService {
    }

    private class CallStateHelper {
        // 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;
Loading