Volvo Cars’ First Open Source In-Car App Simplifies Life for Diabetes Patients

Bure Råman Vinnå
Volvo Cars Engineering
8 min readAug 26, 2024

Data from 2021 shows that 537 million adults are living with diabetes. This is 1 in every 10 person globally that lives with this condition meaning a disease of epidemic proportions. Research shows that drivers with diabetes are more likely to get in car accidents than drivers without diabetes. So how can we help drivers or passengers with diabetes to have full control while navigating the complicated life with diabetes when they’re behind the wheel? To give or get the right assistance, at the right time, to take control and make the road safer for all.

In this story I will tell you about the journey I have had here at Volvo Cars as an engineer, trying to solve challenges I, and million of others, every day encounter.

From the very beginning

So lets start from the beginning. When I was 17 years old I started to feel symptoms that most Type 1 diabetic encounters. For me it started with that I got terrible tiered. Even if I slept well I couldn't shake of the dizziness, my body hearted and I was constantly thirsty.

I tried to overlook the symptoms, and as a teenager, thinking that I could overcome everything just continued as normal. Days went by and I tried to adopt, while my blood sugar level slowly increased. It was first when we were about to buy lunch packages for our school trip that I realized I needed help. When others bought a 50 centiliters juice pack at the grocery store, I ended up buying two liters. After that day I decided to visit my doctor, who quickly thanks to a blood glucose meter, found out that I had type 1 diabetes. A new chapter in my life began. Since that day I have been constantly checking my blood sugar level, to understand what insulin dose I need to inject. While adopting my way of life to keep this roller-coaster in check. Which I promise you is not easy.

In the beginning I used two different types of syringe injections several times per day, along with spot blood sugar readings from my finger tip. Today as the technology evolved I instead use an insulin pump that continuously receives my blood sugar levels from a CGM. To allow my pump to adjust insulin dose automatically. While also notify my loved ones if I need help, thanks to that most CGM solutions are now constantly online and accessible via internet.

So what if we can bring this inside of a car?

So the idea I had was to connect my blood glucose sensor, or any other wearable device in real time to the car. To then allow the application inside the car to give me information and possibilities to take action if needed within the context of the car while driving. Below is a high level solution flowchart how it turned out.

If you are not aware Volvo Cars has since 2017 Android Automotive as our operational system in our Infotainment Head Unit (IHU). This was perfect for me, as a hobby android developer. What if I could just write an Android application that could retrieve my CGM read outs in real time and present that inside the car?

I had before built a similar application for my Magic Mirror. Which gave me the required knowledge of how to obtain the values in near real time. Now instead I just needed to created a simple android application that could draw a graph of my latest five hours of read outs from my Nightscout instance. After two hours I had a working prototype running inside the emulator, I realised this can actually work!

First prototype running in an andround automotive emulator

This helps to minimize distractions and make it safe to access my blood sugar levels behind the wheel without checking my phone while driving.

But what's next?

How can I integrate this more seamlessly and also allow me to take action or act behind the wheel according to my blood sugar level?

In Androids lifecycle architecture, there are different events triggered which an application could listen for via an application intent broadcast receiver. What if the car sent a boot completed event similar to phone? That would allow me to build a service that “kicks off” as soon as the car has finished booting. Also thanks to that most Volvo cars now days are always connected to the internet, my blood sugar values could be retrieved seamlessly, without me acting or the company to have direct access to my sensor or data while run in background every time I used the car. That's magic!

Here is how the manifest looks like:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-feature
android:name="android.hardware.type.automotive"
android:required="true" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application
android:name=".WearableMonitorApp"
android:allowBackup="true"
android:icon="@mipmap/wearable_monitor_ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/wearable_monitor_ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.DiabetesMonitor">

<activity
android:name=".feature_glucose.presentation.MainActivity"
android:exported="true"
android:theme="@style/Theme.CarUi.WithToolbar">
<meta-data
android:name="distractionOptimized"
android:value="true" />

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".feature_glucose.presentation.settings.WearableSettingsActivity"
android:exported="false"
android:label="Settings"
android:theme="@style/Theme.CarUi.WithToolbar">
<intent-filter>
<action android:name="android.intent.action.APPLICATION_PREFERENCES" />
</intent-filter>
</activity>

<receiver
android:name=".service.ServiceStarter"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

<service
android:name=".service.NotificationService"
android:enabled="true" />

<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
tools:node="remove" />
</application>

</manifest>

The “magic part” is the intent filter listening to

android.intent.action.BOOT_COMPLETED

Which will allow me to kick off a foreground service that will keep a persistent notification updated by a background service collecting my CGM readouts. Of course the car application works the same way as any other Android application on other devices. So I need to also request the permission to receive this event, running a foreground service and get access to the internet.

Great, now I have the app always running in background. I have a sticky notification with my latest read out, which I can access easily with just a down-swipe gesture. My car “knows” my trend, where my blood sugar is going.

So how could this be used in a smart way?

A phone based CGM application core feature is to inform the user about critical levels, so that you act in time before its to late. This typically shows up as a heads up notification together with an alarm sound. To be frank, for a type 1 diabetic using a CGM this alarm goes of a lot. I’m also very grateful for it even if it can be annoying as hell. But it gives me back the control.

