|
@ -12,6 +12,7 @@ import com.ouxuan.oxface.utils.LogManager; |
|
|
import com.ouxuan.oxface.utils.MaintenanceScheduler; |
|
|
import com.ouxuan.oxface.utils.MaintenanceScheduler; |
|
|
import com.ouxuan.oxface.utils.MemoryManager; |
|
|
import com.ouxuan.oxface.utils.MemoryManager; |
|
|
import com.ouxuan.oxface.utils.UtilCodeHelper; |
|
|
import com.ouxuan.oxface.utils.UtilCodeHelper; |
|
|
|
|
|
import com.ouxuan.oxface.device.MqttManager; // 添加MQTT管理器导入 |
|
|
import com.blankj.utilcode.util.Utils; |
|
|
import com.blankj.utilcode.util.Utils; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -32,6 +33,7 @@ public class OxFaceApplication extends Application implements |
|
|
private NetworkManager networkManager; |
|
|
private NetworkManager networkManager; |
|
|
private HealthMonitor healthMonitor; |
|
|
private HealthMonitor healthMonitor; |
|
|
private MaintenanceScheduler maintenanceScheduler; |
|
|
private MaintenanceScheduler maintenanceScheduler; |
|
|
|
|
|
private MqttManager mqttManager; // 添加MQTT管理器实例 |
|
|
|
|
|
|
|
|
public static OxFaceApplication getInstance() { |
|
|
public static OxFaceApplication getInstance() { |
|
|
return instance; |
|
|
return instance; |
|
@ -72,10 +74,13 @@ public class OxFaceApplication extends Application implements |
|
|
// 6. 启动维护调度器 |
|
|
// 6. 启动维护调度器 |
|
|
initMaintenanceScheduler(); |
|
|
initMaintenanceScheduler(); |
|
|
|
|
|
|
|
|
// 7. 初始化原有的网络工具 |
|
|
|
|
|
|
|
|
// 7. 初始化MQTT管理器 |
|
|
|
|
|
initMqttManager(); |
|
|
|
|
|
|
|
|
|
|
|
// 8. 初始化原有的网络工具 |
|
|
NetworkUtils.init(this); |
|
|
NetworkUtils.init(this); |
|
|
|
|
|
|
|
|
// 8. 初始化设备选择数据管理器 |
|
|
|
|
|
|
|
|
// 9. 初始化设备选择数据管理器 |
|
|
DeviceSelectDataManager.getInstance(this); |
|
|
DeviceSelectDataManager.getInstance(this); |
|
|
|
|
|
|
|
|
LogManager.logOperation(TAG, "所有管理器初始化完成,应用已准备好24小时无人值守运行"); |
|
|
LogManager.logOperation(TAG, "所有管理器初始化完成,应用已准备好24小时无人值守运行"); |
|
@ -139,6 +144,15 @@ public class OxFaceApplication extends Application implements |
|
|
LogManager.logOperation(TAG, "维护调度器启动"); |
|
|
LogManager.logOperation(TAG, "维护调度器启动"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 初始化MQTT管理器 |
|
|
|
|
|
*/ |
|
|
|
|
|
private void initMqttManager() { |
|
|
|
|
|
mqttManager = MqttManager.getInstance(); |
|
|
|
|
|
mqttManager.initialize(this); |
|
|
|
|
|
LogManager.logOperation(TAG, "MQTT管理器初始化完成"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// ========== NetworkStateListener 接口实现 ========== |
|
|
// ========== NetworkStateListener 接口实现 ========== |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -149,6 +163,11 @@ public class OxFaceApplication extends Application implements |
|
|
if (networkManager != null) { |
|
|
if (networkManager != null) { |
|
|
networkManager.reinitialize(); |
|
|
networkManager.reinitialize(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 网络恢复时重新连接MQTT |
|
|
|
|
|
if (mqttManager != null) { |
|
|
|
|
|
mqttManager.connectAsync(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -227,6 +246,11 @@ public class OxFaceApplication extends Application implements |
|
|
snapshot.append("维护统计: ").append(maintenanceScheduler.getMaintenanceStats()).append("\n"); |
|
|
snapshot.append("维护统计: ").append(maintenanceScheduler.getMaintenanceStats()).append("\n"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// MQTT状态 |
|
|
|
|
|
if (mqttManager != null) { |
|
|
|
|
|
snapshot.append("MQTT状态: ").append(mqttManager.getConnectionStatusDetail()).append("\n"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
snapshot.append("==========================================="); |
|
|
snapshot.append("==========================================="); |
|
|
|
|
|
|
|
|
LogManager.logOperation(TAG, snapshot.toString()); |
|
|
LogManager.logOperation(TAG, snapshot.toString()); |
|
@ -266,6 +290,11 @@ public class OxFaceApplication extends Application implements |
|
|
networkManager.stopNetworkMonitoring(); |
|
|
networkManager.stopNetworkMonitoring(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 停止MQTT管理器 |
|
|
|
|
|
if (mqttManager != null) { |
|
|
|
|
|
mqttManager.release(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 停止日志管理器(最后停止) |
|
|
// 停止日志管理器(最后停止) |
|
|
if (logManager != null) { |
|
|
if (logManager != null) { |
|
|
logManager.stop(); |
|
|
logManager.stop(); |
|
@ -297,4 +326,8 @@ public class OxFaceApplication extends Application implements |
|
|
public MaintenanceScheduler getMaintenanceScheduler() { |
|
|
public MaintenanceScheduler getMaintenanceScheduler() { |
|
|
return maintenanceScheduler; |
|
|
return maintenanceScheduler; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public MqttManager getMqttManager() { |
|
|
|
|
|
return mqttManager; |
|
|
|
|
|
} |
|
|
} |
|
|
} |