Skip to content

Commit

Permalink
ensure androidid called once in a process (#165)
Browse files Browse the repository at this point in the history
ensure androidid called once in a process
  • Loading branch information
cpacm authored Jul 25, 2022
1 parent d81e5e8 commit ab7c82e
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class DeviceInfoProvider {
private static final String DEVICE_TYPE_PHONE = "PHONE";
private static final String DEVICE_TYPE_PAD = "PAD";

private static final String MAGIC_ANDROID_ID = "9774d56d682e549c";
private static final String MAGIC_ANDROID_ID = "9774d56d682e549c"; // Error AndroidID

private final Context mContext;

Expand Down Expand Up @@ -134,10 +134,20 @@ public String getImei() {
}

public String getAndroidId() {
// ensure androidid call once in a process
if (TextUtils.isEmpty(mAndroidId)) {
mAndroidId = Settings.System.getString(mContext.getContentResolver(), Settings.System.ANDROID_ID);
try {
mAndroidId = Settings.System.getString(mContext.getContentResolver(), Settings.System.ANDROID_ID);
if (TextUtils.isEmpty(mAndroidId) || MAGIC_ANDROID_ID.equals(mAndroidId)) {
Logger.e(TAG, "get AndroidId error");
mAndroidId = MAGIC_ANDROID_ID;
}
} catch (Throwable e) {
Logger.e(TAG, "get AndroidId error");
mAndroidId = MAGIC_ANDROID_ID;
}
}
return mAndroidId;
return mAndroidId.equals(MAGIC_ANDROID_ID) ? null : mAndroidId;
}

public String getOaid() {
Expand Down Expand Up @@ -169,7 +179,7 @@ private String calculateDeviceId() {
Logger.d(TAG, "first time calculate deviceId");
String adId = getAndroidId();
String result = null;
if (!TextUtils.isEmpty(adId) && !MAGIC_ANDROID_ID.equals(adId)) {
if (!TextUtils.isEmpty(adId)) {
result = UUID.nameUUIDFromBytes(adId.getBytes(Charset.forName("UTF-8"))).toString();
} else {
String imi = getImei();
Expand Down

0 comments on commit ab7c82e

Please sign in to comment.