From fb52bcd98a07602dbc995f0a1df6f31e10a365de Mon Sep 17 00:00:00 2001 From: TrillGates Date: Wed, 13 Oct 2021 12:03:54 +0800 Subject: [PATCH] =?utf8?q?=E5=A4=9A=E4=BA=A4=E9=93=BE=E6=8E=A5=E5=A4=B1?= =?utf8?q?=E8=B4=A5=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C=E5=B0=B1=E4=BC=9A?= =?utf8?q?=E5=8E=BB=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6=E6=9C=89=E6=89=93?= =?utf8?q?=E5=BC=80wifi=EF=BC=8C=E5=A6=82=E6=9E=9C=E6=89=93=E5=BC=80wifi?= =?utf8?q?=E5=B0=B1=E4=BC=9A=E9=87=8D=E6=96=B0=E5=BC=80=E5=85=B3=EF=BC=8C?= =?utf8?q?=E5=A6=82=E6=9E=9C=E6=B2=A1=E6=9C=89=E6=89=93=E5=BC=80wifi?= =?utf8?q?=EF=BC=8C=E5=B0=B1=E4=BC=9A=E9=87=8D=E6=96=B0=E5=BC=80=E5=85=B3s?= =?utf8?q?im=E5=8D=A1=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../com/enqualcomm/support/CoreService.java | 41 +++++++++++++------ .../com/enqualcomm/support/ICSmsManager.java | 29 ++++++------- .../support/utils/SimSignalUtil.java | 1 - .../com/enqualcomm/support/utils/Util.java | 17 ++++---- 4 files changed, 50 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/com/enqualcomm/support/CoreService.java b/app/src/main/java/com/enqualcomm/support/CoreService.java index 816bb4ef..4469e518 100644 --- a/app/src/main/java/com/enqualcomm/support/CoreService.java +++ b/app/src/main/java/com/enqualcomm/support/CoreService.java @@ -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); } diff --git a/app/src/main/java/com/enqualcomm/support/ICSmsManager.java b/app/src/main/java/com/enqualcomm/support/ICSmsManager.java index 416902e6..031f875d 100644 --- a/app/src/main/java/com/enqualcomm/support/ICSmsManager.java +++ b/app/src/main/java/com/enqualcomm/support/ICSmsManager.java @@ -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!"); diff --git a/app/src/main/java/com/enqualcomm/support/utils/SimSignalUtil.java b/app/src/main/java/com/enqualcomm/support/utils/SimSignalUtil.java index ae7d8e09..22fa5e5b 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/SimSignalUtil.java +++ b/app/src/main/java/com/enqualcomm/support/utils/SimSignalUtil.java @@ -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", ""); diff --git a/app/src/main/java/com/enqualcomm/support/utils/Util.java b/app/src/main/java/com/enqualcomm/support/utils/Util.java index 0656c38c..5f350112 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/Util.java +++ b/app/src/main/java/com/enqualcomm/support/utils/Util.java @@ -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; -- 2.17.1