mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
reformat per coding conventions
This commit is contained in:
parent
2c75d0dee7
commit
5b653d29f8
29 changed files with 207 additions and 149 deletions
|
|
@ -5,7 +5,8 @@ import java.util.*
|
|||
|
||||
open class BLEException(msg: String) : IOException(msg)
|
||||
|
||||
open class BLECharacteristicNotFoundException(uuid: UUID) : BLEException("Can't get characteristic $uuid")
|
||||
open class BLECharacteristicNotFoundException(uuid: UUID) :
|
||||
BLEException("Can't get characteristic $uuid")
|
||||
|
||||
/// Our interface is being shut down
|
||||
open class BLEConnectionClosing() : BLEException("Connection closing ")
|
||||
open class BLEConnectionClosing : BLEException("Connection closing ")
|
||||
|
|
@ -479,8 +479,7 @@ class BluetoothInterface(val service: RadioInterfaceService, val address: String
|
|||
|
||||
try {
|
||||
s?.close()
|
||||
}
|
||||
catch(_: BLEConnectionClosing) {
|
||||
} catch (_: BLEConnectionClosing) {
|
||||
warn("Ignoring BLE errors while closing")
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -26,5 +26,9 @@ class BluetoothStateReceiver(
|
|||
}
|
||||
}
|
||||
|
||||
private val Intent.bluetoothAdapterState: Int get() = getIntExtra(BluetoothAdapter.EXTRA_STATE, -1)
|
||||
private val Intent.bluetoothAdapterState: Int
|
||||
get() = getIntExtra(
|
||||
BluetoothAdapter.EXTRA_STATE,
|
||||
-1
|
||||
)
|
||||
}
|
||||
|
|
@ -1392,7 +1392,7 @@ class MeshService : Service(), Logging {
|
|||
private fun fixupChannelList(lIn: List<ChannelProtos.Channel>): Array<ChannelProtos.Channel> {
|
||||
// When updating old firmware, we will briefly be told that there is zero channels
|
||||
val maxChannels =
|
||||
max(myNodeInfo?.maxChannels ?: 8, 1) // If we don't have my node info, assume 8 channels
|
||||
max(myNodeInfo?.maxChannels ?: 8, 1) // If we don't have my node info, assume 8 channels
|
||||
var l = lIn
|
||||
while (l.size < maxChannels) {
|
||||
val b = ChannelProtos.Channel.newBuilder()
|
||||
|
|
@ -1561,7 +1561,7 @@ class MeshService : Service(), Logging {
|
|||
) {
|
||||
try {
|
||||
val mi = myNodeInfo
|
||||
if(mi != null) {
|
||||
if (mi != null) {
|
||||
debug("Sending our position/time to=$destNum lat=$lat, lon=$lon, alt=$alt")
|
||||
|
||||
val position = MeshProtos.Position.newBuilder().also {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import android.content.Intent
|
|||
import android.os.Parcelable
|
||||
import com.geeksville.mesh.DataPacket
|
||||
import com.geeksville.mesh.NodeInfo
|
||||
import com.geeksville.mesh.Portnums
|
||||
|
||||
class MeshServiceBroadcasts(
|
||||
private val context: Context,
|
||||
|
|
@ -18,7 +17,12 @@ class MeshServiceBroadcasts(
|
|||
*/
|
||||
fun broadcastReceivedData(payload: DataPacket) {
|
||||
|
||||
explicitBroadcast(Intent(MeshService.actionReceived(payload.dataType)).putExtra(EXTRA_PAYLOAD, payload))
|
||||
explicitBroadcast(
|
||||
Intent(MeshService.actionReceived(payload.dataType)).putExtra(
|
||||
EXTRA_PAYLOAD,
|
||||
payload
|
||||
)
|
||||
)
|
||||
|
||||
/*
|
||||
// For the time being we ALSO broadcast using old ACTION_RECEIVED_DATA field for any oldschool opaque packets
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@ class MeshServiceLocationCallback(
|
|||
|
||||
try {
|
||||
// Do we want to broadcast this position globally, or are we just telling the local node what its current position is (
|
||||
val shouldBroadcast = true // no need to rate limit, because we are just sending at the interval requested by the preferences
|
||||
val shouldBroadcast =
|
||||
true // no need to rate limit, because we are just sending at the interval requested by the preferences
|
||||
val destinationNumber =
|
||||
if (shouldBroadcast) DataPacket.NODENUM_BROADCAST else getNodeNum()
|
||||
|
||||
|
|
|
|||
|
|
@ -16,12 +16,9 @@ import androidx.annotation.RequiresApi
|
|||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.drawable.DrawableCompat
|
||||
import com.geeksville.mesh.DataPacket
|
||||
import com.geeksville.mesh.MainActivity
|
||||
import com.geeksville.mesh.R
|
||||
import com.geeksville.mesh.android.notificationManager
|
||||
import com.geeksville.mesh.ui.SLogging
|
||||
import com.geeksville.mesh.utf8
|
||||
import java.io.Closeable
|
||||
|
||||
|
||||
|
|
@ -29,6 +26,7 @@ class MeshServiceNotifications(
|
|||
private val context: Context
|
||||
) : Closeable {
|
||||
private val notificationManager: NotificationManager get() = context.notificationManager
|
||||
|
||||
// We have two notification channels: one for general service status and another one for messages
|
||||
val notifyId = 101
|
||||
private val messageNotifyId = 102
|
||||
|
|
@ -96,12 +94,16 @@ class MeshServiceNotifications(
|
|||
}
|
||||
|
||||
fun updateServiceStateNotification(summaryString: String) =
|
||||
notificationManager.notify(notifyId,
|
||||
createServiceStateNotification(summaryString))
|
||||
notificationManager.notify(
|
||||
notifyId,
|
||||
createServiceStateNotification(summaryString)
|
||||
)
|
||||
|
||||
fun updateMessageNotification(name: String, message: String) =
|
||||
notificationManager.notify(messageNotifyId,
|
||||
createMessageNotifcation(name, message))
|
||||
notificationManager.notify(
|
||||
messageNotifyId,
|
||||
createMessageNotifcation(name, message)
|
||||
)
|
||||
|
||||
private val openAppIntent: PendingIntent by lazy {
|
||||
PendingIntent.getActivity(context, 0, Intent(context, MainActivity::class.java), 0)
|
||||
|
|
@ -126,7 +128,7 @@ class MeshServiceNotifications(
|
|||
return bitmap
|
||||
}
|
||||
|
||||
fun commonBuilder(channel: String) : NotificationCompat.Builder {
|
||||
fun commonBuilder(channel: String): NotificationCompat.Builder {
|
||||
val builder = NotificationCompat.Builder(context, channel)
|
||||
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||
.setContentIntent(openAppIntent)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package com.geeksville.mesh.service
|
||||
|
||||
import com.geeksville.mesh.*
|
||||
import com.geeksville.mesh.DataPacket
|
||||
import com.geeksville.mesh.MyNodeInfo
|
||||
import com.geeksville.mesh.NodeInfo
|
||||
import com.geeksville.mesh.RadioConfigProtos
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/// Our saved preferences as stored on disk
|
||||
|
|
|
|||
|
|
@ -3,18 +3,14 @@ package com.geeksville.mesh.service
|
|||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import androidx.work.BackoffPolicy
|
||||
import androidx.work.OneTimeWorkRequestBuilder
|
||||
import androidx.work.WorkManager
|
||||
import androidx.work.Worker
|
||||
import androidx.work.WorkerParameters
|
||||
import androidx.work.*
|
||||
import com.geeksville.andlib.BuildConfig
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
/**
|
||||
* Helper that calls MeshService.startService()
|
||||
*/
|
||||
public class ServiceStarter(
|
||||
class ServiceStarter(
|
||||
appContext: Context,
|
||||
workerParams: WorkerParameters
|
||||
) : Worker(appContext, workerParams) {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class NopInterface : IRadioInterface {
|
|||
}
|
||||
}
|
||||
|
||||
override fun handleSendToRadio(p: ByteArray) {
|
||||
override fun handleSendToRadio(p: ByteArray) {
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ open class RadioNotConnectedException(message: String = "Not connected to radio"
|
|||
BLEException(message)
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Handles the bluetooth link with a mesh radio device. Does not cache any device state,
|
||||
* just does bluetooth comms etc...
|
||||
|
|
@ -77,7 +76,7 @@ class RadioInterfaceService : Service(), Logging {
|
|||
var address = prefs.getString(DEVADDR_KEY, null)
|
||||
|
||||
// If we are running on the emulator we default to the mock interface, so we can have some data to show to the user
|
||||
if(address == null && isMockInterfaceAvailable(context))
|
||||
if (address == null && isMockInterfaceAvailable(context))
|
||||
address = MockInterface.prefix.toString()
|
||||
|
||||
return address
|
||||
|
|
@ -86,7 +85,8 @@ class RadioInterfaceService : Service(), Logging {
|
|||
/** return true if we should show the mock interface on this device
|
||||
* (ie are we in an emulator or in testlab
|
||||
*/
|
||||
fun isMockInterfaceAvailable(context: Context) = isEmulator || ((context.applicationContext as GeeksvilleApplication).isInTestLab)
|
||||
fun isMockInterfaceAvailable(context: Context) =
|
||||
isEmulator || ((context.applicationContext as GeeksvilleApplication).isInTestLab)
|
||||
|
||||
/** Like getDeviceAddress, but filtered to return only devices we are currently bonded with
|
||||
*
|
||||
|
|
@ -204,7 +204,7 @@ class RadioInterfaceService : Service(), Logging {
|
|||
}
|
||||
|
||||
override fun onBind(intent: Intent?): IBinder? {
|
||||
return binder;
|
||||
return binder
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -227,8 +227,8 @@ class RadioInterfaceService : Service(), Logging {
|
|||
|
||||
val c = address[0]
|
||||
val rest = address.substring(1)
|
||||
radioIf = InterfaceFactory.getFactory(c)?.createInterface(this, rest) ?:
|
||||
NopInterface()
|
||||
radioIf =
|
||||
InterfaceFactory.getFactory(c)?.createInterface(this, rest) ?: NopInterface()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ class SafeBluetooth(private val context: Context, private val device: BluetoothD
|
|||
if (reliable != null)
|
||||
if (!characteristic.value.contentEquals(reliable)) {
|
||||
errormsg("A reliable write failed!")
|
||||
gatt.abortReliableWrite();
|
||||
gatt.abortReliableWrite()
|
||||
completeWork(
|
||||
STATUS_RELIABLE_WRITE_FAILED,
|
||||
characteristic
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import java.util.zip.CRC32
|
|||
/**
|
||||
* Some misformatted ESP32s have problems
|
||||
*/
|
||||
class DeviceRejectedException() : BLEException("Device rejected filesize")
|
||||
class DeviceRejectedException : BLEException("Device rejected filesize")
|
||||
|
||||
/**
|
||||
* Move this somewhere as a generic network byte order function
|
||||
|
|
@ -389,7 +389,7 @@ class SoftwareUpdateService : JobIntentService(), Logging {
|
|||
)
|
||||
if (progress != oldProgress) {
|
||||
debug("sending block ${progress}%")
|
||||
oldProgress = progress;
|
||||
oldProgress = progress
|
||||
}
|
||||
var blockSize = 512 - 3 // Max size MTU excluding framing
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
package com.geeksville.mesh.service
|
||||
|
||||
import com.geeksville.android.Logging
|
||||
import java.io.*
|
||||
import java.io.BufferedInputStream
|
||||
import java.io.BufferedOutputStream
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import java.net.InetAddress
|
||||
import java.net.Socket
|
||||
import kotlin.concurrent.thread
|
||||
|
|
@ -21,7 +24,7 @@ class TCPInterface(service: RadioInterfaceService, private val address: String)
|
|||
}
|
||||
}
|
||||
|
||||
var socket: Socket? = null
|
||||
var socket: Socket? = null
|
||||
lateinit var outStream: OutputStream
|
||||
lateinit var inStream: InputStream
|
||||
|
||||
|
|
@ -30,7 +33,7 @@ class TCPInterface(service: RadioInterfaceService, private val address: String)
|
|||
}
|
||||
|
||||
override fun sendBytes(p: ByteArray) {
|
||||
outStream.write(p)
|
||||
outStream.write(p)
|
||||
}
|
||||
|
||||
override fun flushBytes() {
|
||||
|
|
@ -39,7 +42,7 @@ class TCPInterface(service: RadioInterfaceService, private val address: String)
|
|||
|
||||
override fun onDeviceDisconnect(waitForStopped: Boolean) {
|
||||
val s = socket
|
||||
if(s != null) {
|
||||
if (s != null) {
|
||||
socket = null
|
||||
outStream.close()
|
||||
inStream.close()
|
||||
|
|
@ -68,15 +71,14 @@ class TCPInterface(service: RadioInterfaceService, private val address: String)
|
|||
// No need to keep a reference to this thread - it will exit when we close inStream
|
||||
thread(start = true, isDaemon = true, name = "TCP reader") {
|
||||
try {
|
||||
while(true) {
|
||||
while (true) {
|
||||
val c = inStream.read()
|
||||
if(c == -1)
|
||||
break;
|
||||
if (c == -1)
|
||||
break
|
||||
else
|
||||
readChar(c.toByte())
|
||||
}
|
||||
}
|
||||
catch(ex: Throwable) {
|
||||
} catch (ex: Throwable) {
|
||||
errormsg("Exception in TCP reader: $ex")
|
||||
onDeviceDisconnect(false)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue