From bb39bab1c16afe93829dea2df2ee9dc380dc72b9 Mon Sep 17 00:00:00 2001 From: geeksville Date: Wed, 22 Jan 2020 14:27:22 -0800 Subject: [PATCH] misc --- TODO.md | 16 ++++++--- .../com/geeksville/meshutil/MainActivity.kt | 8 ++++- .../meshutil/SoftwareUpdateService.kt | 36 +++++++++---------- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/TODO.md b/TODO.md index b7e94c655..c5ad40070 100644 --- a/TODO.md +++ b/TODO.md @@ -1,17 +1,25 @@ -* assert() is apparently a noop - change to use my version of assert + * make frontend using https://developer.android.com/jetpack/compose/tutorial +*fix bluetooth # Medium priority * remove secret google settings json before open sourcing * require user auth to pair with the device (i.e. press button on device to allow a new phone to pair with it). Don't leave device discoverable. Don't let unpaired users do thing with device -* add crash reporting + * remove example code boilerplate from the service -* add analytics (make them optional) + # Low priority +* make analytics optional * possibly use finotes for analytics https://finotes.com/ - * also add a receiver that fires after a new update was installed from the play stoe \ No newline at end of file + * also add a receiver that fires after a new update was installed from the play stoe + +# Done + +* assert() is apparently a noop - change to use my version of assert +* DONE add crash reporting +* DONE add analytics (make them optional) diff --git a/app/src/main/java/com/geeksville/meshutil/MainActivity.kt b/app/src/main/java/com/geeksville/meshutil/MainActivity.kt index f10b56e11..a7df116c3 100644 --- a/app/src/main/java/com/geeksville/meshutil/MainActivity.kt +++ b/app/src/main/java/com/geeksville/meshutil/MainActivity.kt @@ -15,12 +15,13 @@ import android.view.MenuItem import android.widget.Toast import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat +import com.geeksville.android.Logging import kotlinx.android.synthetic.main.activity_main.* import java.util.* -class MainActivity : AppCompatActivity() { +class MainActivity : AppCompatActivity(), Logging { companion object { const val REQUEST_ENABLE_BT = 10 @@ -33,6 +34,8 @@ class MainActivity : AppCompatActivity() { } fun requestPermission() { + debug("Checking permissions") + val perms = arrayOf(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_BACKGROUND_LOCATION, Manifest.permission.BLUETOOTH, @@ -72,7 +75,10 @@ class MainActivity : AppCompatActivity() { /* Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show() */ + // test crash reporting + // logAssert(false) // throw NotImplementedError("I like crap") + if(bluetoothAdapter != null) { SoftwareUpdateService.enqueueWork(this, SoftwareUpdateService.scanDevicesIntent) } diff --git a/app/src/main/java/com/geeksville/meshutil/SoftwareUpdateService.kt b/app/src/main/java/com/geeksville/meshutil/SoftwareUpdateService.kt index 4edd556b4..4c6a9d5cf 100644 --- a/app/src/main/java/com/geeksville/meshutil/SoftwareUpdateService.kt +++ b/app/src/main/java/com/geeksville/meshutil/SoftwareUpdateService.kt @@ -7,10 +7,10 @@ import android.content.Intent import android.os.Handler import android.os.ParcelUuid import android.os.SystemClock -import android.util.Log import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.core.app.JobIntentService +import com.geeksville.android.Logging import java.io.InputStream import java.util.* @@ -29,7 +29,7 @@ import java.util.* * FIXME - broadcast when we found devices, made progress sending blocks or when the update is complete * FIXME - make the user decide to start an update on a particular device */ -class SoftwareUpdateService : JobIntentService() { +class SoftwareUpdateService : JobIntentService(), Logging { private val bluetoothAdapter: BluetoothAdapter by lazy(LazyThreadSafetyMode.NONE) { val bluetoothManager = getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager @@ -49,9 +49,9 @@ class SoftwareUpdateService : JobIntentService() { // Start the update by writing the # of bytes in the image val numBytes = firmwareStream.available() - assert(totalSizeDesc.setValue(numBytes, BluetoothGattCharacteristic.FORMAT_UINT32, 0)) - assert(updateGatt.writeCharacteristic(totalSizeDesc)) - assert(updateGatt.readCharacteristic(totalSizeDesc)) + logAssert(totalSizeDesc.setValue(numBytes, BluetoothGattCharacteristic.FORMAT_UINT32, 0)) + logAssert(updateGatt.writeCharacteristic(totalSizeDesc)) + logAssert(updateGatt.readCharacteristic(totalSizeDesc)) } // Send the next block of our file to the device @@ -64,15 +64,15 @@ class SoftwareUpdateService : JobIntentService() { val buffer = ByteArray(blockSize) // slightly expensive to keep reallocing this buffer, but whatever - assert(firmwareStream.read(buffer) == blockSize) + logAssert(firmwareStream.read(buffer) == blockSize) dataDesc = updateService.getCharacteristic(SW_UPDATE_DATA_CHARACTER)!! // updateGatt.beginReliableWrite() dataDesc.value = buffer - assert(updateGatt.writeCharacteristic(dataDesc)) + logAssert(updateGatt.writeCharacteristic(dataDesc)) } else { - assert(false) // fixme + logAssert(false) // fixme } } @@ -110,7 +110,7 @@ class SoftwareUpdateService : JobIntentService() { //intentAction = ACTION_GATT_CONNECTED //connectionState = STATE_CONNECTED // broadcastUpdate(intentAction) - assert(bluetoothGatt.discoverServices()) + logAssert(bluetoothGatt.discoverServices()) } BluetoothProfile.STATE_DISCONNECTED -> { //intentAction = ACTION_GATT_DISCONNECTED @@ -122,7 +122,7 @@ class SoftwareUpdateService : JobIntentService() { // New services discovered override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) { - assert(status == BluetoothGatt.GATT_SUCCESS) + logAssert(status == BluetoothGatt.GATT_SUCCESS) // broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED) @@ -142,13 +142,13 @@ class SoftwareUpdateService : JobIntentService() { characteristic: BluetoothGattCharacteristic, status: Int ) { - assert(status == BluetoothGatt.GATT_SUCCESS) + logAssert(status == BluetoothGatt.GATT_SUCCESS) if (characteristic == totalSizeDesc) { // Our read of this has completed, either fail or continue updating val readvalue = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT32, 0) - assert(readvalue != 0) // FIXME - handle this case + logAssert(readvalue != 0) // FIXME - handle this case enqueueWork(this@SoftwareUpdateService, sendNextBlockIntent) } @@ -160,7 +160,7 @@ class SoftwareUpdateService : JobIntentService() { characteristic: BluetoothGattCharacteristic?, status: Int ) { - assert(status == BluetoothGatt.GATT_SUCCESS) + logAssert(status == BluetoothGatt.GATT_SUCCESS) if (characteristic == dataDesc) { enqueueWork(this@SoftwareUpdateService, sendNextBlockIntent) @@ -169,7 +169,7 @@ class SoftwareUpdateService : JobIntentService() { } bluetoothGatt = result.device.connectGatt(this@SoftwareUpdateService, false, gattCallback)!! toast("FISH " + bluetoothGatt) - assert(bluetoothGatt.discoverServices()) + logAssert(bluetoothGatt.discoverServices()) } } @@ -209,7 +209,7 @@ class SoftwareUpdateService : JobIntentService() { override fun onHandleWork(intent: Intent) { // We have received work to do. The system or framework is already // holding a wake lock for us at this point, so we can just go. - Log.i("SimpleJobIntentService", "Executing work: $intent") + info("Executing work: $intent") var label = intent.getStringExtra("label") if (label == null) { label = intent.toString() @@ -220,12 +220,10 @@ class SoftwareUpdateService : JobIntentService() { scanDevicesIntent.action -> scanLeDevice(true) startUpdateIntent.action -> startUpdate() sendNextBlockIntent.action -> sendNextBlock() - else -> assert(false) + else -> logAssert(false) } - Log.i( - "SimpleJobIntentService", - "Completed service @ " + SystemClock.elapsedRealtime() + info("Completed service @ " + SystemClock.elapsedRealtime() ) }