Using a Raspberry Pi to end an iPhone phone call

Raspberry Pi controls relay to mimic iPhone user clicking headphone switch

Headphone breakout switch

A user can end a phone call by clicking the headphone switch.
A program can end a phone call by closing a headphone breakout switch.

Advantages

Disadvantages

I made a prototype.

Prototype system

The system has several parts

Phoney app, request_web_service_end_call branch

https://github.com/beepscore/Phoney

It has a button to call a phone number.

Phoney XCUITest

XCUITest runs the test from Swift on iOS. It needs a way to ask the raspberry pi to end the call. I didn't see an easy way to issue a system call or spawn a process.
So XCUITest makes an http request to an external web server, ask it to close switch.

iPhone

Making a phone call requires a device, not a simulator.

Raspberry Pi

The Raspberry Pi runs a web service and connects to a relay board.

pi_gpio_service

runs on the local wifi network.
https://github.com/beepscore/pi_gpio_service

Server security

Currently the prototype service runs on the local network, and is not very secured.
By default an iOS app that talks with a web service requires https and TLS 1.2.
Apparently XCUITest doesn't require this, at least when talking with a service on the local network.

Relay

The raspberry pi connects to a relay

The relay acts like the headset "end call" switch, momentarily shorting the headset microphone contact to ground.

Cable, relay to breakout switch

Coaxial splitter, 1 female to 2 males (female unused)

Headphone breakout switch

Making an iPhone Headphone Breakout Switch

Headphone

A standard iPhone wired headphone with a 4 connector plug.

Cable, breakout switch to phone

Connects breakout switch to phone. 3.5 mm 4 conductor male to 3.5 mm 4 conductor male

Test Flow

Test failure

The test adds a UIInterruptionMonitor, then interacts with the app UI via swipeUp or tap.
Without this, the iOS phone call alert handler doesn't fire.
But with it, the test usually ends with error ~ "Application for Target Application 0x1c40af060 is not foreground.".
I fixed the failure by switching to springboard. That made this approach obsolete.

References

XCUITest iOS app phone call

Phoney

Phoney is an iOS application to experiment with testing phone calls.
https://github.com/beepscore/Phoney

request_web_service_end_call branch

Uses XCUITest to make an http request to an external web server, asks it to end call by closing switch.

master branch

Uses XCUITest with Springboard to tap End call button.

pi_gpio_service

Make a simple Python flask web service to read and write Raspberry Pi GPIO.
https://github.com/beepscore/pi_gpio_service

Relay

PiFace Digital 2

purchased from Vetco Electronics

https://www.element14.com/community/docs/DOC-69001/l/piface-digital-2-for-raspberry-p
https://www.piface.org.uk/products/piface_digital/

Headphone breakout switch

Making an iPhone Headphone Breakout Switch