Skip to content

Commit

Permalink
Rename SyncService
Browse files Browse the repository at this point in the history
  • Loading branch information
SeineEloquenz committed Jul 17, 2024
1 parent 1ba9e3d commit 7673622
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
tools:replace="screenOrientation" />

<service
android:name=".sync.bluetooth.BluetoothSyncService"
android:name=".sync.bluetooth.BleSyncService"
android:foregroundServiceType="remoteMessaging"
android:enabled="true"
android:exported="false" />

<receiver
android:name=".sync.bluetooth.BluetoothSyncServiceManager"
android:name=".sync.bluetooth.BleSyncServiceManager"
android:enabled="true"
android:exported="false">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import java.util.concurrent.ConcurrentHashMap


@SuppressLint("MissingPermission")
class BluetoothSyncService : Service() {
class BleSyncService : Service() {
private val devicesLastSynced: ConcurrentHashMap<String, Instant> = ConcurrentHashMap()

private lateinit var bluetoothManager: BluetoothManager
Expand Down Expand Up @@ -83,7 +83,7 @@ class BluetoothSyncService : Service() {

private fun scanCallback(): ScanCallback {
return object : ScanCallback() {
private val messageManager = (this@BluetoothSyncService.application as EmberTalkApplication).container.messageManager
private val messageManager = (this@BleSyncService.application as EmberTalkApplication).container.messageManager

override fun onScanFailed(errorCode: Int) {
super.onScanFailed(errorCode)
Expand Down Expand Up @@ -114,7 +114,7 @@ class BluetoothSyncService : Service() {
devicesLastSynced[remoteDevice.address] = Instant.now()
}
val clientCallback = ClientCallback(remoteDevice.address, messageManager)
val gatt = remoteDevice.connectGatt(this@BluetoothSyncService, false, clientCallback, BluetoothDevice.TRANSPORT_LE)
val gatt = remoteDevice.connectGatt(this@BleSyncService, false, clientCallback, BluetoothDevice.TRANSPORT_LE)
}
}
}
Expand Down Expand Up @@ -188,7 +188,7 @@ class BluetoothSyncService : Service() {
}

companion object {
private const val TAG = "BluetoothSyncService"
private const val TAG = "BleSyncService"

fun canStart(context: Context): CanStartResult {
val packageManager = context.packageManager
Expand All @@ -208,7 +208,7 @@ class BluetoothSyncService : Service() {
when (canStart(context)) {
CanStartResult.CAN_START -> {
Log.d(TAG, "Starting BLE sync service")
context.startForegroundService(Intent(context, BluetoothSyncService::class.java))
context.startForegroundService(Intent(context, BleSyncService::class.java))
}
CanStartResult.BLUETOOTH_OR_BLE_UNSUPPORTED -> {
Log.d(TAG, "BLE not supported, not starting BLE sync service")
Expand All @@ -227,7 +227,7 @@ class BluetoothSyncService : Service() {
}

fun stop(context: Context) {
context.stopService(Intent(context, BluetoothSyncService::class.java))
context.stopService(Intent(context, BleSyncService::class.java))
}

private fun getBluetoothAdapter(context: Context): BluetoothAdapter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent

class BluetoothSyncServiceManager : BroadcastReceiver() {
class BleSyncServiceManager : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action!!.equals(BluetoothAdapter.ACTION_STATE_CHANGED, ignoreCase = true)) {
when (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)) {
BluetoothAdapter.STATE_ON -> BluetoothSyncService.startOrPromptBluetooth(context)
BluetoothAdapter.STATE_ON -> BleSyncService.startOrPromptBluetooth(context)
BluetoothAdapter.STATE_TURNING_OFF, BluetoothAdapter.STATE_OFF -> {
val stopSyncServiceIntent = Intent(context, BluetoothSyncService::class.java)
val stopSyncServiceIntent = Intent(context, BleSyncService::class.java)
context.stopService(stopSyncServiceIntent)
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/edu/kit/tm/ps/embertalk/ui/EmberTalkApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import com.google.accompanist.permissions.rememberMultiplePermissionsState
import edu.kit.tm.ps.embertalk.Preferences
import edu.kit.tm.ps.embertalk.R
import edu.kit.tm.ps.embertalk.app.AppViewModelProvider
import edu.kit.tm.ps.embertalk.sync.bluetooth.BluetoothSyncService
import edu.kit.tm.ps.embertalk.sync.bluetooth.BleSyncService
import edu.kit.tm.ps.embertalk.ui.components.PermissionsRequired
import edu.kit.tm.ps.embertalk.ui.contacts.AddContactView
import edu.kit.tm.ps.embertalk.ui.contacts.ContactsView
Expand Down Expand Up @@ -215,7 +215,7 @@ fun EmberScaffold(
},
actions = {
if (!toolWindow) {
IconButton(onClick = { BluetoothSyncService.startOrPromptBluetooth(context) }) {
IconButton(onClick = { BleSyncService.startOrPromptBluetooth(context) }) {
Icon(
imageVector = Icons.Filled.PlayArrow,
contentDescription = stringResource(R.string.start_service)
Expand Down

0 comments on commit 7673622

Please sign in to comment.