From ea04e8fe75b6a369b487f0f9a1cc180f5227ca3c Mon Sep 17 00:00:00 2001 From: Ryan Bavetta Date: Wed, 2 Mar 2016 18:34:50 -0800 Subject: [PATCH] Fix soundtrigger test, adds null pointer check BUG:27461735 Change-Id: I95ea641e41bcaefce15004f508ddb4bed0b5f2a8 --- .../hardware/soundtrigger/SoundTrigger.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/core/java/android/hardware/soundtrigger/SoundTrigger.java b/core/java/android/hardware/soundtrigger/SoundTrigger.java index cc2b7643d3e67..b635088cb11bb 100644 --- a/core/java/android/hardware/soundtrigger/SoundTrigger.java +++ b/core/java/android/hardware/soundtrigger/SoundTrigger.java @@ -689,12 +689,19 @@ public class SoundTrigger { return false; if (triggerInData != other.triggerInData) return false; - if (captureFormat.getSampleRate() != other.captureFormat.getSampleRate()) - return false; - if (captureFormat.getEncoding() != other.captureFormat.getEncoding()) - return false; - if (captureFormat.getChannelMask() != other.captureFormat.getChannelMask()) - return false; + if (captureFormat == null) { + if (other.captureFormat != null) + return false; + } else { + if (other.captureFormat == null) + return false; + if (captureFormat.getSampleRate() != other.captureFormat.getSampleRate()) + return false; + if (captureFormat.getEncoding() != other.captureFormat.getEncoding()) + return false; + if (captureFormat.getChannelMask() != other.captureFormat.getChannelMask()) + return false; + } return true; } @@ -1002,10 +1009,10 @@ public class SoundTrigger { int encoding = in.readInt(); int channelMask = in.readInt(); captureFormat = (new AudioFormat.Builder()) - .setChannelMask(channelMask) - .setEncoding(encoding) - .setSampleRate(sampleRate) - .build(); + .setChannelMask(channelMask) + .setEncoding(encoding) + .setSampleRate(sampleRate) + .build(); } byte[] data = in.readBlob(); KeyphraseRecognitionExtra[] keyphraseExtras =