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

Side by Side 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 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.device.nfc;
6
7 import org.chromium.device.nfc.mojom.NfcMessage;
8 import org.chromium.device.nfc.mojom.NfcRecord;
9 import org.chromium.device.nfc.mojom.NfcRecordType;
10
11 /**
12 * Utility class that provides validation of NfcMessage.
13 */
14 public final class NfcMessageValidator {
15 /**
16 * Validates NfcMessage.
17 *
18 * @param message to be validated.
19 * @return true if message is valid, false otherwise.
20 */
21 public static boolean isValid(NfcMessage message) {
22 if (message == null || message.data == null || message.data.length == 0) {
23 return false;
24 }
25
26 for (int i = 0; i < message.data.length; ++i) {
27 if (!isValid(message.data[i])) return false;
28 }
29 return true;
30 }
31
32 private static boolean isValid(NfcRecord record) {
33 if (record == null || record.data == null || record.data.length == 0) {
34 return false;
35 }
36
37 if (record.mediaType == null || record.mediaType.isEmpty()
38 || record.recordType == NfcRecordType.EMPTY) {
39 return false;
40 }
41
42 return true;
43 }
44 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698