@Test public void testStartReceiveBluetoothMacAddressMode_1() throws Exception { Field field = mBluetoothMacAddressResolutionHelper.getClass() .getDeclaredField("mReceiveBluetoothMacAddressTimeoutTimer"); field.setAccessible(true); field.set(mBluetoothMacAddressResolutionHelper, mMockCountDownTimer); Field fieldGattManager = mBluetoothMacAddressResolutionHelper.getClass() .getDeclaredField("mBluetoothGattManager"); fieldGattManager.setAccessible(true); fieldGattManager.set(mBluetoothMacAddressResolutionHelper, mMockBluetoothGattManager); Field fieldSettings = mBluetoothMacAddressResolutionHelper.getClass() .getDeclaredField("mSettings"); fieldSettings.setAccessible(true); fieldSettings.set(mBluetoothMacAddressResolutionHelper, mMockDiscoveryManagerSettings); when(mMockDiscoveryManagerSettings.getAutomateBluetoothMacAddressResolution()) .thenReturn(true); when(mMockDiscoveryManagerSettings.getProvideBluetoothMacAddressTimeout()) .thenReturn(0L); when(mMockBluetoothGattManager.getIsBluetoothMacAddressRequestServerStarted()) .thenReturn(false); mBluetoothMacAddressResolutionHelper.startReceiveBluetoothMacAddressMode("1"); verify(mMockDiscoveryManager, times(1)).makeDeviceDiscoverable( DiscoveryManagerSettings.DEFAULT_DEVICE_DISCOVERABLE_DURATION_IN_SECONDS); verify(mMockCountDownTimer, times(1)).cancel(); verify(mMockBluetoothGattManager, times(1)).startBluetoothMacAddressRequestServer("1"); assertThat("mReceiveBluetoothMacAddressTimeoutTimer countdown timer is properly set", field.get(mBluetoothMacAddressResolutionHelper), is(notNullValue())); }
public synchronized void startReceiveBluetoothMacAddressMode(String requestId) { if (!mIsReceiveBluetoothMacAddressModeStarted) { mIsReceiveBluetoothMacAddressModeStarted = true; Log.i(TAG, "startReceiveBluetoothMacAddressMode: Starting..."); if (mReceiveBluetoothMacAddressTimeoutTimer != null) { mReceiveBluetoothMacAddressTimeoutTimer.cancel(); mReceiveBluetoothMacAddressTimeoutTimer = null; } startBluetoothMacAddressGattServer(requestId); if (mSettings.getAutomateBluetoothMacAddressResolution()) { long durationInSeconds = mSettings.getProvideBluetoothMacAddressTimeout(); if (durationInSeconds == 0) { durationInSeconds = DiscoveryManagerSettings.DEFAULT_DEVICE_DISCOVERABLE_DURATION_IN_SECONDS; } else { durationInSeconds /= 1000; } mDiscoveryManager.makeDeviceDiscoverable((int)durationInSeconds); } long timeoutInMilliseconds = mSettings.getProvideBluetoothMacAddressTimeout(); mReceiveBluetoothMacAddressTimeoutTimer = new CountDownTimer(timeoutInMilliseconds, timeoutInMilliseconds) { @Override public void onTick(long l) { } @Override public void onFinish() { Log.d(TAG, "Receive Bluetooth MAC address timeout"); this.cancel(); mReceiveBluetoothMacAddressTimeoutTimer = null; stopReceiveBluetoothMacAddressMode(); } }; mReceiveBluetoothMacAddressTimeoutTimer.start(); } else { Log.d(TAG, "startReceiveBluetoothMacAddressMode: Already started"); } }
BluetoothMacAddressResolutionHelper implements BluetoothDeviceDiscoverer.BluetoothDeviceDiscovererListener,
                   BluetoothGattManager.BluetoothGattManagerListener { public synchronized void startReceiveBluetoothMacAddressMode(String requestId) { if (!mIsReceiveBluetoothMacAddressModeStarted) { mIsReceiveBluetoothMacAddressModeStarted = true; Log.i(TAG, "startReceiveBluetoothMacAddressMode: Starting..."); if (mReceiveBluetoothMacAddressTimeoutTimer != null) { mReceiveBluetoothMacAddressTimeoutTimer.cancel(); mReceiveBluetoothMacAddressTimeoutTimer = null; } startBluetoothMacAddressGattServer(requestId); if (mSettings.getAutomateBluetoothMacAddressResolution()) { long durationInSeconds = mSettings.getProvideBluetoothMacAddressTimeout(); if (durationInSeconds == 0) { durationInSeconds = DiscoveryManagerSettings.DEFAULT_DEVICE_DISCOVERABLE_DURATION_IN_SECONDS; } else { durationInSeconds /= 1000; } mDiscoveryManager.makeDeviceDiscoverable((int)durationInSeconds); } long timeoutInMilliseconds = mSettings.getProvideBluetoothMacAddressTimeout(); mReceiveBluetoothMacAddressTimeoutTimer = new CountDownTimer(timeoutInMilliseconds, timeoutInMilliseconds) { @Override public void onTick(long l) { } @Override public void onFinish() { Log.d(TAG, "Receive Bluetooth MAC address timeout"); this.cancel(); mReceiveBluetoothMacAddressTimeoutTimer = null; stopReceiveBluetoothMacAddressMode(); } }; mReceiveBluetoothMacAddressTimeoutTimer.start(); } else { Log.d(TAG, "startReceiveBluetoothMacAddressMode: Already started"); } } }
