修复启动时 IMEI有时会获取不到的问题。
authorsnicker <snickersun@163.com>
Mon, 30 Mar 2020 02:01:00 +0000 (10:01 +0800)
committersnicker <snickersun@163.com>
Mon, 30 Mar 2020 02:01:00 +0000 (10:01 +0800)
app/src/main/java/com/enqualcomm/support/CoreService.java
app/src/main/java/com/enqualcomm/support/service/KeepAlive.java
app/src/main/java/com/enqualcomm/support/utils/DeviceInfoUtil.java

index e0aa917..c845ea1 100644 (file)
@@ -493,12 +493,7 @@ public class CoreService extends Service {
         this.runtime.setDBHelper(new DBHelper(getContentResolver(), this));\r
         this.runtime.setContextProxy(new ContextProxy(this));\r
         this.runtime.setLbsHelper(new LBSHelper(this,this.runtime.getContextProxy().getWifiManager(), this.runtime));\r
-        if (Config.getIMEI(runtime.getContextProxy().context).isEmpty()){\r
-            //如果配置里有IMEI,优先选配置里的,没有则选择系统的\r
-            runtime.setImeiAndCid(PhoneUtils.getIMEI(this),"");\r
-        }  else{\r
-            runtime.setImeiAndCid(Config.getIMEI(runtime.getContextProxy().context),"");\r
-        }\r
+\r
         this.runtime.setHRS(new heartRateStatus());\r
         this.runtime.setUseQueue(true);\r
         this.runtime.initDnsUtil(ICApplication.getInstance().getApplicationContext());\r
@@ -940,6 +935,7 @@ public class CoreService extends Service {
     public void stopConnectionRetryTimer(){\r
         if (mTimer_retry_connect !=null){\r
             mTimer_retry_connect.cancel();\r
+            mTimer_retry_connect.purge();\r
             mTimer_retry_connect = null;\r
         }\r
     }\r
index ef49526..4ae50ab 100644 (file)
@@ -16,6 +16,7 @@ import com.enqualcomm.support.service.base.AbstractConnectionService;
 import com.enqualcomm.support.utils.AlarmHelper;\r
 import com.enqualcomm.support.utils.AlarmWakeUp;\r
 import com.enqualcomm.support.utils.Connection;\r
+import com.enqualcomm.support.utils.DeviceInfoUtil;\r
 import com.enqualcomm.support.utils.ICLogger;\r
 import com.enqualcomm.support.utils.NettyConnection;\r
 import com.enqualcomm.support.utils.NetworkObservable;\r
@@ -137,6 +138,9 @@ public class KeepAlive extends AbstractConnectionService {
           //心跳开始发送的时候,先重置response检测标志\r
           is_heartBeat_send_success = false;\r
           hearBeatResendCount++;\r
+          //更新系统的IMEI\r
+          boolean ret=DeviceInfoUtil.updateImei(mRuntime);\r
+          ICLogger.i("Update IMEI "+ret);\r
           connection.send(protocolAPIHelper.genStringMessage("heart", protocolAPIHelper.AP03(mRuntime)));\r
         }\r
       }\r
@@ -243,6 +247,9 @@ public class KeepAlive extends AbstractConnectionService {
 //    if (!connectionError) {\r
     connectionError = false;\r
 \r
+    //更新系统的IMEI\r
+    boolean ret=DeviceInfoUtil.updateImei(paramRuntime);\r
+    ICLogger.i("Update IMEI "+ret);\r
     //发送登录包\r
     Observable.timer(500L, TimeUnit.MILLISECONDS).subscribe(new Action1<Long>() {\r
       public void call(Long param1Long) {\r
index f2eeb4c..471b852 100644 (file)
@@ -10,6 +10,7 @@ import android.os.Build;
 import android.provider.Settings;\r
 import android.telephony.TelephonyManager;\r
 \r
+import com.enqualcomm.support.Config;\r
 import com.enqualcomm.support.CoreService;\r
 import com.enqualcomm.support.bean.StepCount;\r
 import com.enqualcomm.support.bean.Runtime;\r
@@ -19,6 +20,8 @@ import com.ic.jni.ICJniUtils;
 import java.io.FileInputStream;\r
 import java.util.ArrayList;\r
 \r
+import chestnut.utils.PhoneUtils;\r
+\r
 public class DeviceInfoUtil {\r
   private static final int CID_LENGTH = 16;\r
   \r
@@ -41,6 +44,23 @@ public class DeviceInfoUtil {
     return Build.MODEL;\r
   }\r
 \r
+  public static boolean updateImei(Runtime runtime){\r
+\r
+    String imei= Config.getIMEI(runtime.getContextProxy().context);\r
+    if (imei.isEmpty()){\r
+      //如果配置里有IMEI,优先选配置里的,没有则选择系统的\r
+      imei= PhoneUtils.getIMEI(runtime.getContextProxy().context);\r
+      if(imei==null) {\r
+        return false;\r
+      }else{\r
+        runtime.setImeiAndCid(imei, "");\r
+      }\r
+    }  else{\r
+      runtime.setImeiAndCid(imei,"");\r
+    }\r
+\r
+    return true;\r
+  }\r
 \r
   /**\r
    * 得到当前应用版本名称的方法\r
@@ -122,15 +142,7 @@ public class DeviceInfoUtil {
     }\r
     return i;\r
   }\r
-  \r
-  public static String getIMEI(Context paramContext) {\r
-    return ((TelephonyManager)paramContext.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();\r
-  }\r
-  \r
-  public static String getIMSI(Context paramContext) {\r
-    return ((TelephonyManager)paramContext.getSystemService(Context.TELEPHONY_SERVICE)).getSubscriberId();\r
-  }\r
-  \r
+\r
   public static boolean getLockSimInfo(Context paramContext) {\r
     int i = 0;\r
     try {\r
@@ -230,6 +242,7 @@ public class DeviceInfoUtil {
             .append(",bph ").append(runtime.getHRS().getBPH())\r
             .append(",bpl ").append(runtime.getHRS().getBPL())\r
             .append(" at ").append(runtime.getHRS().getTestTime())\r
+            .append("\nrealimei:").append(PhoneUtils.getIMEI(runtime.getContextProxy().context))\r
             .toString();\r
   }\r
   public static String getShortDeviceInfo(Runtime runtime){\r