OLD | NEW |
| (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 } | |
OLD | NEW |