@Test public void testStart() throws Exception { mBleAdvertiser.setAdvertiseData(mMockAdvertiseData); assertThat("It should return true if advertising is properly started", mBleAdvertiser.start(), is(true)); verify(mMockBluetoothLeAdvertiser, times(1)).startAdvertising(mMockAdvertiseSettings, mMockAdvertiseData, null, mBleAdvertiser); assertThat("It should return true as the advertiser is either starting or running", mBleAdvertiser.isStarted(), is(true)); verify(mMockListener, never()).onIsAdvertiserStartedChanged(anyBoolean()); reset(mMockBluetoothLeAdvertiser); assertThat("It should return true if advertising is already started", mBleAdvertiser.start(), is(true)); verify(mMockBluetoothLeAdvertiser, never()).startAdvertising( Mockito.any(AdvertiseSettings.class), Mockito.any(AdvertiseData.class), Mockito.any(AdvertiseData.class), Mockito.any(AdvertiseCallback.class)); }
public synchronized boolean start() { Log.d(TAG, "start: state = " + mState + ThreadUtils.currentThreadToString()); if (mState == State.NOT_STARTED) { if (mBluetoothLeAdvertiser != null) { if (mAdvertiseData != null) { try { Log.i(TAG, "start: Starting... advertisement data = " + mAdvertiseData.toString() + ", " + ThreadUtils.currentThreadToString()); mBluetoothLeAdvertiser.startAdvertising(mAdvertiseSettings, mAdvertiseData, null, this); Log.i(TAG, "start: Started advertisment " + ThreadUtils.currentThreadToString()); setState(State.STARTING, true); } catch (Exception e) { Log.e(TAG, "start: Failed to start advertising: " + e.getMessage(), e); } } else { Log.e(TAG, "start: No advertisement data set"); } } else { Log.e(TAG, "start: No BLE advertiser instance"); } } else { Log.d(TAG, "start: Already running"); } try { Log.i(TAG, "start: return, state = " + mState + ThreadUtils.currentThreadToString()); return (mState != State.NOT_STARTED); } finally { Log.d(TAG, "start returned: " + ThreadUtils.currentThreadToString()); } }
BleAdvertiser extends AdvertiseCallback { public synchronized boolean start() { Log.d(TAG, "start: state = " + mState + ThreadUtils.currentThreadToString()); if (mState == State.NOT_STARTED) { if (mBluetoothLeAdvertiser != null) { if (mAdvertiseData != null) { try { Log.i(TAG, "start: Starting... advertisement data = " + mAdvertiseData.toString() + ", " + ThreadUtils.currentThreadToString()); mBluetoothLeAdvertiser.startAdvertising(mAdvertiseSettings, mAdvertiseData, null, this); Log.i(TAG, "start: Started advertisment " + ThreadUtils.currentThreadToString()); setState(State.STARTING, true); } catch (Exception e) { Log.e(TAG, "start: Failed to start advertising: " + e.getMessage(), e); } } else { Log.e(TAG, "start: No advertisement data set"); } } else { Log.e(TAG, "start: No BLE advertiser instance"); } } else { Log.d(TAG, "start: Already running"); } try { Log.i(TAG, "start: return, state = " + mState + ThreadUtils.currentThreadToString()); return (mState != State.NOT_STARTED); } finally { Log.d(TAG, "start returned: " + ThreadUtils.currentThreadToString()); } } }
BleAdvertiser extends AdvertiseCallback { public synchronized boolean start() { Log.d(TAG, "start: state = " + mState + ThreadUtils.currentThreadToString()); if (mState == State.NOT_STARTED) { if (mBluetoothLeAdvertiser != null) { if (mAdvertiseData != null) { try { Log.i(TAG, "start: Starting... advertisement data = " + mAdvertiseData.toString() + ", " + ThreadUtils.currentThreadToString()); mBluetoothLeAdvertiser.startAdvertising(mAdvertiseSettings, mAdvertiseData, null, this); Log.i(TAG, "start: Started advertisment " + ThreadUtils.currentThreadToString()); setState(State.STARTING, true); } catch (Exception e) { Log.e(TAG, "start: Failed to start advertising: " + e.getMessage(), e); } } else { Log.e(TAG, "start: No advertisement data set"); } } else { Log.e(TAG, "start: No BLE advertiser instance"); } } else { Log.d(TAG, "start: Already running"); } try { Log.i(TAG, "start: return, state = " + mState + ThreadUtils.currentThreadToString()); return (mState != State.NOT_STARTED); } finally { Log.d(TAG, "start returned: " + ThreadUtils.currentThreadToString()); } } BleAdvertiser(Listener listener, BluetoothAdapter bluetoothAdapter);   BleAdvertiser(Listener listener, BluetoothAdapter bluetoothAdapter,
                  AdvertiseSettings.Builder builder, DiscoveryManagerSettings settings); }
