Loading services/core/java/com/android/server/location/contexthub/ContextHubEndpointBroker.java +27 −11 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.hardware.location.ContextHubTransaction; import android.hardware.location.IContextHubTransactionCallback; import android.hardware.location.NanoAppState; import android.os.Binder; import android.os.DeadObjectException; import android.os.IBinder; import android.os.PowerManager; import android.os.PowerManager.WakeLock; Loading Loading @@ -90,8 +91,8 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub /** The context of the service. */ private final Context mContext; /** The shared executor service for handling session operation timeout. */ private final ScheduledExecutorService mSessionTimeoutExecutor; /** The shared executor service to defer operations. */ private final ScheduledExecutorService mExecutor; /** The proxy to talk to the Context Hub HAL for endpoint communication. */ @GuardedBy("mRegistrationLock") Loading Loading @@ -267,7 +268,7 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub String packageName, String attributionTag, ContextHubTransactionManager transactionManager, ScheduledExecutorService sessionTimeoutExecutor) { ScheduledExecutorService executor) { mContext = context; mHubInterface = hubInterface; mEndpointManager = endpointManager; Loading @@ -277,7 +278,7 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub mPackageName = packageName; mAttributionTag = attributionTag; mTransactionManager = transactionManager; mSessionTimeoutExecutor = sessionTimeoutExecutor; mExecutor = executor; mPid = Binder.getCallingPid(); mUid = Binder.getCallingUid(); Loading Loading @@ -321,9 +322,20 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub mHalEndpointInfo.id, serviceDescriptor); } catch (RemoteException | IllegalArgumentException | UnsupportedOperationException e) { Log.e(TAG, "Exception while calling HAL openEndpointSession", e); cleanupSessionResources(sessionId); throw e; Log.e( TAG, "Exception on HAL openEndpointSession (id=" + sessionId + "), closing session: " + e.getMessage()); mExecutor.execute( () -> { byte reason = (e instanceof DeadObjectException) ? Reason.HUB_RESET : Reason.UNSPECIFIED; onCloseEndpointSession(sessionId, reason); }); } return sessionId; Loading Loading @@ -413,13 +425,17 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub try { getHubInterface().sendMessageToEndpoint(sessionId, halMessage); } catch (RemoteException e) { byte reason = (e instanceof DeadObjectException) ? Reason.HUB_RESET : Reason.UNSPECIFIED; Log.e( TAG, "Exception while sending message on session " + sessionId + ", closing session", e); notifySessionClosedToBoth(sessionId, Reason.UNSPECIFIED); + ", closing session: " + e.getMessage()); notifySessionClosedToBoth(sessionId, reason); } } else { IContextHubTransactionCallback wrappedCallback = Loading Loading @@ -701,7 +717,7 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub existingSessionActive = false; Session pendingSession = new Session(initiator, true); pendingSession.setSessionOpenTimeoutFuture( mSessionTimeoutExecutor.schedule( mExecutor.schedule( () -> onEndpointSessionOpenRequestTimeout(sessionId), OPEN_SESSION_REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS)); Loading services/core/java/com/android/server/location/contexthub/ContextHubEndpointManager.java +5 −5 Original line number Diff line number Diff line Loading @@ -117,8 +117,8 @@ import java.util.function.Consumer; /** The interface for endpoint communication (retrieved from HAL in init()) */ private IEndpointCommunication mHubInterface = null; /** Thread pool executor for handling timeout */ private final ScheduledExecutorService mSessionTimeoutExecutor; /** Thread pool executor to be shared with all endpoints */ private final ScheduledExecutorService mExecutor; /* * The list of previous registration records. Loading Loading @@ -168,12 +168,12 @@ import java.util.function.Consumer; IContextHubWrapper contextHubProxy, HubInfoRegistry hubInfoRegistry, ContextHubTransactionManager transactionManager, ScheduledExecutorService scheduledExecutorService) { ScheduledExecutorService executor) { mContext = context; mContextHubProxy = contextHubProxy; mHubInfoRegistry = hubInfoRegistry; mTransactionManager = transactionManager; mSessionTimeoutExecutor = scheduledExecutorService; mExecutor = executor; } /* package */ ContextHubEndpointManager( Loading Loading @@ -300,7 +300,7 @@ import java.util.function.Consumer; packageName, attributionTag, mTransactionManager, mSessionTimeoutExecutor); mExecutor); broker.register(); mEndpointMap.put(endpointId, broker); Loading services/core/java/com/android/server/location/contexthub/HubInfoRegistry.java +2 −2 Original line number Diff line number Diff line Loading @@ -179,7 +179,7 @@ class HubInfoRegistry implements ContextHubHalEndpointCallback.IEndpointLifecycl try { hubInfos = mContextHubWrapper.getHubs(); } catch (RemoteException e) { Log.e(TAG, "RemoteException while getting Hub info", e); Log.e(TAG, "RemoteException while getting Hub info: " + e.getMessage()); hubInfos = Collections.emptyList(); } Loading @@ -193,7 +193,7 @@ class HubInfoRegistry implements ContextHubHalEndpointCallback.IEndpointLifecycl try { endpointInfos = mContextHubWrapper.getEndpoints(); } catch (RemoteException e) { Log.e(TAG, "RemoteException while getting Hub info", e); Log.e(TAG, "RemoteException while getting Hub info:" + e.getMessage()); endpointInfos = Collections.emptyList(); } Loading services/tests/servicestests/src/com/android/server/location/contexthub/ContextHubEndpointTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ import android.hardware.contexthub.Reason; import android.hardware.location.IContextHubTransactionCallback; import android.hardware.location.NanoAppState; import android.os.Binder; import android.os.DeadObjectException; import android.os.RemoteException; import android.platform.test.annotations.Presubmit; import android.util.Log; Loading Loading @@ -560,6 +561,24 @@ public class ContextHubEndpointTest { unregisterExampleEndpoint(endpoint); } @Test public void testSendMessageDeadObjectExceptionClosesSession() throws RemoteException { IContextHubEndpoint endpoint = registerExampleEndpoint(); int sessionId = openTestSession(endpoint); doThrow(new DeadObjectException("Intended exception in test")) .when(mMockEndpointCommunications) .sendMessageToEndpoint(anyInt(), any(Message.class)); endpoint.sendMessage(sessionId, SAMPLE_MESSAGE, null); restartHalAndVerifyHubRegistration(); // Confirm that the service can close our session on our behalf when the HAL restarts. verify(mMockCallback).onSessionClosed(sessionId, HubEndpoint.REASON_ENDPOINT_STOPPED); assertThat(mEndpointManager.getNumAvailableSessions()).isEqualTo(SESSION_ID_RANGE); unregisterExampleEndpoint(endpoint); } /** A helper method to create a session and validates reliable message sending. */ private void testMessageTransactionInternal( IContextHubEndpoint endpoint, boolean deliverMessageStatus) throws RemoteException { Loading Loading
services/core/java/com/android/server/location/contexthub/ContextHubEndpointBroker.java +27 −11 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import android.hardware.location.ContextHubTransaction; import android.hardware.location.IContextHubTransactionCallback; import android.hardware.location.NanoAppState; import android.os.Binder; import android.os.DeadObjectException; import android.os.IBinder; import android.os.PowerManager; import android.os.PowerManager.WakeLock; Loading Loading @@ -90,8 +91,8 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub /** The context of the service. */ private final Context mContext; /** The shared executor service for handling session operation timeout. */ private final ScheduledExecutorService mSessionTimeoutExecutor; /** The shared executor service to defer operations. */ private final ScheduledExecutorService mExecutor; /** The proxy to talk to the Context Hub HAL for endpoint communication. */ @GuardedBy("mRegistrationLock") Loading Loading @@ -267,7 +268,7 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub String packageName, String attributionTag, ContextHubTransactionManager transactionManager, ScheduledExecutorService sessionTimeoutExecutor) { ScheduledExecutorService executor) { mContext = context; mHubInterface = hubInterface; mEndpointManager = endpointManager; Loading @@ -277,7 +278,7 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub mPackageName = packageName; mAttributionTag = attributionTag; mTransactionManager = transactionManager; mSessionTimeoutExecutor = sessionTimeoutExecutor; mExecutor = executor; mPid = Binder.getCallingPid(); mUid = Binder.getCallingUid(); Loading Loading @@ -321,9 +322,20 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub mHalEndpointInfo.id, serviceDescriptor); } catch (RemoteException | IllegalArgumentException | UnsupportedOperationException e) { Log.e(TAG, "Exception while calling HAL openEndpointSession", e); cleanupSessionResources(sessionId); throw e; Log.e( TAG, "Exception on HAL openEndpointSession (id=" + sessionId + "), closing session: " + e.getMessage()); mExecutor.execute( () -> { byte reason = (e instanceof DeadObjectException) ? Reason.HUB_RESET : Reason.UNSPECIFIED; onCloseEndpointSession(sessionId, reason); }); } return sessionId; Loading Loading @@ -413,13 +425,17 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub try { getHubInterface().sendMessageToEndpoint(sessionId, halMessage); } catch (RemoteException e) { byte reason = (e instanceof DeadObjectException) ? Reason.HUB_RESET : Reason.UNSPECIFIED; Log.e( TAG, "Exception while sending message on session " + sessionId + ", closing session", e); notifySessionClosedToBoth(sessionId, Reason.UNSPECIFIED); + ", closing session: " + e.getMessage()); notifySessionClosedToBoth(sessionId, reason); } } else { IContextHubTransactionCallback wrappedCallback = Loading Loading @@ -701,7 +717,7 @@ public class ContextHubEndpointBroker extends IContextHubEndpoint.Stub existingSessionActive = false; Session pendingSession = new Session(initiator, true); pendingSession.setSessionOpenTimeoutFuture( mSessionTimeoutExecutor.schedule( mExecutor.schedule( () -> onEndpointSessionOpenRequestTimeout(sessionId), OPEN_SESSION_REQUEST_TIMEOUT_SECONDS, TimeUnit.SECONDS)); Loading
services/core/java/com/android/server/location/contexthub/ContextHubEndpointManager.java +5 −5 Original line number Diff line number Diff line Loading @@ -117,8 +117,8 @@ import java.util.function.Consumer; /** The interface for endpoint communication (retrieved from HAL in init()) */ private IEndpointCommunication mHubInterface = null; /** Thread pool executor for handling timeout */ private final ScheduledExecutorService mSessionTimeoutExecutor; /** Thread pool executor to be shared with all endpoints */ private final ScheduledExecutorService mExecutor; /* * The list of previous registration records. Loading Loading @@ -168,12 +168,12 @@ import java.util.function.Consumer; IContextHubWrapper contextHubProxy, HubInfoRegistry hubInfoRegistry, ContextHubTransactionManager transactionManager, ScheduledExecutorService scheduledExecutorService) { ScheduledExecutorService executor) { mContext = context; mContextHubProxy = contextHubProxy; mHubInfoRegistry = hubInfoRegistry; mTransactionManager = transactionManager; mSessionTimeoutExecutor = scheduledExecutorService; mExecutor = executor; } /* package */ ContextHubEndpointManager( Loading Loading @@ -300,7 +300,7 @@ import java.util.function.Consumer; packageName, attributionTag, mTransactionManager, mSessionTimeoutExecutor); mExecutor); broker.register(); mEndpointMap.put(endpointId, broker); Loading
services/core/java/com/android/server/location/contexthub/HubInfoRegistry.java +2 −2 Original line number Diff line number Diff line Loading @@ -179,7 +179,7 @@ class HubInfoRegistry implements ContextHubHalEndpointCallback.IEndpointLifecycl try { hubInfos = mContextHubWrapper.getHubs(); } catch (RemoteException e) { Log.e(TAG, "RemoteException while getting Hub info", e); Log.e(TAG, "RemoteException while getting Hub info: " + e.getMessage()); hubInfos = Collections.emptyList(); } Loading @@ -193,7 +193,7 @@ class HubInfoRegistry implements ContextHubHalEndpointCallback.IEndpointLifecycl try { endpointInfos = mContextHubWrapper.getEndpoints(); } catch (RemoteException e) { Log.e(TAG, "RemoteException while getting Hub info", e); Log.e(TAG, "RemoteException while getting Hub info:" + e.getMessage()); endpointInfos = Collections.emptyList(); } Loading
services/tests/servicestests/src/com/android/server/location/contexthub/ContextHubEndpointTest.java +19 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ import android.hardware.contexthub.Reason; import android.hardware.location.IContextHubTransactionCallback; import android.hardware.location.NanoAppState; import android.os.Binder; import android.os.DeadObjectException; import android.os.RemoteException; import android.platform.test.annotations.Presubmit; import android.util.Log; Loading Loading @@ -560,6 +561,24 @@ public class ContextHubEndpointTest { unregisterExampleEndpoint(endpoint); } @Test public void testSendMessageDeadObjectExceptionClosesSession() throws RemoteException { IContextHubEndpoint endpoint = registerExampleEndpoint(); int sessionId = openTestSession(endpoint); doThrow(new DeadObjectException("Intended exception in test")) .when(mMockEndpointCommunications) .sendMessageToEndpoint(anyInt(), any(Message.class)); endpoint.sendMessage(sessionId, SAMPLE_MESSAGE, null); restartHalAndVerifyHubRegistration(); // Confirm that the service can close our session on our behalf when the HAL restarts. verify(mMockCallback).onSessionClosed(sessionId, HubEndpoint.REASON_ENDPOINT_STOPPED); assertThat(mEndpointManager.getNumAvailableSessions()).isEqualTo(SESSION_ID_RANGE); unregisterExampleEndpoint(endpoint); } /** A helper method to create a session and validates reliable message sending. */ private void testMessageTransactionInternal( IContextHubEndpoint endpoint, boolean deliverMessageStatus) throws RemoteException { Loading