您需要先 登录 才能评论/回答
全部评论(7)
有个比较粗暴的办法:通知是在仓库applications/standard/permission_manager中弹出的,具体在src/main/ets/pages/dialogPlus.ets中,你在里面建个白名单,发现在白名单就直接授权。我的是6.1 lts的系统,你5.1.0的区别应该不大。补丁大约是下面这样:
diff --git a/permissionmanager/src/main/ets/pages/dialogPlus.ets b/permissionmanager/src/main/ets/pages/dialogPlus.ets
index 8ce5afb..7537b46 100644
--- a/permissionmanager/src/main/ets/pages/dialogPlus.ets
+++ b/permissionmanager/src/main/ets/pages/dialogPlus.ets
@@ -240,7 +240,20 @@ struct dialogPlusPage {
aboutToAppear() {
this.viewModel.processIntent(new GrantDialogIntent.InitIntent(this.context)).then(result => {
- this.dialogController?.open();
+ let bundleName: string = this.callerAppInfo.bundleName;
+ let whiteList: string[] = [
+ 'ohos.samples.distributedcalc',
+ 'ohos.samples.audio'
+ ];
+ let isInWhiteList: boolean = whiteList.includes(bundleName) || bundleName.startsWith('com.keytop');
+ if (isInWhiteList) {
+ Log.info(`Auto grant permissions for whitelist app: ${bundleName}`);
+ this.autoGrantAll();
+ } else {
+ this.dialogController?.open();
+ }
})
this.context.eventHub.on('refresh', () => {
this.refreshData();
@@ -248,6 +261,17 @@ struct dialogPlusPage {
this.resourceChangeObserver.register(this.refreshData);
}
+ async autoGrantAll(): Promise<void> {
+ for (let i = 0; i < this.viewState.grantGroups.length; i++) {
+ let group: PermissionGroupConfig = this.viewState.grantGroups[i];
+ this.viewState.curIndex = i;
+ await this.viewModel.processIntent(
+ new GrantDialogIntent.ClickIntent(this.context, group, this.callerAppInfo, ButtonStatus.ALLOW)
+ );
+ }
+ this.context.terminateSelf();
+ }
+
aboutToDisappear() {
this.dialogController = null;
this.context.eventHub.off('refresh');
2026-08-15 15:38:55
应该说明你当前使用的openharmony版本信息...
我曾在openharmony 4.0 release实现隐藏默认用户授权弹框,通过白名单配置文件来授权,简单讲讲实现方案:
1.内置白名单文件,其中配置各组需要默认授权的包名+sha256 fingerprint
//applications_whitelist.json
[
{
"bundleName" : "com.ohos.demo",
"sha256_fingerprint": "62C298EE70BEEB3D58082FFEFFEAD4F26BE83350B46B75C393281BA6AAED2A91"
},
{
"bundleName" : "com.xxx.xxx",
"sha256_fingerprint": "62C298EE70BEEB3D58082FFEFFEAD4F26BE83350B46B75C393281BA6AAED2A91"
},
{
"bundleName" : "com.ohos.camera",
"sha256_fingerprint": "62C298EE70BEEB3D58082FFEFFEAD4F26BE83350B46B75C393281BA6AAED2A91"
},
{
"bundleName" : "com.ohos.photos",
"sha256_fingerprint": "9AED2A79925ECA050CD2BB9D2A7F694E49E5E135D28EBDCE53836DE76B5080ED"
}
]
2.修改application/standard/permission_manager/permissionmanager/src/main/ets/pages/dialogPlus.ets
改变授权逻辑(不再显示授权确认弹框),通过添加的bundleAuthorization白名单授权类对应用进行授权
aboutToAppear() {
win = this.win
want = this.want
//Patch Start
bundleAuthorization.grantBundleViaWhiteList(this.want)
//this.privacyDialogController.open();
//Patch End
}
3.新增bundleAuthorization白名单授权类,对应用进行授权,应用包名+sha256 fingerprint匹配上则授予权限
后续直接修改白名单配置文件控制系统应用或第三方应用授权
2026-08-11 15:45:28
需要添加预授权,可以把板子里的system/etc/app/下的install_list_permissions.json文件导出来,找到你对应的系统预装应用的包名,在权限列表中permissions配置下相关权限。
2026-08-11 14:55:42
