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 AbilityConstant from '@ohos.app.ability.AbilityConstant'; 16import UIAbility from '@ohos.app.ability.UIAbility'; 17import Want from '@ohos.app.ability.Want'; 18import window from '@ohos.window'; 19import dlpPermission from '@ohos.dlpPermission'; 20import { terminateSelfWithResult } from '../common/utils'; 21import { BusinessError } from '@ohos.base'; 22 23const TAG = "DLP_XTS_SetRetentionStateCallback"; 24 25export default class SetRetentionStateCallback extends UIAbility { 26 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { 27 globalThis.context = this.context; 28 globalThis.want = want; 29 } 30 31 onDestroy() { 32 } 33 34 onWindowStageCreate(windowStage: window.WindowStage) { 35 // Main window is created, set main page for this ability 36 var success = <boolean> globalThis.want.parameters['ohos.dlp.params.success']; 37 var number = <number> globalThis.want.parameters['ohos.dlp.params.number']; 38 let uriArray: string[] = []; 39 if (success) { 40 uriArray = ['uri']; 41 } 42 if (number == 2) { 43 uriArray = ['uri', 'uri2']; 44 } 45 dlpPermission.setRetentionState(uriArray, async (error: BusinessError) => { 46 if (error) { 47 console.error(TAG, "SetRetentionState callback fail", error.code, error.message); 48 terminateSelfWithResult(error.code); 49 } else { 50 console.info(TAG, "SetRetentionState callback pass"); 51 terminateSelfWithResult(0); 52 } 53 }); 54 } 55 56 onWindowStageDestroy() { 57 // Main window is destroyed, release UI related resources 58 } 59 60 onForeground() { 61 // Ability has brought to foreground 62 } 63 64 onBackground() { 65 // Ability has back to background 66 } 67} 68