|
@ -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; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |