实现此导出组件的权限



我正在为Android Automotive OS编写一个应用程序。目前,这是一个简单的Hello World,但到目前为止,这不是该应用程序的问题。

要在 Android Studio的内置汽车模拟器中运行该应用程序(我使用的是 Canary 版本的 Android Studio Electric Eel | 2022.1.1 Canary 10),我必须下载一个名为Google Automotive App Host的应用程序,从现在开始将它们称为GAAH,以便能够运行我自己创建的应用程序。目前为止,一切都好。

现在我在AndroidManifest.xml中遇到了一个"问题",上面写着:Implement permissions on this exported component.在<服务>部分中:

<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>

大多数答案都指出,android:exported应设置为false,这是有道理的,因此其他应用程序无法访问我自己的应用程序。

问题是,它还包括前面提到的 GAAH,我需要能够运行它。这不是破坏游戏的事情,只是处理起来很麻烦。

我的问题是:有没有办法解决这个问题保留 GAAH 在 AAOS 中运行我的应用程序的能力?

提前感谢! 灰色

编辑:将XML部分从<服务>扩展到<应用程序>

Google 汽车应用主机拥有android.car.permission.TEMPLATE_RENDERER权限,因此您应该能够按如下方式使用它:

<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>

此外,您可以通过覆盖 CarAppService::createHostValidator 方法进一步优化您信任的主机。

最新更新