From 23d05c31b6a01be11f5978dad74351c486ee5ac1 Mon Sep 17 00:00:00 2001 From: Arthur Ishiguro Date: Fri, 7 Jan 2022 01:30:39 +0000 Subject: [PATCH] Update AidlContextHubWrapper methods Bug: 213474931 Test: Compile Change-Id: Icf6d90f24191a49ea27f6aab91075e64b181985e --- .../contexthub/IContextHubWrapper.java | 51 ++++++++++++++----- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java b/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java index cc5aaf4f7f452..f84b68e7c5569 100644 --- a/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java +++ b/services/core/java/com/android/server/location/contexthub/IContextHubWrapper.java @@ -453,8 +453,13 @@ public abstract class IContextHubWrapper { public int sendMessageToContextHub( short hostEndpointId, int contextHubId, NanoAppMessage message) throws RemoteException { - return toTransactionResult(mHub.sendMessageToHub(contextHubId, - ContextHubServiceUtil.createAidlContextHubMessage(hostEndpointId, message))); + try { + mHub.sendMessageToHub(contextHubId, + ContextHubServiceUtil.createAidlContextHubMessage(hostEndpointId, message)); + return ContextHubTransaction.RESULT_SUCCESS; + } catch (RemoteException e) { + return ContextHubTransaction.RESULT_FAILED_UNKNOWN; + } } @ContextHubTransaction.Result @@ -462,31 +467,55 @@ public abstract class IContextHubWrapper { int transactionId) throws RemoteException { android.hardware.contexthub.NanoappBinary aidlNanoAppBinary = ContextHubServiceUtil.createAidlNanoAppBinary(binary); - return toTransactionResult( - mHub.loadNanoapp(contextHubId, aidlNanoAppBinary, transactionId)); + try { + mHub.loadNanoapp(contextHubId, aidlNanoAppBinary, transactionId); + return ContextHubTransaction.RESULT_SUCCESS; + } catch (RemoteException e) { + return ContextHubTransaction.RESULT_FAILED_UNKNOWN; + } } @ContextHubTransaction.Result public int unloadNanoapp(int contextHubId, long nanoappId, int transactionId) throws RemoteException { - return toTransactionResult(mHub.unloadNanoapp(contextHubId, nanoappId, transactionId)); + try { + mHub.unloadNanoapp(contextHubId, nanoappId, transactionId); + return ContextHubTransaction.RESULT_SUCCESS; + } catch (RemoteException e) { + return ContextHubTransaction.RESULT_FAILED_UNKNOWN; + } } @ContextHubTransaction.Result public int enableNanoapp(int contextHubId, long nanoappId, int transactionId) throws RemoteException { - return toTransactionResult(mHub.enableNanoapp(contextHubId, nanoappId, transactionId)); + try { + mHub.enableNanoapp(contextHubId, nanoappId, transactionId); + return ContextHubTransaction.RESULT_SUCCESS; + } catch (RemoteException e) { + return ContextHubTransaction.RESULT_FAILED_UNKNOWN; + } } @ContextHubTransaction.Result public int disableNanoapp(int contextHubId, long nanoappId, int transactionId) throws RemoteException { - return toTransactionResult(mHub.disableNanoapp(contextHubId, nanoappId, transactionId)); + try { + mHub.disableNanoapp(contextHubId, nanoappId, transactionId); + return ContextHubTransaction.RESULT_SUCCESS; + } catch (RemoteException e) { + return ContextHubTransaction.RESULT_FAILED_UNKNOWN; + } } @ContextHubTransaction.Result public int queryNanoapps(int contextHubId) throws RemoteException { - return toTransactionResult(mHub.queryNanoapps(contextHubId)); + try { + mHub.queryNanoapps(contextHubId); + return ContextHubTransaction.RESULT_SUCCESS; + } catch (RemoteException e) { + return ContextHubTransaction.RESULT_FAILED_UNKNOWN; + } } public void registerCallback(int contextHubId, ICallback callback) throws RemoteException { @@ -494,12 +523,6 @@ public abstract class IContextHubWrapper { mHub.registerCallback(contextHubId, mAidlCallbackMap.get(contextHubId)); } - @ContextHubTransaction.Result - private int toTransactionResult(boolean success) { - return success ? ContextHubTransaction.RESULT_SUCCESS - : ContextHubTransaction.RESULT_FAILED_UNKNOWN; - } - private void onSettingChanged(byte setting, boolean enabled) { try { mHub.onSettingChanged(setting, enabled);