|
@@ -114,9 +114,11 @@ class CallingbedActivity :BaseActivity<CallingbedActivityPresenter, Callingbed2M
|
|
|
|
|
|
private var clickTime : Long = 0
|
|
|
private var clickSosTime : Long = 0
|
|
|
+ private var checkTime: Long = 0
|
|
|
|
|
|
//网络异常计数
|
|
|
private var netErrCount : Int = 0
|
|
|
+ private var serverConnectTimes: Int = 0
|
|
|
|
|
|
private var copyDone = false
|
|
|
private var serverSuccess = false
|
|
@@ -176,6 +178,8 @@ class CallingbedActivity :BaseActivity<CallingbedActivityPresenter, Callingbed2M
|
|
|
Constant.LOCAL_MAC = NetHelper.getInstance().imei
|
|
|
}
|
|
|
|
|
|
+ checkTime = System.currentTimeMillis()
|
|
|
+
|
|
|
//注册广播
|
|
|
regReceiver()
|
|
|
RecordHelper.getInstance().init()
|
|
@@ -219,6 +223,8 @@ class CallingbedActivity :BaseActivity<CallingbedActivityPresenter, Callingbed2M
|
|
|
|
|
|
checkServer()
|
|
|
|
|
|
+ checkServerConnect()
|
|
|
+
|
|
|
SoundPoolManager.getInstance().init()
|
|
|
|
|
|
if ("rk3128".equals(Build.MODEL)) {
|
|
@@ -290,6 +296,28 @@ class CallingbedActivity :BaseActivity<CallingbedActivityPresenter, Callingbed2M
|
|
|
}
|
|
|
|
|
|
|
|
|
+ private fun checkServerConnect() {
|
|
|
+ val timerTask: TimerTask = object : TimerTask() {
|
|
|
+ override fun run() {
|
|
|
+ if (Constant.TCP_CONNECTED) {
|
|
|
+ serverConnectTimes = 0
|
|
|
+ } else {
|
|
|
+ //设备有ip地址,但是tcp未连接,可能是服务器地址不对或者中途网络断开或者服务端异常
|
|
|
+ if (!TextUtils.isEmpty(NetHelper.getInstance().localIP)) {
|
|
|
+ serverConnectTimes++
|
|
|
+ }
|
|
|
+ Log.e(TAG, "check tcp server connect ===> serverConnectTimes=$serverConnectTimes")
|
|
|
+ if (serverConnectTimes >= 20) {
|
|
|
+ //tcp检测断开连接次数超过20则重启设备
|
|
|
+ AppUpdateHelper.systemRestart()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ val executor = Executors.newSingleThreadScheduledExecutor()
|
|
|
+ executor.scheduleAtFixedRate(timerTask, 120, 100, TimeUnit.SECONDS)
|
|
|
+ }
|
|
|
+
|
|
|
private fun checkServer() {
|
|
|
Thread {
|
|
|
while (!serverSuccess) {
|
|
@@ -806,18 +834,18 @@ class CallingbedActivity :BaseActivity<CallingbedActivityPresenter, Callingbed2M
|
|
|
SettingConfig.setNetErrResetCount(this, 0)
|
|
|
WarningDialogHelper.dismiss()
|
|
|
|
|
|
- Thread(Runnable {
|
|
|
+ Thread {
|
|
|
while (!initialized) {
|
|
|
- runOnUiThread(Runnable {
|
|
|
- initDevice()
|
|
|
- })
|
|
|
+
|
|
|
+ initDevice()
|
|
|
+
|
|
|
try {
|
|
|
- Thread.sleep(20000)
|
|
|
+ Thread.sleep(30000)
|
|
|
} catch (e: Exception) {
|
|
|
//
|
|
|
}
|
|
|
}
|
|
|
- }).start()
|
|
|
+ }.start()
|
|
|
|
|
|
|
|
|
//通过服务端设置语言
|
|
@@ -1446,6 +1474,7 @@ class CallingbedActivity :BaseActivity<CallingbedActivityPresenter, Callingbed2M
|
|
|
+ ", net error count: " + count)
|
|
|
if (!Constant.TCP_CONNECTED && TextUtils.isEmpty(NetHelper.getInstance().localIP)) {
|
|
|
netErrCount++
|
|
|
+ Log.e(TAG, "network error!!! ==> netErrCount: $netErrCount, reset count: $count")
|
|
|
} else {
|
|
|
netErrCount = 0
|
|
|
if (count > 0) {
|
|
@@ -1463,27 +1492,43 @@ class CallingbedActivity :BaseActivity<CallingbedActivityPresenter, Callingbed2M
|
|
|
handler.postDelayed({
|
|
|
AppUpdateHelper.reboot(this, true)
|
|
|
}, 5000)
|
|
|
+
|
|
|
+ netOffReset()
|
|
|
} else {
|
|
|
runOnUiThread {
|
|
|
WarningDialogHelper.showDialog(this@CallingbedActivity)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
//隔2个小时再重启
|
|
|
- val calendar = Calendar.getInstance()
|
|
|
- val hour = calendar[Calendar.HOUR_OF_DAY]
|
|
|
- val minute = calendar[Calendar.MINUTE]
|
|
|
- Log.e(TAG, "show net error dialog --> hour: $hour, minute: $minute")
|
|
|
- if (hour%2 == 0 && minute == 0) {
|
|
|
- handler.postDelayed({
|
|
|
- AppUpdateHelper.reboot(activity, true)
|
|
|
- }, 5000)
|
|
|
+ val time = System.currentTimeMillis()
|
|
|
+ val errTime = time - checkTime
|
|
|
+ Log.e(TAG, "show net error dialog --> errTime = $errTime")
|
|
|
+ if (errTime >= 2*60*60*1000) {
|
|
|
+ checkTime = time
|
|
|
+ netOffReset()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //网卡断电再上电,并重启设备
|
|
|
+ private fun netOffReset() {
|
|
|
+ Thread {
|
|
|
+ try {
|
|
|
+ SerialPortHelper.netOff(true)
|
|
|
+ Thread.sleep(5000)
|
|
|
+ SerialPortHelper.netOff(false)
|
|
|
+
|
|
|
+ //重启
|
|
|
+ Thread.sleep(5000)
|
|
|
+ AppUpdateHelper.reboot(activity, true)
|
|
|
+ } catch (ex: Exception) {
|
|
|
+ //
|
|
|
+ }
|
|
|
+ }.start()
|
|
|
+ }
|
|
|
+
|
|
|
private fun updateStatus(state: String) {
|
|
|
this.runOnUiThread {
|
|
|
when (state) {
|