no.nordicsemi.android.log.LogContract Java Examples

The following examples show how to use no.nordicsemi.android.log.LogContract. 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: TemplateManager.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected void onDeviceReady() {
	super.onDeviceReady();

	// Initialization is now ready.
	// The service or activity has been notified with TemplateManagerCallbacks#onDeviceReady().
	// TODO Do some extra logic here, of remove onDeviceReady().

	// Device is ready, let's read something here. Usually there is nothing else to be done
	// here, as all had been done during initialization.
	readCharacteristic(optionalCharacteristic)
			.with((device, data) -> {
				// Characteristic value has been read
				// Let's do some magic with it.
				if (data.size() > 0) {
					final Integer value = data.getIntValue(Data.FORMAT_UINT8, 0);
					log(LogContract.Log.Level.APPLICATION, "Value '" + value + "' has been read!");
				} else {
					log(Log.WARN, "Value is empty!");
				}
			})
			.enqueue();
}
 
Example #2
Source File: nRFLoggerTree.java    From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected void log(@LogPriority final int priority, @Nullable final String tag,
				   @NonNull final String message, @Nullable final Throwable t) {
	if (session == null)
		return;

	final int level = LogContract.Log.Level.fromPriority(priority);

	// Ignore t. Stack trace is already added to the message by prepareLog

	if (tag == null) {
		Logger.log(session, level, message);
	} else {
		Logger.log(session, level, "[" + tag + "] " + message);
	}
}
 
Example #3
Source File: LocalLogContentProvider.java    From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Ends the current transaction and clears out the member variable. This does not set the
 * transaction as being successful.
 *
 * @param uri           uri to be notified about the change.
 * @param callerIsBatch Whether the caller is operating in batch mode.
 */
@SuppressWarnings("unused")
private void endTransaction(final Uri uri, final boolean callerIsBatch) {
	final LogTransaction transaction = mTransactionHolder.get();
	if (transaction != null && (!transaction.isBatch() || callerIsBatch)) {
		try {
			if (transaction.isDirty()) {
				notifyChange(Uri.withAppendedPath(getAuthorityUri(),
						LogContract.Session.SESSION_CONTENT_DIRECTORY));
			}
			transaction.finish(callerIsBatch);
		} finally {
			// No matter what, make sure we clear out the thread-local transaction reference.
			mTransactionHolder.set(null);
		}
	}
}
 
Example #4
Source File: LocalLogContentProvider.java    From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private char getLevelAsChar(final int level) {
	switch (level) {
		case LogContract.Log.Level.VERBOSE:
			return 'V';
		case LogContract.Log.Level.INFO:
			return 'I';
		case LogContract.Log.Level.APPLICATION:
			return 'A';
		case LogContract.Log.Level.WARNING:
			return 'W';
		case LogContract.Log.Level.ERROR:
			return 'E';
		default:
			return 'D';
	}
}
 
Example #5
Source File: CGMManager.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Sends the request to obtain all records from glucose device. Initially we want to notify the
 * user about the number of the records so the Report Number of Stored Records request is send.
 * The data will be returned to Glucose Measurement characteristic as a notification followed by
 * Record Access Control Point indication with status code Success or other in case of error.
 */
void refreshRecords() {
	if (recordAccessControlPointCharacteristic == null)
		return;

	if (records.size() == 0) {
		getAllRecords();
	} else {
		mCallbacks.onOperationStarted(getBluetoothDevice());

		// Obtain the last sequence number
		final int sequenceNumber = records.keyAt(records.size() - 1) + 1;
		recordAccessRequestInProgress = true;
		writeCharacteristic(recordAccessControlPointCharacteristic, RecordAccessControlPointData.reportStoredRecordsGreaterThenOrEqualTo(sequenceNumber))
				.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"))
				.enqueue();
		// Info:
		// Operators OPERATOR_GREATER_THEN_OR_EQUAL, OPERATOR_LESS_THEN_OR_EQUAL and OPERATOR_RANGE are not supported by the CGMS sample from SDK
		// The "Operation not supported" response will be received
	}
}
 
