1  /*
2   * Copyright (c) 2020 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  #include "dmslite_msg_handler.h"
16  
17  #include "dmsfwk_interface.h"
18  #include "dmslite_famgr.h"
19  #include "dmslite_log.h"
20  #include "dmslite_permission.h"
21  #include "dmslite_session.h"
22  #include "dmslite_tlv_common.h"
23  #include "dmslite_utils.h"
24  
StartAbilityFromRemoteHandler(const TlvNode * tlvHead,StartAbilityCallback onStartAbilityDone)25  int32_t StartAbilityFromRemoteHandler(const TlvNode *tlvHead, StartAbilityCallback onStartAbilityDone)
26  {
27      const char *calleeBundleName = UnMarshallString(tlvHead, CALLEE_BUNDLE_NAME);
28      const char *calleeAbilityName = UnMarshallString(tlvHead, CALLEE_ABILITY_NAME);
29      const char *callerSignature = UnMarshallString(tlvHead, CALLER_SIGNATURE);
30  
31      PermissionCheckInfo permissionCheckInfo;
32      permissionCheckInfo.calleeAbilityName = calleeAbilityName;
33      permissionCheckInfo.calleeBundleName = calleeBundleName;
34      permissionCheckInfo.callerSignature = callerSignature;
35      int32_t errCode = CheckRemotePermission(&permissionCheckInfo);
36      if (errCode != DMS_EC_SUCCESS) {
37          HILOGE("[Remote permission check failed]");
38          return errCode;
39      }
40      return StartAbilityFromRemote(calleeBundleName, calleeAbilityName, onStartAbilityDone);
41  }
42  
ReplyMsgHandler(const TlvNode * tlvHead)43  int32_t ReplyMsgHandler(const TlvNode *tlvHead)
44  {
45      int32_t ret = UnMarshallInt32(tlvHead, REPLY_ERR_CODE);
46      HILOGD("[ReplyMsgHandler ret = %d]", ret);
47      InvokeCallback(NULL, ret);
48      CloseDMSSession();
49      return ret;
50  }