多交链接失败的时候,就会去判断是否有打开wifi,如果打开wifi就会重新开关,如果没有打开wifi,就会重新开关sim卡。
authorTrillGates <williamtrillgates@gmail.com>
Wed, 13 Oct 2021 04:03:54 +0000 (12:03 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Wed, 13 Oct 2021 04:03:54 +0000 (12:03 +0800)
app/src/main/java/com/enqualcomm/support/CoreService.java
app/src/main/java/com/enqualcomm/support/ICSmsManager.java
app/src/main/java/com/enqualcomm/support/utils/SimSignalUtil.java
app/src/main/java/com/enqualcomm/support/utils/Util.java

index 816bb4e..4469e51 100644 (file)
@@ -73,6 +73,8 @@ import com.ic.protocols.protocolAPIHelper;
 import com.ic.s123.IS123WeatherCallback;
 import com.ic.s123.IS123WeatherService;
 
+import org.apache.harmony.misc.SystemUtils;
+
 import java.lang.ref.WeakReference;
 import java.util.ArrayList;
 import java.util.List;
@@ -221,7 +223,7 @@ public class CoreService extends Service {
             ICLogger.i(stringBuilder2.toString());
 
             if (ACTION_SEND_EMEGENCY_LOCATION_START.equals(param1Intent.getAction())) {
-                if(runtime.getLocationInstance().getWorkingMod()!=EMERGNECY_MOD) {
+                if (runtime.getLocationInstance().getWorkingMod() != EMERGNECY_MOD) {
                     //先保存需要恢复的模式, 并且防止出现多次进入紧急模式造成的无法恢复以往状态问题
                     runtime.getLocationInstance().setLastWorkingMode(runtime.getLocationInstance().getWorkingMod());
                 }
@@ -249,7 +251,7 @@ public class CoreService extends Service {
 //                    Deliver.sendLocationMSG(protocolAPIHelper.getWarningMSG(runtime));
 
                 //开启紧急定位模式,GPS 优先1分钟一次定位,持续5分钟
-                if(runtime.getLocationInstance().getWorkingMod()!=EMERGNECY_MOD) {
+                if (runtime.getLocationInstance().getWorkingMod() != EMERGNECY_MOD) {
                     //先保存需要恢复的模式, 并且防止出现多次进入紧急模式造成的无法恢复以往状态问题
                     runtime.getLocationInstance().setLastWorkingMode(runtime.getLocationInstance().getWorkingMod());
                 }
@@ -909,16 +911,15 @@ public class CoreService extends Service {
         Deliver.resetCMDReocrdsDB();
 
 
-        if(Config.custom_name.equals("l004pt")||Config.custom_name.equals("l004")||Config.custom_name.equals("l005"))
-        {
+        if (Config.custom_name.equals("l004pt") || Config.custom_name.equals("l004") || Config.custom_name.equals("l005")) {
             mHandler.postDelayed(new Runnable() {
                 @Override
                 public void run() {
                     //L004PT ,L005 默认开启roaming以及默认使用以下apn
 //                    APNUtil.addVPN("Test","tapn","460","04","","",CoreService.getInstance());
-                    APNUtil.selectAPN("334","020","ctm-mobile",CoreService.getInstance());
+                    APNUtil.selectAPN("334", "020", "ctm-mobile", CoreService.getInstance());
                 }
-            },5000);
+            }, 5000);
 
         }
         ReConnectToServer();
@@ -1162,7 +1163,7 @@ public class CoreService extends Service {
                     ICLogger.d("is open by user == > " + isUserOpen);
                     if ("false".equals(isUserOpen)) {
                         //用户手动打开的,那么就不关闭wifi了
-                        Util.turnOffWifiForSleep((this.runtime.getContextProxy()).context, this.runtime);
+                        Util.turnOffWifiForSleep(this.runtime);
                     }
                 }
 //                setAlarm(alarmCycle);
@@ -1573,8 +1574,22 @@ public class CoreService extends Service {
             stopConnectionRetryTimer();
         }
         if (no_network_Heartbeats_Count > 12) {
+            //如果WIFI打开的,但是还是12次链接不上了,那么就开关一下WIFI,重新连接WIFI
+            //如果没有打开WIFI的,那么就控制Sim卡的开关
             ICLogger.i("当前第" + no_network_Heartbeats_Count + "次心跳都没有连接服务器成功 > 10 ,重置SIM卡尝试重新注册网络!");
-            SimSignalUtil.send_at_to_reset_simcard(runtime); //直接下此命令不能实现断网重连,所以干脆采用关闭网络再打开的方式。
+            String isUserOpenWifi = Util.getSystemProperties("persist.sys.ic.wifi_enable");
+            ICLogger.d("isUserOpenWifi ==> " + isUserOpenWifi);
+            if ("true".equals(isUserOpenWifi)) {
+                //先关闭,然后再打开
+                Util.turnOffWifiForSleep(runtime);
+                ICLogger.d("tun off wifi...");
+                mHandler.postDelayed(() -> {
+                    Util.turnOnWifiForConnect(runtime);
+                    ICLogger.d("tun on wifi...");
+                }, 1000);
+            } else {
+                SimSignalUtil.send_at_to_reset_simcard(runtime); //直接下此命令不能实现断网重连,所以干脆采用关闭网络再打开的方式。
+            }
             no_network_Heartbeats_Count = 0;//重置Sim卡后重置计数。防止后面多次重置Sim卡。
         }
     }
@@ -1703,7 +1718,7 @@ public class CoreService extends Service {
         public void getContacts() {
             //获取联系人
             StringMessage cmdmMembers = protocolAPIHelper.requestVideoCallContact(runtime);
-             //获取佰锐ID
+            //获取佰锐ID
             connection.send(cmdmMembers);
             ICLogger.d("get contacts...");
         }
@@ -1720,7 +1735,7 @@ public class CoreService extends Service {
         @Override
         public void rejectCallInCome(String remoteId, int type) {
             //拒绝来电
-            StringMessage rejectMsg = protocolAPIHelper.rejectVideoCall(runtime,remoteId, type);
+            StringMessage rejectMsg = protocolAPIHelper.rejectVideoCall(runtime, remoteId, type);
             connection.send(rejectMsg);
             ICLogger.d("reject remote call request..." + remoteId + "..." + type);
         }
@@ -1728,7 +1743,7 @@ public class CoreService extends Service {
         @Override
         public void requireCall(int type, int remoteUserId) {
             //请求与对方通话
-            StringMessage talk = protocolAPIHelper.dialVideoCall(runtime,type, remoteUserId);
+            StringMessage talk = protocolAPIHelper.dialVideoCall(runtime, type, remoteUserId);
             connection.send(talk);
             ICLogger.d("require call == > type is " + type + " remote user id is == > " + remoteUserId);
         }
@@ -1744,7 +1759,7 @@ public class CoreService extends Service {
         public void setUpEnvState(int state) {
 
             ICLogger.d("update bairui env state..." + state);
-            protocolAPIHelper.updateEnvState(runtime,state);
+            protocolAPIHelper.updateEnvState(runtime, state);
 
         }
 
@@ -1761,7 +1776,7 @@ public class CoreService extends Service {
         @Override
         public void unbindFriends(String remoteFriendId) {
             ICLogger.d("unbindFriends == > " + remoteFriendId);
-            StringMessage ppr = protocolAPIHelper.unbindFriends(runtime,remoteFriendId);
+            StringMessage ppr = protocolAPIHelper.unbindFriends(runtime, remoteFriendId);
             //解除朋友
             connection.send(ppr);
         }
index 416902e..031f875 100644 (file)
@@ -556,18 +556,18 @@ public class ICSmsManager extends BroadcastReceiver {
                     } else if (tmp[1].startsWith("switch,")) {
                         String tmplist[] = tmp[1].split(",");
                         if (tmplist.length == 2) {
-                            if(tmplist[1].trim().equalsIgnoreCase("on") || tmplist[1].trim().equalsIgnoreCase("1")) {
-                                Util.turnOnWifiForConnect(mContext,runtime);
+                            if (tmplist[1].trim().equalsIgnoreCase("on") || tmplist[1].trim().equalsIgnoreCase("1")) {
+                                Util.turnOnWifiForConnect(runtime);
                                 Util.setSystemProperties("persist.sys.ic.wifi_enable", "true");
                                 sendSMS(phonenumber, "WiFi Switch On !");
-                            }else if(tmplist[1].trim().equalsIgnoreCase("off") || tmplist[1].trim().equalsIgnoreCase("0")){
-                                Util.turnOffWifiForSleep(mContext,runtime);
+                            } else if (tmplist[1].trim().equalsIgnoreCase("off") || tmplist[1].trim().equalsIgnoreCase("0")) {
+                                Util.turnOffWifiForSleep(runtime);
                                 Util.setSystemProperties("persist.sys.ic.wifi_enable", "false");
                                 sendSMS(phonenumber, "WiFi Switch Off !");
-                            }else{
-                                sendSMS(phonenumber, "WiFi Switch Control "+tmplist[1].trim()+" format error!");
+                            } else {
+                                sendSMS(phonenumber, "WiFi Switch Control " + tmplist[1].trim() + " format error!");
                             }
-                        }else{
+                        } else {
                             sendSMS(phonenumber, "WiFi Switch Control format error!");
                         }
 
@@ -600,7 +600,7 @@ public class ICSmsManager extends BroadcastReceiver {
                             runtime.setNoTurnOffOnScreenOff(isenabled);
                             StringBuilder sb = new StringBuilder();
                             if (isenabled && !Util.isWifiIsOpen(runtime.getContextProxy().context, runtime)) {
-                                Util.turnOnWifiForConnect(runtime.getContextProxy().context, runtime);
+                                Util.turnOnWifiForConnect(runtime);
                                 sb.append(" Turn On Wifi first and ");
                             }
                             sb.append("set noTurnOffWhenScreenOff " + enabled);
@@ -863,7 +863,7 @@ public class ICSmsManager extends BroadcastReceiver {
                         /* #setLogSrv#=http://icfota.snicker.com.cn:8089/UploadFile.jsp*/
                         Config.setHttpLogServerUrl(mContext, strtmp);
                         sendSMS(phonenumber, "set setLogSrv to " + strtmp + "!");
-                    }else {
+                    } else {
                         sendSMS(phonenumber, " setLogSrv cmd Format error!");
                     }
 
@@ -898,19 +898,16 @@ public class ICSmsManager extends BroadcastReceiver {
                         runtime.setNoTurnOffOnScreenOff(true);
                         StringBuilder sb = new StringBuilder();
                         if (!Util.isWifiIsOpen(runtime.getContextProxy().context, runtime)) {
-                            Util.turnOnWifiForConnect(runtime.getContextProxy().context, runtime);
+                            Util.turnOnWifiForConnect(runtime);
                         }
                         sb.append("connect to Wifi SSID " + Config.getWiFiSSID(mContext) + ", WiFiPassword " + Config.getWiFiPasswd(mContext) + ", encryptType " + encyptType + "!");
                         sb.append(" And start to Update");
                         cell_number_to_reply = phonenumber;
                         sendSMS(phonenumber, sb.toString());
                         //connect to wifi
-                        mHandler.postDelayed(new Runnable() {
-                            @Override
-                            public void run() {
-                                Deliver.connectToWifi(SSID, PWD, encyptType);
-                                broadCastStartFotaUpdate(mContext);
-                            }
+                        mHandler.postDelayed(() -> {
+                            Deliver.connectToWifi(SSID, PWD, encyptType);
+                            broadCastStartFotaUpdate(mContext);
                         }, 500);
                     } else {
                         sendSMS(phonenumber, "FotaUpdateWiFi Control format error!");
index ae7d8e0..22fa5e5 100644 (file)
@@ -169,7 +169,6 @@ public class SimSignalUtil {
     }
 
     public static void send_at_to_reset_simcard(Runtime runtime) {
-
         Intent intent = new Intent("com.eqc.intent.action.getTelephony.lbs");
         intent.putExtra("command", "AT+SFUN=2"); //重新初始化sim卡
         intent.putExtra("arg2", "");
index 0656c38..5f35011 100644 (file)
@@ -556,7 +556,7 @@ public class Util {
         wifimanagerMethods = wifiManager.getClass().getDeclaredMethods();
         methods_count = wifimanagerMethods.length;
         last_method = null;
-        for (i = 0; i < methods_count;++i) {
+        for (i = 0; i < methods_count; ++i) {
             method_connect = wifimanagerMethods[i];
             if ("connect".equalsIgnoreCase(method_connect.getName())) {
                 parameterTypes = method_connect.getParameterTypes();
@@ -989,11 +989,11 @@ public class Util {
         return arrayOfByte;
     }
 
-    public static void turnOffWifiForSleep(Context paramContext, Runtime paramRuntime) {
+    public static void turnOffWifiForSleep(Runtime paramRuntime) {
         paramRuntime.getContextProxy().getWifiManager().setWifiEnabled(false);
     }
 
-    public static void turnOnWifiForConnect(Context paramContext, Runtime paramRuntime) {
+    public static void turnOnWifiForConnect(Runtime paramRuntime) {
         paramRuntime.getContextProxy().getWifiManager().setWifiEnabled(true);
     }
 
@@ -1100,7 +1100,7 @@ public class Util {
         }
     }
 
-    public static boolean parseToVoicePacketSent(VoiceContent voiceContent,int packetSize) {
+    public static boolean parseToVoicePacketSent(VoiceContent voiceContent, int packetSize) {
 
         long filesize;
         File voicefile = new File(voiceContent.content);
@@ -1124,11 +1124,11 @@ public class Util {
                 fis.close();
                 voicePacket.getInstanceSent().setCurrentIndexToSent(0);
                 voicePacket.getInstanceSent().setPacketTime(TimeUtil.getSystemTime3());
-                if( voiceContent.filetype==1) //* 1 语音——       1.监听语音      *   2.SOS语音      *      3.扩展
+                if (voiceContent.filetype == 1) //* 1 语音——     1.监听语音      *   2.SOS语音      *      3.扩展
                 {
-                    int duration=Util.getDuration(voiceContent.content);
-                    voicePacket.getInstanceSent().setDurationHex(String.format("%04X",duration));
-                }else{
+                    int duration = Util.getDuration(voiceContent.content);
+                    voicePacket.getInstanceSent().setDurationHex(String.format("%04X", duration));
+                } else {
                     voicePacket.getInstanceSent().setDurationHex("0000");
                 }
                 return true;
@@ -1234,6 +1234,7 @@ public class Util {
         }
         return ret;
     }
+
     public static String UrlGB2312ToUTF8(String url) {
         String ret = "";
         String src = url;