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 "work_scheduler_stub.h"
17 #include "work_scheduler_stub_ipc_interface_code.h"
18
19 namespace OHOS {
20 namespace WorkScheduler {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)21 __attribute__((no_sanitize("cfi"))) int32_t WorkSchedulerStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
22 MessageParcel& reply, MessageOption& option)
23 {
24 auto remoteDescriptor = data.ReadInterfaceToken();
25 if (GetDescriptor() != remoteDescriptor) {
26 WS_HILOGE("failed, descriptor is not matched!");
27 return ERR_INVALID_STATE;
28 }
29 switch (code) {
30 case static_cast<uint32_t>(WorkSchedulerStubInterfaceCode::COMMAND_ON_WORK_START): {
31 sptr<WorkInfo> workInfo = data.ReadStrongParcelable<WorkInfo>();
32 if (workInfo == nullptr) {
33 WS_HILOGE("workInfo is nullptr");
34 return ERR_TRANSACTION_FAILED;
35 }
36 OnWorkStart(*workInfo);
37 return ERR_NONE;
38 }
39 case static_cast<uint32_t>(WorkSchedulerStubInterfaceCode::COMMAND_ON_WORK_STOP): {
40 sptr<WorkInfo> workInfo = data.ReadStrongParcelable<WorkInfo>();
41 if (workInfo == nullptr) {
42 WS_HILOGE("workInfo is nullptr");
43 return ERR_TRANSACTION_FAILED;
44 }
45 OnWorkStop(*workInfo);
46 return ERR_NONE;
47 }
48 default:
49 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
50 }
51
52 return ERR_OK;
53 }
54 } // namespace WorkScheduler
55 } // namespace OHOS
56