• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "telephony_call_policy_query.h"
17 
18 #include "telephony_call_policy_serializer.h"
19 #include "edm_log.h"
20 
21 namespace OHOS {
22 namespace EDM {
GetPolicyName()23 std::string TelephonyCallPolicyQuery::GetPolicyName()
24 {
25     return PolicyName::POLICY_TELEPHONY_CALL_POLICY;
26 }
27 
GetPermission(IPlugin::PermissionType,const std::string & permissionTag)28 std::string TelephonyCallPolicyQuery::GetPermission(IPlugin::PermissionType, const std::string &permissionTag)
29 {
30     return EdmPermission::PERMISSION_ENTERPRISE_MANAGE_TELEPHONY;
31 }
32 
QueryPolicy(std::string & policyData,MessageParcel & data,MessageParcel & reply,int32_t userId)33 ErrCode TelephonyCallPolicyQuery::QueryPolicy(std::string &policyData, MessageParcel &data, MessageParcel &reply,
34     int32_t userId)
35 {
36     const std::string callType = data.ReadString();
37     const int32_t flag = data.ReadInt32();
38     EDMLOGI("TelephonyCallPolicyPlugin::OnGetPolicy callType:%{public}s, flag:%{public}d", callType.c_str(), flag);
39 
40     auto serializer = TelephonyCallPolicySerializer::GetInstance();
41     std::map<std::string, TelephonyCallPolicyType> policies;
42     if (!serializer->Deserialize(policyData, policies)) {
43         EDMLOGE("TelephonyCallPolicyPlugin::OnGetPolicy Deserialize fail");
44         return EdmReturnErrCode::SYSTEM_ABNORMALLY;
45     }
46     reply.WriteInt32(ERR_OK);
47     int32_t size = 0;
48     auto it = policies.find(callType);
49     if (it == policies.end()) {
50         reply.WriteInt32(size);
51     } else {
52         if (flag == it->second.policyFlag) {
53             reply.WriteStringVector(it->second.numberList);
54         } else {
55             reply.WriteInt32(size);
56         }
57     }
58     return ERR_OK;
59 }
60 } // namespace EDM
61 } // namespace OHOS