diff options
-rwxr-xr-x | jni/com_android_bluetooth_btservice_AdapterService.cpp | 66 | ||||
-rw-r--r-- | src/com/android/bluetooth/btservice/AdapterService.java | 42 |
2 files changed, 107 insertions, 1 deletions
diff --git a/jni/com_android_bluetooth_btservice_AdapterService.cpp b/jni/com_android_bluetooth_btservice_AdapterService.cpp index 3d7b1eeff..931c73e94 100755 --- a/jni/com_android_bluetooth_btservice_AdapterService.cpp +++ b/jni/com_android_bluetooth_btservice_AdapterService.cpp @@ -1023,6 +1023,67 @@ static jboolean setDevicePropertyNative(JNIEnv *env, jobject obj, jbyteArray add return result; } +static int getSocketOptNative(JNIEnv *env, jobject obj, jint type, jint channel, jint optionName, + jbyteArray optionVal) { + ALOGV("%s:",__FUNCTION__); + + jbyte *option_val = NULL; + int option_len; + bt_status_t status; + + if (!sBluetoothSocketInterface) return -1; + + option_val = env->GetByteArrayElements(optionVal, NULL); + if (option_val == NULL) { + ALOGE("getSocketOptNative :jniThrowIOException "); + jniThrowIOException(env, EINVAL); + return -1; + } + + if ( (status = sBluetoothSocketInterface->get_sock_opt((btsock_type_t)type, channel, + (btsock_option_type_t) optionName, (void *) option_val, &option_len)) != + BT_STATUS_SUCCESS) { + ALOGE("get_sock_opt failed: %d", status); + goto Fail; + } + env->ReleaseByteArrayElements(optionVal, option_val, 0); + + return option_len; +Fail: + env->ReleaseByteArrayElements(optionVal, option_val, 0); + return -1; +} + +static int setSocketOptNative(JNIEnv *env, jobject obj, jint type, jint channel, jint optionName, + jbyteArray optionVal, jint optionLen) { + ALOGV("%s:",__FUNCTION__); + + jbyte *option_val = NULL; + bt_status_t status; + + if (!sBluetoothSocketInterface) return -1; + + option_val = env->GetByteArrayElements(optionVal, NULL); + if (option_val == NULL) { + ALOGE("setSocketOptNative:jniThrowIOException "); + jniThrowIOException(env, EINVAL); + return -1; + } + + if ( (status = sBluetoothSocketInterface->set_sock_opt((btsock_type_t)type, channel, + (btsock_option_type_t) optionName, (void *) option_val, optionLen)) != + BT_STATUS_SUCCESS) { + ALOGE("set_sock_opt failed: %d", status); + goto Fail; + } + env->ReleaseByteArrayElements(optionVal, option_val, 0); + + return 0; +Fail: + env->ReleaseByteArrayElements(optionVal, option_val, 0); + return -1; +} + static jboolean getRemoteServicesNative(JNIEnv *env, jobject obj, jbyteArray address) { ALOGV("%s:",__FUNCTION__); @@ -1199,7 +1260,10 @@ static JNINativeMethod sMethods[] = { {"alarmFiredNative", "()V", (void *) alarmFiredNative}, {"readEnergyInfo", "()I", (void*) readEnergyInfo}, {"dumpNative", "(Ljava/io/FileDescriptor;)V", (void*) dumpNative}, - {"factoryResetNative", "()Z", (void*)factoryResetNative} + {"factoryResetNative", "()Z", (void*)factoryResetNative}, + {"getSocketOptNative", "(III[B)I", (void*) getSocketOptNative}, + {"setSocketOptNative", "(III[BI)I", (void*) setSocketOptNative} + }; int register_com_android_bluetooth_btservice_AdapterService(JNIEnv* env) diff --git a/src/com/android/bluetooth/btservice/AdapterService.java b/src/com/android/bluetooth/btservice/AdapterService.java index 1c3e2b5b9..94a590dff 100644 --- a/src/com/android/bluetooth/btservice/AdapterService.java +++ b/src/com/android/bluetooth/btservice/AdapterService.java @@ -1252,6 +1252,29 @@ public class AdapterService extends Service { return service.sdpSearch(device,uuid); } + public int setSocketOpt(int type, int channel, int optionName, byte [] optionVal, + int optionLen) { + if (!Utils.checkCaller()) { + Log.w(TAG,"setSocketOpt(): not allowed for non-active user"); + return -1; + } + + AdapterService service = getService(); + if (service == null) return -1; + return service.setSocketOpt(type, channel, optionName, optionVal, optionLen); + } + + public int getSocketOpt(int type, int channel, int optionName, byte [] optionVal) { + if (!Utils.checkCaller()) { + Log.w(TAG,"getSocketOpt(): not allowed for non-active user"); + return -1; + } + + AdapterService service = getService(); + if (service == null) return -1; + return service.getSocketOpt(type, channel, optionName, optionVal); + } + public boolean configHciSnoopLog(boolean enable) { if (Binder.getCallingUid() != Process.SYSTEM_UID) { EventLog.writeEvent(0x534e4554 /* SNET */, "Bluetooth", Binder.getCallingUid(), @@ -2002,6 +2025,19 @@ public class AdapterService extends Service { return ParcelFileDescriptor.adoptFd(fd); } + int setSocketOpt(int type, int channel, int optionName, byte [] optionVal, + int optionLen) { + enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); + + return setSocketOptNative(type, channel, optionName, optionVal, optionLen); + } + + int getSocketOpt(int type, int channel, int optionName, byte [] optionVal) { + enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); + + return getSocketOptNative(type, channel, optionName, optionVal); + } + boolean configHciSnoopLog(boolean enable) { enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); return configHciSnoopLogNative(enable); @@ -2323,6 +2359,12 @@ public class AdapterService extends Service { private native int createSocketChannelNative(int type, String serviceName, byte[] uuid, int port, int flag); + private native int setSocketOptNative(int fd, int type, int optionName, + byte [] optionVal, int optionLen); + + private native int getSocketOptNative(int fd, int type, int optionName, + byte [] optionVal); + /*package*/ native boolean configHciSnoopLogNative(boolean enable); /*package*/ native boolean factoryResetNative(); |