• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 
16 #include "quick_fix_manager_stub.h"
17 
18 #include "hilog_wrapper.h"
19 #include "hitrace_meter.h"
20 #include "quick_fix_error_utils.h"
21 
22 namespace OHOS {
23 namespace AAFwk {
QuickFixManagerStub()24 QuickFixManagerStub::QuickFixManagerStub()
25 {
26     requestFuncMap_[ON_APPLY_QUICK_FIX] = &QuickFixManagerStub::ApplyQuickFixInner;
27     requestFuncMap_[ON_GET_APPLYED_QUICK_FIX_INFO] = &QuickFixManagerStub::GetApplyedQuickFixInfoInner;
28 }
29 
~QuickFixManagerStub()30 QuickFixManagerStub::~QuickFixManagerStub()
31 {
32     requestFuncMap_.clear();
33 }
34 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)35 int QuickFixManagerStub::OnRemoteRequest(
36     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
37 {
38     if (data.ReadInterfaceToken() != AAFwk::IQuickFixManager::GetDescriptor()) {
39         HILOG_ERROR("local descriptor is not equal to remote.");
40         return QUICK_FIX_INVALID_PARAM;
41     }
42 
43     auto itFunc = requestFuncMap_.find(code);
44     if (itFunc != requestFuncMap_.end()) {
45         auto requestFunc = itFunc->second;
46         if (requestFunc != nullptr) {
47             return (this->*requestFunc)(data, reply);
48         }
49     }
50 
51     HILOG_WARN("default case, need check value of code.");
52     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
53 }
54 
ApplyQuickFixInner(MessageParcel & data,MessageParcel & reply)55 int32_t QuickFixManagerStub::ApplyQuickFixInner(MessageParcel &data, MessageParcel &reply)
56 {
57     HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
58     std::vector<std::string> hapQuickFixFiles;
59     if (!data.ReadStringVector(&hapQuickFixFiles)) {
60         HILOG_ERROR("Read quick fix files failed.");
61         return QUICK_FIX_READ_PARCEL_FAILED;
62     }
63 
64     auto ret = ApplyQuickFix(hapQuickFixFiles);
65     reply.WriteInt32(ret);
66     return QUICK_FIX_OK;
67 }
68 
GetApplyedQuickFixInfoInner(MessageParcel & data,MessageParcel & reply)69 int32_t QuickFixManagerStub::GetApplyedQuickFixInfoInner(MessageParcel &data, MessageParcel &reply)
70 {
71     HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
72     std::string bundleName = data.ReadString();
73     ApplicationQuickFixInfo quickFixInfo;
74     auto ret = GetApplyedQuickFixInfo(bundleName, quickFixInfo);
75     reply.WriteInt32(ret);
76     if (ret == QUICK_FIX_OK) {
77         if (!reply.WriteParcelable(&quickFixInfo)) {
78             HILOG_ERROR("Write parcelable failed.");
79             return QUICK_FIX_WRITE_PARCEL_FAILED;
80         }
81     }
82     return QUICK_FIX_OK;
83 }
84 } // namespace AAFwk
85 } // namespace OHOS
86