1 /*
2 * Copyright (c) 2023 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 "standby_service_subscriber_stub.h"
17
18 #include <errors.h>
19 #include <ipc_skeleton.h>
20
21 #include "standby_ipc_interface_code.h"
22 #include "standby_service_log.h"
23
24 namespace OHOS {
25 namespace DevStandbyMgr {
StandbyServiceSubscriberStub()26 StandbyServiceSubscriberStub::StandbyServiceSubscriberStub() {}
~StandbyServiceSubscriberStub()27 StandbyServiceSubscriberStub::~StandbyServiceSubscriberStub() {}
28
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)29 ErrCode StandbyServiceSubscriberStub::OnRemoteRequest(uint32_t code,
30 MessageParcel& data, MessageParcel& reply, MessageOption& option)
31 {
32 std::u16string descriptor = StandbyServiceSubscriberStub::GetDescriptor();
33 std::u16string remoteDescriptor = data.ReadInterfaceToken();
34 if (descriptor != remoteDescriptor) {
35 STANDBYSERVICE_LOGW("StandbyServiceSubscriberStub Local descriptor not match remote.");
36 return ERR_TRANSACTION_FAILED;
37 }
38
39 return OnRemoteRequestInner(code, data, reply, option);
40 }
41
OnRemoteRequestInner(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)42 ErrCode StandbyServiceSubscriberStub::OnRemoteRequestInner(uint32_t code,
43 MessageParcel& data, MessageParcel& reply, MessageOption& option)
44 {
45 switch (code) {
46 case (static_cast<uint32_t>(StandbySubscriberInterfaceCode::ON_DEVICE_IDLE_MODE)): {
47 return HandleOnDeviceIdleMode(data);
48 }
49 case (static_cast<uint32_t>(StandbySubscriberInterfaceCode::ON_ALLOW_LIST_CHANGED)): {
50 return HandleOnAllowListChanged(data);
51 }
52 default:
53 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
54 }
55 return ERR_OK;
56 }
57
OnDeviceIdleMode(bool napped,bool sleeped)58 void StandbyServiceSubscriberStub::OnDeviceIdleMode(bool napped, bool sleeped)
59 {}
60
OnAllowListChanged(int32_t uid,const std::string & name,uint32_t allowType,bool added)61 void StandbyServiceSubscriberStub::OnAllowListChanged(int32_t uid, const std::string& name, uint32_t allowType,
62 bool added)
63 {}
64
HandleOnDeviceIdleMode(MessageParcel & data)65 ErrCode StandbyServiceSubscriberStub::HandleOnDeviceIdleMode(MessageParcel& data)
66 {
67 bool napped {false};
68 bool sleeped {false};
69 if (!data.ReadBool(napped) || !data.ReadBool(sleeped)) {
70 STANDBYSERVICE_LOGW("HandleOnDeviceIdleMode Read parcel failed.");
71 return ERR_INVALID_DATA;
72 }
73 OnDeviceIdleMode(napped, sleeped);
74 return ERR_OK;
75 }
76
HandleOnAllowListChanged(MessageParcel & data)77 ErrCode StandbyServiceSubscriberStub::HandleOnAllowListChanged(MessageParcel& data)
78 {
79 int32_t uid {0};
80 std::string name;
81 uint32_t allowType {0};
82 bool added {false};
83 if (!data.ReadInt32(uid) || !data.ReadString(name) ||
84 !data.ReadUint32(allowType) || !data.ReadBool(added)) {
85 STANDBYSERVICE_LOGW("HandleOnAllowListChanged Read parcel failed.");
86 return ERR_INVALID_DATA;
87 }
88 OnAllowListChanged(uid, name, allowType, added);
89 return ERR_OK;
90 }
91 } // namespace DevStandbyMgr
92 } // namespace OHOS