• 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 "ability_info_callback_stub.h"
17 #include "appexecfwk_errors.h"
18 #include "hilog_wrapper.h"
19 #include "ipc_types.h"
20 #include "iremote_object.h"
21 
22 namespace OHOS {
23 namespace AppExecFwk {
AbilityInfoCallbackStub()24 AbilityInfoCallbackStub::AbilityInfoCallbackStub()
25 {
26     memberFuncMap_[static_cast<uint32_t>(
27         IAbilityInfoCallback::Notify_ABILITY_TOKEN)] = &AbilityInfoCallbackStub::HandleNotifyAbilityToken;
28 }
29 
~AbilityInfoCallbackStub()30 AbilityInfoCallbackStub::~AbilityInfoCallbackStub()
31 {
32     memberFuncMap_.clear();
33 }
34 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)35 int AbilityInfoCallbackStub::OnRemoteRequest(
36     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
37 {
38     HILOG_INFO("AbilityInfoCallbackStub::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags());
39     std::u16string descriptor = AbilityInfoCallbackStub::GetDescriptor();
40     std::u16string remoteDescriptor = data.ReadInterfaceToken();
41     if (descriptor != remoteDescriptor) {
42         HILOG_ERROR("local descriptor is not equal to remote");
43         return ERR_INVALID_STATE;
44     }
45 
46     auto itFunc = memberFuncMap_.find(code);
47     if (itFunc != memberFuncMap_.end()) {
48         auto memberFunc = itFunc->second;
49         if (memberFunc != nullptr) {
50             return (this->*memberFunc)(data, reply);
51         }
52     }
53     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
54 }
55 
NotifyAbilityToken(const sptr<IRemoteObject> token,const Want & want)56 void AbilityInfoCallbackStub::NotifyAbilityToken(const sptr<IRemoteObject> token, const Want &want)
57 {
58 }
59 
HandleNotifyAbilityToken(MessageParcel & data,MessageParcel & reply)60 int32_t AbilityInfoCallbackStub::HandleNotifyAbilityToken(MessageParcel &data, MessageParcel &reply)
61 {
62     HILOG_INFO("AbilityInfoCallbackStub");
63     sptr<IRemoteObject> token = data.ReadRemoteObject();
64     Want *want = data.ReadParcelable<Want>();
65 
66     if (!want) {
67         HILOG_ERROR("ReadParcelable<Want> failed");
68         return ERR_APPEXECFWK_PARCEL_ERROR;
69     }
70     NotifyAbilityToken(token, *want);
71     delete want;
72     return NO_ERROR;
73 }
74 }  // namespace AppExecFwk
75 }  // namespace OHOS
76