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

Commit e1ef06a3 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 4402171 from 66d6377a to pi-release

Change-Id: I159ba5acc494dd92468582985dbabbf1f2974905
parents cee34866 66d6377a
Loading
Loading
Loading
Loading
+47 −15
Original line number Diff line number Diff line
@@ -22,6 +22,10 @@
#include "utils/Log.h"
#include "utils/misc.h"

#include <base/logging.h>
#include <base/strings/stringprintf.h>
#include <dlfcn.h>
#include <errno.h>
#include <pthread.h>
#include <string.h>

@@ -29,6 +33,7 @@
#include <sys/prctl.h>
#include <sys/stat.h>

using base::StringPrintf;
using bluetooth::Uuid;

namespace android {
@@ -582,6 +587,47 @@ static bt_os_callouts_t sBluetoothOsCallouts = {
    acquire_wake_lock_callout, release_wake_lock_callout,
};

#if defined(__LP64__)
#define BLUETOOTH_LIBRARY_NAME "/system/lib64/hw/bluetooth.default.so"
#else
#define BLUETOOTH_LIBRARY_NAME "/system/lib/hw/bluetooth.default.so"
#endif

int hal_util_load_bt_library(const bt_interface_t** interface) {
  const char* sym = BLUETOOTH_INTERFACE_STRING;
  bt_interface_t* itf = nullptr;

  // Always try to load the default Bluetooth stack on GN builds.
  const char* path = BLUETOOTH_LIBRARY_NAME;
  void* handle = dlopen(path, RTLD_NOW);
  if (!handle) {
    const char* err_str = dlerror();
    LOG(ERROR) << __func__ << ": failed to load Bluetooth library " << path
               << ", error=" << (err_str ? err_str : "error unknown");
    goto error;
  }

  // Get the address of the bt_interface_t.
  itf = (bt_interface_t*)dlsym(handle, sym);
  if (!itf) {
    LOG(ERROR) << __func__ << ": failed to load symbol from Bluetooth library "
               << sym;
    goto error;
  }

  // Success.
  LOG(INFO) << __func__ << " loaded HAL: btinterface=" << itf
            << ", handle=" << handle;
  *interface = itf;
  return 0;

error:
  *interface = NULL;
  if (handle) dlclose(handle);

  return -EINVAL;
}

static void classInitNative(JNIEnv* env, jclass clazz) {
  jclass jniUidTrafficClass = env->FindClass("android/bluetooth/UidTraffic");
  android_bluetooth_UidTraffic.constructor =
@@ -623,21 +669,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
  method_energyInfo = env->GetMethodID(
      clazz, "energyInfoCallback", "(IIJJJJ[Landroid/bluetooth/UidTraffic;)V");

  const char* id = BT_STACK_MODULE_ID;

  hw_module_t* module;
  int err = hw_get_module(id, (hw_module_t const**)&module);

  if (err == 0) {
    hw_device_t* abstraction;
    err = module->methods->open(module, id, &abstraction);
    if (err == 0) {
      bluetooth_module_t* btStack = (bluetooth_module_t*)abstraction;
      sBluetoothInterface = btStack->get_bluetooth_interface();
    } else {
      ALOGE("Error while opening Bluetooth library");
    }
  } else {
  if (hal_util_load_bt_library((bt_interface_t const**)&sBluetoothInterface)) {
    ALOGE("No Bluetooth Library found");
  }
}
+19 −19
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ import android.util.Log;
 * In both cases the {@link ObexServerSockets} object have terminated, and a new must be created.
 */
public class ObexServerSockets {
    private final String TAG;
    private final String mTag;
    private static final String STAG = "ObexServerSockets";
    private static final boolean D = true; // TODO: set to false!
    private static final int NUMBER_OF_SOCKET_TYPES = 2; // increment if LE will be supported
@@ -68,7 +68,7 @@ public class ObexServerSockets {
        mConHandler = conHandler;
        mRfcommSocket = rfcommSocket;
        mL2capSocket = l2capSocket;
        TAG = "ObexServerSockets" + sInstanceCounter++;
        mTag = "ObexServerSockets" + sInstanceCounter++;
    }

    /**
@@ -96,6 +96,7 @@ public class ObexServerSockets {
                BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP, false);
    }

    private static final int CREATE_RETRY_TIME = 10;
    /**
     * Creates an RFCOMM {@link BluetoothServerSocket} and a L2CAP {@link BluetoothServerSocket}
     * with specific l2cap and RFCOMM channel numbers. It is the responsibility of the caller to
@@ -120,7 +121,6 @@ public class ObexServerSockets {
        BluetoothServerSocket rfcommSocket = null;
        BluetoothServerSocket l2capSocket = null;
        boolean initSocketOK = false;
        final int CREATE_RETRY_TIME = 10;

        // It's possible that create will fail in some cases. retry for 10 times
        for (int i = 0; i < CREATE_RETRY_TIME; i++) {
@@ -198,7 +198,7 @@ public class ObexServerSockets {
     * the {@link IObexConnectionValidator#onConnect()}, at which point both threads will exit.
     */
    private void startAccept() {
        if(D) Log.d(TAG,"startAccept()");
        if(D) Log.d(mTag,"startAccept()");
        prepareForNewConnect();

        mRfcommThread = new SocketAcceptThread(mRfcommSocket);
@@ -213,7 +213,7 @@ public class ObexServerSockets {
     * Signaled through {@link IObexConnectionValidator#onConnect()};
     */
    public synchronized void prepareForNewConnect() {
        if(D) Log.d(TAG, "prepareForNewConnect()");
        if(D) Log.d(mTag, "prepareForNewConnect()");
        mConAccepted = false;
    }

@@ -227,7 +227,7 @@ public class ObexServerSockets {
     * @return true if the connection is accepted, false otherwise.
     */
    private synchronized boolean onConnect(BluetoothDevice device, BluetoothSocket conSocket) {
        if(D) Log.d(TAG, "onConnect() socket: " + conSocket + " mConAccepted = " + mConAccepted);
        if(D) Log.d(mTag, "onConnect() socket: " + conSocket + " mConAccepted = " + mConAccepted);
        if(!mConAccepted && mConHandler.onConnect(device, conSocket)) {
            mConAccepted = true; // TODO: Reset this when ready to accept new connection
            /* Signal the remaining threads to stop.
@@ -244,7 +244,7 @@ public class ObexServerSockets {
        shutdown(false);
        BluetoothAdapter mAdapter = BluetoothAdapter.getDefaultAdapter();
        if ((mAdapter != null) && (mAdapter.getState() == BluetoothAdapter.STATE_ON)) {
            Log.d(TAG, "onAcceptFailed() calling shutdown...");
            Log.d(mTag, "onAcceptFailed() calling shutdown...");
            mConHandler.onAcceptFailed();
        }
    }
@@ -255,7 +255,7 @@ public class ObexServerSockets {
     * has ended execution
     */
    public synchronized void shutdown(boolean block) {
        if(D) Log.d(TAG, "shutdown(block = " + block + ")");
        if(D) Log.d(mTag, "shutdown(block = " + block + ")");
        if(mRfcommThread != null) {
            mRfcommThread.shutdown();
        }
@@ -274,7 +274,7 @@ public class ObexServerSockets {
                        mL2capThread = null;
                    }
                } catch (InterruptedException e) {
                    Log.i(TAG, "shutdown() interrupted, continue waiting...", e);
                    Log.i(mTag, "shutdown() interrupted, continue waiting...", e);
                }
            }
        } else {
@@ -319,24 +319,24 @@ public class ObexServerSockets {
                    BluetoothDevice device;

                    try {
                        if (D) Log.d(TAG, "Accepting socket connection...");
                        if (D) Log.d(mTag, "Accepting socket connection...");

                        connSocket = mServerSocket.accept();
                        if (D) Log.d(TAG, "Accepted socket connection from: " + mServerSocket);
                        if (D) Log.d(mTag, "Accepted socket connection from: " + mServerSocket);

                       if (connSocket == null) {
                           // TODO: Do we need a max error count, to avoid spinning?
                            Log.w(TAG, "connSocket is null - reattempt accept");
                            Log.w(mTag, "connSocket is null - reattempt accept");
                            continue;
                        }
                        device = connSocket.getRemoteDevice();

                        if (device == null) {
                            Log.i(TAG, "getRemoteDevice() = null - reattempt accept");
                            Log.i(mTag, "getRemoteDevice() = null - reattempt accept");
                            try{
                                connSocket.close();
                            } catch (IOException e) {
                                Log.w(TAG, "Error closing the socket. ignoring...",e );
                                Log.w(mTag, "Error closing the socket. ignoring...",e );
                            }
                            continue;
                        }
@@ -349,7 +349,7 @@ public class ObexServerSockets {
                            /* Close connection if we already have a connection with another device
                             * by responding to the OBEX connect request.
                             */
                            Log.i(TAG, "RemoteDevice is invalid - creating ObexRejectServer.");
                            Log.i(mTag, "RemoteDevice is invalid - creating ObexRejectServer.");
                            BluetoothObexTransport obexTrans =
                                    new BluetoothObexTransport(connSocket);
                            // Create and detach a selfdestructing ServerSession to respond to any
@@ -367,7 +367,7 @@ public class ObexServerSockets {
                        if(mStopped) {
                            // Expected exception because of shutdown.
                        } else {
                            Log.w(TAG, "Accept exception for " +
                            Log.w(mTag, "Accept exception for " +
                                    mServerSocket, ex);
                            ObexServerSockets.this.onAcceptFailed();
                        }
@@ -375,7 +375,7 @@ public class ObexServerSockets {
                    }
                } // End while()
            } finally {
                if (D) Log.d(TAG, "AcceptThread ended for: " + mServerSocket);
                if (D) Log.d(mTag, "AcceptThread ended for: " + mServerSocket);
            }
        }

@@ -393,14 +393,14 @@ public class ObexServerSockets {
                try {
                     mServerSocket.close();
                } catch (IOException e) {
                    if(D) Log.d(TAG, "Exception while thread shutdown:", e);
                    if(D) Log.d(mTag, "Exception while thread shutdown:", e);
                }
            }
            // If called from another thread, interrupt the thread
            if(!Thread.currentThread().equals(this)){
                // TODO: Will this interrupt the thread if it is blocked in synchronized?
                // Else: change to use InterruptableLock
                if(D) Log.d(TAG, "shutdown called from another thread - interrupt().");
                if(D) Log.d(mTag, "shutdown called from another thread - interrupt().");
                interrupt();
            }
        }
+11 −11
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ public class A2dpService extends ProfileService {
        }
    };

    private static A2dpService sAd2dpService;
    private static A2dpService sA2dpService;
    static final ParcelUuid[] A2DP_SOURCE_UUID = {
        BluetoothUuid.AudioSource
    };
@@ -154,14 +154,14 @@ public class A2dpService extends ProfileService {
    //API Methods

    public static synchronized A2dpService getA2dpService(){
        if (sAd2dpService != null && sAd2dpService.isAvailable()) {
            if (DBG) Log.d(TAG, "getA2DPService(): returning " + sAd2dpService);
            return sAd2dpService;
        if (sA2dpService != null && sA2dpService.isAvailable()) {
            if (DBG) Log.d(TAG, "getA2DPService(): returning " + sA2dpService);
            return sA2dpService;
        }
        if (DBG)  {
            if (sAd2dpService == null) {
            if (sA2dpService == null) {
                Log.d(TAG, "getA2dpService(): service is NULL");
            } else if (!(sAd2dpService.isAvailable())) {
            } else if (!(sA2dpService.isAvailable())) {
                Log.d(TAG,"getA2dpService(): service is not available");
            }
        }
@@ -170,13 +170,13 @@ public class A2dpService extends ProfileService {

    private static synchronized void setA2dpService(A2dpService instance) {
        if (instance != null && instance.isAvailable()) {
            if (DBG) Log.d(TAG, "setA2dpService(): set to: " + sAd2dpService);
            sAd2dpService = instance;
            if (DBG) Log.d(TAG, "setA2dpService(): set to: " + sA2dpService);
            sA2dpService = instance;
        } else {
            if (DBG)  {
                if (sAd2dpService == null) {
                if (sA2dpService == null) {
                    Log.d(TAG, "setA2dpService(): service not available");
                } else if (!sAd2dpService.isAvailable()) {
                } else if (!sA2dpService.isAvailable()) {
                    Log.d(TAG,"setA2dpService(): service is cleaning up");
                }
            }
@@ -184,7 +184,7 @@ public class A2dpService extends ProfileService {
    }

    private static synchronized void clearA2dpService() {
        sAd2dpService = null;
        sA2dpService = null;
    }

    public boolean connect(BluetoothDevice device) {
+3 −3
Original line number Diff line number Diff line
@@ -962,9 +962,9 @@ final class A2dpStateMachine extends StateMachine {
    }

    private class StackEvent {
        int type = EVENT_TYPE_NONE;
        int valueInt = 0;
        BluetoothDevice device = null;
        public int type = EVENT_TYPE_NONE;
        public int valueInt = 0;
        public BluetoothDevice device = null;

        private StackEvent(int type) {
            this.type = type;
+4 −4
Original line number Diff line number Diff line
@@ -810,10 +810,10 @@ public class A2dpSinkStateMachine extends StateMachine {
    }

    private class StackEvent {
        int type = EVENT_TYPE_NONE;
        int valueInt = 0;
        BluetoothDevice device = null;
        BluetoothAudioConfig audioConfig = null;
        public int type = EVENT_TYPE_NONE;
        public int valueInt = 0;
        public BluetoothDevice device = null;
        public BluetoothAudioConfig audioConfig = null;

        private StackEvent(int type) {
            this.type = type;
Loading