|
|
|
@ -8,15 +8,6 @@
|
|
|
|
|
|
|
|
|
|
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.File;
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
@ -27,6 +18,15 @@ import java.math.BigInteger;
|
|
|
|
|
import java.security.MessageDigest;
|
|
|
|
|
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.
|
|
|
|
|
* <p>
|
|
|
|
@ -46,7 +46,7 @@ import java.security.NoSuchAlgorithmException;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Private constructor prevents instantiation
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @throws UnsupportedOperationException because this class cannot be instantiated.
|
|
|
|
|
*/
|
|
|
|
|
private DatapointHelper()
|
|
|
|
@ -57,7 +57,7 @@ import java.security.NoSuchAlgorithmException;
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param context The context used to access the settings resolver
|
|
|
|
|
* @return An 1-way hashed version of the {@link android.provider.Settings.Secure#ANDROID_ID}. May return null if an Android
|
|
|
|
|
* ID or the hashing algorithm is not available.
|
|
|
|
@ -112,7 +112,7 @@ import java.security.NoSuchAlgorithmException;
|
|
|
|
|
* therefore cannot be used to determine what device this data came from.
|
|
|
|
|
* <p>
|
|
|
|
|
* Note: {@link android.os.Build#SERIAL} was introduced in SDK 9. For older SDKs, this method will return null.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @return An 1-way hashed version of the {@link android.os.Build#SERIAL}. May return null if a serial or the hashing
|
|
|
|
|
* algorithm is not available.
|
|
|
|
|
*/
|
|
|
|
@ -154,7 +154,7 @@ import java.security.NoSuchAlgorithmException;
|
|
|
|
|
* <p>
|
|
|
|
|
* Note: this method will return null if {@link permission#READ_PHONE_STATE} is not available. This method will also return
|
|
|
|
|
* null on devices that do not have telephony.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param context The context used to access the phone state.
|
|
|
|
|
* @return An the {@link TelephonyManager#getDeviceId()}. Null if an ID is not available, or if
|
|
|
|
|
* {@link permission#READ_PHONE_STATE} is not available.
|
|
|
|
@ -163,7 +163,8 @@ import java.security.NoSuchAlgorithmException;
|
|
|
|
|
{
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 8)
|
|
|
|
|
{
|
|
|
|
|
final boolean hasTelephony = ReflectionUtils.tryInvokeInstance(context.getPackageManager(), "hasSystemFeature", new Class<?>[] { String.class }, new Object[] { "android.hardware.telephony" }); //$NON-NLS-1$//$NON-NLS-2$
|
|
|
|
|
final Boolean hasTelephony = ReflectionUtils.tryInvokeInstance(context.getPackageManager(), "hasSystemFeature", //$NON-NLS-1$
|
|
|
|
|
new Class<?>[] { String.class }, new Object[] { "android.hardware.telephony" }); //$NON-NLS-1$
|
|
|
|
|
|
|
|
|
|
if (!hasTelephony)
|
|
|
|
|
{
|
|
|
|
@ -204,7 +205,7 @@ import java.security.NoSuchAlgorithmException;
|
|
|
|
|
* Note: this method will return null if this is a non-telephony device.
|
|
|
|
|
* <p>
|
|
|
|
|
* Note: this method will return null if {@link permission#READ_PHONE_STATE} is not available.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param context The context used to access the phone state.
|
|
|
|
|
* @return An 1-way hashed version of the {@link TelephonyManager#getDeviceId()}. Null if an ID or the hashing algorithm is
|
|
|
|
|
* not available, or if {@link permission#READ_PHONE_STATE} is not available.
|
|
|
|
@ -213,7 +214,8 @@ import java.security.NoSuchAlgorithmException;
|
|
|
|
|
{
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 8)
|
|
|
|
|
{
|
|
|
|
|
final boolean hasTelephony = ReflectionUtils.tryInvokeInstance(context.getPackageManager(), "hasSystemFeature", new Class<?>[] { String.class }, new Object[] { "android.hardware.telephony" }); //$NON-NLS-1$//$NON-NLS-2$
|
|
|
|
|
final Boolean hasTelephony = ReflectionUtils.tryInvokeInstance(context.getPackageManager(), "hasSystemFeature", //$NON-NLS-1$
|
|
|
|
|
new Class<?>[] { String.class }, new Object[] { "android.hardware.telephony" }); //$NON-NLS-1$
|
|
|
|
|
|
|
|
|
|
if (!hasTelephony)
|
|
|
|
|
{
|
|
|
|
@ -254,7 +256,7 @@ import java.security.NoSuchAlgorithmException;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determines the type of network this device is connected to.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param context the context used to access the device's WIFI
|
|
|
|
|
* @param telephonyManager The manager used to access telephony info
|
|
|
|
|
* @return The type of network, or unknown if the information is unavailable
|
|
|
|
@ -282,7 +284,7 @@ import java.security.NoSuchAlgorithmException;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the versionName of the application.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param context {@link Context}. Cannot be null.
|
|
|
|
|
* @return The application's version
|
|
|
|
|
*/
|
|
|
|
@ -320,7 +322,7 @@ import java.security.NoSuchAlgorithmException;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Helper method to generate a SHA-256 hash of a given String
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param string String to hash. Cannot be null.
|
|
|
|
|
* @return hashed version of the string using SHA-256.
|
|
|
|
|
*/
|
|
|
|
|