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

Commit 97340071 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Reduced the impact of "synchronized" statements"

parents bf0fbcda 08eec363
Loading
Loading
Loading
Loading
+235 −132
Original line number Original line Diff line number Diff line
@@ -53,6 +53,8 @@ import java.util.Locale;
import java.util.Map;
import java.util.Map;
import java.util.Set;
import java.util.Set;
import java.util.UUID;
import java.util.UUID;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.ReentrantReadWriteLock;


/**
/**
 * Represents the local device Bluetooth adapter. The {@link BluetoothAdapter}
 * Represents the local device Bluetooth adapter. The {@link BluetoothAdapter}
@@ -487,6 +489,8 @@ public final class BluetoothAdapter {


    private final IBluetoothManager mManagerService;
    private final IBluetoothManager mManagerService;
    private IBluetooth mService;
    private IBluetooth mService;
    private final ReentrantReadWriteLock mServiceLock =
        new ReentrantReadWriteLock();


    private final Object mLock = new Object();
    private final Object mLock = new Object();
    private final Map<LeScanCallback, ScanCallback> mLeScanClients;
    private final Map<LeScanCallback, ScanCallback> mLeScanClients;
@@ -521,8 +525,13 @@ public final class BluetoothAdapter {
            throw new IllegalArgumentException("bluetooth manager service is null");
            throw new IllegalArgumentException("bluetooth manager service is null");
        }
        }
        try {
        try {
            mServiceLock.writeLock().lock();
            mService = managerService.registerAdapter(mManagerCallback);
            mService = managerService.registerAdapter(mManagerCallback);
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        } finally {
            mServiceLock.writeLock().unlock();
        }
        mManagerService = managerService;
        mManagerService = managerService;
        mLeScanClients = new HashMap<LeScanCallback, ScanCallback>();
        mLeScanClients = new HashMap<LeScanCallback, ScanCallback>();
        mToken = new Binder();
        mToken = new Binder();
@@ -609,10 +618,14 @@ public final class BluetoothAdapter {
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    public boolean isEnabled() {
    public boolean isEnabled() {
        try {
        try {
            synchronized(mManagerCallback) {
            mServiceLock.readLock().lock();
            if (mService != null) return mService.isEnabled();
            if (mService != null) return mService.isEnabled();
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }
        } catch (RemoteException e) {Log.e(TAG, "", e);}

        return false;
        return false;
    }
    }


@@ -643,12 +656,12 @@ public final class BluetoothAdapter {
     * or OFF if BT is in BLE_ON state
     * or OFF if BT is in BLE_ON state
     */
     */
    private void notifyUserAction(boolean enable) {
    private void notifyUserAction(boolean enable) {
        try {
            mServiceLock.readLock().lock();
            if (mService == null) {
            if (mService == null) {
                Log.e(TAG, "mService is null");
                Log.e(TAG, "mService is null");
                return;
                return;
            }
            }

        try {
            if (enable) {
            if (enable) {
                mService.onLeServiceUp(); //NA:TODO implementation pending
                mService.onLeServiceUp(); //NA:TODO implementation pending
            } else {
            } else {
@@ -656,6 +669,8 @@ public final class BluetoothAdapter {
            }
            }
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
            Log.e(TAG, "", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }
    }
    }


@@ -787,27 +802,29 @@ public final class BluetoothAdapter {
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    @AdapterState
    @AdapterState
    public int getState() {
    public int getState() {
        int state = BluetoothAdapter.STATE_OFF;

        try {
        try {
            synchronized(mManagerCallback) {
            mServiceLock.readLock().lock();
                if (mService != null)
            if (mService != null) {
                {
                state = mService.getState();
                    int state=  mService.getState();
            }
                    if (VDBG) Log.d(TAG, "" + hashCode() + ": getState(). Returning " + state);
        } catch (RemoteException e) {
                    //consider all internal states as OFF
            Log.e(TAG, "", e);
        } finally {
            mServiceLock.readLock().unlock();
        }

        // Consider all internal states as OFF
        if (state == BluetoothAdapter.STATE_BLE_ON
        if (state == BluetoothAdapter.STATE_BLE_ON
            || state == BluetoothAdapter.STATE_BLE_TURNING_ON
            || state == BluetoothAdapter.STATE_BLE_TURNING_ON
            || state == BluetoothAdapter.STATE_BLE_TURNING_OFF) {
            || state == BluetoothAdapter.STATE_BLE_TURNING_OFF) {
            if (VDBG) Log.d(TAG, "Consider internal state as OFF");
            if (VDBG) Log.d(TAG, "Consider internal state as OFF");
            state = BluetoothAdapter.STATE_OFF;
            state = BluetoothAdapter.STATE_OFF;
        }
        }
        if (VDBG) Log.d(TAG, "" + hashCode() + ": getState(). Returning " + state);
        return state;
        return state;
    }
    }
                // TODO(BT) there might be a small gap during STATE_TURNING_ON that
                //          mService is null, handle that case
            }
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        return STATE_OFF;
    }


    /**
    /**
     * Get the current state of the local Bluetooth adapter
     * Get the current state of the local Bluetooth adapter
@@ -829,19 +846,21 @@ public final class BluetoothAdapter {
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    @RequiresPermission(Manifest.permission.BLUETOOTH)
    @AdapterState
    @AdapterState
    public int getLeState() {
    public int getLeState() {
        int state = BluetoothAdapter.STATE_OFF;

        try {
        try {
            synchronized(mManagerCallback) {
            mServiceLock.readLock().lock();
                if (mService != null)
            if (mService != null) {
                {
                state = mService.getState();
                    int state=  mService.getState();
                    if (VDBG) Log.d(TAG,"getLeState() returning " + state);
                    return state;
                }
            }
            }
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
            Log.e(TAG, "", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }
        return BluetoothAdapter.STATE_OFF;

        if (VDBG) Log.d(TAG,"getLeState() returning " + state);
        return state;
    }
    }


    boolean getLeAccess() {
    boolean getLeAccess() {
@@ -883,16 +902,21 @@ public final class BluetoothAdapter {
     */
     */
    @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
    @RequiresPermission(Manifest.permission.BLUETOOTH_ADMIN)
    public boolean enable() {
    public boolean enable() {
        int state = STATE_OFF;
        int state = BluetoothAdapter.STATE_OFF;
        if (isEnabled() == true) {
        if (isEnabled() == true) {
            if (DBG) Log.d(TAG, "enable(): BT is already enabled..!");
            if (DBG) Log.d(TAG, "enable(): BT is already enabled..!");
            return true;
            return true;
        }
        }
        // Use service interface to get the exact state
        // Use service interface to get the exact state
        if (mService != null) {
        try {
        try {
            mServiceLock.readLock().lock();
            if (mService != null) {
                state = mService.getState();
                state = mService.getState();
            } catch (RemoteException e) {Log.e(TAG, "", e);}
            }
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }


        if (state == BluetoothAdapter.STATE_BLE_ON) {
        if (state == BluetoothAdapter.STATE_BLE_ON) {
@@ -997,10 +1021,13 @@ public final class BluetoothAdapter {
     */
     */
    public boolean configHciSnoopLog(boolean enable) {
    public boolean configHciSnoopLog(boolean enable) {
        try {
        try {
            synchronized(mManagerCallback) {
            mServiceLock.readLock().lock();
            if (mService != null) return mService.configHciSnoopLog(enable);
            if (mService != null) return mService.configHciSnoopLog(enable);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        return false;
        return false;
    }
    }


@@ -1016,12 +1043,16 @@ public final class BluetoothAdapter {
     */
     */
    public boolean factoryReset() {
    public boolean factoryReset() {
        try {
        try {
            mServiceLock.readLock().lock();
            if (mService != null) {
            if (mService != null) {
                return mService.factoryReset();
                return mService.factoryReset();
            } else {
            }
            SystemProperties.set("persist.bluetooth.factoryreset", "true");
            SystemProperties.set("persist.bluetooth.factoryreset", "true");
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        return false;
        return false;
    }
    }


@@ -1036,10 +1067,13 @@ public final class BluetoothAdapter {
    public ParcelUuid[] getUuids() {
    public ParcelUuid[] getUuids() {
        if (getState() != STATE_ON) return null;
        if (getState() != STATE_ON) return null;
        try {
        try {
            synchronized(mManagerCallback) {
            mServiceLock.readLock().lock();
            if (mService != null) return mService.getUuids();
            if (mService != null) return mService.getUuids();
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        return null;
        return null;
    }
    }


@@ -1062,10 +1096,13 @@ public final class BluetoothAdapter {
    public boolean setName(String name) {
    public boolean setName(String name) {
        if (getState() != STATE_ON) return false;
        if (getState() != STATE_ON) return false;
        try {
        try {
            synchronized(mManagerCallback) {
            mServiceLock.readLock().lock();
            if (mService != null) return mService.setName(name);
            if (mService != null) return mService.setName(name);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        return false;
        return false;
    }
    }


@@ -1090,10 +1127,13 @@ public final class BluetoothAdapter {
    public int getScanMode() {
    public int getScanMode() {
        if (getState() != STATE_ON) return SCAN_MODE_NONE;
        if (getState() != STATE_ON) return SCAN_MODE_NONE;
        try {
        try {
            synchronized(mManagerCallback) {
            mServiceLock.readLock().lock();
            if (mService != null) return mService.getScanMode();
            if (mService != null) return mService.getScanMode();
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        return SCAN_MODE_NONE;
        return SCAN_MODE_NONE;
    }
    }


@@ -1128,10 +1168,13 @@ public final class BluetoothAdapter {
    public boolean setScanMode(@ScanMode int mode, int duration) {
    public boolean setScanMode(@ScanMode int mode, int duration) {
        if (getState() != STATE_ON) return false;
        if (getState() != STATE_ON) return false;
        try {
        try {
            synchronized(mManagerCallback) {
            mServiceLock.readLock().lock();
            if (mService != null) return mService.setScanMode(mode, duration);
            if (mService != null) return mService.setScanMode(mode, duration);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        return false;
        return false;
    }
    }


@@ -1146,10 +1189,13 @@ public final class BluetoothAdapter {
    public int getDiscoverableTimeout() {
    public int getDiscoverableTimeout() {
        if (getState() != STATE_ON) return -1;
        if (getState() != STATE_ON) return -1;
        try {
        try {
            synchronized(mManagerCallback) {
            mServiceLock.readLock().lock();
            if (mService != null) return mService.getDiscoverableTimeout();
            if (mService != null) return mService.getDiscoverableTimeout();
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        return -1;
        return -1;
    }
    }


@@ -1157,10 +1203,13 @@ public final class BluetoothAdapter {
    public void setDiscoverableTimeout(int timeout) {
    public void setDiscoverableTimeout(int timeout) {
        if (getState() != STATE_ON) return;
        if (getState() != STATE_ON) return;
        try {
        try {
            synchronized(mManagerCallback) {
            mServiceLock.readLock().lock();
            if (mService != null) mService.setDiscoverableTimeout(timeout);
            if (mService != null) mService.setDiscoverableTimeout(timeout);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }
        } catch (RemoteException e) {Log.e(TAG, "", e);}
    }
    }


    /**
    /**
@@ -1197,10 +1246,13 @@ public final class BluetoothAdapter {
    public boolean startDiscovery() {
    public boolean startDiscovery() {
        if (getState() != STATE_ON) return false;
        if (getState() != STATE_ON) return false;
        try {
        try {
            synchronized(mManagerCallback) {
            mServiceLock.readLock().lock();
            if (mService != null) return mService.startDiscovery();
            if (mService != null) return mService.startDiscovery();
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        return false;
        return false;
    }
    }


@@ -1225,10 +1277,13 @@ public final class BluetoothAdapter {
    public boolean cancelDiscovery() {
    public boolean cancelDiscovery() {
        if (getState() != STATE_ON) return false;
        if (getState() != STATE_ON) return false;
        try {
        try {
            synchronized(mManagerCallback) {
            mServiceLock.readLock().lock();
            if (mService != null) return mService.cancelDiscovery();
            if (mService != null) return mService.cancelDiscovery();
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        return false;
        return false;
    }
    }


@@ -1255,10 +1310,13 @@ public final class BluetoothAdapter {
    public boolean isDiscovering() {
    public boolean isDiscovering() {
        if (getState() != STATE_ON) return false;
        if (getState() != STATE_ON) return false;
        try {
        try {
            synchronized(mManagerCallback) {
            mServiceLock.readLock().lock();
            if (mService != null) return mService.isDiscovering();
            if (mService != null) return mService.isDiscovering();
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        return false;
        return false;
    }
    }


@@ -1270,9 +1328,12 @@ public final class BluetoothAdapter {
    public boolean isMultipleAdvertisementSupported() {
    public boolean isMultipleAdvertisementSupported() {
        if (getState() != STATE_ON) return false;
        if (getState() != STATE_ON) return false;
        try {
        try {
            return mService.isMultiAdvertisementSupported();
            mServiceLock.readLock().lock();
            if (mService != null) return mService.isMultiAdvertisementSupported();
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG, "failed to get isMultipleAdvertisementSupported, error: ", e);
            Log.e(TAG, "failed to get isMultipleAdvertisementSupported, error: ", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }
        return false;
        return false;
    }
    }
@@ -1305,9 +1366,12 @@ public final class BluetoothAdapter {
    public boolean isPeripheralModeSupported() {
    public boolean isPeripheralModeSupported() {
        if (getState() != STATE_ON) return false;
        if (getState() != STATE_ON) return false;
        try {
        try {
            return mService.isPeripheralModeSupported();
            mServiceLock.readLock().lock();
            if (mService != null) return mService.isPeripheralModeSupported();
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG, "failed to get peripheral mode capability: ", e);
            Log.e(TAG, "failed to get peripheral mode capability: ", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }
        return false;
        return false;
    }
    }
@@ -1320,9 +1384,12 @@ public final class BluetoothAdapter {
    public boolean isOffloadedFilteringSupported() {
    public boolean isOffloadedFilteringSupported() {
        if (!getLeAccess()) return false;
        if (!getLeAccess()) return false;
        try {
        try {
            return mService.isOffloadedFilteringSupported();
            mServiceLock.readLock().lock();
            if (mService != null) return mService.isOffloadedFilteringSupported();
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG, "failed to get isOffloadedFilteringSupported, error: ", e);
            Log.e(TAG, "failed to get isOffloadedFilteringSupported, error: ", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }
        return false;
        return false;
    }
    }
@@ -1335,9 +1402,12 @@ public final class BluetoothAdapter {
    public boolean isOffloadedScanBatchingSupported() {
    public boolean isOffloadedScanBatchingSupported() {
        if (!getLeAccess()) return false;
        if (!getLeAccess()) return false;
        try {
        try {
            return mService.isOffloadedScanBatchingSupported();
            mServiceLock.readLock().lock();
            if (mService != null) return mService.isOffloadedScanBatchingSupported();
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG, "failed to get isOffloadedScanBatchingSupported, error: ", e);
            Log.e(TAG, "failed to get isOffloadedScanBatchingSupported, error: ", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }
        return false;
        return false;
    }
    }
@@ -1376,10 +1446,13 @@ public final class BluetoothAdapter {
    public BluetoothActivityEnergyInfo getControllerActivityEnergyInfo(int updateType) {
    public BluetoothActivityEnergyInfo getControllerActivityEnergyInfo(int updateType) {
        if (getState() != STATE_ON) return null;
        if (getState() != STATE_ON) return null;
        try {
        try {
            mServiceLock.readLock().lock();
            BluetoothActivityEnergyInfo record;
            BluetoothActivityEnergyInfo record;
            if (mService != null) {
                if (!mService.isActivityAndEnergyReportingSupported()) {
                if (!mService.isActivityAndEnergyReportingSupported()) {
                    return null;
                    return null;
                }
                }
            }
            synchronized(this) {
            synchronized(this) {
                if (updateType == ACTIVITY_ENERGY_INFO_REFRESHED) {
                if (updateType == ACTIVITY_ENERGY_INFO_REFRESHED) {
                    mService.getActivityEnergyInfoFromController();
                    mService.getActivityEnergyInfoFromController();
@@ -1396,6 +1469,8 @@ public final class BluetoothAdapter {
            Log.e(TAG, "getControllerActivityEnergyInfoCallback wait interrupted: " + e);
            Log.e(TAG, "getControllerActivityEnergyInfoCallback wait interrupted: " + e);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG, "getControllerActivityEnergyInfoCallback: " + e);
            Log.e(TAG, "getControllerActivityEnergyInfoCallback: " + e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }
        return null;
        return null;
    }
    }
@@ -1417,11 +1492,14 @@ public final class BluetoothAdapter {
            return toDeviceSet(new BluetoothDevice[0]);
            return toDeviceSet(new BluetoothDevice[0]);
        }
        }
        try {
        try {
            synchronized(mManagerCallback) {
            mServiceLock.readLock().lock();
            if (mService != null) return toDeviceSet(mService.getBondedDevices());
            if (mService != null) return toDeviceSet(mService.getBondedDevices());
            }
            return toDeviceSet(new BluetoothDevice[0]);
            return toDeviceSet(new BluetoothDevice[0]);
        } catch (RemoteException e) {Log.e(TAG, "", e);}
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        return null;
        return null;
    }
    }


@@ -1441,10 +1519,13 @@ public final class BluetoothAdapter {
    public int getConnectionState() {
    public int getConnectionState() {
        if (getState() != STATE_ON) return BluetoothAdapter.STATE_DISCONNECTED;
        if (getState() != STATE_ON) return BluetoothAdapter.STATE_DISCONNECTED;
        try {
        try {
            synchronized(mManagerCallback) {
            mServiceLock.readLock().lock();
            if (mService != null) return mService.getAdapterConnectionState();
            if (mService != null) return mService.getAdapterConnectionState();
        } catch (RemoteException e) {
            Log.e(TAG, "getConnectionState:", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }
        } catch (RemoteException e) {Log.e(TAG, "getConnectionState:", e);}
        return BluetoothAdapter.STATE_DISCONNECTED;
        return BluetoothAdapter.STATE_DISCONNECTED;
    }
    }


@@ -1467,11 +1548,12 @@ public final class BluetoothAdapter {
    public int getProfileConnectionState(int profile) {
    public int getProfileConnectionState(int profile) {
        if (getState() != STATE_ON) return BluetoothProfile.STATE_DISCONNECTED;
        if (getState() != STATE_ON) return BluetoothProfile.STATE_DISCONNECTED;
        try {
        try {
            synchronized(mManagerCallback) {
            mServiceLock.readLock().lock();
            if (mService != null) return mService.getProfileConnectionState(profile);
            if (mService != null) return mService.getProfileConnectionState(profile);
            }
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG, "getProfileConnectionState:", e);
            Log.e(TAG, "getProfileConnectionState:", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        }
        return BluetoothProfile.STATE_DISCONNECTED;
        return BluetoothProfile.STATE_DISCONNECTED;
    }
    }
@@ -1775,7 +1857,9 @@ public final class BluetoothAdapter {
            byte[] hash;
            byte[] hash;
            byte[] randomizer;
            byte[] randomizer;


            byte[] ret = mService.readOutOfBandData();
            byte[] ret = null;
            mServiceLock.readLock().lock();
            if (mService != null) mService.readOutOfBandData();


            if (ret  == null || ret.length != 32) return null;
            if (ret  == null || ret.length != 32) return null;


@@ -1788,7 +1872,12 @@ public final class BluetoothAdapter {
            }
            }
            return new Pair<byte[], byte[]>(hash, randomizer);
            return new Pair<byte[], byte[]>(hash, randomizer);


        } catch (RemoteException e) {Log.e(TAG, "", e);}*/
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        } finally {
            mServiceLock.readLock().unlock();
        }
        */
        return null;
        return null;
    }
    }


@@ -1917,8 +2006,11 @@ public final class BluetoothAdapter {
        new IBluetoothManagerCallback.Stub() {
        new IBluetoothManagerCallback.Stub() {
            public void onBluetoothServiceUp(IBluetooth bluetoothService) {
            public void onBluetoothServiceUp(IBluetooth bluetoothService) {
                if (VDBG) Log.d(TAG, "onBluetoothServiceUp: " + bluetoothService);
                if (VDBG) Log.d(TAG, "onBluetoothServiceUp: " + bluetoothService);
                synchronized (mManagerCallback) {

                mServiceLock.writeLock().lock();
                mService = bluetoothService;
                mService = bluetoothService;
                mServiceLock.writeLock().unlock();

                synchronized (mProxyServiceStateCallbacks) {
                synchronized (mProxyServiceStateCallbacks) {
                    for (IBluetoothManagerCallback cb : mProxyServiceStateCallbacks ) {
                    for (IBluetoothManagerCallback cb : mProxyServiceStateCallbacks ) {
                        try {
                        try {
@@ -1927,7 +2019,8 @@ public final class BluetoothAdapter {
                            } else {
                            } else {
                                Log.d(TAG, "onBluetoothServiceUp: cb is null!!!");
                                Log.d(TAG, "onBluetoothServiceUp: cb is null!!!");
                            }
                            }
                            } catch (Exception e)  { Log.e(TAG,"",e);}
                        } catch (Exception e) {
                            Log.e(TAG,"",e);
                        }
                        }
                    }
                    }
                }
                }
@@ -1935,11 +2028,14 @@ public final class BluetoothAdapter {


            public void onBluetoothServiceDown() {
            public void onBluetoothServiceDown() {
                if (VDBG) Log.d(TAG, "onBluetoothServiceDown: " + mService);
                if (VDBG) Log.d(TAG, "onBluetoothServiceDown: " + mService);
                synchronized (mManagerCallback) {

                mServiceLock.writeLock().lock();
                mService = null;
                mService = null;
                if (mLeScanClients != null) mLeScanClients.clear();
                if (mLeScanClients != null) mLeScanClients.clear();
                if (sBluetoothLeAdvertiser != null) sBluetoothLeAdvertiser.cleanup();
                if (sBluetoothLeAdvertiser != null) sBluetoothLeAdvertiser.cleanup();
                if (sBluetoothLeScanner != null) sBluetoothLeScanner.cleanup();
                if (sBluetoothLeScanner != null) sBluetoothLeScanner.cleanup();
                mServiceLock.writeLock().unlock();

                synchronized (mProxyServiceStateCallbacks) {
                synchronized (mProxyServiceStateCallbacks) {
                    for (IBluetoothManagerCallback cb : mProxyServiceStateCallbacks ){
                    for (IBluetoothManagerCallback cb : mProxyServiceStateCallbacks ){
                        try {
                        try {
@@ -1948,7 +2044,8 @@ public final class BluetoothAdapter {
                            } else {
                            } else {
                                Log.d(TAG, "onBluetoothServiceDown: cb is null!!!");
                                Log.d(TAG, "onBluetoothServiceDown: cb is null!!!");
                            }
                            }
                            } catch (Exception e)  { Log.e(TAG,"",e);}
                        } catch (Exception e) {
                            Log.e(TAG,"",e);
                        }
                        }
                    }
                    }
                }
                }
@@ -2011,11 +2108,17 @@ public final class BluetoothAdapter {
        //TODO(BT)
        //TODO(BT)
        /*
        /*
        try {
        try {
            mServiceLock.readLock().lock();
            if (mService != null) {
                return mService.changeApplicationBluetoothState(on, new
                return mService.changeApplicationBluetoothState(on, new
                    StateChangeCallbackWrapper(callback), new Binder());
                    StateChangeCallbackWrapper(callback), new Binder());
            }
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG, "changeBluetoothState", e);
            Log.e(TAG, "changeBluetoothState", e);
        }*/
        } finally {
            mServiceLock.readLock().unlock();
        }
        */
        return false;
        return false;
    }
    }