diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt index a4658df67..9a3c6ff51 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshService.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshService.kt @@ -9,38 +9,17 @@ import android.os.IBinder import android.os.RemoteException import androidx.core.app.ServiceCompat import androidx.core.location.LocationCompat -import com.geeksville.mesh.AdminProtos -import com.geeksville.mesh.AppOnlyProtos -import com.geeksville.mesh.BuildConfig -import com.geeksville.mesh.ChannelProtos -import com.geeksville.mesh.ConfigProtos -import com.geeksville.mesh.CoroutineDispatchers -import com.geeksville.mesh.DataPacket -import com.geeksville.mesh.IMeshService +import com.geeksville.mesh.* import com.geeksville.mesh.LocalOnlyProtos.LocalConfig import com.geeksville.mesh.LocalOnlyProtos.LocalModuleConfig -import com.geeksville.mesh.MeshProtos import com.geeksville.mesh.MeshProtos.MeshPacket import com.geeksville.mesh.MeshProtos.ToRadio -import com.geeksville.mesh.MeshUser -import com.geeksville.mesh.MessageStatus -import com.geeksville.mesh.ModuleConfigProtos -import com.geeksville.mesh.MyNodeInfo -import com.geeksville.mesh.NodeInfo -import com.geeksville.mesh.PaxcountProtos -import com.geeksville.mesh.Portnums -import com.geeksville.mesh.Position -import com.geeksville.mesh.R -import com.geeksville.mesh.StoreAndForwardProtos -import com.geeksville.mesh.TelemetryProtos import com.geeksville.mesh.TelemetryProtos.LocalStats import com.geeksville.mesh.analytics.DataPair import com.geeksville.mesh.android.GeeksvilleApplication import com.geeksville.mesh.android.Logging import com.geeksville.mesh.android.hasLocationPermission import com.geeksville.mesh.concurrent.handledLaunch -import com.geeksville.mesh.config -import com.geeksville.mesh.copy import com.geeksville.mesh.database.MeshLogRepository import com.geeksville.mesh.database.PacketRepository import com.geeksville.mesh.database.entity.MeshLog @@ -49,21 +28,14 @@ import com.geeksville.mesh.database.entity.NodeEntity import com.geeksville.mesh.database.entity.Packet import com.geeksville.mesh.database.entity.TapBack import com.geeksville.mesh.database.entity.toNodeInfo -import com.geeksville.mesh.fromRadio import com.geeksville.mesh.model.DeviceVersion import com.geeksville.mesh.model.getTracerouteResponse -import com.geeksville.mesh.position import com.geeksville.mesh.repository.datastore.RadioConfigRepository import com.geeksville.mesh.repository.location.LocationRepository import com.geeksville.mesh.repository.network.MQTTRepository import com.geeksville.mesh.repository.radio.RadioInterfaceService import com.geeksville.mesh.repository.radio.RadioServiceConnectionState -import com.geeksville.mesh.telemetry -import com.geeksville.mesh.user -import com.geeksville.mesh.util.anonymize -import com.geeksville.mesh.util.toOneLineString -import com.geeksville.mesh.util.toPIIString -import com.geeksville.mesh.util.toRemoteExceptions +import com.geeksville.mesh.util.* import com.google.protobuf.ByteString import com.google.protobuf.InvalidProtocolBufferException import dagger.Lazy @@ -200,7 +172,6 @@ class MeshService : Service(), Logging { numOnlineNodes, numNodes ) - ConnectionState.DISCONNECTED -> getString(R.string.disconnected) ConnectionState.DEVICE_SLEEP -> getString(R.string.device_sleeping) } @@ -287,11 +258,7 @@ class MeshService : Service(), Logging { else -> return } - serviceNotifications.updateMessageNotification( - contactKey, - getSenderName(dataPacket), - message - ) + serviceNotifications.updateMessageNotification(contactKey, getSenderName(dataPacket), message) } override fun onCreate() { @@ -472,7 +439,6 @@ class MeshService : Service(), Logging { val n = hexStr.toLong(16).toInt() nodeDBbyNodeNum[n] ?: throw IdNotFoundException(id) } - else -> throw InvalidNodeIdException(id) } } @@ -677,10 +643,7 @@ class MeshService : Service(), Logging { packetRepository.get().apply { insert(packetToSave) val isMuted = getContactSettings(contactKey).isMuted - if (updateNotification && !isMuted) updateMessageNotification( - contactKey, - dataPacket - ) + if (updateNotification && !isMuted) updateMessageNotification(contactKey, dataPacket) } } } @@ -714,6 +677,7 @@ class MeshService : Service(), Logging { return } if (fromUs) return + // TODO temporary solution to Range Test spam, may be removed in the future val isRangeTest = rangeTestRegex.matches(data.payload.toStringUtf8()) if (!moduleConfig.rangeTest.enabled && isRangeTest) return @@ -1360,14 +1324,10 @@ class MeshService : Service(), Logging { MeshProtos.FromRadio.MODULECONFIG_FIELD_NUMBER -> handleModuleConfig(proto.moduleConfig) MeshProtos.FromRadio.QUEUESTATUS_FIELD_NUMBER -> handleQueueStatus(proto.queueStatus) MeshProtos.FromRadio.METADATA_FIELD_NUMBER -> handleMetadata(proto.metadata) - MeshProtos.FromRadio.MQTTCLIENTPROXYMESSAGE_FIELD_NUMBER -> handleMqttProxyMessage( - proto.mqttClientProxyMessage - ) - + MeshProtos.FromRadio.MQTTCLIENTPROXYMESSAGE_FIELD_NUMBER -> handleMqttProxyMessage(proto.mqttClientProxyMessage) MeshProtos.FromRadio.CLIENTNOTIFICATION_FIELD_NUMBER -> { handleClientNotification(proto.clientNotification) } - else -> errormsg("Unexpected FromRadio variant") } } catch (ex: InvalidProtocolBufferException) { @@ -1665,10 +1625,7 @@ class MeshService : Service(), Logging { newNodes.clear() // Just to save RAM ;-) serviceScope.handledLaunch { - radioConfigRepository.installNodeDB( - myNodeInfo!!, - nodeDBbyNodeNum.values.toList() - ) + radioConfigRepository.installNodeDB(myNodeInfo!!, nodeDBbyNodeNum.values.toList()) } haveNodeDB = true // we now have nodes from real hardware @@ -1725,16 +1682,14 @@ class MeshService : Service(), Logging { handleReceivedPosition(mi.myNodeNum, position) } - sendToRadio( - newMeshPacketTo(idNum).buildMeshPacket( - channel = if (destNum == null) 0 else nodeDBbyNodeNum[destNum]?.channel - ?: 0, - priority = MeshPacket.Priority.BACKGROUND, - ) { - portnumValue = Portnums.PortNum.POSITION_APP_VALUE - payload = position.toByteString() - this.wantResponse = wantResponse - }) + sendToRadio(newMeshPacketTo(idNum).buildMeshPacket( + channel = if (destNum == null) 0 else nodeDBbyNodeNum[destNum]?.channel ?: 0, + priority = MeshPacket.Priority.BACKGROUND, + ) { + portnumValue = Portnums.PortNum.POSITION_APP_VALUE + payload = position.toByteString() + this.wantResponse = wantResponse + }) } } catch (ex: BLEException) { warn("Ignoring disconnected radio during gps location update") @@ -2008,31 +1963,26 @@ class MeshService : Service(), Logging { removeByNodenum = nodeNum }) } - override fun requestUserInfo(destNum: Int) = toRemoteExceptions { if (destNum != myNodeNum) { - sendToRadio( - newMeshPacketTo( - destNum - ).buildMeshPacket( - channel = nodeDBbyNodeNum[destNum]?.channel ?: 0 - ) { - portnumValue = Portnums.PortNum.NODEINFO_APP_VALUE - wantResponse = true - payload = nodeDBbyNodeNum[myNodeNum]!!.user.toByteString() - }) - } - } - - override fun requestPosition(destNum: Int, position: Position) = toRemoteExceptions { - sendToRadio( - newMeshPacketTo(destNum).buildMeshPacket( - channel = nodeDBbyNodeNum[destNum]?.channel ?: 0, - priority = MeshPacket.Priority.BACKGROUND, + sendToRadio(newMeshPacketTo(destNum + ).buildMeshPacket( + channel = nodeDBbyNodeNum[destNum]?.channel ?: 0 ) { - portnumValue = Portnums.PortNum.POSITION_APP_VALUE + portnumValue = Portnums.PortNum.NODEINFO_APP_VALUE wantResponse = true + payload = nodeDBbyNodeNum[myNodeNum]!!.user.toByteString() }) + } + } + override fun requestPosition(destNum: Int, position: Position) = toRemoteExceptions { + sendToRadio(newMeshPacketTo(destNum).buildMeshPacket( + channel = nodeDBbyNodeNum[destNum]?.channel ?: 0, + priority = MeshPacket.Priority.BACKGROUND, + ) { + portnumValue = Portnums.PortNum.POSITION_APP_VALUE + wantResponse = true + }) } override fun setFixedPosition(destNum: Int, position: Position) = toRemoteExceptions { @@ -2054,15 +2004,14 @@ class MeshService : Service(), Logging { } override fun requestTraceroute(requestId: Int, destNum: Int) = toRemoteExceptions { - sendToRadio( - newMeshPacketTo(destNum).buildMeshPacket( - wantAck = true, - id = requestId, - channel = nodeDBbyNodeNum[destNum]?.channel ?: 0, - ) { - portnumValue = Portnums.PortNum.TRACEROUTE_APP_VALUE - wantResponse = true - }) + sendToRadio(newMeshPacketTo(destNum).buildMeshPacket( + wantAck = true, + id = requestId, + channel = nodeDBbyNodeNum[destNum]?.channel ?: 0, + ) { + portnumValue = Portnums.PortNum.TRACEROUTE_APP_VALUE + wantResponse = true + }) } override fun requestShutdown(requestId: Int, destNum: Int) = toRemoteExceptions {