Example #6
Source File: TemplateManager.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * This method will write important data to the device.
 *
 * @param parameter parameter to be written.
 */
void performAction(final String parameter) {
	log(Log.VERBOSE, "Changing device name to \"" + parameter + "\"");
	// Write some data to the characteristic.
	writeCharacteristic(deviceNameCharacteristic, Data.from(parameter))
			// If data are longer than MTU-3, they will be chunked into multiple packets.
			// Check out other split options, with .split(...).
			.split()
			// Callback called when data were sent, or added to outgoing queue in case
			// Write Without Request type was used.
			.with((device, data) -> log(Log.DEBUG, data.size() + " bytes were sent"))
			// Callback called when data were sent, or added to outgoing queue in case
			// Write Without Request type was used. This is called after .with(...) callback.
			.done(device -> log(LogContract.Log.Level.APPLICATION, "Device name set to \"" + parameter + "\""))
			// Callback called when write has failed.
			.fail((device, status) -> log(Log.WARN, "Failed to change device name"))
			.enqueue();
}
 
Example #7
Source File: UARTManager.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Sends the given text to RX characteristic.
 * @param text the text to be sent
 */
public void send(final String text) {
	// Are we connected?
	if (rxCharacteristic == null)
		return;

	if (!TextUtils.isEmpty(text)) {
		final WriteRequest request = writeCharacteristic(rxCharacteristic, text.getBytes())
				.with((device, data) -> log(LogContract.Log.Level.APPLICATION,
						"\"" + data.getStringValue(0) + "\" sent"));
		if (!useLongWrite) {
			// This will automatically split the long data into MTU-3-byte long packets.
			request.split();
		}
		request.enqueue();
	}
}
 
Example #8
Source File: ProximityManager.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Writes the HIGH ALERT or NO ALERT command to the target device.
 *
 * @param on true to enable the alarm on proximity tag, false to disable it.
 */
public void writeImmediateAlert(final boolean on) {
	if (!isConnected())
		return;

	writeCharacteristic(alertLevelCharacteristic, on ? AlertLevelData.highAlert() : AlertLevelData.noAlert())
			.before(device -> log(Log.VERBOSE,
					on ? "Setting alarm to HIGH..." : "Disabling alarm..."))
			.with((device, data) -> log(LogContract.Log.Level.APPLICATION,
					"\"" + AlertLevelParser.parse(data) + "\" sent"))
			.done(device -> {
				alertOn = on;
				mCallbacks.onRemoteAlarmSwitched(device, on);
			})
			.fail((device, status) -> log(Log.WARN,
					status == FailCallback.REASON_NULL_ATTRIBUTE ?
							"Alert Level characteristic not found" :
							GattError.parse(status)))
			.enqueue();
}
 
Example #9
Source File: GlucoseManager.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Sends the request to delete all data from the device. A Record Access Control Point
 * indication with status code Success (or other in case of error) will be send.
 */
void deleteAllRecords() {
	if (recordAccessControlPointCharacteristic == null)
		return;
	final BluetoothDevice target = getBluetoothDevice();
	if (target == null)
		return;

	clear();
	mCallbacks.onOperationStarted(target);
	writeCharacteristic(recordAccessControlPointCharacteristic, RecordAccessControlPointData.deleteAllStoredRecords())
			.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"))
			.enqueue();
}
 
Example #10
Source File: MainActivity.java    From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private boolean logProviderExists() {
	// The method below requires API 16
	final ContentProviderClient unstableClient = getContentResolver()
			.acquireUnstableContentProviderClient(LogContract.AUTHORITY);
	if (unstableClient == null)
		return false;

	unstableClient.release();
	return true;
}
 