BleAdvertiser extends AdvertiseCallback { public synchronized boolean start() { Log.d(TAG, "start: state = " + mState + ThreadUtils.currentThreadToString()); if (mState == State.NOT_STARTED) { if (mBluetoothLeAdvertiser != null) { if (mAdvertiseData != null) { try { Log.i(TAG, "start: Starting... advertisement data = " + mAdvertiseData.toString() + ", " + ThreadUtils.currentThreadToString()); mBluetoothLeAdvertiser.startAdvertising(mAdvertiseSettings, mAdvertiseData, null, this); Log.i(TAG, "start: Started advertisment " + ThreadUtils.currentThreadToString()); setState(State.STARTING, true); } catch (Exception e) { Log.e(TAG, "start: Failed to start advertising: " + e.getMessage(), e); } } else { Log.e(TAG, "start: No advertisement data set"); } } else { Log.e(TAG, "start: No BLE advertiser instance"); } } else { Log.d(TAG, "start: Already running"); } try { Log.i(TAG, "start: return, state = " + mState + ThreadUtils.currentThreadToString()); return (mState != State.NOT_STARTED); } finally { Log.d(TAG, "start returned: " + ThreadUtils.currentThreadToString()); } } BleAdvertiser(Listener listener, BluetoothAdapter bluetoothAdapter);   BleAdvertiser(Listener listener, BluetoothAdapter bluetoothAdapter,
                  AdvertiseSettings.Builder builder, DiscoveryManagerSettings settings); void setAdvertiseSettings(AdvertiseSettings advertiseSettings); boolean isStarted(); synchronized boolean start(); synchronized void stop(boolean notifyStateChanged); @Override void onStartFailure(int errorCode); @Override void onStartSuccess(AdvertiseSettings settingsInEffect); }
BleAdvertiser extends AdvertiseCallback { public synchronized boolean start() { Log.d(TAG, "start: state = " + mState + ThreadUtils.currentThreadToString()); if (mState == State.NOT_STARTED) { if (mBluetoothLeAdvertiser != null) { if (mAdvertiseData != null) { try { Log.i(TAG, "start: Starting... advertisement data = " + mAdvertiseData.toString() + ", " + ThreadUtils.currentThreadToString()); mBluetoothLeAdvertiser.startAdvertising(mAdvertiseSettings, mAdvertiseData, null, this); Log.i(TAG, "start: Started advertisment " + ThreadUtils.currentThreadToString()); setState(State.STARTING, true); } catch (Exception e) { Log.e(TAG, "start: Failed to start advertising: " + e.getMessage(), e); } } else { Log.e(TAG, "start: No advertisement data set"); } } else { Log.e(TAG, "start: No BLE advertiser instance"); } } else { Log.d(TAG, "start: Already running"); } try { Log.i(TAG, "start: return, state = " + mState + ThreadUtils.currentThreadToString()); return (mState != State.NOT_STARTED); } finally { Log.d(TAG, "start returned: " + ThreadUtils.currentThreadToString()); } } BleAdvertiser(Listener listener, BluetoothAdapter bluetoothAdapter);   BleAdvertiser(Listener listener, BluetoothAdapter bluetoothAdapter,
                  AdvertiseSettings.Builder builder, DiscoveryManagerSettings settings); void setAdvertiseSettings(AdvertiseSettings advertiseSettings); boolean isStarted(); synchronized boolean start(); synchronized void stop(boolean notifyStateChanged); @Override void onStartFailure(int errorCode); @Override void onStartSuccess(AdvertiseSettings settingsInEffect);  }