2

I want to code an automotive app which should simply display a map while the user is driving. I am developing with Android Studio 4.0.1 and in Kotlin. In order to create an emulator for testing, I used Android Studio 4.2 Beta 1 to download an automotive system image because in 4.0.1 no automotive system image was available.

I am stuck to make this app "distraction optimized", so unfortunately the app still gets overlayed with a black screen and the text "You can't use this feature while driving".

When I follow the Guidelines ([https://source.android.com/devices/automotive/driver_distraction/guidelines][1]), it seems that I simply have to add the following metadata to the activity-element in the manifest.xml (I only have one activity):

<activity>
  ...
  <meta-data android:name="distractionOptimized" android:value="true"/>
  ...
</activity>

Of course I also request the following needed permissions (amongst others) to the manifest-tag in the manifest.xml file:

...
<uses-permission android:name="android.car.permission.CAR_UX_RESTRICTIONS_CONFIGURATION" />
<uses-permission android:name="android.car.permission.CAR_DRIVING_STATE"/>
...

as well as to the permissions array which I pass to the requestPermissions(...)-function

val PERMISSIONS_ARRAY = arrayOf(
        ...
        Car.PERMISSION_CAR_UX_RESTRICTIONS_CONFIGURATION,
        Car.PERMISSION_CAR_DRIVING_STATE,
        ...
    )   
requestPermissions(PERMISSIONS_ARRAY, 0)

In onRequestPermissionsResult(...) I find out that these two permissions are denied. But the user was even not prompted / asked to give that permission at first app start. Also in the settings there is no possibility to give the app these permissions. In a later piece of code getActiveRestrictions() always returns 255, which means that all restrictions are active, right? Another indication that the app is not allowed to handle the Driver Distraction on it's own, and therefore the OS takes care of it by not showing the app at all...

What am I doing wrong? What do I possibly miss? Does anybody have an idea?

Hahnawaggl
  • 21
  • 3

2 Answers2

2

It is not sufficient to mark an activity as DO in the manifest, it must also be downloaded/installed from a trusted source (like Play Store) otherwise CarPackageManagerService won't allow the app to be displayed in any restricted driving-state.

alvAro365
  • 379
  • 4
  • 8
  • Thank you very much for responding! But the question remains because I actually downloaded this hardware image with Android Studio. Is this not a trusted source?? – Hahnawaggl Jan 29 '21 at 09:08
  • What is the source of this information? I am not able to find this stated anywhere. Is it still valid? – Filip Östermark Feb 09 '21 at 15:29
  • 3
    I found this info from here. Row 742. https://android.googlesource.com/platform/packages/services/Car/+/master/service/src/com/android/car/pm/CarPackageManagerService.java – alvAro365 Feb 10 '21 at 15:16
1

Some insight (which is not fully provided by the website documentation) can be gained from reading the following comment in the source code for 'CarPackageManagerService', which performs the checks on apps and activities to see if they are Distraction Optimized (DO), among other things:

https://android.googlesource.com/platform/packages/services/Car/+/master/service/src/com/android/car/pm/CarPackageManagerService.java#740

Effectively, what this means is that your app needs to be either:

  • A system app,
  • Whitelisted in a config.xml file, which is a resource file for OEMs to create configurations for their car services, or
  • Tagged as DO in the app Manifest, and installed by an allowed source. The list of allowed sources is loaded from R.array.allowedAppInstallSources.

An exception to these rules is if your OS is a debug build.

Filip Östermark
  • 311
  • 2
  • 15