1 /* 2 * Copyright (c) 2021-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 #ifndef NET_POLICY_SERVICE_STUB_H 17 #define NET_POLICY_SERVICE_STUB_H 18 19 #include <map> 20 21 #include "ffrt.h" 22 #include "iremote_stub.h" 23 #include "i_net_policy_service.h" 24 #include "net_policy_event_handler.h" 25 26 namespace OHOS { 27 namespace NetManagerStandard { 28 constexpr const char *NET_POLICY_STUB_QUEUE = "NET_POLICY_STUB_QUEUE"; 29 30 class NetPolicyServiceStub : public IRemoteStub<INetPolicyService> { 31 public: 32 NetPolicyServiceStub(); 33 ~NetPolicyServiceStub(); 34 35 int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; 36 37 protected: 38 bool SubCheckPermission(const std::string &permission, uint32_t funcCode); 39 int32_t CheckPolicyPermission(uint32_t funcCode); 40 41 ffrt::queue ffrtQueue_; 42 std::shared_ptr<NetPolicyEventHandler> handler_; 43 44 private: 45 using NetPolicyServiceFunc = int32_t (NetPolicyServiceStub::*)(MessageParcel &, MessageParcel &); 46 47 private: 48 void InitEventHandler(); 49 void ExtraNetPolicyServiceStub(); 50 int32_t OnSetPolicyByUid(MessageParcel &data, MessageParcel &reply); 51 int32_t OnGetPolicyByUid(MessageParcel &data, MessageParcel &reply); 52 int32_t OnGetUidsByPolicy(MessageParcel &data, MessageParcel &reply); 53 int32_t OnIsUidNetAllowedMetered(MessageParcel &data, MessageParcel &reply); 54 int32_t OnIsUidNetAllowedIfaceName(MessageParcel &data, MessageParcel &reply); 55 int32_t OnRegisterNetPolicyCallback(MessageParcel &data, MessageParcel &reply); 56 int32_t OnUnregisterNetPolicyCallback(MessageParcel &data, MessageParcel &reply); 57 int32_t OnSetNetQuotaPolicies(MessageParcel &data, MessageParcel &reply); 58 int32_t OnGetNetQuotaPolicies(MessageParcel &data, MessageParcel &reply); 59 int32_t OnResetPolicies(MessageParcel &data, MessageParcel &reply); 60 int32_t OnSetBackgroundPolicy(MessageParcel &data, MessageParcel &reply); 61 int32_t OnGetBackgroundPolicy(MessageParcel &data, MessageParcel &reply); 62 int32_t OnGetBackgroundPolicyByUid(MessageParcel &data, MessageParcel &reply); 63 int32_t OnSnoozePolicy(MessageParcel &data, MessageParcel &reply); 64 int32_t OnSetDeviceIdleTrustlist(MessageParcel &data, MessageParcel &reply); 65 int32_t OnGetDeviceIdleTrustlist(MessageParcel &data, MessageParcel &reply); 66 int32_t OnSetDeviceIdlePolicy(MessageParcel &data, MessageParcel &reply); 67 int32_t OnGetPowerSaveTrustlist(MessageParcel &data, MessageParcel &reply); 68 int32_t OnSetPowerSaveTrustlist(MessageParcel &data, MessageParcel &reply); 69 int32_t OnSetPowerSavePolicy(MessageParcel &data, MessageParcel &reply); 70 int32_t OnCheckPermission(MessageParcel &data, MessageParcel &reply); 71 int32_t OnFactoryResetPolicies(MessageParcel &data, MessageParcel &reply); 72 int32_t OnSetNetworkAccessPolicy(MessageParcel &data, MessageParcel &reply); 73 int32_t OnGetNetworkAccessPolicy(MessageParcel &data, MessageParcel &reply); 74 int32_t OnNotifyNetAccessPolicyDiag(MessageParcel &data, MessageParcel &reply); 75 int32_t OnSetNicTrafficAllowed(MessageParcel &data, MessageParcel &reply); 76 77 private: 78 std::map<uint32_t, NetPolicyServiceFunc> memberFuncMap_; 79 std::once_flag onceFlag; 80 }; 81 } // namespace NetManagerStandard 82 } // namespace OHOS 83 #endif // NET_POLICY_SERVICE_STUB_H 84