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

Commit 46ca9b54 authored by Brad Ebinger's avatar Brad Ebinger Committed by Android (Google) Code Review
Browse files

Revert "Revert "Speculative fix for concurrency SessionManager i..."

Revert submission 30287372-revert-30239784-spec_session_fix-ZAKHYQBVDW

Reason for revert: broken build due to automerger issue: b/377750579

Reverted changes: /q/submissionid:30287372-revert-30239784-spec_session_fix-ZAKHYQBVDW

Change-Id: I82785545a00ba98385e5cda279731170c979144d
parent 5d8accdd
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ public class Log {
    // Used to synchronize singleton logging lazy initialization
    private static final Object sSingletonSync = new Object();
    private static EventManager sEventManager;
    private static SessionManager sSessionManager;
    private static volatile SessionManager sSessionManager;
    private static Object sLock = null;

    /**
@@ -379,6 +379,23 @@ public class Log {
        return sSessionManager;
    }

    @VisibleForTesting
    public static SessionManager setSessionManager(Context context,
            java.lang.Runnable cleanSessionRunnable) {
        // Checking for null again outside of synchronization because we only need to synchronize
        // during the lazy loading of the session logger. We don't need to synchronize elsewhere.
        if (sSessionManager == null) {
            synchronized (sSingletonSync) {
                if (sSessionManager == null) {
                    sSessionManager = new SessionManager(cleanSessionRunnable);
                    sSessionManager.setContext(context);
                    return sSessionManager;
                }
            }
        }
        return sSessionManager;
    }

    public static void setTag(String tag) {
        TAG = tag;
        DEBUG = isLoggable(android.util.Log.DEBUG);
+21 −13
Original line number Diff line number Diff line
@@ -62,9 +62,7 @@ public class SessionManager {

    @VisibleForTesting
    public final ConcurrentHashMap<Integer, Session> mSessionMapper = new ConcurrentHashMap<>(64);
    @VisibleForTesting
    public java.lang.Runnable mCleanStaleSessions = () ->
            cleanupStaleSessions(getSessionCleanupTimeoutMs());
    private final java.lang.Runnable mCleanStaleSessions;
    private final Handler mSessionCleanupHandler = new Handler(Looper.getMainLooper());

    // Overridden in LogTest to skip query to ContentProvider
@@ -110,27 +108,37 @@ public class SessionManager {
    }

    public SessionManager() {
        mCleanStaleSessions = () -> cleanupStaleSessions(getSessionCleanupTimeoutMs());
    }

    @VisibleForTesting
    public SessionManager(java.lang.Runnable cleanStaleSessionsRunnable) {
        mCleanStaleSessions = cleanStaleSessionsRunnable;
    }

    private long getSessionCleanupTimeoutMs() {
        return mSessionCleanupTimeoutMs.get();
    }

    private synchronized void resetStaleSessionTimer() {
    private void resetStaleSessionTimer() {
        if (!Flags.endSessionImprovements()) {
            mSessionCleanupHandler.removeCallbacksAndMessages(null);
            resetStaleSessionTimerOld();
            return;
        }
        // Will be null in Log Testing
            if (mCleanStaleSessions != null) {
        if (mCleanStaleSessions == null) return;
        synchronized (mSessionCleanupHandler) {
            if (!mSessionCleanupHandler.hasCallbacks(mCleanStaleSessions)) {
                mSessionCleanupHandler.postDelayed(mCleanStaleSessions,
                        getSessionCleanupTimeoutMs());
            }
        } else {
            if (mCleanStaleSessions != null
                    && !mSessionCleanupHandler.hasCallbacks(mCleanStaleSessions)) {
                mSessionCleanupHandler.postDelayed(mCleanStaleSessions,
                        getSessionCleanupTimeoutMs());
        }
    }

    private synchronized void resetStaleSessionTimerOld() {
        if (mCleanStaleSessions == null) return;
        mSessionCleanupHandler.removeCallbacksAndMessages(null);
        mSessionCleanupHandler.postDelayed(mCleanStaleSessions, getSessionCleanupTimeoutMs());
    }

    /**