|
|
|
@ -8,6 +8,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
package com.localytics.android;
|
|
|
|
package com.localytics.android;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.Manifest.permission;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
|
|
|
|
import android.net.ConnectivityManager;
|
|
|
|
|
|
|
|
import android.net.NetworkInfo;
|
|
|
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
|
|
|
import android.telephony.TelephonyManager;
|
|
|
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
@ -18,15 +27,6 @@ import java.math.BigInteger;
|
|
|
|
import java.security.MessageDigest;
|
|
|
|
import java.security.MessageDigest;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
|
|
|
|
|
|
|
|
import android.Manifest.permission;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
|
|
|
|
import android.net.ConnectivityManager;
|
|
|
|
|
|
|
|
import android.net.NetworkInfo;
|
|
|
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
|
|
|
import android.telephony.TelephonyManager;
|
|
|
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Provides a number of static functions to aid in the collection and formatting of datapoints.
|
|
|
|
* Provides a number of static functions to aid in the collection and formatting of datapoints.
|
|
|
|
* <p>
|
|
|
|
* <p>
|
|
|
|
@ -54,6 +54,30 @@ import android.util.Log;
|
|
|
|
throw new UnsupportedOperationException("This class is non-instantiable"); //$NON-NLS-1$
|
|
|
|
throw new UnsupportedOperationException("This class is non-instantiable"); //$NON-NLS-1$
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static int getApiLevel()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Although the Build.VERSION.SDK field has existed since API 1, it is deprecated and could be removed
|
|
|
|
|
|
|
|
// in the future. Therefore use reflection to retrieve it for maximum forward compatibility.
|
|
|
|
|
|
|
|
Class<?> buildClass = Build.VERSION.class;
|
|
|
|
|
|
|
|
String sdkString = (String) buildClass.getField("SDK").get(null); // $NON-NLS-1$
|
|
|
|
|
|
|
|
return Integer.valueOf(sdkString);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Although probably not necessary, protects from the aforementioned deprecation
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Class<?> buildClass = Build.VERSION.class;
|
|
|
|
|
|
|
|
return buildClass.getField("SDK_INT").getInt(null); // $NON-NLS-1$
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception ignore) { }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 3;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Gets a 1-way hashed value of the device's Android ID. This value is encoded using a SHA-256 one way hash and therefore
|
|
|
|
* Gets a 1-way hashed value of the device's Android ID. This value is encoded using a SHA-256 one way hash and therefore
|
|
|
|
* cannot be used to determine what device this data came from.
|
|
|
|
* cannot be used to determine what device this data came from.
|
|
|
|
@ -126,7 +150,7 @@ import android.util.Log;
|
|
|
|
* Obtain the device serial number using reflection, since serial number was added in SDK 9
|
|
|
|
* Obtain the device serial number using reflection, since serial number was added in SDK 9
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
String serialNumber = null;
|
|
|
|
String serialNumber = null;
|
|
|
|
if (Build.VERSION.SDK_INT >= 9)
|
|
|
|
if (Constants.CURRENT_API_LEVEL >= 9)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -161,10 +185,9 @@ import android.util.Log;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static String getTelephonyDeviceIdOrNull(final Context context)
|
|
|
|
public static String getTelephonyDeviceIdOrNull(final Context context)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (Build.VERSION.SDK_INT >= 8)
|
|
|
|
if (Constants.CURRENT_API_LEVEL >= 8)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
final Boolean hasTelephony = ReflectionUtils.tryInvokeInstance(context.getPackageManager(), "hasSystemFeature", //$NON-NLS-1$
|
|
|
|
final Boolean hasTelephony = ReflectionUtils.tryInvokeInstance(context.getPackageManager(), "hasSystemFeature", new Class<?>[] { String.class }, new Object[] { "android.hardware.telephony" }); //$NON-NLS-1$//$NON-NLS-2$
|
|
|
|
new Class<?>[] { String.class }, new Object[] { "android.hardware.telephony" }); //$NON-NLS-1$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!hasTelephony)
|
|
|
|
if (!hasTelephony)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -212,10 +235,9 @@ import android.util.Log;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static String getTelephonyDeviceIdHashOrNull(final Context context)
|
|
|
|
public static String getTelephonyDeviceIdHashOrNull(final Context context)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (Build.VERSION.SDK_INT >= 8)
|
|
|
|
if (Constants.CURRENT_API_LEVEL >= 8)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
final Boolean hasTelephony = ReflectionUtils.tryInvokeInstance(context.getPackageManager(), "hasSystemFeature", //$NON-NLS-1$
|
|
|
|
final Boolean hasTelephony = ReflectionUtils.tryInvokeInstance(context.getPackageManager(), "hasSystemFeature", new Class<?>[] { String.class }, new Object[] { "android.hardware.telephony" }); //$NON-NLS-1$//$NON-NLS-2$
|
|
|
|
new Class<?>[] { String.class }, new Object[] { "android.hardware.telephony" }); //$NON-NLS-1$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!hasTelephony)
|
|
|
|
if (!hasTelephony)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@ -282,6 +304,26 @@ import android.util.Log;
|
|
|
|
return "android_network_type_" + telephonyManager.getNetworkType(); //$NON-NLS-1$
|
|
|
|
return "android_network_type_" + telephonyManager.getNetworkType(); //$NON-NLS-1$
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Gets the device manufacturer's name
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return A string naming the manufacturer
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static String getManufacturer()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
String mfg = "unknown"; // $NON-NLS-1$
|
|
|
|
|
|
|
|
if (Constants.CURRENT_API_LEVEL > 3)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Class<?> buildClass = Build.class;
|
|
|
|
|
|
|
|
mfg = (String) buildClass.getField("MANUFACTURER").get(null); // $NON-NLS-1$
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception ignore) {}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return mfg;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Gets the versionName of the application.
|
|
|
|
* Gets the versionName of the application.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
|