1 /*
2 * Copyright (c) 2024-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_manager_proxy.h"
17
18 #include "edm_constants.h"
19 #include "edm_log.h"
20 #include "func_code.h"
21 #include "message_parcel_utils.h"
22
23 namespace OHOS {
24 namespace EDM {
25 std::shared_ptr<TelephonyManagerProxy> TelephonyManagerProxy::instance_ = nullptr;
26 std::once_flag TelephonyManagerProxy::flag_;
27 const std::u16string DESCRIPTOR = u"ohos.edm.IEnterpriseDeviceMgr";
28
TelephonyManagerProxy()29 TelephonyManagerProxy::TelephonyManagerProxy() {}
30
~TelephonyManagerProxy()31 TelephonyManagerProxy::~TelephonyManagerProxy() {}
32
GetTelephonyManagerProxy()33 std::shared_ptr<TelephonyManagerProxy> TelephonyManagerProxy::GetTelephonyManagerProxy()
34 {
35 std::call_once(flag_, []() {
36 if (instance_ == nullptr) {
37 instance_ = std::make_shared<TelephonyManagerProxy>();
38 }
39 });
40 return instance_;
41 }
42
SetSimDisabled(MessageParcel & data)43 int32_t TelephonyManagerProxy::SetSimDisabled(MessageParcel &data)
44 {
45 EDMLOGD("TelephonyManagerProxy::SetSimDisabled.");
46 std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::DISALLOWED_SIM);
47 return EnterpriseDeviceMgrProxy::GetInstance()->HandleDevicePolicy(funcCode, data);
48 }
49
SetSimEnabled(MessageParcel & data)50 int32_t TelephonyManagerProxy::SetSimEnabled(MessageParcel &data)
51 {
52 EDMLOGD("TelephonyManagerProxy::SetSimEnabled.");
53 std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::REMOVE, EdmInterfaceCode::DISALLOWED_SIM);
54 return EnterpriseDeviceMgrProxy::GetInstance()->HandleDevicePolicy(funcCode, data);
55 }
56
IsSimDisabled(MessageParcel & data,bool & result)57 int32_t TelephonyManagerProxy::IsSimDisabled(MessageParcel &data, bool &result)
58 {
59 EDMLOGD("TelephonyManagerProxy::IsSimDisabled");
60 MessageParcel reply;
61 EnterpriseDeviceMgrProxy::GetInstance()->GetPolicy(EdmInterfaceCode::DISALLOWED_SIM, data, reply);
62 int32_t ret = ERR_INVALID_VALUE;
63 bool isSuccess = reply.ReadInt32(ret) && (ret == ERR_OK);
64 if (!isSuccess) {
65 EDMLOGE("IsSimDisabled:GetPolicy fail. %{public}d", ret);
66 return ret;
67 }
68 reply.ReadBool(result);
69 return ERR_OK;
70 }
71
AddCallPolicyNumbers(const AppExecFwk::ElementName & admin,const std::string & callType,const int32_t policyFlag,const std::vector<std::string> & numbers)72 int32_t TelephonyManagerProxy::AddCallPolicyNumbers(const AppExecFwk::ElementName &admin,
73 const std::string &callType, const int32_t policyFlag, const std::vector<std::string> &numbers)
74 {
75 EDMLOGD("TelephonyManagerProxy::AddCallPolicyNumbers.");
76 MessageParcel data;
77 data.WriteInterfaceToken(DESCRIPTOR);
78 data.WriteInt32(WITHOUT_USERID);
79 data.WriteParcelable(&admin);
80 data.WriteString(WITHOUT_PERMISSION_TAG);
81 data.WriteString(callType);
82 data.WriteInt32(policyFlag);
83 if (numbers.size() > EdmConstants::CallPolicy::NUMBER_LIST_MAX_SIZE) {
84 return ERR_INVALID_VALUE;
85 }
86 data.WriteStringVector(numbers);
87 std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET,
88 EdmInterfaceCode::TELEPHONY_CALL_POLICY);
89 return EnterpriseDeviceMgrProxy::GetInstance()->HandleDevicePolicy(funcCode, data);
90 }
91
RemoveCallPolicyNumbers(const AppExecFwk::ElementName & admin,const std::string & callType,const int32_t policyFlag,const std::vector<std::string> & numbers)92 int32_t TelephonyManagerProxy::RemoveCallPolicyNumbers(const AppExecFwk::ElementName &admin,
93 const std::string &callType, const int32_t policyFlag, const std::vector<std::string> &numbers)
94 {
95 EDMLOGD("TelephonyManagerProxy::RemoveCallPolicyNumbers.");
96 MessageParcel data;
97 data.WriteInterfaceToken(DESCRIPTOR);
98 data.WriteInt32(WITHOUT_USERID);
99 data.WriteParcelable(&admin);
100 data.WriteString(WITHOUT_PERMISSION_TAG);
101 data.WriteString(callType);
102 data.WriteInt32(policyFlag);
103 if (numbers.size() > EdmConstants::CallPolicy::NUMBER_LIST_MAX_SIZE) {
104 return ERR_INVALID_VALUE;
105 }
106 data.WriteStringVector(numbers);
107 std::uint32_t funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::REMOVE,
108 EdmInterfaceCode::TELEPHONY_CALL_POLICY);
109 return EnterpriseDeviceMgrProxy::GetInstance()->HandleDevicePolicy(funcCode, data);
110 }
111
GetCallPolicyNumbers(const AppExecFwk::ElementName & admin,const std::string & callType,const int32_t policyFlag,std::vector<std::string> & numbers)112 int32_t TelephonyManagerProxy::GetCallPolicyNumbers(const AppExecFwk::ElementName &admin,
113 const std::string &callType, const int32_t policyFlag, std::vector<std::string> &numbers)
114 {
115 EDMLOGD("TelephonyManagerProxy::GetCallPolicyNumbers.");
116 MessageParcel data;
117 MessageParcel reply;
118 data.WriteInterfaceToken(DESCRIPTOR);
119 data.WriteInt32(WITHOUT_USERID);
120 data.WriteString(WITHOUT_PERMISSION_TAG);
121 data.WriteInt32(HAS_ADMIN);
122 data.WriteParcelable(&admin);
123 data.WriteString(callType);
124 data.WriteInt32(policyFlag);
125
126 EnterpriseDeviceMgrProxy::GetInstance()->GetPolicy(EdmInterfaceCode::TELEPHONY_CALL_POLICY, data, reply);
127 int32_t ret = ERR_INVALID_VALUE;
128 bool blRes = reply.ReadInt32(ret) && (ret == ERR_OK);
129 if (!blRes) {
130 EDMLOGE("EnterpriseDeviceMgrProxy:GetCallPolicyNumbers fail. %{public}d", ret);
131 return ret;
132 }
133 reply.ReadStringVector(&numbers);
134 EDMLOGD("EnterpriseDeviceMgrProxy:GetCallPolicyNumbers success");
135 return ERR_OK;
136 }
137 } // namespace EDM
138 } // namespace OHOS
139