1 /*
2  * Copyright (c) 2021-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 "test_ondemand_ability_stub.h"
17 
18 #include "ipc_object_stub.h"
19 #include "ipc_types.h"
20 #include "message_option.h"
21 #include "message_parcel.h"
22 
23 using namespace OHOS::HiviewDFX;
24 
25 namespace OHOS {
OnRemoteRequest(uint32_t cmd,MessageParcel & data,MessageParcel & reply,MessageOption & option)26 int32_t TestOnDemandAbilityStub::OnRemoteRequest(uint32_t cmd,
27     MessageParcel& data, MessageParcel& reply, MessageOption& option)
28 {
29     HiLog::Info(label_, "TestOnDemandAbilityStub::OnReceived, cmd = %{public}u, flags= %{public}d",
30         cmd, option.GetFlags());
31     switch (cmd) {
32         case ADD_VOLUME: {
33             int32_t num = 0;
34             bool ret = data.ReadInt32(num);
35             if (!ret) {
36                 HiLog::Error(label_, "TestOnDemandAbilityStub::AddVolume read requestCode failed!");
37                 return ERR_FLATTEN_OBJECT;
38             }
39             ret = reply.WriteInt32(AddVolume(num));
40             if (!ret) {
41                 HiLog::Error(label_, "TestOnDemandAbilityStub:AddVolume write reply failed.");
42                 return ERR_FLATTEN_OBJECT;
43             }
44 
45             return ret;
46         }
47 
48         default:
49             return IPCObjectStub::OnRemoteRequest(cmd, data, reply, option);
50     }
51 }
52 }