Example #11
Source File: LocalLogContentProvider.java    From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private int deleteSession(final long sessionId) {
	final SQLiteDatabase db = mLocalDatabaseHelper.get().getWritableDatabase();
	final String[] args = mSelectionArgs1;
	args[0] = String.valueOf(sessionId);

	db.delete(Tables.LOG, LogContract.Log.SESSION_ID + "=?", args);
	return db.delete(Tables.LOG_SESSIONS, LogContract.Session._ID + "=?", args);
}
 
Example #12
Source File: LocalLogContentProvider.java    From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
@NonNull
public ContentProviderResult[] applyBatch(@NonNull final ArrayList<ContentProviderOperation> operations)
		throws OperationApplicationException {
	int ypCount = 0;
	int opCount = 0;
	final LogTransaction transaction = startTransaction(true);
	try {
		final int numOperations = operations.size();
		final ContentProviderResult[] results = new ContentProviderResult[numOperations];
		for (int i = 0; i < numOperations; i++) {
			if (++opCount >= MAX_OPERATIONS_PER_YIELD_POINT) {
				throw new OperationApplicationException(
						"Too many content provider operations between yield points. " +
						"The maximum number of operations per yield point is " +
						MAX_OPERATIONS_PER_YIELD_POINT, ypCount);
			}
			final ContentProviderOperation operation = operations.get(i);
			if (i > 0 && operation.isYieldAllowed()) {
				opCount = 0;
				try {
					if (yield(transaction)) {
						ypCount++;
					}
				} catch (RuntimeException re) {
					transaction.markYieldFailed();
					throw re;
				}
			}
			results[i] = operation.apply(this, results, i);
		}
		transaction.markSuccessful(true);
		return results;
	} finally {
		endTransaction(LogContract.Session.CONTENT_URI, true);
	}
}
 
Example #13
Source File: BlinkyManager.java    From Android-nRF-Blinky with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onLedStateChanged(@NonNull final BluetoothDevice device,
							  final boolean on) {
	ledOn = on;
	log(LogContract.Log.Level.APPLICATION, "LED " + (on ? "ON" : "OFF"));
	ledState.setValue(on);
}
 
Example #14
Source File: LocalLogContentProvider.java    From nRF-Logger-API with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public String getType(@NonNull final Uri uri) {
	final int match = sUriMatcher.match(uri);
	switch (match) {
		case SESSION_ID:
			return LogContract.Session.CONTENT_ITEM_TYPE;
		case SESSION_ID_LOG:
			return LogContract.Log.CONTENT_TYPE;
	}
	return null;
}
 
Example #15
Source File: BatteryManager.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onBatteryLevelChanged(@NonNull final BluetoothDevice device,
								  @IntRange(from = 0, to = 100) final int batteryLevel) {
	log(LogContract.Log.Level.APPLICATION,"Battery Level received: " + batteryLevel + "%");
	BatteryManager.this.batteryLevel = batteryLevel;
	mCallbacks.onBatteryLevelChanged(device, batteryLevel);
}
 
Example #16
Source File: CGMManager.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Sends the request to remove all stored records from the Continuous Glucose Monitor device.
 * This feature is not supported by the CGMS sample from the SDK, so monitor will answer with
 * the Op Code Not Supported error.
 */
void deleteAllRecords() {
	if (recordAccessControlPointCharacteristic == null)
		return;

	clear();
	mCallbacks.onOperationStarted(getBluetoothDevice());
	writeCharacteristic(recordAccessControlPointCharacteristic, RecordAccessControlPointData.deleteAllStoredRecords())
			.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"))
			.enqueue();
}
 
Example #17
Source File: GlucoseManager.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Sends the request to obtain the last (most recent) record from glucose device. The data will
 * be returned to Glucose Measurement characteristic as a notification followed by Record Access
 * Control Point indication with status code Success or other in case of error.
 */
