Add support for new SessionManager and EventManager tests

Test: Ran new unit tests
Bug: 26571395
Change-Id: I6d14d7c05b8fdc8dc1319a81f0e41f7bcd989b85
diff --git a/telecomm/java/android/telecom/Logging/SessionManager.java b/telecomm/java/android/telecom/Logging/SessionManager.java
index a4e8977..90daee0 100644
--- a/telecomm/java/android/telecom/Logging/SessionManager.java
+++ b/telecomm/java/android/telecom/Logging/SessionManager.java
@@ -19,6 +19,7 @@
 import android.content.Context;
 import android.os.Handler;
 import android.os.Looper;
+import android.os.Process;
 import android.provider.Settings;
 import android.util.Base64;
 
@@ -53,11 +54,11 @@
     private Context mContext;
 
     @VisibleForTesting
-    public ConcurrentHashMap<Integer, Session> sSessionMapper = new ConcurrentHashMap<>(100);
+    public ConcurrentHashMap<Integer, Session> mSessionMapper = new ConcurrentHashMap<>(100);
     @VisibleForTesting
-    public Handler sSessionCleanupHandler = new Handler(Looper.getMainLooper());
+    public Handler mSessionCleanupHandler = new Handler(Looper.getMainLooper());
     @VisibleForTesting
-    public java.lang.Runnable sCleanStaleSessions = () ->
+    public java.lang.Runnable mCleanStaleSessions = () ->
             cleanupStaleSessions(getSessionCleanupTimeoutMs());
 
     // Overridden in LogTest to skip query to ContentProvider
@@ -65,8 +66,16 @@
         long get();
     }
 
+    // Overridden in tests to provide test Thread IDs
+    public interface ICurrentThreadId {
+        int get();
+    }
+
     @VisibleForTesting
