Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Alpha version #96

Merged
merged 5 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ java {

android {
namespace = "com.example.platform.app"
compileSdkPreview = "UpsideDownCake"
compileSdk = 34

defaultConfig {
applicationId = "com.example.platform.app"
Expand Down
4 changes: 2 additions & 2 deletions samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Demonstrates displaying processed pixel data directly from the camera sensor
This sample demonstrates the importance of proper color contrast and how to
- [Communication Audio Manager Sample](connectivity/audio/src/main/java/com/example/platform/connectivity/audio/AudioCommsSample.kt):
This sample shows how to use audio manager to for Communication application that self-manage the call.
- [Companion Device Manager Sample](connectivity/bluetooth/companion/src/main/java/com/example/platform/connectivity/bluetooth/cdm/CompanionDeviceManagerSample.kt):
This samples shows how to use the CDM to pair and connect with BLE devices
- [Companion Device Manager Sample](connectivity/bluetooth/companion/src/main/java/com/example/platform/connectivity/bluetooth/ble/CompanionDeviceManagerSample.kt):
This samples shows how to use the CDM to pair and connect with BLE devices
- [Companion Device Manager Sample](connectivity/bluetooth/companion/src/main/java/com/example/platform/connectivity/bluetooth/cdm/CompanionDeviceManagerSample.kt):
This samples shows how to use the CDM to pair and connect with BLE devices
- [Connect to a GATT server](connectivity/bluetooth/ble/src/main/java/com/example/platform/connectivity/bluetooth/ble/ConnectGATTSample.kt):
Shows how to connect to a GATT server hosted by the BLE device and perform simple operations
- [ConstraintLayout - 1. Centering Views](user-interface/constraintlayout/src/main/java/com/example/platform/ui/constraintlayout/ConstraintLayout.kt):
Expand Down
2 changes: 1 addition & 1 deletion samples/connectivity/telecom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ android {
}

dependencies {
implementation("androidx.core:core-telecom:1.0.0-SNAPSHOT")
implementation("androidx.core:core-telecom:1.0.0-alpha02")
implementation(project(mapOf("path" to ":samples:connectivity:audio")))

androidTestImplementation(platform(libs.compose.bom))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.example.platform.connectivity.telecom.call
import android.Manifest
import android.os.Build
import android.telecom.DisconnectCause
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
Expand Down Expand Up @@ -64,6 +65,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.core.telecom.CallEndpointCompat
import androidx.core.telecom.CallEndpointCompat.Companion.TYPE_BLUETOOTH
Expand Down Expand Up @@ -110,6 +112,7 @@ internal fun TelecomCallScreen(repository: TelecomCallRepository, onCallFinished
isActive = newCall.isActive,
isOnHold = newCall.isOnHold,
isMuted = newCall.isMuted,
errorCode = newCall.errorCode,
currentEndpoint = newCall.currentCallEndpoint,
endpoints = newCall.availableCallEndpoints,
onCallAction = newCall::processAction,
Expand Down Expand Up @@ -139,10 +142,16 @@ private fun CallScreen(
isActive: Boolean,
isOnHold: Boolean,
isMuted: Boolean,
errorCode: Int?,
currentEndpoint: CallEndpointCompat?,
endpoints: List<CallEndpointCompat>,
onCallAction: (TelecomCallAction) -> Unit,
) {

if(errorCode != null) {
Toast.makeText(LocalContext.current, "errorCode=($errorCode)", Toast.LENGTH_SHORT).show()
}

Column(
Modifier
.fillMaxSize(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ class TelecomCallService : Service() {
delay(2000)
}

// Register the call with the Telecom stack
telecomRepository.registerCall(name, uri, incoming)
launch {
// Register the call with the Telecom stack
telecomRepository.registerCall(name, uri, incoming)
}

if (!incoming) {
// If doing an outgoing call, fake the other end picks it up for demo purposes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ sealed class TelecomCall {
val isActive: Boolean,
val isOnHold: Boolean,
val isMuted: Boolean,
val errorCode: Int?,
val currentCallEndpoint: CallEndpointCompat?,
val availableCallEndpoints: List<CallEndpointCompat>,
internal val actionSource: Channel<TelecomCallAction>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ import android.telecom.DisconnectCause
import android.util.Log
import androidx.annotation.RequiresApi
import androidx.core.telecom.CallAttributesCompat
import androidx.core.telecom.CallControlCallback
import androidx.core.telecom.CallControlResult
import androidx.core.telecom.CallControlScope
import androidx.core.telecom.CallEndpointCompat
import androidx.core.telecom.CallException
import androidx.core.telecom.CallsManager
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down Expand Up @@ -107,95 +110,57 @@ class TelecomCallRepository(private val callsManager: CallsManager) {

// Creates a channel to send actions to the call scope.
val actionSource = Channel<TelecomCallAction>()

// Register the call and handle actions in the scope
callsManager.addCall(attributes) {
// TODO this should eventually be moved inside the addCall method b/290562928
setCallback(
// Register the callback to be notified about other call actions
// from other services or devices (e.g Auto, watch)
// In our case we will update the call status based on the callback action and
// return true to let the Telecom SDK continue the action.
object : CallControlCallback {
override suspend fun onAnswer(callType: Int): Boolean {
updateCurrentCall {
copy(isActive = true, isOnHold = false)
}
return true
}
try {
callsManager.addCall(
attributes,
onIsCallAnswered, // Watch needs to know if it can answer the call
onIsCallDisconnected,
onIsCallActive,
onIsCallInactive
) {
// Consume the actions to interact with the call inside the scope
launch {
processCallActions(actionSource.consumeAsFlow())
}

override suspend fun onDisconnect(disconnectCause: DisconnectCause): Boolean {
updateCurrentCall {
TelecomCall.Unregistered(id, callAttributes, disconnectCause)
}
return true
}
// Update the state to registered with default values while waiting for Telecom updates
_currentCall.value = TelecomCall.Registered(
id = getCallId(),
isActive = false,
isOnHold = false,
callAttributes = attributes,
isMuted = false,
errorCode = null,
currentCallEndpoint = null,
availableCallEndpoints = emptyList(),
actionSource = actionSource,
)

override suspend fun onSetActive(): Boolean {
launch {
currentCallEndpoint.collect {
updateCurrentCall {
copy(
isActive = true,
isOnHold = false,
)
copy(currentCallEndpoint = it)
}
return true
}

override suspend fun onSetInactive(): Boolean {
}
launch {
availableEndpoints.collect {
updateCurrentCall {
copy(
isActive = false,
isOnHold = true,
)
copy(availableCallEndpoints = it)
}
return true
}
},
)

// Consume the actions to interact with the call inside the scope
launch {
try {
processCallActions(actionSource.consumeAsFlow())
} finally {
// TODO this should wrap addCall once b/291604411 is fixed
_currentCall.value = TelecomCall.None
}
}

// Update the state to registered with default values while waiting for Telecom updates
_currentCall.value = TelecomCall.Registered(
id = getCallId(),
isActive = false,
isOnHold = false,
callAttributes = attributes,
isMuted = false,
currentCallEndpoint = null,
availableCallEndpoints = emptyList(),
actionSource = actionSource,
)

launch {
currentCallEndpoint.collect {
updateCurrentCall {
copy(currentCallEndpoint = it)
}
}
}
launch {
availableEndpoints.collect {
updateCurrentCall {
copy(availableCallEndpoints = it)
}
}
}
launch {
isMuted.collect {
updateCurrentCall {
copy(isMuted = it)
launch {
isMuted.collect {
updateCurrentCall {
copy(isMuted = it)
}
}
}
}
} finally {
_currentCall.value = TelecomCall.None
}
}

Expand Down Expand Up @@ -228,20 +193,29 @@ class TelecomCallRepository(private val callsManager: CallsManager) {
}

TelecomCallAction.Hold -> {
if (setInactive()) {
updateCurrentCall {
copy(isOnHold = true)
when (val result = setInactive()) {
is CallControlResult.Success -> {
onIsCallInactive()
}

is CallControlResult.Error -> {
updateCurrentCall {
copy(errorCode = result.errorCode)
}
}
}
}

TelecomCallAction.Activate -> {
if (setActive()) {
updateCurrentCall {
copy(
isActive = true,
isOnHold = false,
)
when (val result = setActive()) {
is CallControlResult.Success -> {
onIsCallActive()
}

is CallControlResult.Error -> {
updateCurrentCall {
copy(errorCode = result.errorCode)
}
}
}
}
Expand Down Expand Up @@ -287,24 +261,69 @@ class TelecomCallRepository(private val callsManager: CallsManager) {

private suspend fun CallControlScope.doDisconnect(action: TelecomCallAction.Disconnect) {
disconnect(action.cause)
updateCurrentCall {
TelecomCall.Unregistered(id, callAttributes, action.cause)
}
onIsCallDisconnected(action.cause)
}

private suspend fun CallControlScope.doAnswer() {
if (answer(CallAttributesCompat.CALL_TYPE_AUDIO_CALL)) {
updateCurrentCall {
copy(isActive = true, isOnHold = false)
when (answer(CallAttributesCompat.CALL_TYPE_AUDIO_CALL)) {
is CallControlResult.Success -> {
onIsCallAnswered(CallAttributesCompat.CALL_TYPE_AUDIO_CALL)
}
} else {
updateCurrentCall {
TelecomCall.Unregistered(
id = id,
callAttributes = callAttributes,
disconnectCause = DisconnectCause(DisconnectCause.BUSY),
)

is CallControlResult.Error -> {
updateCurrentCall {
TelecomCall.Unregistered(
id = id,
callAttributes = callAttributes,
disconnectCause = DisconnectCause(DisconnectCause.BUSY),
)
}
}
}
}
}

/**
* Can the call be successfully answered??
* TIP: We would check the connection/call state to see if we can answer a call
* Example you may need to wait for another call to hold.
**/
val onIsCallAnswered: suspend(type: Int) -> Unit = {
updateCurrentCall {
copy(isActive = true, isOnHold = false)
}
}

/**
* Can the call perform a disconnect
*/
val onIsCallDisconnected: suspend (cause: DisconnectCause) -> Unit = {
updateCurrentCall {
TelecomCall.Unregistered(id, callAttributes, it)
}
}

/**
* Check is see if we can make the call active.
* Other calls and state might stop us from activating the call
*/
val onIsCallActive: suspend () -> Unit = {
updateCurrentCall {
copy(
errorCode = null,
isActive = true,
isOnHold = false,
)
}
}

/**
* Check to see if we can make the call inactivate
*/
val onIsCallInactive: suspend () -> Unit = {
updateCurrentCall {
copy(
errorCode = null,
isOnHold = true)
}
}
}
3 changes: 0 additions & 3 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()

// Using SNAPSHOTS for Telecom SDK. This should be removed once telecom SDK is stable
maven { url = uri("https://androidx.dev/snapshots/builds/10626110/artifacts/repository") }
}
}

Expand Down
Loading