Permalink
Browse files

Add Javadoc. Cosmetic

Bump Maven plugin to 3.3.1. Set API target to 2.3.3.

Cosmetic, add Javadoc

Remove overly defensive code

Typo

Cosmetic

Cosmetic

Cosmetic

Cosmetic
  • Loading branch information...
1 parent b12025f commit 4d2312ae5ced52f2224f5b8ef2e93dc727d8b559 @daggerrz daggerrz committed Aug 22, 2012
View
@@ -20,6 +20,7 @@
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
+ <version>${android.api.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
View
@@ -15,6 +15,7 @@
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
+ <version>${android.api.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
@@ -9,8 +9,20 @@
* is honored immediately while avoiding static coupling.
*/
public interface DeviceIdentifier {
+
+ /**
+ * Get the primary id for the device.
+ */
String get();
+
+ /**
+ * Get the full list of all collected device identifiers with type information.
+ */
String getTypedIds();
+
+ /**
+ * Check if the user has opted out of personalization.
+ */
boolean isOptedOut();
}
@@ -6,19 +6,12 @@
public class DeviceInfo {
/**
- * Check if the screen configuration indicates that this is a tablet.
+ * Gets the device's browser user agent.
*/
- public static boolean isTablet(Context context) {
- return context.getResources().getConfiguration().screenLayout == 4; // SCREENLAYOUT_SIZE_XLARGE
- }
-
public static String getUserAgent(Context context) {
WebView wv = new WebView(context);
String userAgent = wv.getSettings().getUserAgentString();
wv.destroy();
-
return userAgent;
-// if (isTablet(context)) return "Android Tablet/TapadEventAPI/1.0";
-// else return "Android Mobile/TapadEventAPI/1.0";
}
}
@@ -17,7 +17,7 @@
* <action android:name="com.android.vending.INSTALL_REFERRER" />
* </intent-filter>
* </receiver>
- *
+ * <p/>
* To test referral:
* <pre>
* adb shell
@@ -39,20 +39,13 @@ public void onReceive(Context context, Intent intent) {
if (referrerString == null) {
Tracking.get().onEvent(Tracking.EVENT_INSTALL);
- }
- else {
- try {
- Tracking.get().onEvent(Tracking.EVENT_INSTALL, "android_referrer=" + URLEncoder.encode(referrerString, "UTF-8"));
- }
- catch (java.io.UnsupportedEncodingException uee) {
- Logging.error("Tapad/InstallReferrerReceiver", "Error encoding referrer. Install event will not be sent with referrer value. " + uee.getMessage());
- Tracking.get().onEvent(Tracking.EVENT_INSTALL);
- }
+ } else {
+ Tracking.get().onEvent(Tracking.EVENT_INSTALL, "android_referrer=" + URLEncoder.encode(referrerString, "UTF-8"));
}
// Register that the install event now has been sent
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(Tracking.PREF_INSTALL_SENT, true).commit();
- }
- catch (Exception e) {
+ } catch (Exception e) {
+ // Precautionary
Logging.error("Tapad/InstallReferrerReceiver", "Unexpected error caught in INSTALL_REFERRER intent receiver. Install event will not be sent. " + e.getMessage());
}
}
@@ -5,17 +5,12 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.preference.PreferenceManager;
-import android.provider.Settings;
import android.text.TextUtils;
-import com.tapad.tracking.deviceidentification.AndroidId;
-import com.tapad.tracking.deviceidentification.IdentifierSource;
-import com.tapad.tracking.deviceidentification.IdentifierSourceAggregator;
-import com.tapad.tracking.deviceidentification.TypedIdentifier;
+import com.tapad.tracking.deviceidentification.*;
import com.tapad.util.Logging;
-import java.math.BigInteger;
-import java.security.MessageDigest;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.UUID;
@@ -61,12 +56,13 @@ public boolean isOptedOut() {
* <meta-data android:name="tapad.APP_ID" android:value="INSERT_APP_ID_HERE"/>
* ...
* </application>
- *
- * The default id sources are AndroidId. Optionally, the id sources can be specified through the AndroidManifest.xml:
+ * <p/>
+ * The default id sources are AndroidId, PhoneId, WifiMac and BuildSerial, but
+ * this can be configured to suit the developer's privacy policy through the AndroidManifest.xml:
* <p/>
* <application>
- * <meta-data android:name="tapad.ID_SOURCES" android:value="AndroidId,PhoneId,WifiMac,BuildSerial"/>
- * ...
+ * <meta-data android:name="tapad.ID_SOURCES" android:value="AndroidId,PhoneId,WifiMac,BuildSerial"/>
+ * ...
* </application>
*
* @param context a context reference
@@ -84,11 +80,10 @@ public static void init(Context context) {
* <p/>
* One of the initialization functions must be called before TrackingService.get().
*
- * @param context a context reference
- * @param appId the application identifier
+ * @param context a context reference
+ * @param appId the application identifier
* @param idSources a list of identifier sources to use to collect ids
* @see #init(android.content.Context)
- *
*/
public static void init(Context context, String appId, List<IdentifierSource> idSources) {
setupAPI(context, appId, idSources);
@@ -127,19 +122,17 @@ protected static void setupAPI(Context context, String appId, List<IdentifierSou
ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
String[] idSourceClasses = ai.metaData.getString("tapad.ID_SOURCES").split(",");
idSources = new ArrayList<IdentifierSource>();
- for (int i=0; i<idSourceClasses.length; i++) {
+ for (String className : idSourceClasses) {
try {
- idSources.add((IdentifierSource)Class.forName("com.tapad.tracking.deviceidentification." + idSourceClasses[i].trim()).newInstance());
- }
- catch (Exception e) {
- Logging.warn("Tracking", "Unable to instantiate identifier source: " + idSourceClasses[i].trim());
+ idSources.add((IdentifierSource) Class.forName("com.tapad.tracking.deviceidentification." + className.trim()).newInstance());
+ } catch (Exception e) {
+ Logging.warn("Tracking", "Unable to instantiate identifier source: " + className.trim());
}
}
if (idSources.isEmpty()) {
idSources = defaultIdSources();
}
- }
- catch (Exception e) {
+ } catch (Exception e) {
idSources = defaultIdSources();
}
}
@@ -156,14 +149,12 @@ protected static void setupAPI(Context context, String appId, List<IdentifierSou
/**
* Creates the default identifier sources to use should none be specified.
- * The default is AndroidId
+ * The default is all.
*
* @return the list of default id sources
*/
private static List<IdentifierSource> defaultIdSources() {
- List<IdentifierSource> idSources = new ArrayList<IdentifierSource>();
- idSources.add(new AndroidId());
- return (idSources);
+ return Arrays.asList(new AndroidId(), new PhoneId(), new WifiMac(), new BuildSerial());
}
/**
@@ -178,22 +169,20 @@ private static void collectIds(Context context) {
// do not attempt to collect any ids if the device is opted out
if (OPTED_OUT_DEVICE_ID.equals(deviceId)) {
typedDeviceIds = null;
- }
- else {
+ } else {
// collect ids
List<TypedIdentifier> ids = idCollector.get(context);
// if no ids
if (ids.isEmpty()) {
// generate and store a new id if there is no saved id
if (deviceId == null) {
- Logging.warn("Tracking", "Unable to retrieve any device identifiers, using a UDID instead.");
+ Logging.warn("Tracking", "Unable to retrieve any device identifiers, using a UUID instead.");
deviceId = UUID.randomUUID().toString();
PreferenceManager.getDefaultSharedPreferences(context).edit().putString(PREF_TAPAD_DEVICE_ID, deviceId).commit();
}
// ensure that typed id is set to null
typedDeviceIds = null;
- }
- else {
+ } else {
// set the deviceId to the first typed id, but don't save it in prefs because that space is reserved for the generated UUID/Opt-out
deviceId = ids.get(0).getValue();
// set the typedDeviceIds to the full string representation
@@ -2,7 +2,6 @@
import android.content.Context;
import android.os.Build;
-import android.provider.Settings;
import com.tapad.util.DigestUtil;
import com.tapad.util.Logging;
@@ -13,7 +12,7 @@
/**
* This class knows how to fetch and encode android.os.Build.SERIAL
* This constant is only available as of 2.3 (API level 9).
- *
+ * <p/>
* Gets the build serial hashed with MD5 and formatted as a 32 byte hexadecimal number.
* Gets the build serial hashed with SHA1 and formatted as a 40 byte hexadecimal number.
*/
@@ -26,18 +25,15 @@
if (buildSerial != null) {
try {
ids.add(new TypedIdentifier(TypedIdentifier.TYPE_BUILD_SERIAL_MD5, DigestUtil.md5Hash(buildSerial)));
- }
- catch (NoSuchAlgorithmException nsae) {
+ } catch (NoSuchAlgorithmException nsae) {
Logging.error("Tracking", "Error hashing Build.SERIAL - MD5 not supported");
}
try {
ids.add(new TypedIdentifier(TypedIdentifier.TYPE_BUILD_SERIAL_SHA1, DigestUtil.sha1Hash(buildSerial)));
- }
- catch (NoSuchAlgorithmException nsae) {
+ } catch (NoSuchAlgorithmException nsae) {
Logging.error("Tracking", "Error hashing Build.SERIAL - SHA1 not supported");
}
- }
- else {
+ } else {
Logging.warn("Tracking", "Error retrieving Build.SERIAL.");
}
return (ids);
@@ -11,36 +11,32 @@
/**
* This class knows how to fetch and encode values from telephonyManager.getDeviceId
- *
+ * <p/>
* Gets the Phone ID hashed with MD5 and formatted as a 32 byte hexadecimal number.
* Gets the Phone ID hashed with SHA1 and formatted as a 40 byte hexadecimal number.
- *
+ * <p/>
* Usage of this class requires adding the following to the AndroidManifest.xml
* <p/>
* <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
- *
*/
public class PhoneId implements IdentifierSource {
@Override
public List<TypedIdentifier> get(Context context) {
- TelephonyManager telephonyManager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
+ TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String phoneId = telephonyManager.getDeviceId();
List<TypedIdentifier> ids = new ArrayList<TypedIdentifier>();
if (phoneId != null) {
try {
ids.add(new TypedIdentifier(TypedIdentifier.TYPE_PHONE_ID_MD5, DigestUtil.md5Hash(phoneId)));
- }
- catch (NoSuchAlgorithmException nsae) {
+ } catch (NoSuchAlgorithmException nsae) {
Logging.error("Tracking", "Error hashing PHONE_ID - MD5 not supported");
}
try {
ids.add(new TypedIdentifier(TypedIdentifier.TYPE_PHONE_ID_SHA1, DigestUtil.sha1Hash(phoneId)));
- }
- catch (NoSuchAlgorithmException nsae) {
+ } catch (NoSuchAlgorithmException nsae) {
Logging.error("Tracking", "Error hashing PHONE_ID - SHA1 not supported");
}
- }
- else {
+ } else {
Logging.warn("Tracking", "Error retrieving PHONE_ID.");
}
return (ids);
@@ -11,36 +11,32 @@
/**
* This class knows how to fetch and encode the WIFI MAC address
- *
+ * <p/>
* Gets the WIFI MAC address hashed with MD5 and formatted as a 32 byte hexadecimal number.
* Gets the WIFI MAC address hashed with SHA1 and formatted as a 40 byte hexadecimal number.
- *
+ * <p/>
* Usage of this class requires adding the following to the AndroidManifest.xml
* <p/>
* <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
- *
*/
public class WifiMac implements IdentifierSource {
@Override
public List<TypedIdentifier> get(Context context) {
- WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
+ WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
String wifiMac = wifiManager.getConnectionInfo().getMacAddress();
List<TypedIdentifier> ids = new ArrayList<TypedIdentifier>();
if (wifiMac != null) {
try {
ids.add(new TypedIdentifier(TypedIdentifier.TYPE_WIFI_MAC_MD5, DigestUtil.md5Hash(wifiMac)));
- }
- catch (NoSuchAlgorithmException nsae) {
+ } catch (NoSuchAlgorithmException nsae) {
Logging.error("Tracking", "Error hashing WIFI_MAC - MD5 not supported");
}
try {
ids.add(new TypedIdentifier(TypedIdentifier.TYPE_WIFI_MAC_SHA1, DigestUtil.sha1Hash(wifiMac)));
- }
- catch (NoSuchAlgorithmException nsae) {
+ } catch (NoSuchAlgorithmException nsae) {
Logging.error("Tracking", "Error hashing WIFI_MAC - SHA1 not supported");
}
- }
- else {
+ } else {
Logging.warn("Tracking", "Error retrieving WIFI_MAC.");
}
return (ids);
View
10 pom.xml
@@ -9,18 +9,14 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<buildVersion>1.0.2-SNAPSHOT</buildVersion>
+ <android.api.version>2.3.3</android.api.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
- <version>1.6_r2</version>
- </dependency>
- <dependency>
- <groupId>com.google.android</groupId>
- <artifactId>android-test</artifactId>
- <version>1.6_r2</version>
+ <version>${android.api.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
@@ -30,7 +26,7 @@
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
- <version>3.1.1</version>
+ <version>3.3.0</version>
<configuration>
<sdk>
<platform>10</platform>
View
@@ -23,6 +23,7 @@
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
+ <version>${android.api.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

0 comments on commit 4d2312a

Please sign in to comment.