Make test with service working

This commit is contained in:
Sylwester Zieliński
2023-06-23 10:55:26 +02:00
parent dfd307a698
commit 2870ef109e
21 changed files with 682 additions and 86 deletions

View File

@@ -31,41 +31,11 @@
package no.nordicsemi.android.service
import android.bluetooth.BluetoothDevice
import android.content.Context
import android.content.Intent
import dagger.hilt.android.qualifiers.ApplicationContext
import no.nordicsemi.android.kotlin.ble.core.ServerDevice
import javax.inject.Inject
const val DEVICE_DATA = "device-data"
class ServiceManager @Inject constructor(
@ApplicationContext
private val context: Context
) {
interface ServiceManager {
fun <T> startService(service: Class<T>, device: ServerDevice) {
val intent = Intent(context, service).apply {
putExtra(DEVICE_DATA, device)
}
context.startService(intent)
}
fun <T> startService(service: Class<T>, device: BluetoothDevice) {
val intent = Intent(context, service).apply {
putExtra(DEVICE_DATA, device)
}
context.startService(intent)
}
fun <T> startService(service: Class<T>) {
val intent = Intent(context, service)
context.startService(intent)
}
fun <T> stopService(service: Class<T>) {
val intent = Intent(context, service)
context.stopService(intent)
}
fun <T> startService(service: Class<T>, device: ServerDevice)
}

View File

@@ -0,0 +1,21 @@
package no.nordicsemi.android.service
import android.content.Context
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
@Module
@InstallIn(SingletonComponent::class)
class ServiceManagerHiltModule {
@Provides
fun createServiceManager(
@ApplicationContext
context: Context,
): ServiceManager {
return ServiceManagerImpl(context)
}
}

View File

@@ -0,0 +1,20 @@
package no.nordicsemi.android.service
import android.content.Context
import android.content.Intent
import dagger.hilt.android.qualifiers.ApplicationContext
import no.nordicsemi.android.kotlin.ble.core.ServerDevice
import javax.inject.Inject
class ServiceManagerImpl @Inject constructor(
@ApplicationContext
private val context: Context
): ServiceManager {
override fun <T> startService(service: Class<T>, device: ServerDevice) {
val intent = Intent(context, service).apply {
putExtra(DEVICE_DATA, device)
}
context.startService(intent)
}
}