MediaDataSource: address API council comments

- throw IOExecption on fatal errors

- add offset argument to readAt

- and fix a crash in MediaExtractor

bug: 21045118
bug: 21163225
Change-Id: I3c0ff42e539868b9374a4f1f3a9852143f68ba68
diff --git a/media/jni/android_media_MediaExtractor.cpp b/media/jni/android_media_MediaExtractor.cpp
index b6b7a80..4e9b726 100644
--- a/media/jni/android_media_MediaExtractor.cpp
+++ b/media/jni/android_media_MediaExtractor.cpp
@@ -715,6 +715,11 @@
     status_t err = extractor->setDataSource(bridge);
 
     if (err != OK) {
+        // Clear bridge so that JMediaDataSource::close() is called _before_
+        // we throw the IOException.
+        // Otherwise close() gets called when we go out of scope, it calls
+        // Java with a pending exception and crashes the process.
+        bridge.clear();
         jniThrowException(
                 env,
                 "java/io/IOException",