platform: android-13.0.0_r32
路径:packages/apps/Car/MyHvac
package {
default_applicable_licenses: ["Android-Apache-2.0"],
}
android_app {
# app的名字
name: "MyHvac",
# 源码
srcs: ["src/**/*.java"],
# 资源
resource_dirs: ["res"],
platform_apis: true,
# platform 签名
certificate: "platform",
# 是否是特权app
privileged: true,
# 依赖 car-lib
libs: ["android.car-system-stubs"],
# 这是app的常用依赖
static_libs: [
"jsr305",
"androidx.legacy_legacy-support-v4",
"androidx.appcompat_appcompat",
"androidx-constraintlayout_constraintlayout",
"androidx.lifecycle_lifecycle-extensions",
"car-apps-common",
],
optimize: {
enabled: false,
},
dex_preopt: {
enabled: false,
},
product_variables: {
pdk: {
enabled: false,
},
},
# 这里就是请求特权的模块信息了
required: ["allowed_privapp_com.jiangc.myhvac"]
}
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jiangc.myhvac">
<uses-sdk
android:minSdkVersion="22"
android:targetSdkVersion="31"/>
<uses-permission android:name="android.car.permission.CONTROL_CAR_CLIMATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
<protected-broadcast android:name="android.car.intent.action.TOGGLE_HVAC_CONTROLS" />
<uses-feature
android:name="android.hardware.type.automotive"
android:required="true" />
<application
android:allowBackup="true"
android:appCategory="audio"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyHvac">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
intent-filter>
activity>
application>
manifest>
其中INTERACT_ACROSS_USERS、CONTROL_CAR_CLIMATE为特殊权限
路径:packages/services/Car/data/etc/
以包名创建一个xml文件,比如本例中的com.jiangc.myhvac.xml
内容如下:将特殊权限放到这里
<permissions>
<privapp-permissions package="com.jiangc.myhvac">
<permission name="android.permission.INTERACT_ACROSS_USERS"/>
<permission name="android.car.permission.CONTROL_CAR_CLIMATE"/>
privapp-permissions>
permissions>
然后在Android.bp中添加一个模块
prebuilt_etc {
# 模块名,和前面Android.bp中匹配
name: "allowed_privapp_com.jiangc.myhvac",
sub_dir: "permissions",
# 这里是我们上面添加的特权文件名
src: "com.jiangc.myhvac.xml",
filename_from_src: true,
}
接下来修改packages/services/Car/car_product/overlay/frameworks/base/core/res/res/values/policy_exempt_apps.xml
添加应用的包名
<resources>
<string-array translatable="false" name="policy_exempt_apps">
<item>com.android.car.cluster.homeitem>
<item>com.android.car.hvacitem>
<item>com.android.car.mediaitem>
<item>com.android.car.radioitem>
<item>com.jiangc.myhvacitem>
string-array>
resources>
然后make