void getLastRecord() {
	if (recordAccessControlPointCharacteristic == null)
		return;
	final BluetoothDevice target = getBluetoothDevice();
	if (target == null)
		return;

	clear();
	mCallbacks.onOperationStarted(target);
	writeCharacteristic(recordAccessControlPointCharacteristic, RecordAccessControlPointData.reportLastStoredRecord())
			.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"))
			.enqueue();
}
 
Example #18
Source File: CGMManager.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Sends the request to obtain all records from glucose device. Initially we want to notify the
 * user about the number of the records so the Report Number of Stored Records request is send.
 * The data will be returned to Glucose Measurement characteristic as a notification followed by
 * Record Access Control Point indication with status code Success or other in case of error.
 */
void getAllRecords() {
	if (recordAccessControlPointCharacteristic == null)
		return;

	clear();
	mCallbacks.onOperationStarted(getBluetoothDevice());
	recordAccessRequestInProgress = true;
	writeCharacteristic(recordAccessControlPointCharacteristic, RecordAccessControlPointData.reportNumberOfAllStoredRecords())
			.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"))
			.enqueue();
}
 
Example #19
Source File: CGMManager.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Sends abort operation signal to the device.
 */
void abort() {
	if (recordAccessControlPointCharacteristic == null)
		return;

	writeCharacteristic(recordAccessControlPointCharacteristic, RecordAccessControlPointData.abortOperation())
			.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"))
			.enqueue();
}
 
Example #20
Source File: CGMManager.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Sends the request to obtain the first (oldest) record from glucose device.
 * The data will be returned to Glucose Measurement characteristic as a notification followed by
    * Record Access Control Point indication with status code Success or other in case of error.
 */
void getFirstRecord() {
	if (recordAccessControlPointCharacteristic == null)
		return;

	clear();
	mCallbacks.onOperationStarted(getBluetoothDevice());
	recordAccessRequestInProgress = true;
	writeCharacteristic(recordAccessControlPointCharacteristic, RecordAccessControlPointData.reportFirstStoredRecord())
			.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"))
			.enqueue();
}
 
Example #21
Source File: CGMManager.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Sends the request to obtain the last (most recent) record from glucose device.
    * The data will be returned to Glucose Measurement characteristic as a notification followed by
    * Record Access Control Point indication with status code Success or other in case of error.
 */
void getLastRecord() {
	if (recordAccessControlPointCharacteristic == null)
		return;

	clear();
	mCallbacks.onOperationStarted(getBluetoothDevice());
	recordAccessRequestInProgress = true;
	writeCharacteristic(recordAccessControlPointCharacteristic, RecordAccessControlPointData.reportLastStoredRecord())
			.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"))
			.enqueue();
}
 
Example #22
Source File: GlucoseManager.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Sends the request to obtain the first (oldest) record from glucose device. The data will be
 * returned to Glucose Measurement characteristic as a notification followed by Record Access
 * Control Point indication with status code Success or other in case of error.
 */
void getFirstRecord() {
	if (recordAccessControlPointCharacteristic == null)
		return;
	final BluetoothDevice target = getBluetoothDevice();
	if (target == null)
		return;

	clear();
	mCallbacks.onOperationStarted(target);
	writeCharacteristic(recordAccessControlPointCharacteristic, RecordAccessControlPointData.reportFirstStoredRecord())
			.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"))
			.enqueue();
}
 
Example #23
Source File: UARTLogFragment.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NonNull
@Override
public Loader<Cursor> onCreateLoader(final int id, final Bundle args) {
	switch (id) {
		case LOG_REQUEST_ID: {
			return new CursorLoader(requireContext(), logSession.getSessionEntriesUri(), LOG_PROJECTION, null, null, LogContract.Log.TIME);
		}
	}
	throw new UnsupportedOperationException("Could not create loader with ID " + id);
}
 
Example #24
Source File: GlucoseManager.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Sends the request to obtain all records from glucose device. Initially we want to notify user
 * about the number of the records so the 'Report Number of Stored Records' is send. The data
 * will be returned to Glucose Measurement characteristic as a notification followed by
 * Record Access Control Point indication with status code Success or other in case of error.
 */
