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