BluetoothMacAddressResolutionHelper implements BluetoothDeviceDiscoverer.BluetoothDeviceDiscovererListener,
                   BluetoothGattManager.BluetoothGattManagerListener { public synchronized void startReceiveBluetoothMacAddressMode(String requestId) { if (!mIsReceiveBluetoothMacAddressModeStarted) { mIsReceiveBluetoothMacAddressModeStarted = true; Log.i(TAG, "startReceiveBluetoothMacAddressMode: Starting..."); if (mReceiveBluetoothMacAddressTimeoutTimer != null) { mReceiveBluetoothMacAddressTimeoutTimer.cancel(); mReceiveBluetoothMacAddressTimeoutTimer = null; } startBluetoothMacAddressGattServer(requestId); if (mSettings.getAutomateBluetoothMacAddressResolution()) { long durationInSeconds = mSettings.getProvideBluetoothMacAddressTimeout(); if (durationInSeconds == 0) { durationInSeconds = DiscoveryManagerSettings.DEFAULT_DEVICE_DISCOVERABLE_DURATION_IN_SECONDS; } else { durationInSeconds /= 1000; } mDiscoveryManager.makeDeviceDiscoverable((int)durationInSeconds); } long timeoutInMilliseconds = mSettings.getProvideBluetoothMacAddressTimeout(); mReceiveBluetoothMacAddressTimeoutTimer = new CountDownTimer(timeoutInMilliseconds, timeoutInMilliseconds) { @Override public void onTick(long l) { } @Override public void onFinish() { Log.d(TAG, "Receive Bluetooth MAC address timeout"); this.cancel(); mReceiveBluetoothMacAddressTimeoutTimer = null; stopReceiveBluetoothMacAddressMode(); } }; mReceiveBluetoothMacAddressTimeoutTimer.start(); } else { Log.d(TAG, "startReceiveBluetoothMacAddressMode: Already started"); } } BluetoothMacAddressResolutionHelper(
            Context context, BluetoothAdapter bluetoothAdapter, DiscoveryManager discoveryManager,
            UUID bleServiceUuid, UUID provideBluetoothMacAddressRequestUuid);  BluetoothMacAddressResolutionHelper(
            Context context, BluetoothAdapter bluetoothAdapter, DiscoveryManager discoveryManager,
            UUID bleServiceUuid, UUID provideBluetoothMacAddressRequestUuid, SharedPreferences preferences); }
BluetoothMacAddressResolutionHelper implements BluetoothDeviceDiscoverer.BluetoothDeviceDiscovererListener,
                   BluetoothGattManager.BluetoothGattManagerListener { public synchronized void startReceiveBluetoothMacAddressMode(String requestId) { if (!mIsReceiveBluetoothMacAddressModeStarted) { mIsReceiveBluetoothMacAddressModeStarted = true; Log.i(TAG, "startReceiveBluetoothMacAddressMode: Starting..."); if (mReceiveBluetoothMacAddressTimeoutTimer != null) { mReceiveBluetoothMacAddressTimeoutTimer.cancel(); mReceiveBluetoothMacAddressTimeoutTimer = null; } startBluetoothMacAddressGattServer(requestId); if (mSettings.getAutomateBluetoothMacAddressResolution()) { long durationInSeconds = mSettings.getProvideBluetoothMacAddressTimeout(); if (durationInSeconds == 0) { durationInSeconds = DiscoveryManagerSettings.DEFAULT_DEVICE_DISCOVERABLE_DURATION_IN_SECONDS; } else { durationInSeconds /= 1000; } mDiscoveryManager.makeDeviceDiscoverable((int)durationInSeconds); } long timeoutInMilliseconds = mSettings.getProvideBluetoothMacAddressTimeout(); mReceiveBluetoothMacAddressTimeoutTimer = new CountDownTimer(timeoutInMilliseconds, timeoutInMilliseconds) { @Override public void onTick(long l) { } @Override public void onFinish() { Log.d(TAG, "Receive Bluetooth MAC address timeout"); this.cancel(); mReceiveBluetoothMacAddressTimeoutTimer = null; stopReceiveBluetoothMacAddressMode(); } }; mReceiveBluetoothMacAddressTimeoutTimer.start(); } else { Log.d(TAG, "startReceiveBluetoothMacAddressMode: Already started"); } } BluetoothMacAddressResolutionHelper(
            Context context, BluetoothAdapter bluetoothAdapter, DiscoveryManager discoveryManager,
            UUID bleServiceUuid, UUID provideBluetoothMacAddressRequestUuid);  BluetoothMacAddressResolutionHelper(
            Context context, BluetoothAdapter bluetoothAdapter, DiscoveryManager discoveryManager,
            UUID bleServiceUuid, UUID provideBluetoothMacAddressRequestUuid, SharedPreferences preferences); UUID getProvideBluetoothMacAddressRequestUuid(); String getCurrentProvideBluetoothMacAddressRequestId(); boolean getIsProvideBluetoothMacAddressModeStarted(); boolean getIsBluetoothMacAddressGattServerStarted(); boolean getIsReceiveBluetoothMacAddressModeStarted(); synchronized void stopAllBluetoothMacAddressResolutionOperations(); synchronized boolean startProvideBluetoothMacAddressMode(String requestId); synchronized void stopProvideBluetoothMacAddressMode(); void provideBluetoothMacAddressToDevice(BluetoothDevice bluetoothDevice); synchronized void startReceiveBluetoothMacAddressMode(String requestId); synchronized void stopReceiveBluetoothMacAddressMode(); void startBluetoothMacAddressGattServer(String requestId); synchronized boolean startBluetoothDeviceDiscovery(); synchronized boolean stopBluetoothDeviceDiscovery(); @Override void onBluetoothDeviceDiscovered(BluetoothDevice bluetoothDevice); @Override void onBluetoothGattClientOperationCountInQueueChanged(int operationCountInQueue); @Override void onProvideBluetoothMacAddressResult(String requestId, boolean wasCompleted); @Override void onBluetoothMacAddressResolved(String bluetoothMacAddress); }
