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() {}
27
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)28 ErrCode StandbyServiceSubscriberStub::OnRemoteRequest(uint32_t code,
29 MessageParcel& data, MessageParcel& reply, MessageOption& option)
30 {
31 std::u16string descriptor = StandbyServiceSubscriberStub::GetDescriptor();
32 std::u16string remoteDescriptor = data.ReadInterfaceToken();
33 if (descriptor != remoteDescriptor) {
34 STANDBYSERVICE_LOGW("StandbyServiceSubscriberStub Local descriptor not match remote.");
35 return ERR_TRANSACTION_FAILED;
36 }
37
38 return OnRemoteRequestInner(code, data, reply, option);
39 }
40
OnRemoteRequestInner(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)41 ErrCode StandbyServiceSubscriberStub::OnRemoteRequestInner(uint32_t code,
42 MessageParcel& data, MessageParcel& reply, MessageOption& option)
43 {
44 switch (code) {
45 case (static_cast<uint32_t>(StandbySubscriberInterfaceCode::ON_DEVICE_IDLE_MODE)): {
46 return HandleOnDeviceIdleMode(data);
47 }
48 case (static_cast<uint32_t>(StandbySubscriberInterfaceCode::ON_ALLOW_LIST_CHANGED)): {
49 return HandleOnAllowListChanged(data);
50 }
51 case (static_cast<uint32_t>(StandbySubscriberInterfaceCode::ON_POWER_OVERUSED)): {
52 return HandleOnPowerOverused(data);
53 }
54 default:
55 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
56 }
57 return ERR_OK;
58 }
59
OnDeviceIdleMode(bool napped,bool sleeped)60 void StandbyServiceSubscriberStub::OnDeviceIdleMode(bool napped, bool sleeped)
61 {}
62
OnAllowListChanged(int32_t uid,const std::string & name,uint32_t allowType,bool added)63 void StandbyServiceSubscriberStub::OnAllowListChanged(int32_t uid, const std::string& name, uint32_t allowType,
64 bool added)
65 {}
66
OnPowerOverused(const std::string & module,uint32_t level)67 void StandbyServiceSubscriberStub::OnPowerOverused(const std::string& module, uint32_t level)
68 {}
69
HandleOnDeviceIdleMode(MessageParcel & data)70 ErrCode StandbyServiceSubscriberStub::HandleOnDeviceIdleMode(MessageParcel& data)
71 {
72 bool napped {false};
73 bool sleeped {false};
74 if (!data.ReadBool(napped) || !data.ReadBool(sleeped)) {
75 STANDBYSERVICE_LOGW("HandleOnDeviceIdleMode Read parcel failed.");
76 return ERR_INVALID_DATA;
77 }
78 OnDeviceIdleMode(napped, sleeped);
79 return ERR_OK;
80 }
81
HandleOnAllowListChanged(MessageParcel & data)82 ErrCode StandbyServiceSubscriberStub::HandleOnAllowListChanged(MessageParcel& data)
83 {
84 int32_t uid {0};
85 std::string name;
86 uint32_t allowType {0};
87 bool added {false};
88 if (!data.ReadInt32(uid) || !data.ReadString(name) ||
89 !data.ReadUint32(allowType) || !data.ReadBool(added)) {
90 STANDBYSERVICE_LOGW("HandleOnAllowListChanged Read parcel failed.");
91 return ERR_INVALID_DATA;
92 }
93 OnAllowListChanged(uid, name, allowType, added);
94 return ERR_OK;
95 }
96
HandleOnPowerOverused(MessageParcel & data)97 ErrCode StandbyServiceSubscriberStub::HandleOnPowerOverused(MessageParcel& data)
98 {
99 std::string module{""};
100 uint32_t level{0};
101
102 if (!data.ReadString(module) || !data.ReadUint32(level)) {
103 STANDBYSERVICE_LOGW("HandleOnPowerOverused Read parcel failed.");
104 return ERR_INVALID_DATA;
105 }
106
107 OnPowerOverused(module, level);
108 return ERR_OK;
109 }
110
111 } // namespace DevStandbyMgr
112 } // namespace OHOS