BluetoothMacAddressResolutionHelper implements BluetoothDeviceDiscoverer.BluetoothDeviceDiscovererListener,
                   BluetoothGattManager.BluetoothGattManagerListener { public synchronized boolean startProvideBluetoothMacAddressMode(String requestId) { Log.d(TAG, "startProvideBluetoothMacAddressMode: " + requestId); boolean wasStarted = false; if (mDiscoveryManager.isBleMultipleAdvertisementSupported()) { if (!mIsProvideBluetoothMacAddressModeStarted) { mIsProvideBluetoothMacAddressModeStarted = true; mCurrentProvideBluetoothMacAddressRequestId = requestId; if (mCurrentProvideBluetoothMacAddressRequestId != null && mCurrentProvideBluetoothMacAddressRequestId.length() > 0) { if (startBluetoothDeviceDiscovery()) { BlePeerDiscoverer blePeerDiscoverer = mDiscoveryManager.getBlePeerDiscovererInstanceAndCheckBluetoothMacAddress(); if (blePeerDiscoverer.startPeerAddressHelperAdvertiser( mCurrentProvideBluetoothMacAddressRequestId, PeerProperties.BLUETOOTH_MAC_ADDRESS_UNKNOWN, mSettings.getProvideBluetoothMacAddressTimeout())) { mDiscoveryManager.onProvideBluetoothMacAddressModeStartedChanged(true); wasStarted = true; } else { Log.e(TAG, "startProvideBluetoothMacAddressMode: Failed to start advertising our willingness to help via BLE"); } } else { Log.e(TAG, "startProvideBluetoothMacAddressMode: Failed to start Bluetooth device discovery"); } } else { Log.e(TAG, "startProvideBluetoothMacAddressMode: Invalid request ID: " + mCurrentProvideBluetoothMacAddressRequestId); } } else { Log.d(TAG, "startProvideBluetoothMacAddressMode: Already started"); } } else { Log.e(TAG, "startProvideBluetoothMacAddressMode: Bluetooth LE advertising is not supported on this device"); } if (!wasStarted) { stopProvideBluetoothMacAddressMode(); } return wasStarted; } 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);  }
@Test public void testStartProvideBluetoothMacAddressMode_Success() throws Exception { String reqId = "requestID"; Field fieldGattManager = mBluetoothMacAddressResolutionHelper.getClass() .getDeclaredField("mBluetoothGattManager"); fieldGattManager.setAccessible(true); fieldGattManager.set(mBluetoothMacAddressResolutionHelper, mMockBluetoothGattManager); Field fieldBTDiscoverer = mBluetoothMacAddressResolutionHelper.getClass() .getDeclaredField("mBluetoothDeviceDiscoverer"); fieldBTDiscoverer.setAccessible(true); fieldBTDiscoverer.set(mBluetoothMacAddressResolutionHelper, mMockBluetoothDeviceDiscoverer); Field fieldReqID = mBluetoothMacAddressResolutionHelper.getClass() .getDeclaredField("mCurrentProvideBluetoothMacAddressRequestId"); fieldReqID.setAccessible(true); fieldReqID.set(mBluetoothMacAddressResolutionHelper, "dummyReqID"); Field fieldIsProvideBTModeStarted = mBluetoothMacAddressResolutionHelper.getClass() .getDeclaredField("mIsProvideBluetoothMacAddressModeStarted"); fieldIsProvideBTModeStarted.setAccessible(true); fieldIsProvideBTModeStarted.set(mBluetoothMacAddressResolutionHelper, false); when(mMockDiscoveryManager.isBleMultipleAdvertisementSupported()).thenReturn(true); EnumSet<BlePeerDiscoverer.BlePeerDiscovererStateSet> mStateSet = EnumSet.of(BlePeerDiscoverer.BlePeerDiscovererStateSet.NOT_STARTED); when(mMockBlePeerDiscoverer.getState()).thenReturn(mStateSet); when(mMockBluetoothDeviceDiscoverer.isRunning()).thenReturn(true); when(mMockBluetoothAdapter.isDiscovering()).thenReturn(true); doReturn(true).when(mMockBlePeerDiscoverer) .startPeerAddressHelperAdvertiser(anyString(), anyString(), anyLong()); assertThat("is True, if the \"Provide Bluetooth MAC address\" mode was started successfully", mBluetoothMacAddressResolutionHelper.startProvideBluetoothMacAddressMode(reqId), is(true)); verify(mMockDiscoveryManager, times(1)). onProvideBluetoothMacAddressModeStartedChanged(true); }