BluetoothMacAddressResolutionHelper implements BluetoothDeviceDiscoverer.BluetoothDeviceDiscovererListener,
                   BluetoothGattManager.BluetoothGattManagerListener { public synchronized void startReceiveBluetoothMacAddressMode(String requestId) { if (!mIsReceiveBluetoothMacAddressModeStarted) { mIsReceiveBluetoothMacAddressModeStarted = true; Log.i(TAG, "startReceiveBluetoothMacAddressMode: Starting..."); if (mReceiveBluetoothMacAddressTimeoutTimer != null) { mReceiveBluetoothMacAddressTimeoutTimer.cancel(); mReceiveBluetoothMacAddressTimeoutTimer = null; } startBluetoothMacAddressGattServer(requestId); if (mSettings.getAutomateBluetoothMacAddressResolution()) { long durationInSeconds = mSettings.getProvideBluetoothMacAddressTimeout(); if (durationInSeconds == 0) { durationInSeconds = DiscoveryManagerSettings.DEFAULT_DEVICE_DISCOVERABLE_DURATION_IN_SECONDS; } else { durationInSeconds /= 1000; } mDiscoveryManager.makeDeviceDiscoverable((int)durationInSeconds); } long timeoutInMilliseconds = mSettings.getProvideBluetoothMacAddressTimeout(); mReceiveBluetoothMacAddressTimeoutTimer = new CountDownTimer(timeoutInMilliseconds, timeoutInMilliseconds) { @Override public void onTick(long l) { } @Override public void onFinish() { Log.d(TAG, "Receive Bluetooth MAC address timeout"); this.cancel(); mReceiveBluetoothMacAddressTimeoutTimer = null; stopReceiveBluetoothMacAddressMode(); } }; mReceiveBluetoothMacAddressTimeoutTimer.start(); } else { Log.d(TAG, "startReceiveBluetoothMacAddressMode: Already started"); } } BluetoothMacAddressResolutionHelper(
            Context context, BluetoothAdapter bluetoothAdapter, DiscoveryManager discoveryManager,
            UUID bleServiceUuid, UUID provideBluetoothMacAddressRequestUuid);  BluetoothMacAddressResolutionHelper(
            Context context, BluetoothAdapter bluetoothAdapter, DiscoveryManager discoveryManager,
            UUID bleServiceUuid, UUID provideBluetoothMacAddressRequestUuid, SharedPreferences preferences); UUID getProvideBluetoothMacAddressRequestUuid(); String getCurrentProvideBluetoothMacAddressRequestId(); boolean getIsProvideBluetoothMacAddressModeStarted(); boolean getIsBluetoothMacAddressGattServerStarted(); boolean getIsReceiveBluetoothMacAddressModeStarted(); synchronized void stopAllBluetoothMacAddressResolutionOperations(); synchronized boolean startProvideBluetoothMacAddressMode(String requestId); synchronized void stopProvideBluetoothMacAddressMode(); void provideBluetoothMacAddressToDevice(BluetoothDevice bluetoothDevice); synchronized void startReceiveBluetoothMacAddressMode(String requestId); synchronized void stopReceiveBluetoothMacAddressMode(); void startBluetoothMacAddressGattServer(String requestId); synchronized boolean startBluetoothDeviceDiscovery(); synchronized boolean stopBluetoothDeviceDiscovery(); @Override void onBluetoothDeviceDiscovered(BluetoothDevice bluetoothDevice); @Override void onBluetoothGattClientOperationCountInQueueChanged(int operationCountInQueue); @Override void onProvideBluetoothMacAddressResult(String requestId, boolean wasCompleted); @Override void onBluetoothMacAddressResolved(String bluetoothMacAddress);  }