Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class AppFunctionInstrumentationTest {
sendMessageFunctionMetadata.parameters,
sendMessageFunctionMetadata.components,
)
.setString("name", testRecipient.name)
.setString("endpointValue", testRecipient.id)
.setString("messageBody", "Hello!")
.build(),
Expand Down Expand Up @@ -122,7 +121,6 @@ class AppFunctionInstrumentationTest {
sendMessageFunctionMetadata.parameters,
sendMessageFunctionMetadata.components,
)
.setString("name", testRecipient.name)
.setString("endpointValue", testRecipient.id)
.setString("messageBody", "")
.build(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class AppFunctionsTest {
@Test
fun send_validMessage_returnsSuccess() {
runTest {
val result = appFunctions.send(testContext, "Alice Smith", "1", "Hello")
val result = appFunctions.send(testContext, "1", "Hello")
Assert.assertEquals(
AppFunctions.Result(
"Message ID",
Expand All @@ -150,7 +150,6 @@ class AppFunctionsTest {
val result =
appFunctions.send(
testContext,
"Alice Smith",
"1",
"Hello",
listOf(Uri.parse("content://media/1")),
Expand All @@ -168,7 +167,7 @@ class AppFunctionsTest {
@Test
fun send_toGroup_success() {
runTest {
val result = appFunctions.send(testContext, "Work Friends", "g1", "Hello")
val result = appFunctions.send(testContext, "g1", "Hello")
Assert.assertEquals(
AppFunctions.Result(
"Message ID",
Expand All @@ -182,22 +181,22 @@ class AppFunctionsTest {
@Test(expected = AppFunctionInvalidArgumentException::class)
fun send_emptyContent_fails() {
runTest {
appFunctions.send(testContext, "Alice Smith", "1", "")
appFunctions.send(testContext, "1", "")
}
}

@Test(expected = AppFunctionElementNotFoundException::class)
fun send_invalidRecipient_fails() {
runTest {
appFunctions.send(testContext, "Unknown", "nonexistent_id", "Hello")
appFunctions.send(testContext, "nonexistent_id", "Hello")
}
}

@Test(expected = AppFunctionAppUnknownException::class)
fun send_repositoryError_returnsError() {
runTest {
messageRepository.shouldFail = true
appFunctions.send(testContext, "Alice Smith", "1", "Hello")
appFunctions.send(testContext, "1", "Hello")
}
}

Expand All @@ -209,27 +208,6 @@ class AppFunctionsTest {
}
}

@Test
fun makeCall_withContactName_success() {
runBlocking {
val pendingIntent = appFunctions.makeCall(testContext, contactName = "Alice Smith")
Assert.assertNotNull(pendingIntent)
}
}

@Test(expected = AppFunctionInvalidArgumentException::class)
fun makeCall_missingParameters_fails() {
runBlocking {
appFunctions.makeCall(testContext, contactName = null, endpointValue = null)
}
}

@Test(expected = AppFunctionElementNotFoundException::class)
fun makeCall_invalidContactName_fails() {
runBlocking {
appFunctions.makeCall(testContext, contactName = "Unknown")
}
}

@Test(expected = AppFunctionElementNotFoundException::class)
fun makeCall_invalidEndpointValue_fails() {
Expand All @@ -238,11 +216,4 @@ class AppFunctionsTest {
}
}

@Test(expected = AppFunctionInvalidArgumentException::class)
fun makeCall_duplicateContactName_fails() {
runBlocking {
// "Bob Johnson" has two entries (ID 2 and ID 7)
appFunctions.makeCall(testContext, contactName = "Bob Johnson")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ class CallManager
?: recipientsRepository.getGroupById(recipientId)?.let {
Recipient(it.id, it.name, "")
}
?: recipientsRepository.getRecipientByName(recipientId).let { list ->
if (list.size == 1) list.first() else null
}
?: Recipient(recipientId, recipientId, "")
Comment thread
corinac123 marked this conversation as resolved.
startCall(recipient)
}
Expand Down
2 changes: 1 addition & 1 deletion ChatApp/app/src/main/res/xml/app_metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ Operational Patterns:
- Passing a blank query to 'searchContacts' retrieves the most recent contacts.
Constraints:
- Message content cannot be empty or blank.
- Calls can be initiated by either contact name or unique identifier.
- Calls are initiated by unique identifier.
- Media attachments are supported via a list of URIs."
appfn:displayDescription="@string/app_function_app_display_description"/>
1 change: 1 addition & 0 deletions ChatApp/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ dependencies {
implementation(libs.androidx.appfunctions)
implementation(libs.androidx.appfunctions.service)
ksp(libs.androidx.appfunctions.compiler)

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ class ChatViewModel
?: recipientsRepository.getGroupById(recipientId)?.let {
Recipient(it.id, it.name, "")
}
?: recipientsRepository.getRecipientByName(recipientId).let { list ->
if (list.size == 1) list.first() else null
}
?: if (recipientId == "bot") {
Recipient("bot", "Assistant", "bot@example.com")
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,13 @@ class AppFunctions
* Send a text message with optional image attachments.
*
* @param appFunctionContext The context of this app function call.
* @param name The display name of the recipient for confirmation purposes.
* @param endpointValue The unique identifier for the recipient or group.
* @param messageBody The text content of the message. Cannot be empty.
* @param imageUris List of URIs for images to attach.
*/
@AppFunction(isDescribedByKDoc = true)
suspend fun send(
appFunctionContext: AppFunctionContext,
name: String,
endpointValue: String,
messageBody: String,
imageUris: List<Uri>? = null,
Expand Down Expand Up @@ -140,43 +138,18 @@ class AppFunctions
* Initiate a voice call.
*
* @param appFunctionContext The context of this app function call.
* @param contactName The name of the contact. Use this if the ID is unknown.
* @param endpointValue The unique identifier for the recipient.
*/
@AppFunction(isDescribedByKDoc = true)
suspend fun makeCall(
appFunctionContext: AppFunctionContext,
contactName: String? = null,
endpointValue: String? = null,
endpointValue: String,
): PendingIntent {
if (contactName == null && endpointValue == null) {
throw AppFunctionInvalidArgumentException(
"Specify either contactName or endpointValue. Both cannot be null.",
)
}

val recipient =
with(recipientsRepository) {
if (endpointValue == null) {
val matches = getRecipientByName(checkNotNull(contactName))
if (matches.isEmpty()) {
throw AppFunctionElementNotFoundException(
"No recipient exists for contactName: $contactName",
)
}
if (matches.size > 1) {
throw AppFunctionInvalidArgumentException(
"Multiple contacts found with name $contactName. Please be more specific.",
)
}
matches.first()
} else {
getRecipientById(endpointValue)
?: throw AppFunctionElementNotFoundException(
"No recipient exists for endpointValue: $endpointValue",
)
}
}
recipientsRepository.getRecipientById(endpointValue)
?: throw AppFunctionElementNotFoundException(
"No recipient exists for endpointValue: $endpointValue",
)
Comment thread
corinac123 marked this conversation as resolved.

// Call manager should technically also record it here depending on app architecture,
// but we will launch the intent to handle it in the UI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ class CallManager
?: recipientsRepository.getGroupById(recipientId)?.let {
Recipient(it.id, it.name, "")
}
?: recipientsRepository.getRecipientByName(recipientId).let { list ->
if (list.size == 1) list.first() else null
}
?: Recipient(recipientId, recipientId, "")
startCall(recipient)
}
Expand Down
1 change: 1 addition & 0 deletions ChatApp/wear/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ dependencies {
implementation(libs.androidx.appfunctions)
implementation(libs.androidx.appfunctions.service)
ksp(libs.androidx.appfunctions.compiler)

}

// AppFunctions ksp option
Expand Down