From 46a8fc712a1ac3fbd9df81937da73aacf9b3954a Mon Sep 17 00:00:00 2001 From: Arthur Ishiguro Date: Fri, 10 Sep 2021 10:51:19 -0700 Subject: [PATCH] Catch exceptions when creating AIDL nanoapp binary Avoid remote exception at the service. Bug: 194285834 Test: Run CHQTS bad nanoapp test and verify no crash Change-Id: I235f8e950ad747b99eedec41da70bac045bd29f5 --- .../location/contexthub/ContextHubServiceUtil.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/location/contexthub/ContextHubServiceUtil.java b/services/core/java/com/android/server/location/contexthub/ContextHubServiceUtil.java index 1de749bd5b9d1..2cdf75d98659a 100644 --- a/services/core/java/com/android/server/location/contexthub/ContextHubServiceUtil.java +++ b/services/core/java/com/android/server/location/contexthub/ContextHubServiceUtil.java @@ -165,7 +165,18 @@ import java.util.List; aidlNanoAppBinary.flags = nanoAppBinary.getFlags(); aidlNanoAppBinary.targetChreApiMajorVersion = nanoAppBinary.getTargetChreApiMajorVersion(); aidlNanoAppBinary.targetChreApiMinorVersion = nanoAppBinary.getTargetChreApiMinorVersion(); - aidlNanoAppBinary.customBinary = nanoAppBinary.getBinaryNoHeader(); + // This explicit definition is required to avoid erroneous behavior at the binder. + aidlNanoAppBinary.customBinary = new byte[0]; + + // Log exceptions while processing the binary, but continue to pass down the binary + // since the error checking is deferred to the Context Hub. + try { + aidlNanoAppBinary.customBinary = nanoAppBinary.getBinaryNoHeader(); + } catch (IndexOutOfBoundsException e) { + Log.w(TAG, e.getMessage()); + } catch (NullPointerException e) { + Log.w(TAG, "NanoApp binary was null"); + } return aidlNanoAppBinary; }