void getAllRecords() {
	if (recordAccessControlPointCharacteristic == null)
		return;
	final BluetoothDevice target = getBluetoothDevice();
	if (target == null)
		return;

	clear();
	mCallbacks.onOperationStarted(target);
	writeCharacteristic(recordAccessControlPointCharacteristic, RecordAccessControlPointData.reportNumberOfAllStoredRecords())
			.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"))
			.enqueue();
}
 
Example #25
Source File: UARTManager.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void initialize() {
	setNotificationCallback(txCharacteristic)
			.with((device, data) -> {
				final String text = data.getStringValue(0);
				log(LogContract.Log.Level.APPLICATION, "\"" + text + "\" received");
				mCallbacks.onDataReceived(device, text);
			});
	requestMtu(260).enqueue();
	enableNotifications(txCharacteristic).enqueue();
}
 
Example #26
Source File: GlucoseManager.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Sends the request to obtain from the glucose device all records newer than the newest one
 * from local storage. The data will be returned to Glucose Measurement characteristic as
 * a notification followed by Record Access Control Point indication with status code Success
 * or other in case of error.
 * <p>
 * Refresh button will not download records older than the oldest in the local memory.
 * E.g. if you have pressed Last and then Refresh, than it will try to get only newer records.
 * However if there are no records, it will download all existing (using {@link #getAllRecords()}).
 */
void refreshRecords() {
	if (recordAccessControlPointCharacteristic == null)
		return;
	final BluetoothDevice target = getBluetoothDevice();
	if (target == null)
		return;

	if (records.size() == 0) {
		getAllRecords();
	} else {
		mCallbacks.onOperationStarted(target);

		// obtain the last sequence number
		final int sequenceNumber = records.keyAt(records.size() - 1) + 1;

		writeCharacteristic(recordAccessControlPointCharacteristic,
				RecordAccessControlPointData.reportStoredRecordsGreaterThenOrEqualTo(sequenceNumber))
				.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"))
				.enqueue();
		// Info:
		// Operators OPERATOR_LESS_THEN_OR_EQUAL and OPERATOR_RANGE are not supported by Nordic Semiconductor Glucose Service in SDK 4.4.2.
	}
}
 
Example #27
Source File: ProximityService.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onReceive(final Context context, final Intent intent) {
    final BluetoothDevice device = intent.getParcelableExtra(EXTRA_DEVICE);
    switch (intent.getAction()) {
        case ACTION_FIND:
            binder.log(device, LogContract.Log.Level.INFO, "[Notification] FIND action pressed");
            break;
        case ACTION_SILENT:
            binder.log(device, LogContract.Log.Level.INFO, "[Notification] SILENT action pressed");
            break;
    }
    binder.toggleImmediateAlert(device);
}
 
Example #28
Source File: GlucoseManager.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Sends abort operation signal to the device.
 */
void abort() {
	if (recordAccessControlPointCharacteristic == null)
		return;
	final BluetoothDevice target = getBluetoothDevice();
	if (target == null)
		return;

	writeCharacteristic(recordAccessControlPointCharacteristic, RecordAccessControlPointData.abortOperation())
			.with((device, data) -> log(LogContract.Log.Level.APPLICATION, "\"" + RecordAccessControlPointParser.parse(data) + "\" sent"))
			.enqueue();
}
 
Example #29
Source File: LoggableBleManager.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void log(final int priority, @NonNull final String message) {
	Logger.log(mLogSession, LogContract.Log.Level.fromPriority(priority), message);
	Log.println(priority, "BleManager", message);
}
 
Example #30
Source File: ProximityService.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void onReceive(final Context context, final Intent intent) {
    final BluetoothDevice device = intent.getParcelableExtra(EXTRA_DEVICE);
    binder.log(device, LogContract.Log.Level.INFO, "[Notification] DISCONNECT action pressed");
    binder.disconnect(device);
}