2 * Copyright (C) 2013 Tobias Brunner
4 * Copyright (C) secunet Security Networks AG
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>.
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
17 package org
.strongswan
.android
.logic
.imc
;
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
;
29 import android
.content
.Context
;
31 public class AndroidImc
33 private final Context mContext
;
35 public AndroidImc(Context context
)
41 * Get a measurement (the binary encoding of the requested attribute) for
42 * the given vendor specific attribute type.
44 * @param vendor vendor ID
45 * @param type vendor specific attribute type
46 * @return encoded attribute, or null if not available or failed
48 public byte[] getMeasurement(int vendor
, int type
)
50 return getMeasurement(vendor
, type
, null);
54 * Get a measurement (the binary encoding of the requested attribute) for
55 * the given vendor specific attribute type.
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
62 public byte[] getMeasurement(int vendor
, int type
, String
[] args
)
64 AttributeType attributeType
= AttributeType
.fromValues(vendor
, type
);
65 Collector collector
= null;
67 switch (attributeType
)
69 case IETF_PRODUCT_INFORMATION
:
70 collector
= new ProductInformationCollector();
72 case IETF_STRING_VERSION
:
73 collector
= new StringVersionCollector();
75 case IETF_PORT_FILTER
:
76 collector
= new PortFilterCollector();
78 case IETF_INSTALLED_PACKAGES
:
79 collector
= new InstalledPackagesCollector(mContext
);
82 collector
= new SettingsCollector(mContext
, args
);
85 collector
= new DeviceIdCollector(mContext
);
90 if (collector
!= null)
92 Attribute attribute
= collector
.getMeasurement();
93 if (attribute
!= null)
95 return attribute
.getEncoding();