Grey
Grey

Reputation: 126

Implement permissions on this exported component

I am coding an application for Android Automotive OS. It is a simple Hello World for now, but that is not the problem of the app so far.

To run the app in the in-built automotive emulator of Android Studio (I use the Canary version of Android Studio Electric Eel | 2022.1.1 Canary 10) I had to download an app called Google Automotive App Host, gonna refer to them as GAAH from now on, to be able to run my own created app. So far so good.

Now I came across a "problem" in my AndroidManifest.xml which says: Implement permissions on this exported component. in the <service> section:

<application
        android:allowBackup="true"
        android:icon="@mipmap/example_icon"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/example_icon_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.Example">

        <meta-data
            android:name="androidx.car.app.minCarApiLevel"
            android:value="1" />

        <service
            android:name="com.example.launcher.services.LauncherService"
            android:exported="true">
            <intent-filter>
                <action android:name="androidx.car.app.CarAppService" />
            </intent-filter>
        </service>

        <activity
            android:name="androidx.car.app.activity.CarAppActivity"
            android:exported="true"
            android:launchMode="singleTask"
            android:theme="@android:style/Theme.DeviceDefault.NoActionBar">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data
                android:name="distractionOptimized"
                android:value="true" />
        </activity>

    </application>

Most of the answers stated, that android:exported should be set to false, which makes sense, so other apps don't have access to my own app.

The problem is, it also includes the aforementioned GAAH, which I need to be able to run it at all. It is not something game-breaking, it is just an inconvenience to deal with.

My question is: Are there ways to fix this issue and retain the ability for GAAH to run my app in AAOS?

Thanks in advance! Grey

Edit: Expanded the XML section from <service> to <application>

Upvotes: 1

Views: 1306

Answers (1)

Ben Sagmoe
Ben Sagmoe

Reputation: 1447

The Google Automotive App Host holds the android.car.permission.TEMPLATE_RENDERER permission, so you should be able to use that as follows:

<service
   android:name=(hidden)
   android:exported="true"
   android:permission="android.car.permission.TEMPLATE_RENDERER">
   <intent-filter>
      <action android:name="androidx.car.app.CarAppService" />
   </intent-filter>
</service>

Additionally, you can further refine which hosts you trust by overriding the CarAppService::createHostValidator method.

Upvotes: 1

Related Questions