1/* 2 * Copyright (c) 2023 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 */ 15import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; 16import type { Permissions } from '@ohos.abilityAccessCtrl'; 17 18const TAG = 'PermissionUtil'; 19 20export class PermissionUtil { 21 private static permissions: Array<Permissions> = ['ohos.permission.READ_CALENDAR']; 22 23 public static async requestOAIDTrackingConsentPermissions(context: any): Promise<void> { 24 let atManager = abilityAccessCtrl.createAtManager(); 25 return new Promise<void>(async (resolve, reject) => { 26 console.log(TAG, 'requestPermission begin'); 27 let data = await atManager.requestPermissionsFromUser(context, ['ohos.permission.APP_TRACKING_CONSENT']); 28 console.log(TAG, 'requestPermissionsFromUser data=' + JSON.stringify(data)); 29 if (data && data.authResults) { 30 let result = 0; 31 for (let i = 0; i < data.authResults.length; i++) { 32 result += data.authResults[i]; 33 } 34 if (result === 0) { 35 resolve(); 36 } else { 37 console.log(TAG, 'requestPermission user rejected'); 38 reject(); 39 } 40 } else { 41 console.log(TAG, 'requestPermission failed'); 42 reject(); 43 } 44 console.log(TAG, 'requestPermission end'); 45 }); 46 } 47}