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

Commit 1f69a9cf authored by Arthur Ishiguro's avatar Arthur Ishiguro
Browse files

Refactor HubEndpoint code to get active HubEndpointSession

Fixes: 378974199
Flag: android.chre.flags.offload_implementation
Test: Tests pass
Change-Id: I0b0b8cdb617c16f9972a2b7c71c009d049afc66e
parent 90bad16d
Loading
Loading
Loading
Loading
+14 −30
Original line number Diff line number Diff line
@@ -122,16 +122,11 @@ public class HubEndpoint {
                        HubEndpointInfo initiator,
                        @Nullable String serviceDescriptor)
                        throws RemoteException {
                    boolean sessionExists;
                    synchronized (mLock) {
                        sessionExists = mActiveSessions.contains(sessionId);
                        // TODO(b/378974199): Consider refactor these assertions
                    boolean sessionExists = getActiveSession(sessionId) != null;
                    if (sessionExists) {
                        Log.w(
                                TAG,
                                    "onSessionOpenComplete: session already exists, id="
                                            + sessionId);
                        }
                                "onSessionOpenComplete: session already exists, id=" + sessionId);
                    }

                    if (!sessionExists && mLifecycleCallback != null) {
@@ -150,13 +145,7 @@ public class HubEndpoint {

                @Override
                public void onSessionOpenComplete(int sessionId) throws RemoteException {
                    final HubEndpointSession activeSession;

                    // Retrieve the active session
                    synchronized (mLock) {
                        activeSession = mActiveSessions.get(sessionId);
                    }
                    // TODO(b/378974199): Consider refactor these assertions
                    final HubEndpointSession activeSession = getActiveSession(sessionId);
                    if (activeSession == null) {
                        Log.w(
                                TAG,
@@ -179,13 +168,7 @@ public class HubEndpoint {

                @Override
                public void onSessionClosed(int sessionId, int reason) throws RemoteException {
                    final HubEndpointSession activeSession;

                    // Retrieve the active session
                    synchronized (mLock) {
                        activeSession = mActiveSessions.get(sessionId);
                    }
                    // TODO(b/378974199): Consider refactor these assertions
                    final HubEndpointSession activeSession = getActiveSession(sessionId);
                    if (activeSession == null) {
                        Log.w(TAG, "onSessionClosed: session not active, id=" + sessionId);
                    }
@@ -211,12 +194,7 @@ public class HubEndpoint {
                @Override
                public void onMessageReceived(int sessionId, HubMessage message)
                        throws RemoteException {
                    final HubEndpointSession activeSession;

                    // Retrieve the active session
                    synchronized (mLock) {
                        activeSession = mActiveSessions.get(sessionId);
                    }
                    final HubEndpointSession activeSession = getActiveSession(sessionId);
                    if (activeSession == null) {
                        Log.w(TAG, "onMessageReceived: session not active, id=" + sessionId);
                    }
@@ -233,6 +211,12 @@ public class HubEndpoint {
                    }
                }

                private HubEndpointSession getActiveSession(int sessionId) {
                    synchronized (mLock) {
                        return mActiveSessions.get(sessionId);
                    }
                }

                private void sendMessageDeliveryStatus(
                        int sessionId, HubMessage message, byte errorCode) {
                    if (message.isResponseRequired()) {