diff options
author | Andy Hung <hunga@google.com> | 2015-06-17 19:18:15 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-06-17 19:18:17 +0000 |
commit | a56eadb2737288091dc111a886ae83ae066317fa (patch) | |
tree | 811700e7dd794065f4bce1ed49dd99b841ca5179 | |
parent | 97f4d3b40754e4496caeb29ee54c330d8bc9f2d7 (diff) | |
parent | e244922ababf64fbac64c2ab375de54fa3a83f0a (diff) | |
download | frameworks_base-a56eadb2737288091dc111a886ae83ae066317fa.zip frameworks_base-a56eadb2737288091dc111a886ae83ae066317fa.tar.gz frameworks_base-a56eadb2737288091dc111a886ae83ae066317fa.tar.bz2 |
Merge "AudioRecord.Builder should throw exception on failure." into mnc-dev
-rw-r--r-- | media/java/android/media/AudioRecord.java | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/media/java/android/media/AudioRecord.java b/media/java/android/media/AudioRecord.java index 3cbc405..974b62e 100644 --- a/media/java/android/media/AudioRecord.java +++ b/media/java/android/media/AudioRecord.java @@ -527,10 +527,11 @@ public class AudioRecord } /** - * @return a new {@link AudioRecord} instance initialized with all the parameters set - * on this <code>Builder</code> + * @return a new {@link AudioRecord} instance successfully initialized with all + * the parameters set on this <code>Builder</code>. * @throws UnsupportedOperationException if the parameters set on the <code>Builder</code> - * were incompatible, or if they are not supported by the device. + * were incompatible, or if they are not supported by the device, + * or if the device was not available. */ public AudioRecord build() throws UnsupportedOperationException { if (mFormat == null) { @@ -564,7 +565,13 @@ public class AudioRecord mBufferSizeInBytes = mFormat.getChannelCount() * mFormat.getBytesPerSample(mFormat.getEncoding()); } - return new AudioRecord(mAttributes, mFormat, mBufferSizeInBytes, mSessionId); + final AudioRecord record = new AudioRecord( + mAttributes, mFormat, mBufferSizeInBytes, mSessionId); + if (record.getState() == STATE_UNINITIALIZED) { + // release is not necessary + throw new UnsupportedOperationException("Cannot create AudioRecord"); + } + return record; } catch (IllegalArgumentException e) { throw new UnsupportedOperationException(e.getMessage()); } |