1/* 2 * Copyright (c) 2024 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 rpc from '@ohos.rpc'; 17import ConnectService from './ConnectService'; 18import { HiLog } from '../HiLog'; 19import Constants from '../constant'; 20 21const TAG = 'CredCallbackStub'; 22 23export default class CredCallbackStub extends rpc.RemoteObject { 24 private connectService: ConnectService = new ConnectService(getContext(this)); 25 private static readonly DESCRIPTOR: string = 'OHOS.HapDlpCredAbilityServiceStub'; 26 27 constructor(des: string) { 28 super(des); 29 } 30 31 asObject(): rpc.IRemoteObject { 32 return this; 33 } 34 35 async onRemoteMessageRequest(code: number, data: rpc.MessageSequence): Promise<boolean> { 36 HiLog.info(TAG, `onRemoteMessageRequest called, code = ${code}`); 37 if (data.readInterfaceToken() !== CredCallbackStub.DESCRIPTOR) { 38 HiLog.info(TAG, `DESCRIPTOR unmatched.`); 39 return false; 40 } 41 switch (code) { 42 case Constants.COMMAND_SEARCH_USER_INFO: { 43 let storage = LocalStorage.getShared(); 44 HiLog.info(TAG, `onRemoteMessageRequest command search user info`); 45 let resultVar = data.readString(); 46 storage.setOrCreate('commandSearchUserInfo', resultVar); 47 this.connectService.disconnectServiceShareAbility(`connection_${Constants.COMMAND_SEARCH_USER_INFO}`); 48 return true; 49 } 50 case Constants.COMMAND_GET_ACCOUNT_INFO: { 51 let storage = LocalStorage.getShared(); 52 HiLog.info(TAG, `onRemoteMessageRequest command get account info`); 53 let resultVar = data.readString(); 54 storage.setOrCreate('commandGetAccountInfo', resultVar); 55 this.connectService.disconnectServiceShareAbility(`connection_${Constants.COMMAND_GET_ACCOUNT_INFO}`); 56 return true; 57 } 58 default: { 59 HiLog.error(TAG, `invalid request code: ${code}`); 60 break; 61 } 62 } 63 return false; 64 } 65}