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 { HiLog } from '../../../common/HiLog'; 17import rpc from '@ohos.rpc'; 18import Constants from '../../../common/constant'; 19import ViewAbilityService from '../service/ViewAbilityService'; 20import OpeningDialogManager from '../../../OpenDlpFile/manager/OpeningDialogManager'; 21import TerminateView from '../../../OpenDlpFile/TerminateView/TerminateView'; 22 23const TAG = 'ViewAbilityStub'; 24 25export default class ViewAbilityStub extends rpc.RemoteObject { 26 constructor(des: string) { 27 super(des); 28 } 29 30 asObject(): rpc.IRemoteObject { 31 return this; 32 } 33 34 private checkParams(code: number, data: rpc.MessageSequence): boolean { 35 if (!code || !data) { 36 HiLog.error(TAG, 'ViewAbilityStub params is invalid'); 37 return false; 38 } 39 HiLog.info(TAG, `ViewAbilityStub onRemoteMessageRequest called, code = ${code}`); 40 try { 41 if (data.readInterfaceToken() !== Constants.DLP_MGR_OPENING_DIALOG_TOKEN) { 42 HiLog.error(TAG, 'ViewAbilityStub InterfaceToken unmatched.'); 43 return false; 44 } 45 } catch (error) { 46 HiLog.wrapError(TAG, error, 'ViewAbilityStub read data exception'); 47 return false; 48 } 49 return true; 50 } 51 52 async onRemoteMessageRequest(code: number, data: rpc.MessageSequence): Promise<boolean> { 53 if (!this.checkParams(code, data)) { 54 HiLog.error(TAG, 'onRemoteMessageRequest checkParams failed'); 55 return false; 56 } 57 switch (code) { 58 case Constants.COMMAND_SET_REMOTE_OBJECT: { 59 HiLog.info(TAG, 'command set remote object'); 60 try { 61 await ViewAbilityService.getInstance().setRemoteProxy(data.readRemoteObject()); 62 } catch (error) { 63 HiLog.wrapError(TAG, error, 'readRemoteObject error'); 64 return false; 65 } 66 return true; 67 } 68 case Constants.COMMAND_DIALOG_DISAPPEAR: { 69 HiLog.info(TAG, 'command dialog disappear'); 70 let resultVar = ''; 71 try { 72 resultVar = data.readString(); 73 } catch (error) { 74 HiLog.error(TAG, `read string exception, error is ${JSON.stringify(error)}`); 75 return false; 76 } 77 await OpeningDialogManager.getInstance().dialogDisappear(resultVar); 78 return true; 79 } 80 case Constants.COMMAND_DIALOG_TIMEOUT: { 81 HiLog.info(TAG, 'command dialog timeout'); 82 let resultVar = ''; 83 try { 84 resultVar = data.readString(); 85 } catch (error) { 86 HiLog.error(TAG, `read string exception, error is ${JSON.stringify(error)}`); 87 return false; 88 } 89 await OpeningDialogManager.getInstance().dialogTimeout(resultVar); 90 await TerminateView.terminate(); 91 return true; 92 } 93 default: { 94 HiLog.error(TAG, `OpeningDialogStub invalid request code: ${code}`); 95 break; 96 } 97 } 98 return false; 99 } 100}