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 
16 #ifdef SUPPORT_GRAPHICS
17 #include "ability_first_frame_state_observer_stub.h"
18 
19 #include "hilog_tag_wrapper.h"
20 #include "appexecfwk_errors.h"
21 #include "ipc_types.h"
22 #include "iremote_object.h"
23 
24 #include "ability_first_frame_state_data.h"
25 
26 namespace OHOS {
27 namespace AppExecFwk {
AbilityFirstFrameStateObserverStub()28 AbilityFirstFrameStateObserverStub::AbilityFirstFrameStateObserverStub() {}
29 
~AbilityFirstFrameStateObserverStub()30 AbilityFirstFrameStateObserverStub::~AbilityFirstFrameStateObserverStub() {}
31 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)32 int32_t AbilityFirstFrameStateObserverStub::OnRemoteRequest(
33     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
34 {
35     TAG_LOGD(AAFwkTag::ABILITYMGR, "called");
36     std::u16string descriptor = AbilityFirstFrameStateObserverStub::GetDescriptor();
37     std::u16string remoteDescriptor = data.ReadInterfaceToken();
38     if (descriptor != remoteDescriptor) {
39         TAG_LOGE(AAFwkTag::ABILITYMGR, "invalid descriptor");
40         return ERR_INVALID_STATE;
41     }
42 
43     if (code == static_cast<uint32_t>(IAbilityFirstFrameStateObserver::Message::ON_ABILITY_FIRST_FRAME_STATE)) {
44         return HandleOnAbilityFirstFrameStateChanged(data, reply);
45     }
46     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
47 }
48 
HandleOnAbilityFirstFrameStateChanged(MessageParcel & data,MessageParcel & reply)49 int32_t AbilityFirstFrameStateObserverStub::HandleOnAbilityFirstFrameStateChanged(MessageParcel &data,
50     MessageParcel &reply)
51 {
52     std::unique_ptr<AbilityFirstFrameStateData> stateData(data.ReadParcelable<AbilityFirstFrameStateData>());
53     if (stateData == nullptr) {
54         TAG_LOGE(AAFwkTag::ABILITYMGR, "null stateData");
55         return ERR_APPEXECFWK_PARCEL_ERROR;
56     }
57     OnAbilityFirstFrameState(*stateData);
58     return NO_ERROR;
59 }
60 
AbilityFirstFrameStateObserverRecipient(RemoteDiedHandler handler)61 AbilityFirstFrameStateObserverRecipient::AbilityFirstFrameStateObserverRecipient(RemoteDiedHandler handler)
62     : handler_(handler)
63 {}
64 
OnRemoteDied(const wptr<IRemoteObject> & remote)65 void AbilityFirstFrameStateObserverRecipient::OnRemoteDied(const wptr<IRemoteObject> &__attribute__((unused)) remote)
66 {
67     TAG_LOGE(AAFwkTag::ABILITYMGR, "Remote died");
68     if (handler_) {
69         handler_(remote);
70     }
71 }
72 } // namespace AppExecFwk
73 } // namespace OHOS
74 #endif