1 /*
2  * Copyright (c) 2021 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_proxy.h"
17 
18 #include "errors.h"
19 #include "ipc_types.h"
20 #include "iremote_object.h"
21 #include "message_option.h"
22 #include "message_parcel.h"
23 
24 using namespace OHOS::HiviewDFX;
25 
26 namespace OHOS {
AddVolume(int volume)27 int TestOnDemandAbilityProxy::AddVolume(int volume)
28 {
29     HiLog::Info(label_, "%{public}s called, volume = %{public}d", __func__, volume);
30 
31     auto remote = Remote();
32     if (remote == nullptr) {
33         HiLog::Error(label_, "AddVolume remote is NULL !");
34         return ERR_FLATTEN_OBJECT;
35     }
36 
37     MessageParcel data;
38     int32_t result = 0;
39     bool ret = data.WriteInt32(volume);
40     if (!ret) {
41         HiLog::Error(label_, "AddVolume parcel write volume failed");
42         return ERR_FLATTEN_OBJECT;
43     }
44 
45     MessageParcel reply;
46     MessageOption option;
47     int32_t res = remote->SendRequest(ADD_VOLUME, data, reply, option);
48     if (res != ERR_OK) {
49         HiLog::Error(label_, "AddVolume Transact error:%{public}d!", res);
50         return ERR_FLATTEN_OBJECT;
51     }
52 
53     ret = reply.ReadInt32(result);
54     if (!ret) {
55         HiLog::Error(label_, "AddVolume parcel read volume failed");
56         return ERR_FLATTEN_OBJECT;
57     }
58     HiLog::Info(label_, "%{public}s:finish = %{public}d", __func__, result);
59     return result;
60 }
61 }
62