Usually what I need to do when the alarm goes of is to eat something which raises my blood sugar quickly, like a dextrose tablet. If the alarm go off due to high blood sugar I have more time. But its equally important that I act in time and find a way to adjust my insulin.

So even if I already get notified in my pump and phone, the main difference is the context I'm in. Behind the wheel I have less possibilities and time to act, I also need to potentially get the warning earlier and I need to get help to perform the action which I don't when outside of the car. So this is the perfect use case for an in-car CGM application. To actually give me back more time, to integrate it with features like Pilot Assist or similar. This will give me possibility to slightly lower my focus on the road and inject insulin or find my snack.

So I decided to create a heads up notification that integrates with cars navigation system via a navigation intent to search for closest parking or convenience store. Just imagine when 3rd party applications could utilize the power of this and give drivers the right recommendations based on their glucose levels!

Thanks to intent filters I can integrate with other applications and features in Android easily. So created two different intents which I can take action on via the heads up notification. That will enable me to easily navigate to the closest convenience store or find the best parking space, with just one click.

Here is how I create the notifications and the uri definitions of finding the closest convenience store or parking space.

<!--NotificationServiceModule -->
<string name="uri_find_parking" translatable="false">geo:0,0?q=parking</string>
<string name="uri_find_store" translatable="false">geo:0,0?q=convenience store</string>
    @ServiceScoped
@Provides
@Named(KEY_FIND_PARK_INTENT)
fun provideFindParkingIntent(
@ApplicationContext context: Context,
): PendingIntent = PendingIntent.getActivity(
context,
0,
Intent(
Intent.ACTION_VIEW, Uri.parse(context.getString(R.string.uri_find_parking))
).setPackage("com.google.android.apps.maps"), PendingIntent.FLAG_IMMUTABLE
)

@ServiceScoped
@Provides
@Named(KEY_FIND_SNACK_INTENT)
fun provideFindSnackIntent(
@ApplicationContext context: Context,
): PendingIntent = PendingIntent.getActivity(
context,
0,
Intent(
Intent.ACTION_VIEW, Uri.parse(context.getString(R.string.uri_find_store))
).setPackage("com.google.android.apps.maps"), PendingIntent.FLAG_IMMUTABLE
)

@ServiceScoped
@Provides
@Named(KEY_CRITICAL_NOTIFICATION)
fun provideCriticalNotification(
@ApplicationContext context: Context,
@Named(KEY_CONTENT_INTENT) contentIntent: PendingIntent,
@Named(KEY_IMPORTANCE_HIGH) criticalNotificationChannel: NotificationChannel,
@Named(KEY_FIND_SNACK_INTENT) findSnackIntent: PendingIntent,
@Named(KEY_FIND_PARK_INTENT) findParkingIntent: PendingIntent,
mainActivityIntent: Intent,
): NotificationCompat.Builder =
NotificationCompat.Builder(context, criticalNotificationChannel.id)
.setSmallIcon(R.drawable.ic_baseline_notification_important_24)
.setContentIntent(contentIntent)
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setPriority(criticalNotificationChannel.importance)
.setAutoCancel(true)
.setContentIntent(
PendingIntent.getActivity(
context,
0,
mainActivityIntent,
0
)
)
.addAction(
0,
context.getString(R.string.alarm_critical_notification_buttonText_snack),
findSnackIntent
)
.addAction(
0,
context.getString(R.string.alarm_critical_notification_buttonText_parking),
findParkingIntent
)

Finally I have a minimal loveable product.

How does it work in a car?

So lets try this out in a real car! Here is a demonstration video of the application running and how I interact with it during the drive.

As you can see from the video above, with one push of a button, I received all the information I need to act. So now we have a concept application tested and verified in a test car.

How do we bring it to more people?

Googles Android Automotive and Auto category Internet Of Things, would allow any 3rd party developer to build and release in-car applications. They also make it possible companies to transform their phone applications to in-car applications with little or much less development efforts with their existing in car app template. Releasing a 3rd part application would also mean that it can reach all drivers of an android powered or capable car, which is what we also want todo, reach not only Volvo Cars drivers!

With help from my amazing colleagues in Volvo Cars, we rewrote the app according to best practices but also push for releasing the source code open source we have published the application on Github. You can see how it was made, test it, or just use this as a reference when building your own in-car application. So just go ahead an clone it!

PS: try it out within a virtual “car” by using our public emulator: https://developer.volvocars.com/in-car-apps/android-emulator-xc40/

Of course the story doesn't end here. So keep your eye out for Part 2, which will be around how I released Nightrider to the public, through a personal 3rd party app, and what adoptions are needed in order to support and release a 3rd party automotive app. You can download it already today on Google Play Store: https://play.google.com/store/apps/details?id=com.buredroid.nightrider!

Plus some extras from our trip to Copenhagen when we visit the Diabetes Gala and reflections and support we got from meeting experts in the field.

Me, Peter Jihde, Niclas and Paul demonstrating the application after the BEAT Diabetes — Fight for life gala in Copenhagen 2022

--

--