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