1/* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { BasePermissionStrategy } from '../base/BasePermissionStrategy'; 17import { PermissionUtils } from '../utils/permissionUtils'; 18import { Permission, PermissionGroup, PermissionOption } from '../model/definition'; 19import { PermissionGroupConfig, PermissionWithOption } from '../model/typedef'; 20import Constants from '../utils/constant'; 21 22const groupConfig: PermissionGroupConfig = new PermissionGroupConfig({ 23 groupName: PermissionGroup.ADS, 24 permissions: [Permission.APP_TRACKING_CONSENT], 25 icon: $r('app.media.track'), 26 title: '', 27 reason: '', 28 buttonList: [] 29}) 30 31export class AdsStrategy extends BasePermissionStrategy { 32 public override getPermissionGroupConfig(): PermissionGroupConfig { 33 return groupConfig; 34 } 35 36 public override getGroupTitle(appName: string, locationFlag: number): ResourceStr { 37 return $r('app.string.group_label_ADS', appName); 38 } 39 40 public override async preProcessingPermission( 41 permission: Permission, tokenId: number 42 ): Promise<PermissionWithOption[]> { 43 let permissionWithOptionList: PermissionWithOption[] = []; 44 if (!groupConfig.permissions.includes(permission)) { 45 return []; 46 } 47 let isPermissionQueryEnabled = await PermissionUtils.isPermissionQueryEnabled(permission); 48 if (!isPermissionQueryEnabled) { 49 await PermissionUtils.grantPermissionWithResult(permission, Constants.PERMISSION_FLAG, tokenId); 50 permissionWithOptionList.push({ permission, permissionOption: PermissionOption.GRANT }); 51 } 52 return permissionWithOptionList; 53 } 54}