• 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         default:
58             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
59     }
60     return ERR_OK;
61 }
62 
OnDeviceIdleMode(bool napped,bool sleeped)63 void StandbyServiceSubscriberStub::OnDeviceIdleMode(bool napped, bool sleeped)
64 {}
65 
OnAllowListChanged(int32_t uid,const std::string & name,uint32_t allowType,bool added)66 void StandbyServiceSubscriberStub::OnAllowListChanged(int32_t uid, const std::string& name, uint32_t allowType,
67     bool added)
68 {}
69 
OnRestrictListChanged(int32_t uid,const std::string & name,uint32_t allowType,bool added)70 void StandbyServiceSubscriberStub::OnRestrictListChanged(int32_t uid, const std::string& name, uint32_t allowType,
71     bool added)
72 {}
73 
OnPowerOverused(const std::string & module,uint32_t level)74 void StandbyServiceSubscriberStub::OnPowerOverused(const std::string& module, uint32_t level)
75 {}
76 
HandleOnDeviceIdleMode(MessageParcel & data)77 ErrCode StandbyServiceSubscriberStub::HandleOnDeviceIdleMode(MessageParcel& data)
78 {
79     bool napped {false};
80     bool sleeped {false};
81     if (!data.ReadBool(napped) || !data.ReadBool(sleeped)) {
82         STANDBYSERVICE_LOGW("HandleOnDeviceIdleMode Read parcel failed.");
83         return ERR_INVALID_DATA;
84     }
85     OnDeviceIdleMode(napped, sleeped);
86     return ERR_OK;
87 }
88 
HandleOnAllowListChanged(MessageParcel & data)89 ErrCode StandbyServiceSubscriberStub::HandleOnAllowListChanged(MessageParcel& data)
90 {
91     int32_t uid {0};
92     std::string name;
93     uint32_t allowType {0};
94     bool added {false};
95     if (!data.ReadInt32(uid) || !data.ReadString(name) ||
96         !data.ReadUint32(allowType) || !data.ReadBool(added)) {
97         STANDBYSERVICE_LOGW("HandleOnAllowListChanged Read parcel failed.");
98         return ERR_INVALID_DATA;
99     }
100     OnAllowListChanged(uid, name, allowType, added);
101     return ERR_OK;
102 }
103 
HandleOnRestrictListChanged(MessageParcel & data)104 ErrCode StandbyServiceSubscriberStub::HandleOnRestrictListChanged(MessageParcel& data)
105 {
106     int32_t uid {0};
107     std::string name;
108     uint32_t allowType {0};
109     bool added {false};
110     if (!data.ReadInt32(uid) || !data.ReadString(name) ||
111         !data.ReadUint32(allowType) || !data.ReadBool(added)) {
112         STANDBYSERVICE_LOGW("HandleOnRestrictListChanged Read parcel failed.");
113         return ERR_INVALID_DATA;
114     }
115     OnRestrictListChanged(uid, name, allowType, added);
116     return ERR_OK;
117 }
118 
HandleOnPowerOverused(MessageParcel & data)119 ErrCode StandbyServiceSubscriberStub::HandleOnPowerOverused(MessageParcel& data)
120 {
121     std::string module{""};
122     uint32_t level{0};
123 
124     if (!data.ReadString(module) || !data.ReadUint32(level)) {
125         STANDBYSERVICE_LOGW("HandleOnPowerOverused Read parcel failed.");
126         return ERR_INVALID_DATA;
127     }
128 
129     OnPowerOverused(module, level);
130     return ERR_OK;
131 }
132 
133 }  // namespace DevStandbyMgr
134 }  // namespace OHOS