@SuppressWarnings({"unused","WeakerAccess"})
    @RequiresApi(21)
    public boolean runTransmitterTest(final Context context) {
        initializeWithContext(context);
        this.mTransmitterTestResult = null;
        long testStartTime = System.currentTimeMillis();
        if (mAdapter != null) {
            final BluetoothLeAdvertiser advertiser = getAdvertiserSafely(mAdapter);
            if(advertiser != null) {
                AdvertiseSettings settings = (new Builder()).setAdvertiseMode(0).build();
                AdvertiseData data = (new android.bluetooth.le.AdvertiseData.Builder())
                        .addManufacturerData(0, new byte[]{0}).build();
                LogManager.i(TAG, "Starting transmitter test");
                advertiser.startAdvertising(settings, data, new AdvertiseCallback() {
                    public void onStartSuccess(AdvertiseSettings settingsInEffect) {
                        super.onStartSuccess(settingsInEffect);
                        LogManager.i(BluetoothMedic.TAG, "Transmitter test succeeded");
                        advertiser.stopAdvertising(this);
                        BluetoothMedic.this.mTransmitterTestResult = true;
                    }

                    public void onStartFailure(int errorCode) {
                        super.onStartFailure(errorCode);
                        Intent intent = new Intent("onStartFailed");
                        intent.putExtra("errorCode", errorCode);
                        LogManager.d(BluetoothMedic.TAG, "Sending onStartFailure broadcast with "
                                + BluetoothMedic.this.mLocalBroadcastManager);
                        if (BluetoothMedic.this.mLocalBroadcastManager != null) {
                            BluetoothMedic.this.mLocalBroadcastManager.sendBroadcast(intent);
                        }
                        if(errorCode == 4) {
                            BluetoothMedic.this.mTransmitterTestResult = false;
                            LogManager.w(BluetoothMedic.TAG,
                                    "Transmitter test failed in a way we consider a test failure");
                            BluetoothMedic.this.sendNotification(context, "transmitter failed",
                                    "bluetooth not ok");
                        } else {
                            BluetoothMedic.this.mTransmitterTestResult = true;
                            LogManager.i(BluetoothMedic.TAG,
                                    "Transmitter test failed, but not in a way we consider a test failure");
                        }

                    }
                });
            } else {
                LogManager.d(TAG, "Cannot get advertiser");
            }
            while(this.mTransmitterTestResult == null) {
                LogManager.d(TAG, "Waiting for transmitter test to complete...");

                try {
                    Thread.sleep(1000L);
                } catch (InterruptedException e) { /* do nothing */ }

                if(System.currentTimeMillis() - testStartTime > 5000L) {
                    LogManager.d(TAG, "Timeout running transmitter test");
                    break;
                }
            }
        }

        LogManager.d(TAG, "transmitter test complete");
        return this.mTransmitterTestResult != null && this.mTransmitterTestResult;
    }
@ SuppressWarnings ( { "unused" , "WeakerAccess" } ) @ RequiresApi ( 21 ) public boolean runTransmitterTest ( final Context context ) { initializeWithContext ( context ) ; this . mTransmitterTestResult = null ; long testStartTime = System . currentTimeMillis ( ) ; if ( mAdapter != null ) { final BluetoothLeAdvertiser advertiser = getAdvertiserSafely ( mAdapter ) ; if ( advertiser != null ) { AdvertiseSettings settings = ( new Builder ( ) ) . setAdvertiseMode ( 0 ) . build ( ) ; AdvertiseData data = ( new android . bluetooth . le . AdvertiseData . Builder ( ) ) . addManufacturerData ( 0 , new byte [ ] { 0 } ) . build ( ) ; LogManager . i ( TAG , "Starting transmitter test" ) ; advertiser . startAdvertising ( settings , data , new AdvertiseCallback ( ) { public void onStartSuccess ( AdvertiseSettings settingsInEffect ) { super . onStartSuccess ( settingsInEffect ) ; LogManager . i ( BluetoothMedic . TAG , "Transmitter test succeeded" ) ; advertiser . stopAdvertising ( this ) ; BluetoothMedic . this . mTransmitterTestResult = true ; } public void onStartFailure ( int errorCode ) { super . onStartFailure ( errorCode ) ; Intent intent = new Intent ( "onStartFailed" ) ; intent . putExtra ( "errorCode" , errorCode ) ; LogManager . d ( BluetoothMedic . TAG , "Sending onStartFailure broadcast with " + BluetoothMedic . this . mLocalBroadcastManager ) ; if ( BluetoothMedic . this . mLocalBroadcastManager != null ) { BluetoothMedic . this . mLocalBroadcastManager . sendBroadcast ( intent ) ; } if ( errorCode == 4 ) { BluetoothMedic . this . mTransmitterTestResult = false ; LogManager . w ( BluetoothMedic . TAG , "Transmitter test failed in a way we consider a test failure" ) ; BluetoothMedic . this . sendNotification ( context , "transmitter failed" , "bluetooth not ok" ) ; } else { BluetoothMedic . this . mTransmitterTestResult = true ; LogManager . i ( BluetoothMedic . TAG , "Transmitter test failed, but not in a way we consider a test failure" ) ; } } } ) ; } else { LogManager . d ( TAG , "Cannot get advertiser" ) ; } while ( this . mTransmitterTestResult == null ) { LogManager . d ( TAG , "Waiting for transmitter test to complete..." ) ; try { Thread . sleep ( 1000L ) ; } catch ( InterruptedException e ) { } if ( System . currentTimeMillis ( ) - testStartTime > 5000L ) { LogManager . d ( TAG , "Timeout running transmitter test" ) ; break ; } } } LogManager . d ( TAG , "transmitter test complete" ) ; return this . mTransmitterTestResult != null && this . mTransmitterTestResult ; }
Starts up a beacon transmitter with the intent of seeing if it results in an error condition
indicating the bluetooth stack may be in a bad state.

If the failure error code matches a pattern known to be associated with a bad bluetooth stack
state, then the bluetooth stack is turned off and then back on after a short delay in order
to try to recover.

@return false if the test indicates a failure indicating a bad state of the bluetooth stack