Browse Source

add mqtt reboot

devab
MTing 4 weeks ago
parent
commit
cf6e2b169f
  1. 16
      app/src/main/java/com/ouxuan/oxface/device/MqttManager.java
  2. 42
      app/src/main/java/com/ouxuan/oxface/utils/ShellCommandManager.java

16
app/src/main/java/com/ouxuan/oxface/device/MqttManager.java

@ -763,7 +763,21 @@ public class MqttManager {
if (messageReceivedListener != null) { if (messageReceivedListener != null) {
mainHandler.post(() -> messageReceivedListener.onRebootCommandReceived()); mainHandler.post(() -> messageReceivedListener.onRebootCommandReceived());
} }
LogManager.logWarning(TAG, "设备重启功能待实现");
// 执行设备重启
LogManager.logInfo(TAG, "准备执行设备重启");
if (context != null) {
com.ouxuan.oxface.utils.ShellCommandManager shellManager =
com.ouxuan.oxface.utils.ShellCommandManager.getInstance(context);
boolean success = shellManager.rebootDevice();
if (success) {
LogManager.logInfo(TAG, "设备重启命令执行成功");
} else {
LogManager.logError(TAG, "设备重启命令执行失败");
}
} else {
LogManager.logError(TAG, "Context为空,无法执行重启命令");
}
} catch (Exception e) { } catch (Exception e) {
LogManager.logError(TAG, "处理设备重启命令异常", e); LogManager.logError(TAG, "处理设备重启命令异常", e);
} }

42
app/src/main/java/com/ouxuan/oxface/utils/ShellCommandManager.java

@ -272,4 +272,46 @@ public class ShellCommandManager {
return info.toString(); return info.toString();
} }
/**
* 重启设备
* @return 是否执行成功
*/
public boolean rebootDevice() {
try {
Log.i(TAG, "准备重启设备");
LogManager.logOperation(TAG, "执行设备重启命令");
// 尝试使用root权限执行重启命令
ShellUtils.CommandResult result = executeCommand("reboot", true);
boolean success = result.result == 0;
if (success) {
Log.i(TAG, "设备重启命令执行成功");
LogManager.logOperation(TAG, "设备重启命令执行成功");
} else {
Log.w(TAG, "使用root权限重启失败,尝试使用adb命令重启: " + result.errorMsg);
LogManager.logWarning(TAG, "使用root权限重启失败: " + result.errorMsg);
// 如果root权限失败尝试使用am命令重启系统
result = executeCommand("am start -a android.intent.action.REBOOT", true);
success = result.result == 0;
if (success) {
Log.i(TAG, "使用am命令重启成功");
LogManager.logOperation(TAG, "使用am命令重启成功");
} else {
Log.e(TAG, "设备重启失败: " + result.errorMsg);
LogManager.logError(TAG, "设备重启失败: " + result.errorMsg);
}
}
return success;
} catch (Exception e) {
Log.e(TAG, "重启设备异常", e);
LogManager.logError(TAG, "重启设备异常", e);
return false;
}
}
} }
Loading…
Cancel
Save