android: Add measurement collector for ITA Device ID
authorTobias Brunner <tobias@strongswan.org>
Mon, 24 Jun 2013 13:50:48 +0000 (15:50 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 8 Jul 2013 16:49:28 +0000 (18:49 +0200)
src/frontends/android/src/org/strongswan/android/logic/imc/AndroidImc.java
src/frontends/android/src/org/strongswan/android/logic/imc/attributes/AttributeType.java
src/frontends/android/src/org/strongswan/android/logic/imc/attributes/DeviceIdAttribute.java [new file with mode: 0644]
src/frontends/android/src/org/strongswan/android/logic/imc/collectors/DeviceIdCollector.java [new file with mode: 0644]

index 1c298be..351fab8 100644 (file)
@@ -18,6 +18,7 @@ package org.strongswan.android.logic.imc;
 import org.strongswan.android.logic.imc.attributes.Attribute;
 import org.strongswan.android.logic.imc.attributes.AttributeType;
 import org.strongswan.android.logic.imc.collectors.Collector;
 import org.strongswan.android.logic.imc.attributes.Attribute;
 import org.strongswan.android.logic.imc.attributes.AttributeType;
 import org.strongswan.android.logic.imc.collectors.Collector;
+import org.strongswan.android.logic.imc.collectors.DeviceIdCollector;
 import org.strongswan.android.logic.imc.collectors.InstalledPackagesCollector;
 import org.strongswan.android.logic.imc.collectors.PortFilterCollector;
 import org.strongswan.android.logic.imc.collectors.ProductInformationCollector;
 import org.strongswan.android.logic.imc.collectors.InstalledPackagesCollector;
 import org.strongswan.android.logic.imc.collectors.PortFilterCollector;
 import org.strongswan.android.logic.imc.collectors.ProductInformationCollector;
@@ -79,6 +80,9 @@ public class AndroidImc
                        case ITA_SETTINGS:
                                collector = new SettingsCollector(mContext, args);
                                break;
                        case ITA_SETTINGS:
                                collector = new SettingsCollector(mContext, args);
                                break;
+                       case ITA_DEVICE_ID:
+                               collector = new DeviceIdCollector(mContext);
+                               break;
                        default:
                                break;
                }
                        default:
                                break;
                }
index 52eef97..11f1c61 100644 (file)
@@ -35,7 +35,8 @@ public enum AttributeType
        IETF_FACTORY_DEFAULT_PWD_ENABLED(PrivateEnterpriseNumber.IETF, 12),
        IETF_RESERVED(PrivateEnterpriseNumber.IETF, 0xffffffff),
        /* ITA attributes */
        IETF_FACTORY_DEFAULT_PWD_ENABLED(PrivateEnterpriseNumber.IETF, 12),
        IETF_RESERVED(PrivateEnterpriseNumber.IETF, 0xffffffff),
        /* ITA attributes */
-       ITA_SETTINGS(PrivateEnterpriseNumber.ITA, 4);
+       ITA_SETTINGS(PrivateEnterpriseNumber.ITA, 4),
+       ITA_DEVICE_ID(PrivateEnterpriseNumber.ITA, 8);
 
        private PrivateEnterpriseNumber mVendor;
        private int mType;
 
        private PrivateEnterpriseNumber mVendor;
        private int mType;
diff --git a/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/DeviceIdAttribute.java b/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/DeviceIdAttribute.java
new file mode 100644 (file)
index 0000000..ecab7db
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2013 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+package org.strongswan.android.logic.imc.attributes;
+
+/**
+ * ITA Device ID attribute
+ *
+ *                       1                   2                   3
+ *   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *  | Device ID (Variable Length)                                   |
+ *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+public class DeviceIdAttribute implements Attribute
+{
+       private String mDeviceId;
+
+       /**
+        * Set the device ID
+        * @param version version number
+        */
+       public void setDeviceId(String deviceId)
+       {
+               this.mDeviceId = deviceId;
+       }
+
+       @Override
+       public byte[] getEncoding()
+       {
+               return mDeviceId.getBytes();
+       }
+}
diff --git a/src/frontends/android/src/org/strongswan/android/logic/imc/collectors/DeviceIdCollector.java b/src/frontends/android/src/org/strongswan/android/logic/imc/collectors/DeviceIdCollector.java
new file mode 100644 (file)
index 0000000..ebe9e10
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2013 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+package org.strongswan.android.logic.imc.collectors;
+
+import org.strongswan.android.logic.imc.attributes.Attribute;
+import org.strongswan.android.logic.imc.attributes.DeviceIdAttribute;
+
+import android.content.ContentResolver;
+import android.content.Context;
+
+public class DeviceIdCollector implements Collector
+{
+       private final ContentResolver mContentResolver;
+
+       public DeviceIdCollector(Context context)
+       {
+               mContentResolver = context.getContentResolver();
+       }
+
+       @Override
+       public Attribute getMeasurement()
+       {
+               String id = android.provider.Settings.Secure.getString(mContentResolver, "android_id");
+               if (id != null)
+               {
+                       DeviceIdAttribute attribute = new DeviceIdAttribute();
+                       attribute.setDeviceId(id);
+                       return attribute;
+               }
+               return null;
+       }
+}