add shutdown & reboot admin commands

master
andrekir 2022-06-06 17:29:09 -03:00
rodzic 6c6b22ad7d
commit 47793a2086
5 zmienionych plików z 82 dodań i 0 usunięć

Wyświetl plik

@ -95,6 +95,12 @@ interface IMeshService {
/// It sets a ChannelSet protobuf
void setChannels(in byte []payload);
/// Send Shutdown admin packet to nodeNum
void requestShutdown(in String nodeId);
/// Send Reboot admin packet to nodeNum
void requestReboot(in String nodeId);
/**
Is the packet radio currently connected to the phone? Returns a ConnectionState string.
*/

Wyświetl plik

@ -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.
*/

Wyświetl plik

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

Wyświetl plik

@ -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()
}
}
}

Wyświetl plik

@ -65,4 +65,27 @@
app:layout_constraintBottom_toBottomOf="@id/lsSleepView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/lsSleepView" />
<com.google.android.material.button.MaterialButton
android:id="@+id/shutdownButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="4dp"
android:text="shutdown"
app:layout_constraintEnd_toStartOf="@id/rebootButton"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/lsSleepView" />
<com.google.android.material.button.MaterialButton
android:id="@+id/rebootButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginEnd="16dp"
android:text="reboot"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/shutdownButton"
app:layout_constraintTop_toTopOf="@id/shutdownButton" />
</androidx.constraintlayout.widget.ConstraintLayout>