summaryrefslogtreecommitdiffstats
path: root/core/jni
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-02 22:54:33 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-02 22:54:33 -0800
commit3dec7d563a2f3e1eb967ce2054a00b6620e3558c (patch)
treeaa3b0365c47cb3c1607c0dc76c8d32b4046fc287 /core/jni
parent15ab3eae2ec3d73b3e8aa60b33ae41445bf83f4b (diff)
downloadframeworks_base-3dec7d563a2f3e1eb967ce2054a00b6620e3558c.zip
frameworks_base-3dec7d563a2f3e1eb967ce2054a00b6620e3558c.tar.gz
frameworks_base-3dec7d563a2f3e1eb967ce2054a00b6620e3558c.tar.bz2
auto import from //depot/cupcake/@137055
Diffstat (limited to 'core/jni')
-rw-r--r--core/jni/android_database_SQLiteDatabase.cpp8
-rw-r--r--core/jni/android_hardware_Camera.cpp286
-rw-r--r--core/jni/android_media_AudioTrack.cpp34
-rw-r--r--core/jni/android_os_ParcelFileDescriptor.cpp30
-rw-r--r--core/jni/android_server_BluetoothEventLoop.cpp9
-rw-r--r--core/jni/android_util_Binder.cpp1
-rw-r--r--core/jni/server/com_android_server_AlarmManagerService.cpp7
7 files changed, 232 insertions, 143 deletions
diff --git a/core/jni/android_database_SQLiteDatabase.cpp b/core/jni/android_database_SQLiteDatabase.cpp
index 66f0118..66858f9 100644
--- a/core/jni/android_database_SQLiteDatabase.cpp
+++ b/core/jni/android_database_SQLiteDatabase.cpp
@@ -45,6 +45,8 @@
#define INVALID_VERSION -1
#define SQLITE_SOFT_HEAP_LIMIT (4 * 1024 * 1024)
#define ANDROID_TABLE "android_metadata"
+/* uncomment the next line to force-enable logging of all statements */
+// #define DB_LOG_STATEMENTS
namespace android {
@@ -197,7 +199,11 @@ static void native_execSQL(JNIEnv* env, jobject object, jstring sqlString)
env->ReleaseStringUTFChars(sqlString, sql8);
}
- } else IF_LOGV() {
+ } else
+#ifndef DB_LOG_STATEMENTS
+ IF_LOGV()
+#endif
+ {
char const * sql8 = env->GetStringUTFChars(sqlString, NULL);
LOGV("Success on %p when executing '%s'\n", handle, sql8);
env->ReleaseStringUTFChars(sqlString, sql8);
diff --git a/core/jni/android_hardware_Camera.cpp b/core/jni/android_hardware_Camera.cpp
index 2f1f9b8..f6cd211 100644
--- a/core/jni/android_hardware_Camera.cpp
+++ b/core/jni/android_hardware_Camera.cpp
@@ -15,7 +15,9 @@
** limitations under the License.
*/
+//#define LOG_NDEBUG 0
#define LOG_TAG "Camera-JNI"
+#include <utils/Log.h>
#include "jni.h"
#include "JNIHelp.h"
@@ -45,38 +47,43 @@ enum CameraError {
struct fields_t {
jfieldID context;
jfieldID surface;
- jfieldID listener_context;
jmethodID post_event;
};
static fields_t fields;
static Mutex sLock;
-static jclass sCameraClass;
-struct callback_cookie {
- jobject camera_ref;
+struct camera_context_t {
+ jobject mCameraJObjectWeak; // weak reference to java object
+ jclass mCameraJClass; // strong reference to java class
+ sp<Camera> mCamera; // strong reference to native object
};
-sp<Camera> get_native_camera(JNIEnv *env, jobject thiz)
+sp<Camera> get_native_camera(JNIEnv *env, jobject thiz, camera_context_t** pContext)
{
+ sp<Camera> camera;
Mutex::Autolock _l(sLock);
- sp<Camera> c = reinterpret_cast<Camera*>(env->GetIntField(thiz, fields.context));
- if (c == 0)
+ camera_context_t* context = reinterpret_cast<camera_context_t*>(env->GetIntField(thiz, fields.context));
+ if (context != NULL) {
+ camera = context->mCamera;
+ }
+ LOGV("get_native_camera: context=%p, camera=%p", context, camera.get());
+ if (camera == 0) {
jniThrowException(env, "java/lang/RuntimeException", "Method called after release()");
+ }
- return c;
+ if (pContext != NULL) *pContext = context;
+ return camera;
}
static void err_callback(status_t err, void *cookie)
{
- JNIEnv *env = AndroidRuntime::getJNIEnv();
- if (env == NULL) {
- LOGE("err_callback on dead VM");
- return;
- }
- callback_cookie *c = (callback_cookie *)cookie;
- int error;
+ camera_context_t* context = reinterpret_cast<camera_context_t*>(cookie);
+ if ((context == NULL) || (context->mCamera == 0)) return;
+
+ LOGV("err_callback: context=%p, camera=%p", context, context->mCamera.get());
+ int error;
switch (err) {
case DEAD_OBJECT:
error = kCameraErrorMediaServer;
@@ -85,29 +92,32 @@ static void err_callback(status_t err, void *cookie)
error = kCameraErrorUnknown;
break;
}
- LOGV("err_callback: camera_ref=%x, cookie=%x", (int)c->camera_ref, (int)cookie);
- env->CallStaticVoidMethod(sCameraClass, fields.post_event,
- c->camera_ref, kErrorCallback, error, 0, NULL);
+ JNIEnv *env = AndroidRuntime::getJNIEnv();
+ if (env == NULL) {
+ LOGE("err_callback on dead VM");
+ return;
+ }
+ env->CallStaticVoidMethod(context->mCameraJClass, fields.post_event,
+ context->mCameraJObjectWeak, kErrorCallback, error, 0, NULL);
}
// connect to camera service
static void android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz, jobject weak_this)
{
- sp<Camera> c = Camera::connect();
+ sp<Camera> camera = Camera::connect();
- if (c == NULL) {
+ if (camera == NULL) {
jniThrowException(env, "java/lang/RuntimeException", "Out of memory");
return;
}
// make sure camera hardware is alive
- if (c->getStatus() != NO_ERROR) {
+ if (camera->getStatus() != NO_ERROR) {
jniThrowException(env, "java/io/IOException", "Camera initialization failed");
return;
}
- callback_cookie *cookie = new callback_cookie;
jclass clazz = env->GetObjectClass(thiz);
if (clazz == NULL) {
LOGE("Can't find android/hardware/Camera");
@@ -118,71 +128,84 @@ static void android_hardware_Camera_native_setup(JNIEnv *env, jobject thiz, jobj
// We use a weak reference so the Camera object can be garbage collected.
// The reference is only used as a proxy for callbacks.
- cookie->camera_ref = env->NewGlobalRef(weak_this);
- env->SetIntField(thiz, fields.listener_context, (int)cookie);
-
- LOGV("native_setup: camera_ref=%x, camera_obj=%x, cookie=%x", (int)cookie->camera_ref, (int)thiz, (int)cookie);
+ camera_context_t* context = new camera_context_t;
+ context->mCameraJObjectWeak = env->NewGlobalRef(weak_this);
+ context->mCameraJClass = (jclass)env->NewGlobalRef(clazz);
+ context->mCamera = camera;
- // save camera object in opaque field
- env->SetIntField(thiz, fields.context, reinterpret_cast<int>(c.get()));
+ // save context in opaque field
+ env->SetIntField(thiz, fields.context, (int)context);
- c->setErrorCallback(err_callback, cookie);
+ LOGV("native_setup: mCameraJObjectWeak=%x, camera_obj=%x, context=%p",
+ (int)context->mCameraJObjectWeak, (int)thiz, context);
- // hold a strong reference so the camera doesn't go away while the app is still running
- c->incStrong(thiz);
+ // set error callback
+ camera->setErrorCallback(err_callback, context);
}
// disconnect from camera service
+// It's okay to call this when the native camera context is already null.
+// This handles the case where the user has called release() and the
+// finalizer is invoked later.
static void android_hardware_Camera_release(JNIEnv *env, jobject thiz)
{
- Mutex::Autolock _l(sLock);
- sp<Camera> c = reinterpret_cast<Camera*>(env->GetIntField(thiz, fields.context));
- // It's okay to call this when the native camera context is already null.
- // This handles the case where the user has called release() and the
- // finalizer is invoked later.
- if (c != 0) {
- // Make sure that we do not attempt to deliver an eror callback on a deleted
- // Java object.
- c->setErrorCallback(NULL, NULL);
- c->disconnect();
-
- // remove our strong reference created in native setup
- c->decStrong(thiz);
- env->SetIntField(thiz, fields.context, 0);
-
- callback_cookie *cookie = (callback_cookie *)env->GetIntField(thiz, fields.listener_context);
+ camera_context_t* context = NULL;
+ sp<Camera> camera;
+ {
+ Mutex::Autolock _l(sLock);
+ context = reinterpret_cast<camera_context_t*>(env->GetIntField(thiz, fields.context));
- LOGV("release: camera_ref=%x, camera_obj=%x, cookie=%x", (int)cookie->camera_ref, (int)thiz, (int)cookie);
+ // Make sure we do not attempt to callback on a deleted Java object.
+ env->SetIntField(thiz, fields.context, 0);
+ }
- if (cookie) {
- env->DeleteGlobalRef(cookie->camera_ref);
- delete cookie;
- env->SetIntField(thiz, fields.listener_context, 0);
+ // clean up if release has not been called before
+ if (context != NULL) {
+ camera = context->mCamera;
+ context->mCamera.clear();
+ LOGV("native_release: context=%p camera=%p", context, camera.get());
+
+ // clear callbacks
+ if (camera != NULL) {
+ camera->setPreviewCallback(NULL, NULL, FRAME_CALLBACK_FLAG_NOOP);
+ camera->setErrorCallback(NULL, NULL);
+ camera->disconnect();
+ env->DeleteGlobalRef(context->mCameraJObjectWeak);
+ env->DeleteGlobalRef(context->mCameraJClass);
}
+
+ // remove context to prevent further Java access
+ delete context;
}
}
-static void android_hardware_Camera_setPreviewDisplay(JNIEnv *env, jobject thiz, jobject surface)
+static void android_hardware_Camera_setPreviewDisplay(JNIEnv *env, jobject thiz, jobject jSurface)
{
- sp<Camera> c = get_native_camera(env, thiz);
- if (c == 0)
- return;
+ LOGV("setPreviewDisplay");
+ sp<Camera> camera = get_native_camera(env, thiz, NULL);
+ if (camera == 0) return;
- sp<Surface> s = (Surface *)env->GetIntField(surface, fields.surface);
- if (c->setPreviewDisplay(s) != NO_ERROR) {
+ sp<Surface> surface = reinterpret_cast<Surface*>(env->GetIntField(jSurface, fields.surface));
+ if (camera->setPreviewDisplay(surface) != NO_ERROR) {
jniThrowException(env, "java/io/IOException", "setPreviewDisplay failed");
- return;
}
}
static void preview_callback(const sp<IMemory>& mem, void *cookie)
{
+ LOGV("preview_callback");
JNIEnv *env = AndroidRuntime::getJNIEnv();
if (env == NULL) {
LOGE("preview_callback on dead VM");
return;
}
- callback_cookie *c = (callback_cookie *)cookie;
+ camera_context_t* context = reinterpret_cast<camera_context_t*>(cookie);
+ if ((context == NULL) || (context->mCamera == 0)) {
+ LOGW("context or camera is NULL in preview_callback");
+ return;
+ }
+ LOGV("native_release: context=%p camera=%p", context, context->mCamera.get());
+
int arg1 = 0, arg2 = 0;
jobject obj = NULL;
@@ -205,18 +228,18 @@ static void preview_callback(const sp<IMemory>& mem, void *cookie)
obj = array;
- env->CallStaticVoidMethod(sCameraClass, fields.post_event,
- c->camera_ref, kPreviewCallback, arg1, arg2, obj);
+ env->CallStaticVoidMethod(context->mCameraJClass, fields.post_event,
+ context->mCameraJObjectWeak, kPreviewCallback, arg1, arg2, obj);
env->DeleteLocalRef(array);
}
static void android_hardware_Camera_startPreview(JNIEnv *env, jobject thiz)
{
- sp<Camera> c = get_native_camera(env, thiz);
- if (c == 0)
- return;
+ LOGV("startPreview");
+ sp<Camera> camera = get_native_camera(env, thiz, NULL);
+ if (camera == 0) return;
- if (c->startPreview() != NO_ERROR) {
+ if (camera->startPreview() != NO_ERROR) {
jniThrowException(env, "java/io/IOException", "startPreview failed");
return;
}
@@ -224,32 +247,30 @@ static void android_hardware_Camera_startPreview(JNIEnv *env, jobject thiz)
static void android_hardware_Camera_stopPreview(JNIEnv *env, jobject thiz)
{
- sp<Camera> c = get_native_camera(env, thiz);
- if (c == 0)
- return;
+ LOGV("stopPreview");
+ sp<Camera> c = get_native_camera(env, thiz, NULL);
+ if (c == 0) return;
c->stopPreview();
}
static bool android_hardware_Camera_previewEnabled(JNIEnv *env, jobject thiz)
{
- sp<Camera> c = get_native_camera(env, thiz);
- if (c == 0)
- return false;
+ LOGV("previewEnabled");
+ sp<Camera> c = get_native_camera(env, thiz, NULL);
+ if (c == 0) return false;
return c->previewEnabled();
}
static void android_hardware_Camera_setHasPreviewCallback(JNIEnv *env, jobject thiz, jboolean installed, jboolean oneshot)
{
- sp<Camera> c = get_native_camera(env, thiz);
- if (c == 0)
- return;
-
// Important: Only install preview_callback if the Java code has called
// setPreviewCallback() with a non-null value, otherwise we'd pay to memcpy
// each preview frame for nothing.
- callback_cookie *cookie = (callback_cookie *)env->GetIntField(thiz, fields.listener_context);
+ camera_context_t* context;
+ sp<Camera> camera = get_native_camera(env, thiz, &context);
+ if (camera == 0) return;
int callback_flag;
if (installed) {
@@ -257,29 +278,31 @@ static void android_hardware_Camera_setHasPreviewCallback(JNIEnv *env, jobject t
} else {
callback_flag = FRAME_CALLBACK_FLAG_NOOP;
}
- c->setPreviewCallback(installed ? preview_callback : NULL, cookie, callback_flag);
+ camera->setPreviewCallback(installed ? preview_callback : NULL, context, callback_flag);
}
static void autofocus_callback_impl(bool success, void *cookie)
{
+ LOGV("autoFocusCallback");
+ camera_context_t* context = reinterpret_cast<camera_context_t*>(cookie);
+
JNIEnv *env = AndroidRuntime::getJNIEnv();
if (env == NULL) {
LOGE("autofocus_callback on dead VM");
return;
}
- callback_cookie *c = (callback_cookie *)cookie;
- env->CallStaticVoidMethod(sCameraClass, fields.post_event,
- c->camera_ref, kAutoFocusCallback,
- success, 0, NULL);
+ env->CallStaticVoidMethod(context->mCameraJClass, fields.post_event,
+ context->mCameraJObjectWeak, kAutoFocusCallback, success, 0, NULL);
}
static void android_hardware_Camera_autoFocus(JNIEnv *env, jobject thiz)
{
- sp<Camera> c = get_native_camera(env, thiz);
- if (c == 0)
- return;
- callback_cookie *cookie = (callback_cookie *)env->GetIntField(thiz, fields.listener_context);
- c->setAutoFocusCallback(autofocus_callback_impl, cookie);
+ LOGV("autoFocus");
+ camera_context_t* context;
+ sp<Camera> c = get_native_camera(env, thiz, &context);
+ if (c == 0) return;
+
+ c->setAutoFocusCallback(autofocus_callback_impl, context);
if (c->autoFocus() != NO_ERROR) {
jniThrowException(env, "java/io/IOException", "autoFocus failed");
}
@@ -287,18 +310,20 @@ static void android_hardware_Camera_autoFocus(JNIEnv *env, jobject thiz)
static void jpeg_callback(const sp<IMemory>& mem, void *cookie)
{
+ LOGV("jpegCallback");
+ camera_context_t* context = reinterpret_cast<camera_context_t*>(cookie);
+
JNIEnv *env = AndroidRuntime::getJNIEnv();
if (env == NULL) {
LOGE("jpeg`_callback on dead VM");
return;
}
- callback_cookie *c = (callback_cookie *)cookie;
int arg1 = 0, arg2 = 0;
jobject obj = NULL;
if (mem == NULL) {
- env->CallStaticVoidMethod(sCameraClass, fields.post_event,
- c->camera_ref, kJpegCallback, arg1, arg2, NULL);
+ env->CallStaticVoidMethod(context->mCameraJClass, fields.post_event,
+ context->mCameraJObjectWeak, kJpegCallback, arg1, arg2, NULL);
return;
}
ssize_t offset;
@@ -327,48 +352,51 @@ static void jpeg_callback(const sp<IMemory>& mem, void *cookie)
obj = array;
- env->CallStaticVoidMethod(sCameraClass, fields.post_event,
- c->camera_ref, kJpegCallback, arg1, arg2, obj);
+ env->CallStaticVoidMethod(context->mCameraJClass, fields.post_event,
+ context->mCameraJObjectWeak, kJpegCallback, arg1, arg2, obj);
env->DeleteLocalRef(array);
}
static void shutter_callback_impl(void *cookie)
{
+ LOGV("shutterCallback");
+ camera_context_t* context = reinterpret_cast<camera_context_t*>(cookie);
+
JNIEnv *env = AndroidRuntime::getJNIEnv();
if (env == NULL) {
LOGE("shutter_callback on dead VM");
return;
}
- callback_cookie *c = (callback_cookie *)cookie;
- env->CallStaticVoidMethod(sCameraClass, fields.post_event,
- c->camera_ref, kShutterCallback, 0, 0, NULL);
+ env->CallStaticVoidMethod(context->mCameraJClass, fields.post_event,
+ context->mCameraJObjectWeak, kShutterCallback, 0, 0, NULL);
}
static void raw_callback(const sp<IMemory>& mem __attribute__((unused)),
void *cookie)
{
+ LOGV("rawCallback");
+ camera_context_t* context = reinterpret_cast<camera_context_t*>(cookie);
+
JNIEnv *env = AndroidRuntime::getJNIEnv();
if (env == NULL) {
LOGE("raw_callback on dead VM");
return;
}
- callback_cookie *c = (callback_cookie *)cookie;
- env->CallStaticVoidMethod(sCameraClass, fields.post_event,
- c->camera_ref, kRawCallback, 0, 0, NULL);
+ env->CallStaticVoidMethod(context->mCameraJClass, fields.post_event,
+ context->mCameraJObjectWeak, kRawCallback, 0, 0, NULL);
}
static void android_hardware_Camera_takePicture(JNIEnv *env, jobject thiz)
{
- sp<Camera> c = get_native_camera(env, thiz);
- if (c == 0)
- return;
-
- callback_cookie *cookie =
- (callback_cookie *)env->GetIntField(thiz, fields.listener_context);
- c->setShutterCallback(shutter_callback_impl, cookie);
- c->setRawCallback(raw_callback, cookie);
- c->setJpegCallback(jpeg_callback, cookie);
- if (c->takePicture() != NO_ERROR) {
+ LOGV("takePicture");
+ camera_context_t* context;
+ sp<Camera> camera = get_native_camera(env, thiz, &context);
+ if (camera == 0) return;
+
+ camera->setShutterCallback(shutter_callback_impl, context);
+ camera->setRawCallback(raw_callback, context);
+ camera->setJpegCallback(jpeg_callback, context);
+ if (camera->takePicture() != NO_ERROR) {
jniThrowException(env, "java/io/IOException", "takePicture failed");
return;
}
@@ -378,9 +406,9 @@ static void android_hardware_Camera_takePicture(JNIEnv *env, jobject thiz)
static void android_hardware_Camera_setParameters(JNIEnv *env, jobject thiz, jstring params)
{
- sp<Camera> c = get_native_camera(env, thiz);
- if (c == 0)
- return;
+ LOGV("setParameters");
+ sp<Camera> camera = get_native_camera(env, thiz, NULL);
+ if (camera == 0) return;
const jchar* str = env->GetStringCritical(params, 0);
String8 params8;
@@ -388,7 +416,7 @@ static void android_hardware_Camera_setParameters(JNIEnv *env, jobject thiz, jst
params8 = String8(str, env->GetStringLength(params));
env->ReleaseStringCritical(params, str);
}
- if (c->setParameters(params8) != NO_ERROR) {
+ if (camera->setParameters(params8) != NO_ERROR) {
jniThrowException(env, "java/lang/IllegalArgumentException", "setParameters failed");
return;
}
@@ -396,20 +424,20 @@ static void android_hardware_Camera_setParameters(JNIEnv *env, jobject thiz, jst
static jstring android_hardware_Camera_getParameters(JNIEnv *env, jobject thiz)
{
- sp<Camera> c = get_native_camera(env, thiz);
- if (c == 0)
- return 0;
+ LOGV("getParameters");
+ sp<Camera> camera = get_native_camera(env, thiz, NULL);
+ if (camera == 0) return 0;
- return env->NewStringUTF(c->getParameters().string());
+ return env->NewStringUTF(camera->getParameters().string());
}
static void android_hardware_Camera_reconnect(JNIEnv *env, jobject thiz)
{
- sp<Camera> c = get_native_camera(env, thiz);
- if (c == 0)
- return;
+ LOGV("reconnect");
+ sp<Camera> camera = get_native_camera(env, thiz, NULL);
+ if (camera == 0) return;
- if (c->reconnect() != NO_ERROR) {
+ if (camera->reconnect() != NO_ERROR) {
jniThrowException(env, "java/io/IOException", "reconnect failed");
return;
}
@@ -417,18 +445,18 @@ static void android_hardware_Camera_reconnect(JNIEnv *env, jobject thiz)
static jint android_hardware_Camera_lock(JNIEnv *env, jobject thiz)
{
- sp<Camera> c = get_native_camera(env, thiz);
- if (c == 0)
- return INVALID_OPERATION;
- return (jint) c->lock();
+ LOGV("lock");
+ sp<Camera> camera = get_native_camera(env, thiz, NULL);
+ if (camera == 0) return INVALID_OPERATION;
+ return (jint) camera->lock();
}
static jint android_hardware_Camera_unlock(JNIEnv *env, jobject thiz)
{
- sp<Camera> c = get_native_camera(env, thiz);
- if (c == 0)
- return INVALID_OPERATION;
- return (jint) c->unlock();
+ LOGV("unlock");
+ sp<Camera> camera = get_native_camera(env, thiz, NULL);
+ if (camera == 0) return INVALID_OPERATION;
+ return (jint) camera->unlock();
}
//-------------------------------------------------
@@ -512,7 +540,6 @@ int register_android_hardware_Camera(JNIEnv *env)
{
field fields_to_find[] = {
{ "android/hardware/Camera", "mNativeContext", "I", &fields.context },
- { "android/hardware/Camera", "mListenerContext", "I", &fields.listener_context },
{ "android/view/Surface", "mSurface", "I", &fields.surface }
};
@@ -520,7 +547,6 @@ int register_android_hardware_Camera(JNIEnv *env)
return -1;
jclass clazz = env->FindClass("android/hardware/Camera");
- sCameraClass = (jclass)env->NewGlobalRef(clazz);
fields.post_event = env->GetStaticMethodID(clazz, "postEventFromNative",
"(Ljava/lang/Object;IIILjava/lang/Object;)V");
if (fields.post_event == NULL) {
diff --git a/core/jni/android_media_AudioTrack.cpp b/core/jni/android_media_AudioTrack.cpp
index d9effee..f625ffb 100644
--- a/core/jni/android_media_AudioTrack.cpp
+++ b/core/jni/android_media_AudioTrack.cpp
@@ -688,15 +688,33 @@ static jint android_media_AudioTrack_reload(JNIEnv *env, jobject thiz) {
// ----------------------------------------------------------------------------
-static jint android_media_AudioTrack_get_output_sample_rate(JNIEnv *env, jobject thiz) {
- int afSamplingRate;
- AudioTrackJniStorage* lpJniStorage = (AudioTrackJniStorage *)env->GetIntField(
- thiz, javaAudioTrackFields.jniData);
- if (lpJniStorage == NULL) {
- return DEFAULT_OUTPUT_SAMPLE_RATE;
+static jint android_media_AudioTrack_get_output_sample_rate(JNIEnv *env, jobject thiz,
+ jint javaStreamType) {
+ int afSamplingRate;
+ // convert the stream type from Java to native value
+ // FIXME: code duplication with android_media_AudioTrack_native_setup()
+ AudioSystem::stream_type nativeStreamType;
+ if (javaStreamType == javaAudioTrackFields.STREAM_VOICE_CALL) {
+ nativeStreamType = AudioSystem::VOICE_CALL;
+ } else if (javaStreamType == javaAudioTrackFields.STREAM_SYSTEM) {
+ nativeStreamType = AudioSystem::SYSTEM;
+ } else if (javaStreamType == javaAudioTrackFields.STREAM_RING) {
+ nativeStreamType = AudioSystem::RING;
+ } else if (javaStreamType == javaAudioTrackFields.STREAM_MUSIC) {
+ nativeStreamType = AudioSystem::MUSIC;
+ } else if (javaStreamType == javaAudioTrackFields.STREAM_ALARM) {
+ nativeStreamType = AudioSystem::ALARM;
+ } else if (javaStreamType == javaAudioTrackFields.STREAM_NOTIFICATION) {
+ nativeStreamType = AudioSystem::NOTIFICATION;
+ } else if (javaStreamType == javaAudioTrackFields.STREAM_BLUETOOTH_SCO) {
+ nativeStreamType = AudioSystem::BLUETOOTH_SCO;
+ } else {
+ nativeStreamType = AudioSystem::DEFAULT;
}
- if (AudioSystem::getOutputSamplingRate(&afSamplingRate, lpJniStorage->mStreamType) != NO_ERROR) {
+ if (AudioSystem::getOutputSamplingRate(&afSamplingRate, nativeStreamType) != NO_ERROR) {
+ LOGE("AudioSystem::getOutputSamplingRate() for stream type %d failed in AudioTrack JNI",
+ nativeStreamType);
return DEFAULT_OUTPUT_SAMPLE_RATE;
} else {
return afSamplingRate;
@@ -766,7 +784,7 @@ static JNINativeMethod gMethods[] = {
{"native_set_loop", "(III)I", (void *)android_media_AudioTrack_set_loop},
{"native_reload_static", "()I", (void *)android_media_AudioTrack_reload},
{"native_get_output_sample_rate",
- "()I", (void *)android_media_AudioTrack_get_output_sample_rate},
+ "(I)I", (void *)android_media_AudioTrack_get_output_sample_rate},
{"native_get_min_buff_size",
"(III)I", (void *)android_media_AudioTrack_get_min_buff_size},
};
diff --git a/core/jni/android_os_ParcelFileDescriptor.cpp b/core/jni/android_os_ParcelFileDescriptor.cpp
index 465e233..1429f58 100644
--- a/core/jni/android_os_ParcelFileDescriptor.cpp
+++ b/core/jni/android_os_ParcelFileDescriptor.cpp
@@ -60,9 +60,37 @@ static jobject android_os_ParcelFileDescriptor_getFileDescriptorFromSocket(JNIEn
return fileDescriptorClone;
}
+static jlong android_os_ParcelFileDescriptor_getStatSize(JNIEnv* env,
+ jobject clazz)
+{
+ jint fd = env->GetIntField(clazz, gFileDescriptorOffsets.mDescriptor);
+
+ struct stat st;
+ if (fstat(fd, &st) != 0) {
+ return -1;
+ }
+
+ if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) {
+ return st.st_size;
+ }
+
+ return -1;
+}
+
+static jlong android_os_ParcelFileDescriptor_seekTo(JNIEnv* env,
+ jobject clazz, jlong pos)
+{
+ jint fd = env->GetIntField(clazz, gFileDescriptorOffsets.mDescriptor);
+ return lseek(fd, pos, SEEK_SET);
+}
+
static const JNINativeMethod gParcelFileDescriptorMethods[] = {
{"getFileDescriptorFromSocket", "(Ljava/net/Socket;)Ljava/io/FileDescriptor;",
- (void*)android_os_ParcelFileDescriptor_getFileDescriptorFromSocket}
+ (void*)android_os_ParcelFileDescriptor_getFileDescriptorFromSocket},
+ {"getStatSize", "()J",
+ (void*)android_os_ParcelFileDescriptor_getStatSize},
+ {"seekTo", "(J)J",
+ (void*)android_os_ParcelFileDescriptor_seekTo}
};
const char* const kParcelFileDescriptorPathName = "android/os/ParcelFileDescriptor";
diff --git a/core/jni/android_server_BluetoothEventLoop.cpp b/core/jni/android_server_BluetoothEventLoop.cpp
index 9100e81..adfd912 100644
--- a/core/jni/android_server_BluetoothEventLoop.cpp
+++ b/core/jni/android_server_BluetoothEventLoop.cpp
@@ -721,6 +721,7 @@ static jboolean waitForAndDispatchEventNative(JNIEnv *env, jobject object,
#define BOND_RESULT_AUTH_REJECTED 2
#define BOND_RESULT_AUTH_CANCELED 3
#define BOND_RESULT_REMOTE_DEVICE_DOWN 4
+#define BOND_RESULT_DISCOVERY_IN_PROGRESS 5
void onCreateBondingResult(DBusMessage *msg, void *user) {
LOGV(__FUNCTION__);
@@ -755,10 +756,14 @@ void onCreateBondingResult(DBusMessage *msg, void *user) {
// already bonded
LOGV("... error = %s (%s)\n", err.name, err.message);
result = BOND_RESULT_SUCCESS;
- } else if (!strcmp(err.name, BLUEZ_DBUS_BASE_IFC ".Error.InProgress")) {
- // don't make the java callback
+ } else if (!strcmp(err.name, BLUEZ_DBUS_BASE_IFC ".Error.InProgress") &&
+ !strcmp(err.message, "Bonding in progress")) {
LOGV("... error = %s (%s)\n", err.name, err.message);
goto done;
+ } else if (!strcmp(err.name, BLUEZ_DBUS_BASE_IFC ".Error.InProgress") &&
+ !strcmp(err.message, "Discover in progress")) {
+ LOGV("... error = %s (%s)\n", err.name, err.message);
+ result = BOND_RESULT_DISCOVERY_IN_PROGRESS;
} else {
LOGE("%s: D-Bus error: %s (%s)\n", __FUNCTION__, err.name, err.message);
result = BOND_RESULT_ERROR;
diff --git a/core/jni/android_util_Binder.cpp b/core/jni/android_util_Binder.cpp
index 24404a8..7325432 100644
--- a/core/jni/android_util_Binder.cpp
+++ b/core/jni/android_util_Binder.cpp
@@ -1223,6 +1223,7 @@ static jobject android_os_Parcel_openFileDescriptor(JNIEnv* env, jobject clazz,
if (mode&0x08000000) flags |= O_CREAT;
if (mode&0x04000000) flags |= O_TRUNC;
+ if (mode&0x02000000) flags |= O_APPEND;
int realMode = S_IRWXU|S_IRWXG;
if (mode&0x00000001) realMode |= S_IROTH;
diff --git a/core/jni/server/com_android_server_AlarmManagerService.cpp b/core/jni/server/com_android_server_AlarmManagerService.cpp
index 0f37921..1d66fb1 100644
--- a/core/jni/server/com_android_server_AlarmManagerService.cpp
+++ b/core/jni/server/com_android_server_AlarmManagerService.cpp
@@ -52,12 +52,17 @@ static jint android_server_AlarmManagerService_setKernelTimezone(JNIEnv* env, jo
tz.tz_minuteswest = minswest;
tz.tz_dsttime = 0;
- int result = ioctl(fd, ANDROID_ALARM_SET_TIMEZONE, &tz);
+ int result = settimeofday(NULL, &tz);
if (result < 0) {
LOGE("Unable to set kernel timezone to %d: %s\n", minswest, strerror(errno));
return -1;
+ } else {
+ LOGD("Kernel timezone updated to %d minutes west of GMT\n", minswest);
}
+
return 0;
+#else
+ return -ENOSYS;
#endif
}