add shutdown & reboot admin commands

This commit is contained in:
andrekir 2022-06-06 17:29:09 -03:00
parent 6c6b22ad7d
commit 47793a2086
5 changed files with 82 additions and 0 deletions

View file

@ -279,6 +279,14 @@ class UIViewModel @Inject constructor(
}
}
fun requestShutdown() {
meshService?.requestShutdown(DataPacket.ID_LOCAL)
}
fun requestReboot() {
meshService?.requestReboot(DataPacket.ID_LOCAL)
}
/**
* Write the persisted packet data out to a CSV file in the specified location.
*/

View file

@ -1406,6 +1406,18 @@ class MeshService : Service(), Logging {
})
}
private fun requestShutdown(nodeId: String) {
sendToRadio(newMeshPacketTo(toNodeNum(nodeId)).buildAdminPacket {
shutdownSeconds = 5
})
}
private fun requestReboot(nodeId: String) {
sendToRadio(newMeshPacketTo(toNodeNum(nodeId)).buildAdminPacket {
rebootSeconds = 5
})
}
/**
* Start the modern (REV2) API configuration flow
*/
@ -1763,6 +1775,14 @@ class MeshService : Service(), Logging {
override fun stopProvideLocation() = toRemoteExceptions {
stopLocationRequests()
}
override fun requestShutdown(nodeId: String) = toRemoteExceptions {
this@MeshService.requestShutdown(nodeId)
}
override fun requestReboot(nodeId: String) = toRemoteExceptions {
this@MeshService.requestReboot(nodeId)
}
}
}

View file

@ -14,6 +14,7 @@ import com.geeksville.mesh.model.ChannelOption
import com.geeksville.mesh.model.UIViewModel
import com.geeksville.mesh.service.MeshService
import com.geeksville.util.exceptionToSnackbar
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import dagger.hilt.android.AndroidEntryPoint
@ -52,6 +53,8 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
binding.lsSleepView.isEnabled = connected && model.isPowerSaving ?: false
binding.positionBroadcastSwitch.isEnabled = connected
binding.lsSleepSwitch.isEnabled = connected
binding.shutdownButton.isEnabled = connected
binding.rebootButton.isEnabled = connected
}
binding.positionBroadcastPeriodEditText.on(EditorInfo.IME_ACTION_DONE) {
@ -106,5 +109,27 @@ class AdvancedSettingsFragment : ScreenFragment("Advanced Settings"), Logging {
debug("User changed isPowerSaving to $isChecked")
}
}
binding.shutdownButton.setOnClickListener {
MaterialAlertDialogBuilder(requireContext())
.setMessage("${getString(R.string.update_firmware)}?")
.setNeutralButton(R.string.cancel) { _, _ ->
}
.setPositiveButton(getString(R.string.okay)) { _, _ ->
model.requestShutdown()
}
.show()
}
binding.rebootButton.setOnClickListener {
MaterialAlertDialogBuilder(requireContext())
.setMessage("${getString(R.string.update_firmware)}?")
.setNeutralButton(R.string.cancel) { _, _ ->
}
.setPositiveButton(getString(R.string.okay)) { _, _ ->
model.requestReboot()
}
.show()
}
}
}