Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(303)

Unified Diff: device/nfc/android/java/src/org/chromium/device/nfc/NfcMessageValidator.java

Issue 1765533004: [webnfc] Implement watch method for Android nfc mojo service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@implement_nfc_watch_in_blink
Patch Set: Rebased to master Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: device/nfc/android/java/src/org/chromium/device/nfc/NfcMessageValidator.java
diff --git a/device/nfc/android/java/src/org/chromium/device/nfc/NfcMessageValidator.java b/device/nfc/android/java/src/org/chromium/device/nfc/NfcMessageValidator.java
new file mode 100644
index 0000000000000000000000000000000000000000..0c7cc54b5001e01d50eee5c3dd5e400bb3762c0f
--- /dev/null
+++ b/device/nfc/android/java/src/org/chromium/device/nfc/NfcMessageValidator.java
@@ -0,0 +1,44 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.device.nfc;
+
+import org.chromium.device.nfc.mojom.NfcMessage;
+import org.chromium.device.nfc.mojom.NfcRecord;
+import org.chromium.device.nfc.mojom.NfcRecordType;
+
+/**
+ * Utility class that provides validation of NfcMessage.
+ */
+public final class NfcMessageValidator {
+ /**
+ * Validates NfcMessage.
+ *
+ * @param message to be validated.
+ * @return true if message is valid, false otherwise.
+ */
+ public static boolean isValid(NfcMessage message) {
+ if (message == null || message.data == null || message.data.length == 0) {
+ return false;
+ }
+
+ for (int i = 0; i < message.data.length; ++i) {
+ if (!isValid(message.data[i])) return false;
+ }
+ return true;
+ }
+
+ private static boolean isValid(NfcRecord record) {
+ if (record == null || record.data == null || record.data.length == 0) {
+ return false;
+ }
+
+ if (record.mediaType == null || record.mediaType.isEmpty()
+ || record.recordType == NfcRecordType.EMPTY) {
+ return false;
+ }
+
+ return true;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698