Skip to content
Snippets Groups Projects
Commit 7c3a6a68 authored by Anon's avatar Anon
Browse files

Use first bonded card10 in ConnectionService.

parent 8e7a0fba
No related branches found
No related tags found
No related merge requests found
/*
* Copyright by the original author or authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package de.ccc.events.badge.card10.common
import android.content.res.Resources
import de.ccc.events.badge.card10.R
import java.lang.Exception
class ConnectionException(message: String = Resources.getSystem().getString(R.string.connection_error_generic)) :
Exception(message)
\ No newline at end of file
......@@ -22,12 +22,11 @@
package de.ccc.events.badge.card10.common
import android.bluetooth.BluetoothDevice
import android.bluetooth.BluetoothGatt
import android.bluetooth.BluetoothGattCallback
import android.bluetooth.BluetoothGattCharacteristic
import android.bluetooth.*
import android.content.Context
import android.util.Log
import de.ccc.events.badge.card10.CARD10_BLUETOOTH_MAC_PREFIX
import de.ccc.events.badge.card10.R
import de.ccc.events.badge.card10.filetransfer.LowEffortService
import java.lang.IllegalStateException
import java.lang.NullPointerException
......@@ -68,6 +67,20 @@ object ConnectionService {
throw IllegalStateException()
}
// Use first BLE devices that is bonded
val bondedDevices = BluetoothAdapter.getDefaultAdapter().bondedDevices.filter {
it.address.startsWith(
CARD10_BLUETOOTH_MAC_PREFIX,
true
)
}
if (bondedDevices.isEmpty()) {
throw ConnectionException(context.getString(R.string.connection_error_no_bonded_device))
}
device = bondedDevices[0]
// 1. Connect
// 2. Discover services
// 3. Change MTU
......
......@@ -34,6 +34,7 @@ import android.widget.ProgressBar
import android.widget.TextView
import androidx.annotation.UiThread
import androidx.fragment.app.Fragment
import de.ccc.events.badge.card10.CARD10_BLUETOOTH_MAC_PREFIX
import de.ccc.events.badge.card10.R
import de.ccc.events.badge.card10.common.ConnectionService
import de.ccc.events.badge.card10.common.GattListener
......@@ -72,15 +73,11 @@ class FileTransferFragment : Fragment(), GattListener, FileTransferListener{
buttonStartStop = view.findViewById(R.id.button_start_stop_transfer)
connect()
initConnection()
toggleControls()
}
private fun connect() {
// Test function that connects to specific card10
val remoteDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice("00:05:8B:44:42:42")
ConnectionService.device = remoteDevice
private fun initConnection() {
val ctx = context ?: throw IllegalStateException()
ConnectionService.connect(ctx)
}
......
......@@ -24,4 +24,7 @@
<string name="app_detail_downloads">Downloads: %1$d</string>
<string name="app_detail_content_size">Size: %1$d</string>
<string name="app_detail_button_download">Download</string>
<string name="connection_error_generic">Connection error</string>
<string name="connection_error_no_bonded_device">No bonded card10s available</string>
</resources>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment