-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use CovesaServiceClient to connect to PushService
- Loading branch information
Showing
10 changed files
with
91 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...client/src/main/kotlin/global/covesa/sdk/api/client/internal/InternalPushServiceClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package global.covesa.sdk.api.client.internal | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.IBinder | ||
import global.covesa.sdk.api.client.CovesaServiceClient | ||
import global.covesa.sdk.api.client.push.PushService | ||
import global.covesa.sdk.api.client.push.data.FailedReason | ||
import global.covesa.sdk.api.client.push.data.PushEndpoint | ||
import global.covesa.sdk.api.client.push.data.PushMessage | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.first | ||
|
||
/** | ||
* This is used to connect to the service implementing [PushService] | ||
*/ | ||
internal class InternalPushServiceClient( | ||
context: Context, | ||
coroutineScope: CoroutineScope = CoroutineScope(Dispatchers.IO) | ||
) : CovesaServiceClient<PushService.PushBinder>(context, coroutineScope, TAG) { | ||
|
||
private val packageName = context.packageName | ||
|
||
override fun interfaceFromBinder(service: IBinder): PushService.PushBinder { | ||
return service as PushService.PushBinder | ||
} | ||
|
||
override fun serviceIntent(): Intent { | ||
return Intent().apply { | ||
action = PushService.ACTION_PUSH_EVENT | ||
`package` = packageName | ||
} | ||
} | ||
|
||
suspend fun newEndpoint(endpoint: PushEndpoint, instance: String) { | ||
getService()?.onNewEndpoint(endpoint, instance) | ||
} | ||
|
||
suspend fun message(message: PushMessage, instance: String) { | ||
getService()?.onMessage(message, instance) | ||
} | ||
|
||
suspend fun registrationFailed(reason: FailedReason, instance: String) { | ||
getService()?.onRegistrationFailed(reason, instance) | ||
} | ||
|
||
suspend fun unregistered(instance: String) { | ||
getService()?.onUnregistered(instance) | ||
} | ||
|
||
private suspend fun getService(): PushService? { | ||
return remoteService.first()?.getService() | ||
} | ||
|
||
companion object { | ||
private const val TAG = "InternalPushServiceClient" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 0 additions & 99 deletions
99
api/client/src/main/kotlin/global/covesa/sdk/api/client/push/ServiceConnetion.kt
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...ovesa/sdk/api/client/push/FailedReason.kt → .../sdk/api/client/push/data/FailedReason.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ovesa/sdk/api/client/push/PublicKeySet.kt → .../sdk/api/client/push/data/PublicKeySet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ovesa/sdk/api/client/push/PushEndpoint.kt → .../sdk/api/client/push/data/PushEndpoint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...covesa/sdk/api/client/push/PushMessage.kt → ...a/sdk/api/client/push/data/PushMessage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
samples/client/src/main/java/global/covesa/sdk/client/push/PushServiceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters