• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_RESTRICT_LIST_CHANGED)): {
52             return HandleOnRestrictListChanged(data);
53         }
54         case (static_cast<uint32_t>(StandbySubscriberInterfaceCode::ON_POWER_OVERUSED)): {
55             return HandleOnPowerOverused(data);
56         }
57         case (static_cast<uint32_t>(StandbySubscriberInterfaceCode::ON_ACTION_CHANGED)): {
58             return HandleOnActionChanged(data);
59         }
60         default:
61             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
62     }
63     return ERR_OK;
64 }
65 
OnDeviceIdleMode(bool napped,bool sleeped)66 void StandbyServiceSubscriberStub::OnDeviceIdleMode(bool napped, bool sleeped)
67 {}
68 
OnAllowListChanged(int32_t uid,const std::string & name,uint32_t allowType,bool added)69 void StandbyServiceSubscriberStub::OnAllowListChanged(int32_t uid, const std::string& name, uint32_t allowType,
70     bool added)
71 {}
72 
OnRestrictListChanged(int32_t uid,const std::string & name,uint32_t allowType,bool added)73 void StandbyServiceSubscriberStub::OnRestrictListChanged(int32_t uid, const std::string& name, uint32_t allowType,
74     bool added)
75 {}
76 
OnPowerOverused(const std::string & module,uint32_t level)77 void StandbyServiceSubscriberStub::OnPowerOverused(const std::string& module, uint32_t level)
78 {}
79 
OnActionChanged(const std::string & module,uint32_t action)80 void StandbyServiceSubscriberStub::OnActionChanged(const std::string& module, uint32_t action)
81 {}
82 
HandleOnDeviceIdleMode(MessageParcel & data)83 ErrCode StandbyServiceSubscriberStub::HandleOnDeviceIdleMode(MessageParcel& data)
84 {
85     bool napped {false};
86     bool sleeped {false};
87     if (!data.ReadBool(napped) || !data.ReadBool(sleeped)) {
88         STANDBYSERVICE_LOGW("HandleOnDeviceIdleMode Read parcel failed.");
89         return ERR_INVALID_DATA;
90     }
91     OnDeviceIdleMode(napped, sleeped);
92     return ERR_OK;
93 }
94 
HandleOnAllowListChanged(MessageParcel & data)95 ErrCode StandbyServiceSubscriberStub::HandleOnAllowListChanged(MessageParcel& data)
96 {
97     int32_t uid {0};
98     std::string name;
99     uint32_t allowType {0};
100     bool added {false};
101     if (!data.ReadInt32(uid) || !data.ReadString(name) ||
102         !data.ReadUint32(allowType) || !data.ReadBool(added)) {
103         STANDBYSERVICE_LOGW("HandleOnAllowListChanged Read parcel failed.");
104         return ERR_INVALID_DATA;
105     }
106     OnAllowListChanged(uid, name, allowType, added);
107     return ERR_OK;
108 }
109 
HandleOnRestrictListChanged(MessageParcel & data)110 ErrCode StandbyServiceSubscriberStub::HandleOnRestrictListChanged(MessageParcel& data)
111 {
112     int32_t uid {0};
113     std::string name;
114     uint32_t allowType {0};
115     bool added {false};
116     if (!data.ReadInt32(uid) || !data.ReadString(name) ||
117         !data.ReadUint32(allowType) || !data.ReadBool(added)) {
118         STANDBYSERVICE_LOGW("HandleOnRestrictListChanged Read parcel failed.");
119         return ERR_INVALID_DATA;
120     }
121     OnRestrictListChanged(uid, name, allowType, added);
122     return ERR_OK;
123 }
124 
HandleOnPowerOverused(MessageParcel & data)125 ErrCode StandbyServiceSubscriberStub::HandleOnPowerOverused(MessageParcel& data)
126 {
127     std::string module{""};
128     uint32_t level{0};
129 
130     if (!data.ReadString(module) || !data.ReadUint32(level)) {
131         STANDBYSERVICE_LOGW("HandleOnPowerOverused Read parcel failed.");
132         return ERR_INVALID_DATA;
133     }
134 
135     OnPowerOverused(module, level);
136     return ERR_OK;
137 }
138 
HandleOnActionChanged(MessageParcel & data)139 ErrCode StandbyServiceSubscriberStub::HandleOnActionChanged(MessageParcel& data)
140 {
141     std::string module{""};
142     uint32_t action{0};
143 
144     if (!data.ReadString(module) || !data.ReadUint32(action)) {
145         STANDBYSERVICE_LOGW("HandleOnActionChanged Read parcel failed.");
146         return ERR_INVALID_DATA;
147     }
148 
149     OnActionChanged(module, action);
150     return ERR_OK;
151 }
152 
153 }  // namespace DevStandbyMgr
154 }  // namespace OHOS