From: snicker Date: Mon, 30 Mar 2020 02:01:00 +0000 (+0800) Subject: 修复启动时 IMEI有时会获取不到的问题。 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=4c8644701f1724187b1eb97ae498b2e1cdf3ab22;p=icsupport.git 修复启动时 IMEI有时会获取不到的问题。 --- diff --git a/app/src/main/java/com/enqualcomm/support/CoreService.java b/app/src/main/java/com/enqualcomm/support/CoreService.java index e0aa917b..c845ea16 100644 --- a/app/src/main/java/com/enqualcomm/support/CoreService.java +++ b/app/src/main/java/com/enqualcomm/support/CoreService.java @@ -493,12 +493,7 @@ public class CoreService extends Service { this.runtime.setDBHelper(new DBHelper(getContentResolver(), this)); this.runtime.setContextProxy(new ContextProxy(this)); this.runtime.setLbsHelper(new LBSHelper(this,this.runtime.getContextProxy().getWifiManager(), this.runtime)); - if (Config.getIMEI(runtime.getContextProxy().context).isEmpty()){ - //如果配置里有IMEI,优先选配置里的,没有则选择系统的 - runtime.setImeiAndCid(PhoneUtils.getIMEI(this),""); - } else{ - runtime.setImeiAndCid(Config.getIMEI(runtime.getContextProxy().context),""); - } + this.runtime.setHRS(new heartRateStatus()); this.runtime.setUseQueue(true); this.runtime.initDnsUtil(ICApplication.getInstance().getApplicationContext()); @@ -940,6 +935,7 @@ public class CoreService extends Service { public void stopConnectionRetryTimer(){ if (mTimer_retry_connect !=null){ mTimer_retry_connect.cancel(); + mTimer_retry_connect.purge(); mTimer_retry_connect = null; } } diff --git a/app/src/main/java/com/enqualcomm/support/service/KeepAlive.java b/app/src/main/java/com/enqualcomm/support/service/KeepAlive.java index ef49526d..4ae50ab0 100644 --- a/app/src/main/java/com/enqualcomm/support/service/KeepAlive.java +++ b/app/src/main/java/com/enqualcomm/support/service/KeepAlive.java @@ -16,6 +16,7 @@ import com.enqualcomm.support.service.base.AbstractConnectionService; import com.enqualcomm.support.utils.AlarmHelper; import com.enqualcomm.support.utils.AlarmWakeUp; import com.enqualcomm.support.utils.Connection; +import com.enqualcomm.support.utils.DeviceInfoUtil; import com.enqualcomm.support.utils.ICLogger; import com.enqualcomm.support.utils.NettyConnection; import com.enqualcomm.support.utils.NetworkObservable; @@ -137,6 +138,9 @@ public class KeepAlive extends AbstractConnectionService { //心跳开始发送的时候,先重置response检测标志 is_heartBeat_send_success = false; hearBeatResendCount++; + //更新系统的IMEI + boolean ret=DeviceInfoUtil.updateImei(mRuntime); + ICLogger.i("Update IMEI "+ret); connection.send(protocolAPIHelper.genStringMessage("heart", protocolAPIHelper.AP03(mRuntime))); } } @@ -243,6 +247,9 @@ public class KeepAlive extends AbstractConnectionService { // if (!connectionError) { connectionError = false; + //更新系统的IMEI + boolean ret=DeviceInfoUtil.updateImei(paramRuntime); + ICLogger.i("Update IMEI "+ret); //发送登录包 Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1() { public void call(Long param1Long) { diff --git a/app/src/main/java/com/enqualcomm/support/utils/DeviceInfoUtil.java b/app/src/main/java/com/enqualcomm/support/utils/DeviceInfoUtil.java index f2eeb4c7..471b852b 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/DeviceInfoUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/DeviceInfoUtil.java @@ -10,6 +10,7 @@ import android.os.Build; import android.provider.Settings; import android.telephony.TelephonyManager; +import com.enqualcomm.support.Config; import com.enqualcomm.support.CoreService; import com.enqualcomm.support.bean.StepCount; import com.enqualcomm.support.bean.Runtime; @@ -19,6 +20,8 @@ import com.ic.jni.ICJniUtils; import java.io.FileInputStream; import java.util.ArrayList; +import chestnut.utils.PhoneUtils; + public class DeviceInfoUtil { private static final int CID_LENGTH = 16; @@ -41,6 +44,23 @@ public class DeviceInfoUtil { return Build.MODEL; } + public static boolean updateImei(Runtime runtime){ + + String imei= Config.getIMEI(runtime.getContextProxy().context); + if (imei.isEmpty()){ + //如果配置里有IMEI,优先选配置里的,没有则选择系统的 + imei= PhoneUtils.getIMEI(runtime.getContextProxy().context); + if(imei==null) { + return false; + }else{ + runtime.setImeiAndCid(imei, ""); + } + } else{ + runtime.setImeiAndCid(imei,""); + } + + return true; + } /** * 得到当前应用版本名称的方法 @@ -122,15 +142,7 @@ public class DeviceInfoUtil { } return i; } - - public static String getIMEI(Context paramContext) { - return ((TelephonyManager)paramContext.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId(); - } - - public static String getIMSI(Context paramContext) { - return ((TelephonyManager)paramContext.getSystemService(Context.TELEPHONY_SERVICE)).getSubscriberId(); - } - + public static boolean getLockSimInfo(Context paramContext) { int i = 0; try { @@ -230,6 +242,7 @@ public class DeviceInfoUtil { .append(",bph ").append(runtime.getHRS().getBPH()) .append(",bpl ").append(runtime.getHRS().getBPL()) .append(" at ").append(runtime.getHRS().getTestTime()) + .append("\nrealimei:").append(PhoneUtils.getIMEI(runtime.getContextProxy().context)) .toString(); } public static String getShortDeviceInfo(Runtime runtime){