-    public ISessionCleanupTimeoutMs sSessionCleanupTimeoutMs = () -> {
+    public ICurrentThreadId mCurrentThreadId = Process::myTid;
+
+    @VisibleForTesting
+    public ISessionCleanupTimeoutMs mSessionCleanupTimeoutMs = () -> {
         // mContext may be null in some cases, such as testing. For these cases, use the
         // default value.
         if (mContext == null) {
@@ -99,14 +108,14 @@
     }
 
     private long getSessionCleanupTimeoutMs() {
-        return sSessionCleanupTimeoutMs.get();
+        return mSessionCleanupTimeoutMs.get();
     }
 
     private synchronized void resetStaleSessionTimer() {
-        sSessionCleanupHandler.removeCallbacksAndMessages(null);
+        mSessionCleanupHandler.removeCallbacksAndMessages(null);
         // Will be null in Log Testing
-        if (sCleanStaleSessions != null) {
-            sSessionCleanupHandler.postDelayed(sCleanStaleSessions, getSessionCleanupTimeoutMs());
+        if (mCleanStaleSessions != null) {
+            mSessionCleanupHandler.postDelayed(mCleanStaleSessions, getSessionCleanupTimeoutMs());
         }
     }
 
@@ -118,7 +127,7 @@
             String callerIdentification) {
         resetStaleSessionTimer();
         int threadId = getCallingThreadId();
-        Session activeSession = sSessionMapper.get(threadId);
+        Session activeSession = mSessionMapper.get(threadId);
         // We have called startSession within an active session that has not ended... Register this
         // session as a subsession.
         if (activeSession != null) {
@@ -128,9 +137,9 @@
         }
         Session newSession = new Session(getNextSessionID(), shortMethodName,
                 System.currentTimeMillis(), threadId, false, callerIdentification);
-        sSessionMapper.put(threadId, newSession);
+        mSessionMapper.put(threadId, newSession);
 
-        android.telecom.Log.v(LOGGING_TAG, Session.START_SESSION);
+        android.util.Slog.v(LOGGING_TAG, Session.START_SESSION);
     }
 
 
@@ -145,9 +154,9 @@
 
     private synchronized Session createSubsession(boolean isStartedFromActiveSession) {
         int threadId = getCallingThreadId();
-        Session threadSession = sSessionMapper.get(threadId);
+        Session threadSession = mSessionMapper.get(threadId);
         if (threadSession == null) {
-            android.telecom.Log.d(LOGGING_TAG, "Log.createSubsession was called with no session " +
+            android.util.Slog.d(LOGGING_TAG, "Log.createSubsession was called with no session " +
                     "active.");
             return null;
         }
@@ -159,10 +168,10 @@
         newSubsession.setParentSession(threadSession);
 
         if (!isStartedFromActiveSession) {
-            android.telecom.Log.v(LOGGING_TAG, Session.CREATE_SUBSESSION + " " +
+            android.util.Slog.v(LOGGING_TAG, Session.CREATE_SUBSESSION + " " +
                     newSubsession.toString());
         } else {
-            android.telecom.Log.v(LOGGING_TAG, Session.CREATE_SUBSESSION +
+            android.util.Slog.v(LOGGING_TAG, Session.CREATE_SUBSESSION +
                     " (Invisible subsession)");
         }
         return newSubsession;
@@ -171,14 +180,14 @@
     /**
      * Cancels a subsession that had Log.createSubsession() called on it, but will never have
      * Log.continueSession(...) called on it due to an error. Allows the subsession to be cleaned
-     * gracefully instead of being removed by the sSessionCleanupHandler forcefully later.
+     * gracefully instead of being removed by the mSessionCleanupHandler forcefully later.
      */
     public synchronized void cancelSubsession(Session subsession) {
         if (subsession == null) {
             return;
         }
 
-        subsession.markSessionCompleted(0);
+        subsession.markSessionCompleted(Session.UNDEFINED);
         endParentSessions(subsession);
     }
 
@@ -197,16 +206,16 @@
         subsession.setExecutionStartTimeMs(System.currentTimeMillis());
         Session parentSession = subsession.getParentSession();
         if (parentSession == null) {
-            android.telecom.Log.d(LOGGING_TAG, "Log.continueSession was called with no session " +
-                    "active for method %s.", shortMethodName);
+            android.util.Slog.d(LOGGING_TAG, "Log.continueSession was called with no session " +
+                    "active for method " + shortMethodName);
             return;
         }
 
-        sSessionMapper.put(getCallingThreadId(), subsession);
+        mSessionMapper.put(getCallingThreadId(), subsession);
         if (!subsession.isStartedFromActiveSession()) {
-            android.telecom.Log.v(LOGGING_TAG, Session.CONTINUE_SUBSESSION);
+            android.util.Slog.v(LOGGING_TAG, Session.CONTINUE_SUBSESSION);
         } else {
-            android.telecom.Log.v(LOGGING_TAG, Session.CONTINUE_SUBSESSION +
+            android.util.Slog.v(LOGGING_TAG, Session.CONTINUE_SUBSESSION +
                     " (Invisible Subsession) with Method " + shortMethodName);
         }
     }
@@ -217,30 +226,30 @@
      */
     public synchronized void endSession() {
         int threadId = getCallingThreadId();
-        Session completedSession = sSessionMapper.get(threadId);
+        Session completedSession = mSessionMapper.get(threadId);
         if (completedSession == null) {
-            android.telecom.Log.w(LOGGING_TAG, "Log.endSession was called with no session active.");
+            android.util.Slog.w(LOGGING_TAG, "Log.endSession was called with no session active.");
             return;
         }
 
         completedSession.markSessionCompleted(System.currentTimeMillis());
         if (!completedSession.isStartedFromActiveSession()) {
-            android.telecom.Log.v(LOGGING_TAG, Session.END_SUBSESSION + " (dur: " +
+            android.util.Slog.v(LOGGING_TAG, Session.END_SUBSESSION + " (dur: " +
                     completedSession.getLocalExecutionTime() + " mS)");
         } else {
-            android.telecom.Log.v(LOGGING_TAG, Session.END_SUBSESSION +
+            android.util.Slog.v(LOGGING_TAG, Session.END_SUBSESSION +
                     " (Invisible Subsession) (dur: " + completedSession.getLocalExecutionTime() +
                     " ms)");
         }
         // Remove after completed so that reference still exists for logging the end events
         Session parentSession = completedSession.getParentSession();
-        sSessionMapper.remove(threadId);
+        mSessionMapper.remove(threadId);
         endParentSessions(completedSession);
         // If this subsession was started from a parent session using Log.startSession, return the
         // ThreadID back to the parent after completion.
         if (parentSession != null && !parentSession.isSessionCompleted() &&
                 completedSession.isStartedFromActiveSession()) {
-            sSessionMapper.put(threadId, parentSession);
+            mSessionMapper.put(threadId, parentSession);
         }
     }
 
@@ -262,7 +271,7 @@
             // running time of the session.
             long fullSessionTimeMs =
                     System.currentTimeMillis() - subsession.getExecutionStartTimeMilliseconds();
-            android.telecom.Log.v(LOGGING_TAG, Session.END_SESSION + " (dur: " + fullSessionTimeMs
+            android.util.Slog.d(LOGGING_TAG, Session.END_SESSION + " (dur: " + fullSessionTimeMs
                     + " ms): " + subsession.toString());
             // TODO: Add analytics hook
             for (ISessionListener l : mSessionListeners) {
@@ -272,7 +281,7 @@
     }
 
     public String getSessionId() {
-        Session currentSession = sSessionMapper.get(getCallingThreadId());
+        Session currentSession = mSessionMapper.get(getCallingThreadId());
         return currentSession != null ? currentSession.toString() : "";
     }
 
@@ -304,7 +313,7 @@
     }
 
     public int getCallingThreadId() {
-        return android.os.Process.myTid();
+        return mCurrentThreadId.get();
     }
 
     @VisibleForTesting
@@ -317,7 +326,7 @@
         // If this occurs, then there is most likely a Session active that never had
         // Log.endSession called on it.
         for (Iterator<ConcurrentHashMap.Entry<Integer, Session>> it =
-             sSessionMapper.entrySet().iterator(); it.hasNext(); ) {
+             mSessionMapper.entrySet().iterator(); it.hasNext(); ) {
             ConcurrentHashMap.Entry<Integer, Session> entry = it.next();
             Session session = entry.getValue();
             if (currentTimeMs - session.getExecutionStartTimeMilliseconds() > timeoutMs) {
@@ -327,9 +336,9 @@
             }
         }
         if (isSessionsStale) {
-            android.telecom.Log.w(LOGGING_TAG, logMessage);
+            android.util.Slog.w(LOGGING_TAG, logMessage);
         } else {
-            android.telecom.Log.v(LOGGING_TAG, "No stale logging sessions needed to be cleaned...");
+            android.util.Slog.v(LOGGING_TAG, "No stale logging sessions needed to be cleaned...");
         }
     }