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

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

Merge "Remove Recursion from Telecom Session Management/Traversal" into main

parents f9945ac6 049ca168
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ aconfig_declarations {
        "telecom_bluetoothdevicemanager_flags.aconfig",
        "telecom_non_critical_security_flags.aconfig",
        "telecom_headless_system_user_mode.aconfig",
        "telecom_session_flags.aconfig",
        "telecom_metrics_flags.aconfig",
    ],
}
+13 −0
Original line number Diff line number Diff line
package: "com.android.server.telecom.flags"
container: "system"

# OWNER=breadley TARGET=25Q1
flag {
  name: "end_session_improvements"
  namespace: "telecom"
  description: "Ensure that ending a session doesnt cause a stack overflow"
  bug: "370349160"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}
 No newline at end of file
+33 −0
Original line number Diff line number Diff line
@@ -21,10 +21,14 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import android.telecom.Log;
import android.telecom.Logging.Session;
import android.telecom.Logging.SessionManager;

import com.android.server.telecom.flags.Flags;

import androidx.test.filters.SmallTest;

import org.junit.After;
@@ -411,4 +415,33 @@ public class SessionManagerTest extends TelecomTestCase {
        assertTrue(mTestSessionManager.mSessionMapper.isEmpty());
        assertNull(sessionRef.get());
    }

    /**
     * If Telecom gets into a situation where there are MANY sub-sessions created in a deep tree,
     * ensure that cleanup still happens properly.
     */
    @SmallTest
    @Test
    public void testManySubsessionCleanupStress() {
        // This test will mostly likely fail with recursion due to stack overflow
        if (!Flags.endSessionImprovements()) return;
        Log.setIsExtendedLoggingEnabled(false);
        mTestSessionManager.mCurrentThreadId = () -> TEST_PARENT_THREAD_ID;
        mTestSessionManager.startSession(TEST_PARENT_NAME, null);
        Session parentSession = mTestSessionManager.mSessionMapper.get(TEST_PARENT_THREAD_ID);
        Session subsession;
        try {
            for (int i = 0; i < 10000; i++) {
                subsession = mTestSessionManager.createSubsession();
                mTestSessionManager.endSession();
                mTestSessionManager.continueSession(subsession, TEST_CHILD_NAME + i);
            }
            mTestSessionManager.endSession();
        } catch (Exception e) {
            fail("Exception: " + e);
        }
        assertTrue(mTestSessionManager.mSessionMapper.isEmpty());
        assertTrue(parentSession.isSessionCompleted());
        assertTrue(parentSession.getChildSessions().isEmpty());
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -269,6 +269,6 @@ public class SessionTest extends TelecomTestCase {
    }

    private Session createTestSession(String name, String methodName) {
        return new Session(name, methodName, 0, false, null);
        return new Session(name, methodName, 0, false, false ,null);
    }
}