android: Add measurement collector for ITA Device ID
[strongswan.git] / src / frontends / android / src / org / strongswan / android / logic / imc / AndroidImc.java
1 /*
2 * Copyright (C) 2013 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 package org.strongswan.android.logic.imc;
17
18 import org.strongswan.android.logic.imc.attributes.Attribute;
19 import org.strongswan.android.logic.imc.attributes.AttributeType;
20 import org.strongswan.android.logic.imc.collectors.Collector;
21 import org.strongswan.android.logic.imc.collectors.DeviceIdCollector;
22 import org.strongswan.android.logic.imc.collectors.InstalledPackagesCollector;
23 import org.strongswan.android.logic.imc.collectors.PortFilterCollector;
24 import org.strongswan.android.logic.imc.collectors.ProductInformationCollector;
25 import org.strongswan.android.logic.imc.collectors.SettingsCollector;
26 import org.strongswan.android.logic.imc.collectors.StringVersionCollector;
27
28 import android.content.Context;
29
30 public class AndroidImc
31 {
32 private final Context mContext;
33
34 public AndroidImc(Context context)
35 {
36 mContext = context;
37 }
38
39 /**
40 * Get a measurement (the binary encoding of the requested attribute) for
41 * the given vendor specific attribute type.
42 *
43 * @param vendor vendor ID
44 * @param type vendor specific attribute type
45 * @return encoded attribute, or null if not available or failed
46 */
47 public byte[] getMeasurement(int vendor, int type)
48 {
49 return getMeasurement(vendor, type, null);
50 }
51
52 /**
53 * Get a measurement (the binary encoding of the requested attribute) for
54 * the given vendor specific attribute type.
55 *
56 * @param vendor vendor ID
57 * @param type vendor specific attribute type
58 * @param args optional arguments for a measurement
59 * @return encoded attribute, or null if not available or failed
60 */
61 public byte[] getMeasurement(int vendor, int type, String[] args)
62 {
63 AttributeType attributeType = AttributeType.fromValues(vendor, type);
64 Collector collector = null;
65
66 switch (attributeType)
67 {
68 case IETF_PRODUCT_INFORMATION:
69 collector = new ProductInformationCollector();
70 break;
71 case IETF_STRING_VERSION:
72 collector = new StringVersionCollector();
73 break;
74 case IETF_PORT_FILTER:
75 collector = new PortFilterCollector();
76 break;
77 case IETF_INSTALLED_PACKAGES:
78 collector = new InstalledPackagesCollector(mContext);
79 break;
80 case ITA_SETTINGS:
81 collector = new SettingsCollector(mContext, args);
82 break;
83 case ITA_DEVICE_ID:
84 collector = new DeviceIdCollector(mContext);
85 break;
86 default:
87 break;
88 }
89 if (collector != null)
90 {
91 Attribute attribute = collector.getMeasurement();
92 if (attribute != null)
93 {
94 return attribute.getEncoding();
95 }
96 }
97 return null;
98 }
99 }