1 /*
2 * Copyright (c) 2023-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 #include "auto_startup_callback_proxy.h"
17
18 #include "ability_manager_errors.h"
19 #include "hilog_tag_wrapper.h"
20 #include "ipc_types.h"
21 #include "message_parcel.h"
22
23 namespace OHOS {
24 namespace AbilityRuntime {
25 using namespace OHOS::AAFwk;
OnAutoStartupOn(const AutoStartupInfo & info)26 void AutoStartupCallBackProxy::OnAutoStartupOn(const AutoStartupInfo &info)
27 {
28 MessageParcel data;
29 MessageParcel reply;
30 MessageOption option;
31 if (!data.WriteInterfaceToken(AutoStartupCallBackProxy::GetDescriptor())) {
32 TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Write interface token failed");
33 return;
34 }
35
36 if (!data.WriteParcelable(&info)) {
37 TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Write info failed");
38 return;
39 }
40
41 auto ret = SendRequest(AbilityManagerInterfaceCode::ON_AUTO_STARTUP_ON, data, reply, option);
42 if (ret != NO_ERROR) {
43 TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Send request error: %{public}d", ret);
44 }
45 }
46
OnAutoStartupOff(const AutoStartupInfo & info)47 void AutoStartupCallBackProxy::OnAutoStartupOff(const AutoStartupInfo &info)
48 {
49 MessageParcel data;
50 MessageParcel reply;
51 MessageOption option;
52 if (!data.WriteInterfaceToken(AutoStartupCallBackProxy::GetDescriptor())) {
53 TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Write interface token failed");
54 return;
55 }
56
57 if (!data.WriteParcelable(&info)) {
58 TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Write info failed");
59 return;
60 }
61
62 auto ret = SendRequest(AbilityManagerInterfaceCode::ON_AUTO_STARTUP_OFF, data, reply, option);
63 if (ret != NO_ERROR) {
64 TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Send request error: %{public}d", ret);
65 }
66 }
67
SendRequest(AbilityManagerInterfaceCode code,MessageParcel & data,MessageParcel & reply,MessageOption & option)68 ErrCode AutoStartupCallBackProxy::SendRequest(
69 AbilityManagerInterfaceCode code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
70 {
71 sptr<IRemoteObject> remote = Remote();
72 if (remote == nullptr) {
73 TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null remote");
74 return INNER_ERR;
75 }
76
77 return remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
78 }
79 } // namespace AbilityRuntime
80 } // namespace OHOS
81