Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b21ac537 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by android-build-merger
Browse files

Merge "Add IBluetoothSocketManager (2/3)" am: fd72f8ff am: 11ae4ad5

am: f9386a93

Change-Id: Ie13e9875c141c4672dcc6245de16346713490e3a
parents 40b1870f f9386a93
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ cc_library_shared {
    name: "libbluetooth_jni",
    compile_multilib: "first",
    srcs: [
        "bluetooth_socket_manager.cc",
        "com_android_bluetooth_btservice_AdapterService.cpp",
        "com_android_bluetooth_hfp.cpp",
        "com_android_bluetooth_hfpclient.cpp",
@@ -26,6 +27,7 @@ cc_library_shared {
    shared_libs: [
        "libandroid_runtime",
        "libbinder",
        "libbluetooth-binder",
        "libchrome",
        "libnativehelper",
        "liblog",
+21 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "bluetooth_socket_manager.h"

namespace android {
namespace bluetooth {}  // namespace bluetooth
}  // namespace android
+40 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <android/bluetooth/BnBluetoothSocketManager.h>
#include <android/bluetooth/IBluetoothSocketManager.h>
#include <base/macros.h>
#include <binder/IBinder.h>
#include <binder/IInterface.h>
#include <hardware/bluetooth.h>
#include <hardware/bt_sock.h>

namespace android {
namespace bluetooth {

using ::android::binder::Status;

class BluetoothSocketManagerBinderServer : public BnBluetoothSocketManager {
 public:
  explicit BluetoothSocketManagerBinderServer(
      const btsock_interface_t* socketInterface) {}
  ~BluetoothSocketManagerBinderServer() override = default;

 private:
  DISALLOW_COPY_AND_ASSIGN(BluetoothSocketManagerBinderServer);
};
}  // namespace bluetooth
}  // namespace android
 No newline at end of file
+18 −0
Original line number Diff line number Diff line
@@ -17,12 +17,14 @@
#define LOG_TAG "BluetoothServiceJni"
#include "android_runtime/AndroidRuntime.h"
#include "android_runtime/Log.h"
#include "bluetooth_socket_manager.h"
#include "com_android_bluetooth.h"
#include "hardware/bt_sock.h"
#include "permission_helpers.h"
#include "utils/Log.h"
#include "utils/misc.h"

#include <android_util_Binder.h>
#include <base/logging.h>
#include <base/strings/stringprintf.h>
#include <dlfcn.h>
@@ -36,6 +38,7 @@

using base::StringPrintf;
using bluetooth::Uuid;
using android::bluetooth::BluetoothSocketManagerBinderServer;

namespace android {
// OOB_LE_BD_ADDR_SIZE is 6 bytes addres + 1 byte address type
@@ -71,6 +74,10 @@ static jobject sJniAdapterServiceObj;
static jobject sJniCallbacksObj;
static jfieldID sJniCallbacksField;

namespace {
android::sp<BluetoothSocketManagerBinderServer> socketManager = NULL;
}

const bt_interface_t* getBluetoothInterface() { return sBluetoothInterface; }

JNIEnv* getCallbackEnv() { return callbackEnv; }
@@ -732,6 +739,7 @@ static bool cleanupNative(JNIEnv* env, jobject obj) {
    android_bluetooth_UidTraffic.clazz = NULL;
  }

  socketManager = nullptr;
  return JNI_TRUE;
}

@@ -1184,6 +1192,14 @@ static int createSocketChannelNative(JNIEnv* env, jobject object, jint type,
  return socket_fd;
}

static jobject getSocketManagerNative(JNIEnv* env) {
  if (!socketManager.get())
    socketManager =
        new BluetoothSocketManagerBinderServer(sBluetoothSocketInterface);

  return javaObjectForIBinder(env, IInterface::asBinder(socketManager));
}

static void setSystemUiUidNative(JNIEnv* env, jobject obj, jint uid) {
  android::bluetooth::systemUiUid = uid;
}
@@ -1283,6 +1299,8 @@ static JNINativeMethod sMethods[] = {
    {"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},
    {"setForegroundUserIdNative", "(I)V", (void*)setForegroundUserIdNative},
    {"alarmFiredNative", "()V", (void*)alarmFiredNative},
+23 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.IBluetooth;
import android.bluetooth.IBluetoothCallback;
import android.bluetooth.IBluetoothSocketManager;
import android.bluetooth.OobData;
import android.bluetooth.UidTraffic;
import android.content.BroadcastReceiver;
@@ -1489,6 +1490,15 @@ public class AdapterService extends Service {
            return service.createSocketChannel(type, serviceName, uuid, port, flag);
        }

        @Override
        public IBluetoothSocketManager getSocketManager() {
            AdapterService service = getService();
            if (service == null) {
                return null;
            }
            return service.getSocketManager();
        }

        @Override
        public boolean sdpSearch(BluetoothDevice device, ParcelUuid uuid) {
            if (!Utils.checkCaller()) {
@@ -2184,6 +2194,15 @@ public class AdapterService extends Service {
        return ParcelFileDescriptor.adoptFd(fd);
    }

    IBluetoothSocketManager getSocketManager() {
        android.os.IBinder obj = getSocketManagerNative();
        if (obj == null) {
            return null;
        }

        return IBluetoothSocketManager.Stub.asInterface(obj);
    }

    boolean factoryReset() {
        enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, "Need BLUETOOTH permission");
        return factoryResetNative();
@@ -2651,8 +2670,12 @@ public class AdapterService extends Service {
    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);

    private static native void setForegroundUserIdNative(int foregroundUserId);

    /*package*/
    native boolean factoryResetNative();