将应用加入白名单

背景:
项目中需要把一个自己写的应用加入到android系统的/system/priv-app目录下面,在该应用的AndroidManifest.xml中添加权限

<uses-permission android:name="android.permission.REBOOT"
        tools:ignore="ProtectedPermissions" />

将该应用系统签名打包放入设备/system/priv-app目录下,重启设备,系统启动报错:

[2023/5/25 16:03:44] 05-25 15:04:19.646 E/AndroidRuntime( 2981): *** FATAL EXCEPTION IN SYSTEM PROCESS: main
[2023/5/25 16:03:44] 05-25 15:04:19.646 E/AndroidRuntime( 2981): java.lang.IllegalStateException: Signature|privileged permissions not in privapp-permissions whitelist: {com.htkj.carstation: android.permission.REBOOT}
[2023/5/25 16:03:47] 05-25 15:04:19.646 E/AndroidRuntime( 2981): 	at com.android.server.pm.permission.PermissionManagerService.systemReady(PermissionManagerService.java:2946)
[2023/5/25 16:03:47] 05-25 15:04:19.646 E/AndroidRuntime( 2981): 	at com.android.server.pm.permission.PermissionManagerService.access$100(PermissionManagerService.java:123)
[2023/5/25 16:03:47] 05-25 15:04:19.646 E/AndroidRuntime( 2981): 	at com.android.server.pm.permission.PermissionManagerService$PermissionManagerServiceInternalImpl.systemReady(PermissionManagerService.java:3007)
[2023/5/25 16:03:47] 05-25 15:04:19.646 E/AndroidRuntime( 2981): 	at com.android.server.pm.PackageManagerService.systemReady(PackageManagerService.java:22079)
[2023/5/25 16:03:47] 05-25 15:04:19.646 E/AndroidRuntime( 2981): 	at com.android.server.SystemServer.startOtherServices(SystemServer.java:2027)
[2023/5/25 16:03:47] 05-25 15:04:19.646 E/AndroidRuntime( 2981): 	at com.android.server.SystemServer.run(SystemServer.java:525)
[2023/5/25 16:03:47] 05-25 15:04:19.646 E/AndroidRuntime( 2981): 	at com.android.server.SystemServer.main(SystemServer.java:352)
[2023/5/25 16:03:47] 05-25 15:04:19.646 E/AndroidRuntime( 2981): 	at java.lang.reflect.Method.invoke(Native Method)
[2023/5/25 16:03:47] 05-25 15:04:19.646 E/AndroidRuntime( 2981): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
[2023/5/25 16:03:47] 05-25 15:04:19.646 E/AndroidRuntime( 2981): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:973)
[2023/5/25 16:03:47] 05-25 15:04:19.649 I/SdException( 2981): eventType = crash, processName = system_server
[2023/5/25 16:03:47] 05-25 15:04:19.649 I/SdException( 2981): data = crash|0|system_server

经过查找,参考链接https://blog.csdn.net/HongEnIT/article/details/124888610
手动修改方式:
修改下面文件:/system/etc/permissions/privapp-permissions-platform.xml,添加新增应用包名及权限,如下:

<!--xxx add start 20230526-->
	<privapp-permissions package="com.xxx.carstation">
        <permission name="android.permission.REBOOT" />
    </privapp-permissions>
<!--xxx add end 20230526-->

在android系统源码中修改:
修改文件:/home/ss/X9-work/buildsystem/android/frameworks/base/data/etc/privapp-permissions-platform.xml
同样添加新增应用包名及权限,如下:

<!--xxx add start 20230526-->
	<privapp-permissions package="com.xxx.carstation">
        <permission name="android.permission.REBOOT" />
    </privapp-permissions>
<!--xxx add end 20230526-->

编译系统程序,烧录到设备中。问题解决。

你可能感兴趣的:(android)