Skip to content

Instantly share code, notes, and snippets.

@dalingrin
Created May 24, 2011 20:15
Show Gist options
  • Save dalingrin/989573 to your computer and use it in GitHub Desktop.
Save dalingrin/989573 to your computer and use it in GitHub Desktop.
frameworks/base diff for imei nonsense
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index 69673b1..95de8cf 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -19,6 +19,9 @@ package android.telephony;
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.content.Context;
+import android.content.pm.PackageManager.*;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -31,7 +34,13 @@ import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.RILConstants;
import com.android.internal.telephony.TelephonyProperties;
+import android.util.Log;
+import java.math.BigInteger;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
import java.util.List;
/**
@@ -184,11 +193,35 @@ public class TelephonyManager {
*/
public String getDeviceId() {
try {
- return getSubscriberInfo().getDeviceId();
+ String deviceId = getSubscriberInfo().getDeviceId();
+ if (deviceId == null) {
+ PackageManager pm = mContext.getPackageManager();
+ PackageInfo pInfo = pm.getPackageInfo(mContext.getPackageName(), 0);
+ String packageName = pInfo.packageName;
+ Log.i(TAG, "DeviceId() called by: " + packageName);
+
+ String wifiInterfaceName = SystemProperties.get("wifi.interface");
+ Log.i(TAG, "Wifi interface name: " + wifiInterfaceName);
+ String wifiMac = new String(NetworkInterface.getByName(wifiInterfaceName).getHardwareAddress());
+ MessageDigest md = MessageDigest.getInstance("MD5");
+ deviceId = new BigInteger(1, md.digest(wifiMac.getBytes())).toString(16).toUpperCase();
+ Log.i(TAG, "DeviceId created: " + deviceId);
+ }
+
+ return deviceId;
} catch (RemoteException ex) {
return null;
} catch (NullPointerException ex) {
return null;
+ } catch (NameNotFoundException ex) {
+ Log.e(TAG, "Unable to get package name: " + ex.getMessage());
+ return null;
+ } catch (SocketException ex) {
+ Log.e(TAG, "Unable to access wifi interface: " + ex.getMessage());
+ return null;
+ } catch (NoSuchAlgorithmException ex) {
+ Log.e(TAG, "Unable to hash wifi mac address: " + ex.getMessage());
+ return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment