Java Code Examples for no.nordicsemi.android.ble.callback.FailCallback#REASON_BLUETOOTH_DISABLED

The following examples show how to use no.nordicsemi.android.ble.callback.FailCallback#REASON_BLUETOOTH_DISABLED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleRequest.java    From Android-BLE-Library with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Synchronously waits until the request is done.
 * <p>
 * Callbacks set using {@link #before(BeforeCallback)}, {@link #done(SuccessCallback)} and
 * {@link #fail(FailCallback)} will be ignored.
 * <p>
 * This method may not be called from the main (UI) thread.
 *
 * @throws RequestFailedException      thrown when the BLE request finished with status other
 *                                     than {@link BluetoothGatt#GATT_SUCCESS}.
 * @throws IllegalStateException       thrown when you try to call this method from the main
 *                                     (UI) thread.
 * @throws DeviceDisconnectedException thrown when the device disconnected before the request
 *                                     was completed.
 * @throws BluetoothDisabledException  thrown when the Bluetooth adapter has been disabled.
 * @throws InvalidRequestException     thrown when the request was called before the device was
 *                                     connected at least once (unknown device).
 */
public final void await() throws RequestFailedException, DeviceDisconnectedException,
		BluetoothDisabledException, InvalidRequestException {
	assertNotMainThread();

	final BeforeCallback bc = beforeCallback;
	final SuccessCallback sc = successCallback;
	final FailCallback fc = failCallback;
	try {
		syncLock.close();
		final RequestCallback callback = new RequestCallback();
		beforeCallback = null;
		done(callback).fail(callback).invalid(callback).enqueue();

		syncLock.block();
		if (!callback.isSuccess()) {
			if (callback.status == FailCallback.REASON_DEVICE_DISCONNECTED) {
				throw new DeviceDisconnectedException();
			}
			if (callback.status == FailCallback.REASON_BLUETOOTH_DISABLED) {
				throw new BluetoothDisabledException();
			}
			if (callback.status == RequestCallback.REASON_REQUEST_INVALID) {
				throw new InvalidRequestException(this);
			}
			throw new RequestFailedException(this, callback.status);
		}
	} finally {
		beforeCallback = bc;
		successCallback = sc;
		failCallback = fc;
	}
}
 
Example 2
Source File: TimeoutableRequest.java    From Android-BLE-Library with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Synchronously waits until the request is done.
 * <p>
 * Use {@link #timeout(long)} to set the maximum time the manager should wait until the request
 * is ready. When the timeout occurs, the {@link InterruptedException} will be thrown.
 * <p>
 * Callbacks set using {@link #done(SuccessCallback)} and {@link #fail(FailCallback)}
 * will be ignored.
 * <p>
 * This method may not be called from the main (UI) thread.
 *
 * @throws RequestFailedException      thrown when the BLE request finished with status other
 *                                     than {@link BluetoothGatt#GATT_SUCCESS}.
 * @throws InterruptedException        thrown if the timeout occurred before the request has
 *                                     finished.
 * @throws IllegalStateException       thrown when you try to call this method from the main
 *                                     (UI) thread.
 * @throws DeviceDisconnectedException thrown when the device disconnected before the request
 *                                     was completed.
 * @throws BluetoothDisabledException  thrown when the Bluetooth adapter has been disabled.
 * @throws InvalidRequestException     thrown when the request was called before the device was
 *                                     connected at least once (unknown device).
 * @see #enqueue()
 */
public final void await() throws RequestFailedException, DeviceDisconnectedException,
		BluetoothDisabledException, InvalidRequestException, InterruptedException {
	assertNotMainThread();

	final SuccessCallback sc = successCallback;
	final FailCallback fc = failCallback;
	try {
		syncLock.close();
		final RequestCallback callback = new RequestCallback();
		done(callback).fail(callback).invalid(callback).enqueue();

		if (!syncLock.block(timeout)) {
			throw new InterruptedException();
		}
		if (!callback.isSuccess()) {
			if (callback.status == FailCallback.REASON_DEVICE_DISCONNECTED) {
				throw new DeviceDisconnectedException();
			}
			if (callback.status == FailCallback.REASON_BLUETOOTH_DISABLED) {
				throw new BluetoothDisabledException();
			}
			if (callback.status == RequestCallback.REASON_REQUEST_INVALID) {
				throw new InvalidRequestException(this);
			}
			throw new RequestFailedException(this, callback.status);
		}
	} finally {
		successCallback = sc;
		failCallback = fc;
	}
}
 
Example 3
Source File: RequestQueue.java    From Android-BLE-Library with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Synchronously waits until all enqueued requests are done. The queue will fail if any of
 * the enqueued requests fails. All following requests will be ignored.
 * <p>
 * Callbacks set using {@link #before(BeforeCallback)}, {@link #done(SuccessCallback)} and
 * {@link #fail(FailCallback)} will be ignored.
 * <p>
 * This method may not be called from the main (UI) thread.
 *
 * @throws RequestFailedException      thrown when the BLE request finished with status other
 *                                     than {@link BluetoothGatt#GATT_SUCCESS}.
 * @throws IllegalStateException       thrown when you try to call this method from the main
 *                                     (UI) thread.
 * @throws DeviceDisconnectedException thrown when the device disconnected before the request
 *                                     was completed.
 * @throws BluetoothDisabledException  thrown when the Bluetooth adapter has been disabled.
 * @throws InvalidRequestException     thrown when the request was called before the device was
 *                                     connected at least once (unknown device).
 * @throws InterruptedException        thrown when one of the request has failed with a timeout.
 */
public final void await() throws RequestFailedException, DeviceDisconnectedException,
		BluetoothDisabledException, InvalidRequestException, InterruptedException {
	assertNotMainThread();

	final BeforeCallback bc = beforeCallback;
	final SuccessCallback sc = successCallback;
	final FailCallback fc = failCallback;
	try {
		syncLock.close();
		final RequestCallback callback = new RequestCallback();
		beforeCallback = null;
		done(callback).fail(callback).invalid(callback).enqueue();

		syncLock.block();
		if (!callback.isSuccess()) {
			if (callback.status == FailCallback.REASON_DEVICE_DISCONNECTED) {
				throw new DeviceDisconnectedException();
			}
			if (callback.status == FailCallback.REASON_BLUETOOTH_DISABLED) {
				throw new BluetoothDisabledException();
			}
			if (callback.status == FailCallback.REASON_TIMEOUT) {
				throw new InterruptedException();
			}
			if (callback.status == RequestCallback.REASON_REQUEST_INVALID) {
				throw new InvalidRequestException(this);
			}
			throw new RequestFailedException(this, callback.status);
		}
	} finally {
		beforeCallback = bc;
		successCallback = sc;
		failCallback = fc;
	}
}