Loading android/app/jni/bluetooth_socket_manager.cc +51 −1 Original line number Diff line number Diff line Loading @@ -15,7 +15,57 @@ */ #include "bluetooth_socket_manager.h" #include "permission_helpers.h" #include <base/logging.h> #include <binder/IPCThreadState.h> using ::android::binder::Status; using ::android::OK; using ::android::os::ParcelFileDescriptor; using ::android::os::ParcelUuid; using ::android::String8; namespace android { namespace bluetooth {} // namespace bluetooth namespace bluetooth { Status BluetoothSocketManagerBinderServer::createSocketChannel( int32_t type, const std::unique_ptr<::android::String16>& serviceName, const std::unique_ptr<ParcelUuid>& uuid, int32_t port, int32_t flag, std::unique_ptr<ParcelFileDescriptor>* _aidl_return) { if (!isCallerActiveUserOrManagedProfile()) { LOG(WARNING) << "createSocketChannel() - Not allowed for non-active users"; return Status::ok(); } ENFORCE_PERMISSION(PERMISSION_BLUETOOTH); VLOG(1) << __func__ << ": SOCK FLAG=" << flag; IPCThreadState* ipc = IPCThreadState::self(); int socket_fd = -1; const std::string payload_url{}; bt_status_t status = socketInterface->listen( (btsock_type_t)type, serviceName ? String8{*serviceName}.c_str() : nullptr, uuid ? &uuid->uuid : nullptr, port, &socket_fd, flag, ipc->getCallingUid()); if (status != BT_STATUS_SUCCESS) { LOG(ERROR) << "Socket listen failed: " << +status; socket_fd = -1; } if (socket_fd < 0) { LOG(ERROR) << "Failed to create file descriptor on socket fd"; return Status::ok(); } _aidl_return->reset(new ParcelFileDescriptor()); (*_aidl_return)->fd = socket_fd; return Status::ok(); } } // namespace bluetooth } // namespace android android/app/jni/bluetooth_socket_manager.h +10 −1 Original line number Diff line number Diff line Loading @@ -30,10 +30,19 @@ using ::android::binder::Status; class BluetoothSocketManagerBinderServer : public BnBluetoothSocketManager { public: explicit BluetoothSocketManagerBinderServer( const btsock_interface_t* socketInterface) {} const btsock_interface_t* socketInterface) : socketInterface(socketInterface) {} ~BluetoothSocketManagerBinderServer() override = default; Status createSocketChannel( int32_t type, const std::unique_ptr<::android::String16>& serviceName, const std::unique_ptr<::android::os::ParcelUuid>& uuid, int32_t port, int32_t flag, std::unique_ptr<::android::os::ParcelFileDescriptor>* _aidl_return) override; private: const btsock_interface_t* socketInterface; DISALLOW_COPY_AND_ASSIGN(BluetoothSocketManagerBinderServer); }; } // namespace bluetooth Loading android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp +0 −42 Original line number Diff line number Diff line Loading @@ -1152,46 +1152,6 @@ static int connectSocketNative(JNIEnv* env, jobject object, jbyteArray address, return socket_fd; } static int createSocketChannelNative(JNIEnv* env, jobject object, jint type, jstring name_str, jbyteArray uuidObj, jint channel, jint flag, jint callingUid) { if (!sBluetoothSocketInterface) return -1; ALOGV("%s: SOCK FLAG = %x", __func__, flag); const char* service_name = NULL; if (name_str != NULL) { service_name = env->GetStringUTFChars(name_str, NULL); } Uuid uuid; if (uuidObj != NULL) { jbyte* tmp = env->GetByteArrayElements(uuidObj, NULL); if (!tmp) { ALOGE("failed to get uuid"); if (service_name) env->ReleaseStringUTFChars(name_str, service_name); return -1; } uuid = Uuid::From128BitBE(reinterpret_cast<uint8_t*>(tmp)); env->ReleaseByteArrayElements(uuidObj, tmp, 0); } int socket_fd = -1; bt_status_t status = sBluetoothSocketInterface->listen( (btsock_type_t)type, service_name, uuidObj ? &uuid : nullptr, channel, &socket_fd, flag, callingUid); if (status != BT_STATUS_SUCCESS) { ALOGE("Socket listen failed: %d", status); socket_fd = -1; } else if (socket_fd < 0) { ALOGE("Fail to creat file descriptor on socket fd"); } if (service_name) env->ReleaseStringUTFChars(name_str, service_name); return socket_fd; } static jobject getSocketManagerNative(JNIEnv* env) { if (!socketManager.get()) socketManager = Loading Loading @@ -1297,8 +1257,6 @@ static JNINativeMethod sMethods[] = { {"sspReplyNative", "([BIZI)Z", (void*)sspReplyNative}, {"getRemoteServicesNative", "([B)Z", (void*)getRemoteServicesNative}, {"connectSocketNative", "([BI[BIII)I", (void*)connectSocketNative}, {"createSocketChannelNative", "(ILjava/lang/String;[BIII)I", (void*)createSocketChannelNative}, {"getSocketManagerNative", "()Landroid/os/IBinder;", (void*)getSocketManagerNative}, {"setSystemUiUidNative", "(I)V", (void*)setSystemUiUidNative}, Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +0 −30 Original line number Diff line number Diff line Loading @@ -1475,21 +1475,6 @@ public class AdapterService extends Service { return service.connectSocket(device, type, uuid, port, flag); } @Override public ParcelFileDescriptor createSocketChannel(int type, String serviceName, ParcelUuid uuid, int port, int flag) { if (!Utils.checkCallerAllowManagedProfiles(mService)) { Log.w(TAG, "createSocketChannel() - Not allowed for non-active user"); return null; } AdapterService service = getService(); if (service == null) { return null; } return service.createSocketChannel(type, serviceName, uuid, port, flag); } @Override public IBluetoothSocketManager getSocketManager() { AdapterService service = getService(); Loading Loading @@ -2182,18 +2167,6 @@ public class AdapterService extends Service { return ParcelFileDescriptor.adoptFd(fd); } ParcelFileDescriptor createSocketChannel(int type, String serviceName, ParcelUuid uuid, int port, int flag) { enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); int fd = createSocketChannelNative(type, serviceName, Utils.uuidToByteArray(uuid), port, flag, Binder.getCallingUid()); if (fd < 0) { errorLog("Failed to create socket channel"); return null; } return ParcelFileDescriptor.adoptFd(fd); } IBluetoothSocketManager getSocketManager() { android.os.IBinder obj = getSocketManagerNative(); if (obj == null) { Loading Loading @@ -2667,9 +2640,6 @@ public class AdapterService extends Service { private native int connectSocketNative(byte[] address, int type, byte[] uuid, int port, int flag, int callingUid); private native int createSocketChannelNative(int type, String serviceName, byte[] uuid, int port, int flag, int callingUid); private native IBinder getSocketManagerNative(); private native void setSystemUiUidNative(int systemUiUid); Loading Loading
android/app/jni/bluetooth_socket_manager.cc +51 −1 Original line number Diff line number Diff line Loading @@ -15,7 +15,57 @@ */ #include "bluetooth_socket_manager.h" #include "permission_helpers.h" #include <base/logging.h> #include <binder/IPCThreadState.h> using ::android::binder::Status; using ::android::OK; using ::android::os::ParcelFileDescriptor; using ::android::os::ParcelUuid; using ::android::String8; namespace android { namespace bluetooth {} // namespace bluetooth namespace bluetooth { Status BluetoothSocketManagerBinderServer::createSocketChannel( int32_t type, const std::unique_ptr<::android::String16>& serviceName, const std::unique_ptr<ParcelUuid>& uuid, int32_t port, int32_t flag, std::unique_ptr<ParcelFileDescriptor>* _aidl_return) { if (!isCallerActiveUserOrManagedProfile()) { LOG(WARNING) << "createSocketChannel() - Not allowed for non-active users"; return Status::ok(); } ENFORCE_PERMISSION(PERMISSION_BLUETOOTH); VLOG(1) << __func__ << ": SOCK FLAG=" << flag; IPCThreadState* ipc = IPCThreadState::self(); int socket_fd = -1; const std::string payload_url{}; bt_status_t status = socketInterface->listen( (btsock_type_t)type, serviceName ? String8{*serviceName}.c_str() : nullptr, uuid ? &uuid->uuid : nullptr, port, &socket_fd, flag, ipc->getCallingUid()); if (status != BT_STATUS_SUCCESS) { LOG(ERROR) << "Socket listen failed: " << +status; socket_fd = -1; } if (socket_fd < 0) { LOG(ERROR) << "Failed to create file descriptor on socket fd"; return Status::ok(); } _aidl_return->reset(new ParcelFileDescriptor()); (*_aidl_return)->fd = socket_fd; return Status::ok(); } } // namespace bluetooth } // namespace android
android/app/jni/bluetooth_socket_manager.h +10 −1 Original line number Diff line number Diff line Loading @@ -30,10 +30,19 @@ using ::android::binder::Status; class BluetoothSocketManagerBinderServer : public BnBluetoothSocketManager { public: explicit BluetoothSocketManagerBinderServer( const btsock_interface_t* socketInterface) {} const btsock_interface_t* socketInterface) : socketInterface(socketInterface) {} ~BluetoothSocketManagerBinderServer() override = default; Status createSocketChannel( int32_t type, const std::unique_ptr<::android::String16>& serviceName, const std::unique_ptr<::android::os::ParcelUuid>& uuid, int32_t port, int32_t flag, std::unique_ptr<::android::os::ParcelFileDescriptor>* _aidl_return) override; private: const btsock_interface_t* socketInterface; DISALLOW_COPY_AND_ASSIGN(BluetoothSocketManagerBinderServer); }; } // namespace bluetooth Loading
android/app/jni/com_android_bluetooth_btservice_AdapterService.cpp +0 −42 Original line number Diff line number Diff line Loading @@ -1152,46 +1152,6 @@ static int connectSocketNative(JNIEnv* env, jobject object, jbyteArray address, return socket_fd; } static int createSocketChannelNative(JNIEnv* env, jobject object, jint type, jstring name_str, jbyteArray uuidObj, jint channel, jint flag, jint callingUid) { if (!sBluetoothSocketInterface) return -1; ALOGV("%s: SOCK FLAG = %x", __func__, flag); const char* service_name = NULL; if (name_str != NULL) { service_name = env->GetStringUTFChars(name_str, NULL); } Uuid uuid; if (uuidObj != NULL) { jbyte* tmp = env->GetByteArrayElements(uuidObj, NULL); if (!tmp) { ALOGE("failed to get uuid"); if (service_name) env->ReleaseStringUTFChars(name_str, service_name); return -1; } uuid = Uuid::From128BitBE(reinterpret_cast<uint8_t*>(tmp)); env->ReleaseByteArrayElements(uuidObj, tmp, 0); } int socket_fd = -1; bt_status_t status = sBluetoothSocketInterface->listen( (btsock_type_t)type, service_name, uuidObj ? &uuid : nullptr, channel, &socket_fd, flag, callingUid); if (status != BT_STATUS_SUCCESS) { ALOGE("Socket listen failed: %d", status); socket_fd = -1; } else if (socket_fd < 0) { ALOGE("Fail to creat file descriptor on socket fd"); } if (service_name) env->ReleaseStringUTFChars(name_str, service_name); return socket_fd; } static jobject getSocketManagerNative(JNIEnv* env) { if (!socketManager.get()) socketManager = Loading Loading @@ -1297,8 +1257,6 @@ static JNINativeMethod sMethods[] = { {"sspReplyNative", "([BIZI)Z", (void*)sspReplyNative}, {"getRemoteServicesNative", "([B)Z", (void*)getRemoteServicesNative}, {"connectSocketNative", "([BI[BIII)I", (void*)connectSocketNative}, {"createSocketChannelNative", "(ILjava/lang/String;[BIII)I", (void*)createSocketChannelNative}, {"getSocketManagerNative", "()Landroid/os/IBinder;", (void*)getSocketManagerNative}, {"setSystemUiUidNative", "(I)V", (void*)setSystemUiUidNative}, Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +0 −30 Original line number Diff line number Diff line Loading @@ -1475,21 +1475,6 @@ public class AdapterService extends Service { return service.connectSocket(device, type, uuid, port, flag); } @Override public ParcelFileDescriptor createSocketChannel(int type, String serviceName, ParcelUuid uuid, int port, int flag) { if (!Utils.checkCallerAllowManagedProfiles(mService)) { Log.w(TAG, "createSocketChannel() - Not allowed for non-active user"); return null; } AdapterService service = getService(); if (service == null) { return null; } return service.createSocketChannel(type, serviceName, uuid, port, flag); } @Override public IBluetoothSocketManager getSocketManager() { AdapterService service = getService(); Loading Loading @@ -2182,18 +2167,6 @@ public class AdapterService extends Service { return ParcelFileDescriptor.adoptFd(fd); } ParcelFileDescriptor createSocketChannel(int type, String serviceName, ParcelUuid uuid, int port, int flag) { enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission"); int fd = createSocketChannelNative(type, serviceName, Utils.uuidToByteArray(uuid), port, flag, Binder.getCallingUid()); if (fd < 0) { errorLog("Failed to create socket channel"); return null; } return ParcelFileDescriptor.adoptFd(fd); } IBluetoothSocketManager getSocketManager() { android.os.IBinder obj = getSocketManagerNative(); if (obj == null) { Loading Loading @@ -2667,9 +2640,6 @@ public class AdapterService extends Service { private native int connectSocketNative(byte[] address, int type, byte[] uuid, int port, int flag, int callingUid); private native int createSocketChannelNative(int type, String serviceName, byte[] uuid, int port, int flag, int callingUid); private native IBinder getSocketManagerNative(); private native void setSystemUiUidNative(int systemUiUid); Loading