• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "iremote_stub.h"
22 
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_WORK_THREAD = "NET_POLICY_WORK_THREAD";
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     std::shared_ptr<AppExecFwk::EventRunner> runner_;
41     std::shared_ptr<NetPolicyEventHandler> handler_;
42 
43 private:
44     using NetPolicyServiceFunc = int32_t (NetPolicyServiceStub::*)(MessageParcel &, MessageParcel &);
45 
46 private:
47     void InitEventHandler();
48     int32_t OnSetPolicyByUid(MessageParcel &data, MessageParcel &reply);
49     int32_t OnGetPolicyByUid(MessageParcel &data, MessageParcel &reply);
50     int32_t OnGetUidsByPolicy(MessageParcel &data, MessageParcel &reply);
51     int32_t OnIsUidNetAllowedMetered(MessageParcel &data, MessageParcel &reply);
52     int32_t OnIsUidNetAllowedIfaceName(MessageParcel &data, MessageParcel &reply);
53     int32_t OnRegisterNetPolicyCallback(MessageParcel &data, MessageParcel &reply);
54     int32_t OnUnregisterNetPolicyCallback(MessageParcel &data, MessageParcel &reply);
55     int32_t OnSetNetQuotaPolicies(MessageParcel &data, MessageParcel &reply);
56     int32_t OnGetNetQuotaPolicies(MessageParcel &data, MessageParcel &reply);
57     int32_t OnResetPolicies(MessageParcel &data, MessageParcel &reply);
58     int32_t OnSetBackgroundPolicy(MessageParcel &data, MessageParcel &reply);
59     int32_t OnGetBackgroundPolicy(MessageParcel &data, MessageParcel &reply);
60     int32_t OnGetBackgroundPolicyByUid(MessageParcel &data, MessageParcel &reply);
61     int32_t OnSnoozePolicy(MessageParcel &data, MessageParcel &reply);
62     int32_t OnSetDeviceIdleTrustlist(MessageParcel &data, MessageParcel &reply);
63     int32_t OnGetDeviceIdleTrustlist(MessageParcel &data, MessageParcel &reply);
64     int32_t OnSetDeviceIdlePolicy(MessageParcel &data, MessageParcel &reply);
65     int32_t OnGetPowerSaveTrustlist(MessageParcel &data, MessageParcel &reply);
66     int32_t OnSetPowerSaveTrustlist(MessageParcel &data, MessageParcel &reply);
67     int32_t OnSetPowerSavePolicy(MessageParcel &data, MessageParcel &reply);
68     int32_t OnCheckPermission(MessageParcel &data, MessageParcel &reply);
69     int32_t OnFactoryResetPolicies(MessageParcel &data, MessageParcel &reply);
70 
71 private:
72     std::map<uint32_t, NetPolicyServiceFunc> memberFuncMap_;
73 };
74 } // namespace NetManagerStandard
75 } // namespace OHOS
76 #endif // NET_POLICY_SERVICE_STUB_H
77