OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.device.nfc; | 5 package org.chromium.device.nfc; |
6 | 6 |
7 import android.Manifest; | 7 import android.Manifest; |
8 import android.annotation.TargetApi; | 8 import android.annotation.TargetApi; |
9 import android.app.Activity; | 9 import android.app.Activity; |
10 import android.content.Context; | 10 import android.content.Context; |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 try { | 459 try { |
460 mTagHandler.connect(); | 460 mTagHandler.connect(); |
461 mTagHandler.write(NfcTypeConverter.toNdefMessage(mPendingPushOperati
on.nfcMessage)); | 461 mTagHandler.write(NfcTypeConverter.toNdefMessage(mPendingPushOperati
on.nfcMessage)); |
462 pendingPushOperationCompleted(null); | 462 pendingPushOperationCompleted(null); |
463 } catch (InvalidNfcMessageException e) { | 463 } catch (InvalidNfcMessageException e) { |
464 Log.w(TAG, "Cannot write data to NFC tag. Invalid NfcMessage."); | 464 Log.w(TAG, "Cannot write data to NFC tag. Invalid NfcMessage."); |
465 pendingPushOperationCompleted(createError(NfcErrorType.INVALID_MESSA
GE)); | 465 pendingPushOperationCompleted(createError(NfcErrorType.INVALID_MESSA
GE)); |
466 } catch (TagLostException e) { | 466 } catch (TagLostException e) { |
467 Log.w(TAG, "Cannot write data to NFC tag. Tag is lost."); | 467 Log.w(TAG, "Cannot write data to NFC tag. Tag is lost."); |
468 pendingPushOperationCompleted(createError(NfcErrorType.IO_ERROR)); | 468 pendingPushOperationCompleted(createError(NfcErrorType.IO_ERROR)); |
469 } catch (FormatException | IOException e) { | 469 } catch (FormatException | IllegalStateException | IOException e) { |
470 Log.w(TAG, "Cannot write data to NFC tag. IO_ERROR."); | 470 Log.w(TAG, "Cannot write data to NFC tag. IO_ERROR."); |
471 pendingPushOperationCompleted(createError(NfcErrorType.IO_ERROR)); | 471 pendingPushOperationCompleted(createError(NfcErrorType.IO_ERROR)); |
472 } | 472 } |
473 } | 473 } |
474 | 474 |
475 /** | 475 /** |
476 * Reads NfcMessage from a tag and forwards message to matching method. | 476 * Reads NfcMessage from a tag and forwards message to matching method. |
477 */ | 477 */ |
478 private void processPendingWatchOperations() { | 478 private void processPendingWatchOperations() { |
479 if (mTagHandler == null || mClient == null || mWatchers.size() == 0) ret
urn; | 479 if (mTagHandler == null || mClient == null || mWatchers.size() == 0) ret
urn; |
(...skipping 12 matching lines...) Expand all Loading... |
492 | 492 |
493 try { | 493 try { |
494 mTagHandler.connect(); | 494 mTagHandler.connect(); |
495 message = mTagHandler.read(); | 495 message = mTagHandler.read(); |
496 if (message.getByteArrayLength() > NfcMessage.MAX_SIZE) { | 496 if (message.getByteArrayLength() > NfcMessage.MAX_SIZE) { |
497 Log.w(TAG, "Cannot read data from NFC tag. NfcMessage exceeds al
lowed size."); | 497 Log.w(TAG, "Cannot read data from NFC tag. NfcMessage exceeds al
lowed size."); |
498 return; | 498 return; |
499 } | 499 } |
500 } catch (TagLostException e) { | 500 } catch (TagLostException e) { |
501 Log.w(TAG, "Cannot read data from NFC tag. Tag is lost."); | 501 Log.w(TAG, "Cannot read data from NFC tag. Tag is lost."); |
502 } catch (FormatException | IOException e) { | 502 } catch (FormatException | IllegalStateException | IOException e) { |
503 Log.w(TAG, "Cannot read data from NFC tag. IO_ERROR."); | 503 Log.w(TAG, "Cannot read data from NFC tag. IO_ERROR."); |
504 } | 504 } |
505 | 505 |
506 if (message != null) notifyMatchingWatchers(message); | 506 if (message != null) notifyMatchingWatchers(message); |
507 } | 507 } |
508 | 508 |
509 /** | 509 /** |
510 * Iterates through active watchers and if any of those match NfcWatchOption
s criteria, | 510 * Iterates through active watchers and if any of those match NfcWatchOption
s criteria, |
511 * delivers NfcMessage to the client. | 511 * delivers NfcMessage to the client. |
512 */ | 512 */ |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 processPendingPushOperation(); | 593 processPendingPushOperation(); |
594 if (mTagHandler != null && mTagHandler.isConnected()) { | 594 if (mTagHandler != null && mTagHandler.isConnected()) { |
595 try { | 595 try { |
596 mTagHandler.close(); | 596 mTagHandler.close(); |
597 } catch (IOException e) { | 597 } catch (IOException e) { |
598 Log.w(TAG, "Cannot close NFC tag connection."); | 598 Log.w(TAG, "Cannot close NFC tag connection."); |
599 } | 599 } |
600 } | 600 } |
601 } | 601 } |
602 } | 602 } |
OLD | NEW |