]> git.ipfire.org Git - thirdparty/strongswan.git/blob
658c2daea0899209d636f951e3a52526e7132012
[thirdparty/strongswan.git] /
1 /*
2 * Copyright (C) 2013 Tobias Brunner
3 * Copyright (C) 2012 Christoph Buehler
4 * Copyright (C) 2012 Patrick Loetscher
5 * Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 package org.strongswan.android.logic.imc.collectors;
19
20 import java.util.Locale;
21
22 import org.strongswan.android.logic.imc.attributes.Attribute;
23 import org.strongswan.android.logic.imc.attributes.SettingsAttribute;
24
25 import android.content.ContentResolver;
26 import android.content.Context;
27
28 public class SettingsCollector implements Collector
29 {
30 private final ContentResolver mContentResolver;
31 private final String[] mSettings;
32
33 public SettingsCollector(Context context, String[] args)
34 {
35 mContentResolver = context.getContentResolver();
36 mSettings = args;
37 }
38
39 @Override
40 public Attribute getMeasurement()
41 {
42 if (mSettings == null || mSettings.length == 0)
43 {
44 return null;
45 }
46 SettingsAttribute attribute = new SettingsAttribute();
47 for (String name : mSettings)
48 {
49 String value = android.provider.Settings.Secure.getString(mContentResolver, name.toLowerCase(Locale.US));
50 if (value == null)
51 {
52 value = android.provider.Settings.System.getString(mContentResolver, name.toLowerCase(Locale.US));
53 }
54 if (value != null)
55 {
56 attribute.addSetting(name, value);
57 }
58 }
59 return attribute;
60 }
61 }