Remove need for EapAuthenticator to take a callback handler

EapAuthenticator is already a handler, and as such should not need to
take in an additional handler to perform the callbacks.

Bug: 137396147
Test: FrameworksIkeTests ran, passing
Change-Id: I0a489383a5f7b5612e8301a5fd0839b8321d8cca
diff --git a/src/java/com/android/ike/eap/EapAuthenticator.java b/src/java/com/android/ike/eap/EapAuthenticator.java
index d60020f..eca9969 100644
--- a/src/java/com/android/ike/eap/EapAuthenticator.java
+++ b/src/java/com/android/ike/eap/EapAuthenticator.java
@@ -46,7 +46,6 @@
     private final Executor mWorkerPool;
     private final EapStateMachine mStateMachine;
     private final IEapCallback mCb;
-    private final Handler mCbHandler;
     private final long mTimeoutMillis;
     private boolean mCallbackFired = false;
 
@@ -61,13 +60,11 @@
      */
     public EapAuthenticator(
             Looper looper,
-            Handler cbHandler,
             IEapCallback cb,
             Context context,
             EapSessionConfig eapSessionConfig) {
         this(
                 looper,
-                cbHandler,
                 cb,
                 new EapStateMachine(context, eapSessionConfig, new SecureRandom()),
                 Executors.newSingleThreadExecutor(),
@@ -77,14 +74,12 @@
     @VisibleForTesting
     EapAuthenticator(
             Looper looper,
-            Handler cbHandler,
             IEapCallback cb,
             EapStateMachine eapStateMachine,
             Executor executor,
             long timeoutMillis) {
         super(looper);
 
-        mCbHandler = cbHandler;
         mCb = cb;
         mStateMachine = eapStateMachine;
         mWorkerPool = executor;
@@ -108,48 +103,54 @@
         // reset
         mCallbackFired = false;
 
-        mCbHandler.postDelayed(() -> {
-            if (!mCallbackFired) {
-                // Fire failed callback
-                mCallbackFired = true;
-                mCb.onError(new TimeoutException("Timeout while processing message"));
-            }
-        }, EapAuthenticator.this, mTimeoutMillis);
+        postDelayed(
+                () -> {
+                    if (!mCallbackFired) {
+                        // Fire failed callback
+                        mCallbackFired = true;
+                        mCb.onError(new TimeoutException("Timeout while processing message"));
+                    }
+                },
+                EapAuthenticator.this,
+                mTimeoutMillis);
 
         // proxy to worker thread for async processing
-        mWorkerPool.execute(() -> {
-            // Any unhandled exceptions within the state machine are caught here to make sure that
-            // the caller does not wait for the full timeout duration before being notified of a
-            // failure.
-            EapResult processResponse;
-            try {
-                processResponse = mStateMachine.process(msgBytes);
-            } catch (Exception ex) {
-                Log.e(TAG, "Exception thrown while processing message", ex);
-                processResponse = new EapError(ex);
-            }
-
-            final EapResult finalProcessResponse = processResponse;
-            mCbHandler.post(() -> {
-                // No synchronization needed, since Handler serializes
-                if (!mCallbackFired) {
-                    if (finalProcessResponse instanceof EapResponse) {
-                        mCb.onResponse(((EapResponse) finalProcessResponse).packet);
-                    } else if (finalProcessResponse instanceof EapError) {
-                        mCb.onError(((EapError) finalProcessResponse).cause);
-                    } else if (finalProcessResponse instanceof EapSuccess) {
-                        EapSuccess eapSuccess = (EapSuccess) finalProcessResponse;
-                        mCb.onSuccess(eapSuccess.msk, eapSuccess.emsk);
-                    } else { // finalProcessResponse instanceof EapFailure
-                        mCb.onFail();
+        mWorkerPool.execute(
+                () -> {
+                    // Any unhandled exceptions within the state machine are caught here to make
+                    // sure that the caller does not wait for the full timeout duration before being
+                    // notified of a failure.
+                    EapResult processResponse;
+                    try {
+                        processResponse = mStateMachine.process(msgBytes);
+                    } catch (Exception ex) {
+                        Log.e(TAG, "Exception thrown while processing message", ex);
+                        processResponse = new EapError(ex);
                     }
 
-                    mCallbackFired = true;
+                    final EapResult finalProcessResponse = processResponse;
+                    EapAuthenticator.this.post(
+                            () -> {
+                                // No synchronization needed, since Handler serializes
+                                if (!mCallbackFired) {
+                                    if (finalProcessResponse instanceof EapResponse) {
+                                        mCb.onResponse(((EapResponse) finalProcessResponse).packet);
+                                    } else if (finalProcessResponse instanceof EapError) {
+                                        mCb.onError(((EapError) finalProcessResponse).cause);
+                                    } else if (finalProcessResponse instanceof EapSuccess) {
+                                        EapSuccess eapSuccess = (EapSuccess) finalProcessResponse;
+                                        mCb.onSuccess(eapSuccess.msk, eapSuccess.emsk);
+                                    } else { // finalProcessResponse instanceof EapFailure
+                                        mCb.onFail();
+                                    }
 
-                    // Ensure delayed timeout runnable does not fire
-                    mCbHandler.removeCallbacksAndMessages(EapAuthenticator.this);
-                }
-            });
-        });
+                                    mCallbackFired = true;
+
+                                    // Ensure delayed timeout runnable does not fire
+                                    EapAuthenticator.this.removeCallbacksAndMessages(
+                                            EapAuthenticator.this);
+                                }
+                            });
+                });
     }
 }
diff --git a/tests/iketests/src/java/com/android/ike/eap/EapAuthenticatorTest.java b/tests/iketests/src/java/com/android/ike/eap/EapAuthenticatorTest.java
index 3026933..11d4661 100644
--- a/tests/iketests/src/java/com/android/ike/eap/EapAuthenticatorTest.java
+++ b/tests/iketests/src/java/com/android/ike/eap/EapAuthenticatorTest.java
@@ -32,7 +32,6 @@
 import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.when;
 
-import android.os.Handler;
 import android.os.Looper;
 import android.os.test.TestLooper;
 
@@ -64,7 +63,6 @@
 
     private EapStateMachine mMockEapStateMachine;
 
-    private Handler mCallbackHandler;
     private TestLooper mTestLooper;
     private boolean mCallbackFired;
 
@@ -75,7 +73,6 @@
         mMockEapStateMachine = mock(EapStateMachine.class);
 
         mTestLooper = new TestLooper();
-        mCallbackHandler = new Handler(mTestLooper.getLooper());
         mCallbackFired = false;
     }
 
@@ -225,7 +222,6 @@
     private EapAuthenticator getEapAuthenticatorWithCallback(EapCallback eapCallback) {
         return new EapAuthenticator(
                 mTestLooper.getLooper(),
-                mCallbackHandler,
                 eapCallback,
                 mMockEapStateMachine,
                 (runnable) -> runnable.run(),
diff --git a/tests/iketests/src/java/com/android/ike/eap/EapSimTest.java b/tests/iketests/src/java/com/android/ike/eap/EapSimTest.java
index 6f53c75..0dc4065 100644
--- a/tests/iketests/src/java/com/android/ike/eap/EapSimTest.java
+++ b/tests/iketests/src/java/com/android/ike/eap/EapSimTest.java
@@ -27,7 +27,6 @@
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
-import android.os.Handler;
 import android.os.test.TestLooper;
 import android.telephony.TelephonyManager;
 
@@ -99,7 +98,6 @@
     private IEapCallback mMockCallback;
 
     private TestLooper mTestLooper;
-    private Handler mHandler;
     private EapSessionConfig mEapSessionConfig;
     private EapAuthenticator mEapAuthenticator;
 
@@ -111,12 +109,10 @@
         mMockCallback = mock(IEapCallback.class);
 
         mTestLooper = new TestLooper();
-        mHandler = new Handler(mTestLooper.getLooper());
         mEapSessionConfig = new EapSessionConfig.Builder().setEapSimConfig(SUB_ID).build();
         mEapAuthenticator =
                 new EapAuthenticator(
                         mTestLooper.getLooper(),
-                        mHandler,
                         mMockCallback,
                         new EapStateMachine(mMockContext, mEapSessionConfig, mMockSecureRandom),
                         (runnable) -> runnable.run(),