• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 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 "sandbox_manager_proxy.h"
17 
18 #include <cstddef>
19 #include <string>
20 #include "iremote_object.h"
21 #include "iremote_proxy.h"
22 #include "message_option.h"
23 #include "message_parcel.h"
24 #include "parcel.h"
25 #include "policy_info_parcel.h"
26 #include "policy_info_vector_parcel.h"
27 #include "sandboxmanager_service_ipc_interface_code.h"
28 #include "sandbox_manager_err_code.h"
29 #include "sandbox_manager_log.h"
30 #include "string_ex.h"
31 
32 namespace OHOS {
33 namespace AccessControl {
34 namespace SandboxManager {
35 namespace {
36 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE,
37     ACCESSCONTROL_DOMAIN_SANDBOXMANAGER, "SandboxManagerProxy"};
38 }
39 
SandboxManagerProxy(const sptr<IRemoteObject> & impl)40 SandboxManagerProxy::SandboxManagerProxy(const sptr<IRemoteObject> &impl)
41     : IRemoteProxy<ISandboxManager>(impl)
42 {}
43 
~SandboxManagerProxy()44 SandboxManagerProxy::~SandboxManagerProxy()
45 {}
46 
SendRequest(SandboxManagerInterfaceCode code,MessageParcel & data,MessageParcel & reply)47 int32_t SandboxManagerProxy::SendRequest(SandboxManagerInterfaceCode code, MessageParcel &data, MessageParcel &reply)
48 {
49     MessageOption option(MessageOption::TF_SYNC);
50     return SendRequest(code, data, reply, option);
51 }
52 
SendRequest(SandboxManagerInterfaceCode code,MessageParcel & data,MessageParcel & reply,MessageOption & option)53 int32_t SandboxManagerProxy::SendRequest(SandboxManagerInterfaceCode code, MessageParcel &data, MessageParcel &reply,
54     MessageOption &option)
55 {
56     sptr<IRemoteObject> remote = Remote();
57     if (remote == nullptr) {
58         SANDBOXMANAGER_LOG_ERROR(LABEL, "remote service null.");
59         return SANDBOX_MANAGER_SERVICE_REMOTE_ERR;
60     }
61     int32_t requestResult = remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
62     if (requestResult != SANDBOX_MANAGER_OK) {
63         SANDBOXMANAGER_LOG_ERROR(LABEL, "request fail, result: %{public}d", requestResult);
64     }
65     return requestResult;
66 }
67 
CleanPersistPolicyByPath(const std::vector<std::string> & filePathList)68 int32_t SandboxManagerProxy::CleanPersistPolicyByPath(const std::vector<std::string>& filePathList)
69 {
70     MessageParcel data;
71     if (!data.WriteInterfaceToken(ISandboxManager::GetDescriptor())) {
72         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write descriptor fail");
73         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
74     }
75 
76     if (!data.WriteStringVector(filePathList)) {
77         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write filePathList failed.");
78         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
79     }
80 
81     MessageParcel reply;
82     MessageOption option(MessageOption::TF_ASYNC);
83     return SendRequest(SandboxManagerInterfaceCode::CLEAN_PERSIST_POLICY_BY_PATH, data, reply, option);
84 }
85 
PersistPolicy(const std::vector<PolicyInfo> & policy,std::vector<uint32_t> & result)86 int32_t SandboxManagerProxy::PersistPolicy(const std::vector<PolicyInfo> &policy, std::vector<uint32_t> &result)
87 {
88     MessageParcel data;
89     if (!data.WriteInterfaceToken(ISandboxManager::GetDescriptor())) {
90         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write descriptor fail");
91         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
92     }
93 
94     PolicyInfoVectorParcel policyInfoVectorParcel;
95     policyInfoVectorParcel.policyVector = policy;
96     if (!data.WriteParcelable(&policyInfoVectorParcel)) {
97         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write policyInfoVectorParcel fail");
98         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
99     }
100 
101     MessageParcel reply;
102     int32_t requestRet = SendRequest(SandboxManagerInterfaceCode::PERSIST_PERMISSION, data, reply);
103     if (requestRet != SANDBOX_MANAGER_OK) {
104         SANDBOXMANAGER_LOG_ERROR(LABEL, "remote fail");
105         return requestRet;
106     }
107 
108     int32_t remoteRet;
109     if (!reply.ReadInt32(remoteRet)) {
110         SANDBOXMANAGER_LOG_ERROR(LABEL, "read ret fail");
111         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
112     }
113 
114     if (remoteRet == SANDBOX_MANAGER_OK && !reply.ReadUInt32Vector(&result)) {
115         SANDBOXMANAGER_LOG_ERROR(LABEL, "read result fail");
116         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
117     }
118     return remoteRet;
119 }
120 
UnPersistPolicy(const std::vector<PolicyInfo> & policy,std::vector<uint32_t> & result)121 int32_t SandboxManagerProxy::UnPersistPolicy(const std::vector<PolicyInfo> &policy, std::vector<uint32_t> &result)
122 {
123     MessageParcel data;
124     if (!data.WriteInterfaceToken(ISandboxManager::GetDescriptor())) {
125         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write descriptor fail");
126         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
127     }
128 
129     PolicyInfoVectorParcel policyInfoVectorParcel;
130     policyInfoVectorParcel.policyVector = policy;
131     if (!data.WriteParcelable(&policyInfoVectorParcel)) {
132         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write policyInfoVectorParcel fail");
133         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
134     }
135 
136     MessageParcel reply;
137     int32_t requestRet = SendRequest(SandboxManagerInterfaceCode::UNPERSIST_PERMISSION, data, reply);
138     if (requestRet != SANDBOX_MANAGER_OK) {
139         SANDBOXMANAGER_LOG_ERROR(LABEL, "remote fail");
140         return requestRet;
141     }
142 
143     int32_t remoteRet;
144     if (!reply.ReadInt32(remoteRet)) {
145         SANDBOXMANAGER_LOG_ERROR(LABEL, "read ret fail");
146         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
147     }
148 
149     if (remoteRet == SANDBOX_MANAGER_OK && !reply.ReadUInt32Vector(&result)) {
150         SANDBOXMANAGER_LOG_ERROR(LABEL, "read result fail");
151         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
152     }
153     return remoteRet;
154 }
155 
PersistPolicyByTokenId(uint32_t tokenId,const std::vector<PolicyInfo> & policy,std::vector<uint32_t> & result)156 int32_t SandboxManagerProxy::PersistPolicyByTokenId(
157     uint32_t tokenId, const std::vector<PolicyInfo> &policy, std::vector<uint32_t> &result)
158 {
159     MessageParcel data;
160     if (!data.WriteInterfaceToken(ISandboxManager::GetDescriptor())) {
161         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write descriptor fail");
162         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
163     }
164     if (!data.WriteUint32(tokenId)) {
165         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write tokenId fail");
166         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
167     }
168 
169     PolicyInfoVectorParcel policyInfoVectorParcel;
170     policyInfoVectorParcel.policyVector = policy;
171     if (!data.WriteParcelable(&policyInfoVectorParcel)) {
172         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write policyInfoVectorParcel fail");
173         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
174     }
175 
176     MessageParcel reply;
177     int32_t requestRet = SendRequest(SandboxManagerInterfaceCode::PERSIST_PERMISSION_BY_TOKENID, data, reply);
178     if (requestRet != SANDBOX_MANAGER_OK) {
179         SANDBOXMANAGER_LOG_ERROR(LABEL, "remote fail");
180         return requestRet;
181     }
182 
183     int32_t remoteRet;
184     if (!reply.ReadInt32(remoteRet)) {
185         SANDBOXMANAGER_LOG_ERROR(LABEL, "read ret fail");
186         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
187     }
188 
189     if (remoteRet == SANDBOX_MANAGER_OK && !reply.ReadUInt32Vector(&result)) {
190         SANDBOXMANAGER_LOG_ERROR(LABEL, "read result fail");
191         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
192     }
193     return remoteRet;
194 }
195 
UnPersistPolicyByTokenId(uint32_t tokenId,const std::vector<PolicyInfo> & policy,std::vector<uint32_t> & result)196 int32_t SandboxManagerProxy::UnPersistPolicyByTokenId(
197     uint32_t tokenId, const std::vector<PolicyInfo> &policy, std::vector<uint32_t> &result)
198 {
199     MessageParcel data;
200     if (!data.WriteInterfaceToken(ISandboxManager::GetDescriptor())) {
201         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write descriptor fail");
202         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
203     }
204     if (!data.WriteUint32(tokenId)) {
205         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write tokenId fail");
206         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
207     }
208     PolicyInfoVectorParcel policyInfoVectorParcel;
209     policyInfoVectorParcel.policyVector = policy;
210     if (!data.WriteParcelable(&policyInfoVectorParcel)) {
211         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write policyInfoVectorParcel fail");
212         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
213     }
214 
215     MessageParcel reply;
216     int32_t requestRet = SendRequest(SandboxManagerInterfaceCode::UNPERSIST_PERMISSION_BY_TOKENID, data, reply);
217     if (requestRet != SANDBOX_MANAGER_OK) {
218         SANDBOXMANAGER_LOG_ERROR(LABEL, "remote fail");
219         return requestRet;
220     }
221 
222     int32_t remoteRet;
223     if (!reply.ReadInt32(remoteRet)) {
224         SANDBOXMANAGER_LOG_ERROR(LABEL, "read ret fail");
225         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
226     }
227 
228     if (remoteRet == SANDBOX_MANAGER_OK && !reply.ReadUInt32Vector(&result)) {
229         SANDBOXMANAGER_LOG_ERROR(LABEL, "read result fail");
230         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
231     }
232     return remoteRet;
233 }
234 
WriteSetPolicyParcel(MessageParcel & data,uint32_t tokenId,const std::vector<PolicyInfo> & policy,uint64_t policyFlag,uint64_t timestamp)235 static bool WriteSetPolicyParcel(MessageParcel &data, uint32_t tokenId, const std::vector<PolicyInfo> &policy,
236                                  uint64_t policyFlag, uint64_t timestamp)
237 {
238     if (!data.WriteInterfaceToken(ISandboxManager::GetDescriptor())) {
239         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write descriptor failed.");
240         return false;
241     }
242     if (!data.WriteUint32(tokenId)) {
243         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write tokenId failed.");
244         return false;
245     }
246     if (!data.WriteUint64(timestamp)) {
247         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write timestamp failed.");
248         return false;
249     }
250 
251     PolicyInfoVectorParcel policyInfoVectorParcel;
252     policyInfoVectorParcel.policyVector = policy;
253     if (!data.WriteParcelable(&policyInfoVectorParcel)) {
254         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write policyInfoVectorParcel failed.");
255         return false;
256     }
257 
258     if (!data.WriteUint64(policyFlag)) {
259         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write policyFlag failed.");
260         return false;
261     }
262     return true;
263 }
264 
SetPolicy(uint32_t tokenId,const std::vector<PolicyInfo> & policy,uint64_t policyFlag,std::vector<uint32_t> & result,uint64_t timestamp)265 int32_t SandboxManagerProxy::SetPolicy(uint32_t tokenId, const std::vector<PolicyInfo> &policy,
266                                        uint64_t policyFlag, std::vector<uint32_t> &result, uint64_t timestamp)
267 {
268     MessageParcel data;
269     if (!WriteSetPolicyParcel(data, tokenId, policy, policyFlag, timestamp)) {
270         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
271     }
272 
273     MessageParcel reply;
274     int32_t requestRet = SendRequest(SandboxManagerInterfaceCode::SET_POLICY, data, reply);
275     if (requestRet != SANDBOX_MANAGER_OK) {
276         return requestRet;
277     }
278 
279     int32_t remoteRet;
280     if (!reply.ReadInt32(remoteRet)) {
281         SANDBOXMANAGER_LOG_ERROR(LABEL, "read ret failed.");
282         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
283     }
284     result.clear();
285     if (remoteRet != SANDBOX_MANAGER_OK) {
286         return remoteRet;
287     }
288     if (!reply.ReadUInt32Vector(&result)) {
289         SANDBOXMANAGER_LOG_ERROR(LABEL, "Read result failed.");
290         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
291     }
292     return remoteRet;
293 }
294 
SetPolicyAsync(uint32_t tokenId,const std::vector<PolicyInfo> & policy,uint64_t policyFlag,uint64_t timestamp)295 int32_t SandboxManagerProxy::SetPolicyAsync(uint32_t tokenId, const std::vector<PolicyInfo> &policy,
296                                             uint64_t policyFlag, uint64_t timestamp)
297 {
298     MessageParcel data;
299     if (!WriteSetPolicyParcel(data, tokenId, policy, policyFlag, timestamp)) {
300         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
301     }
302 
303     MessageParcel reply;
304     MessageOption option(MessageOption::TF_ASYNC);
305     return SendRequest(SandboxManagerInterfaceCode::SET_POLICY_ASYNC, data, reply, option);
306 }
307 
WriteUnSetPolicyParcel(MessageParcel & data,uint32_t tokenId,const PolicyInfo & policy)308 static bool WriteUnSetPolicyParcel(MessageParcel &data, uint32_t tokenId, const PolicyInfo &policy)
309 {
310     if (!data.WriteInterfaceToken(ISandboxManager::GetDescriptor())) {
311         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write descriptor failed.");
312         return false;
313     }
314     if (!data.WriteUint32(tokenId)) {
315         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write tokenId failed.");
316         return false;
317     }
318 
319     PolicyInfoParcel policyInfoParcel;
320     policyInfoParcel.policyInfo = policy;
321     if (!data.WriteParcelable(&policyInfoParcel)) {
322         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write policyInfoParcel failed.");
323         return false;
324     }
325     return true;
326 }
327 
UnSetPolicy(uint32_t tokenId,const PolicyInfo & policy)328 int32_t SandboxManagerProxy::UnSetPolicy(uint32_t tokenId, const PolicyInfo &policy)
329 {
330     MessageParcel data;
331     if (!WriteUnSetPolicyParcel(data, tokenId, policy)) {
332         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
333     }
334 
335     MessageParcel reply;
336     int32_t requestRet = SendRequest(SandboxManagerInterfaceCode::UNSET_POLICY, data, reply);
337     if (requestRet != SANDBOX_MANAGER_OK) {
338         return requestRet;
339     }
340 
341     int32_t remoteRet;
342     if (!reply.ReadInt32(remoteRet)) {
343         SANDBOXMANAGER_LOG_ERROR(LABEL, "Read ret failed.");
344         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
345     }
346     return remoteRet;
347 }
348 
UnSetPolicyAsync(uint32_t tokenId,const PolicyInfo & policy)349 int32_t SandboxManagerProxy::UnSetPolicyAsync(uint32_t tokenId, const PolicyInfo &policy)
350 {
351     MessageParcel data;
352     if (!WriteUnSetPolicyParcel(data, tokenId, policy)) {
353         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
354     }
355 
356     MessageParcel reply;
357     MessageOption option(MessageOption::TF_ASYNC);
358     return SendRequest(SandboxManagerInterfaceCode::UNSET_POLICY_ASYNC, data, reply, option);
359 }
360 
CheckPolicy(uint32_t tokenId,const std::vector<PolicyInfo> & policy,std::vector<bool> & result)361 int32_t SandboxManagerProxy::CheckPolicy(uint32_t tokenId, const std::vector<PolicyInfo> &policy,
362     std::vector<bool> &result)
363 {
364     MessageParcel data;
365     if (!data.WriteInterfaceToken(ISandboxManager::GetDescriptor())) {
366         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write descriptor failed.");
367         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
368     }
369     if (!data.WriteUint32(tokenId)) {
370         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write tokenId failed.");
371         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
372     }
373 
374     PolicyInfoVectorParcel policyInfoVectorParcel;
375     policyInfoVectorParcel.policyVector = policy;
376     if (!data.WriteParcelable(&policyInfoVectorParcel)) {
377         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write policyInfoVectorParcel failed.");
378         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
379     }
380 
381     MessageParcel reply;
382     int32_t requestRet = SendRequest(SandboxManagerInterfaceCode::CHECK_POLICY, data, reply);
383     if (requestRet != SANDBOX_MANAGER_OK) {
384         return requestRet;
385     }
386 
387     int32_t remoteRet;
388     if (!reply.ReadInt32(remoteRet)) {
389         SANDBOXMANAGER_LOG_ERROR(LABEL, "Read ret failed.");
390         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
391     }
392     result.clear();
393     if (remoteRet != SANDBOX_MANAGER_OK) {
394         return remoteRet;
395     }
396     if (!reply.ReadBoolVector(&result)) {
397         SANDBOXMANAGER_LOG_ERROR(LABEL, "Read result failed.");
398         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
399     }
400     return remoteRet;
401 }
402 
StartAccessingPolicy(const std::vector<PolicyInfo> & policy,std::vector<uint32_t> & result,bool useCallerToken,uint32_t tokenId,uint64_t timestamp)403 int32_t SandboxManagerProxy::StartAccessingPolicy(const std::vector<PolicyInfo> &policy, std::vector<uint32_t> &result,
404     bool useCallerToken, uint32_t tokenId, uint64_t timestamp)
405 {
406     MessageParcel data;
407     if (!data.WriteInterfaceToken(ISandboxManager::GetDescriptor())) {
408         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write descriptor fail");
409         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
410     }
411 
412     if (!data.WriteBool(useCallerToken)) {
413         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write useCallerToken failed.");
414         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
415     }
416 
417     if (!data.WriteUint32(tokenId)) {
418         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write tokenId failed.");
419         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
420     }
421 
422     if (!data.WriteUint64(timestamp)) {
423         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write timestamp failed.");
424         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
425     }
426 
427     PolicyInfoVectorParcel policyInfoVectorParcel;
428     policyInfoVectorParcel.policyVector = policy;
429     if (!data.WriteParcelable(&policyInfoVectorParcel)) {
430         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write policyInfoVectorParcel fail");
431         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
432     }
433 
434     MessageParcel reply;
435     int32_t requestRet = SendRequest(SandboxManagerInterfaceCode::START_ACCESSING_URI, data, reply);
436     if (requestRet != SANDBOX_MANAGER_OK) {
437         SANDBOXMANAGER_LOG_ERROR(LABEL, "remote fail");
438         return requestRet;
439     }
440 
441     int32_t remoteRet;
442     if (!reply.ReadInt32(remoteRet)) {
443         SANDBOXMANAGER_LOG_ERROR(LABEL, "read ret fail");
444         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
445     }
446 
447     if (remoteRet == SANDBOX_MANAGER_OK && !reply.ReadUInt32Vector(&result)) {
448         SANDBOXMANAGER_LOG_ERROR(LABEL, "read result fail");
449         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
450     }
451     return remoteRet;
452 }
453 
StopAccessingPolicy(const std::vector<PolicyInfo> & policy,std::vector<uint32_t> & result)454 int32_t SandboxManagerProxy::StopAccessingPolicy(const std::vector<PolicyInfo> &policy, std::vector<uint32_t> &result)
455 {
456     MessageParcel data;
457     if (!data.WriteInterfaceToken(ISandboxManager::GetDescriptor())) {
458         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write descriptor fail");
459         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
460     }
461 
462     PolicyInfoVectorParcel policyInfoVectorParcel;
463     policyInfoVectorParcel.policyVector = policy;
464     if (!data.WriteParcelable(&policyInfoVectorParcel)) {
465         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write policyInfoVectorParcel fail");
466         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
467     }
468 
469     MessageParcel reply;
470     int32_t requestRet = SendRequest(SandboxManagerInterfaceCode::STOP_ACCESSING_URI, data, reply);
471     if (requestRet != SANDBOX_MANAGER_OK) {
472         SANDBOXMANAGER_LOG_ERROR(LABEL, "remote fail");
473         return requestRet;
474     }
475 
476     int32_t remoteRet;
477     if (!reply.ReadInt32(remoteRet)) {
478         SANDBOXMANAGER_LOG_ERROR(LABEL, "read ret fail");
479         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
480     }
481 
482     if (remoteRet == SANDBOX_MANAGER_OK && !reply.ReadUInt32Vector(&result)) {
483         SANDBOXMANAGER_LOG_ERROR(LABEL, "read result fail");
484         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
485     }
486     return remoteRet;
487 }
488 
CheckPersistPolicy(uint32_t tokenId,const std::vector<PolicyInfo> & policy,std::vector<bool> & result)489 int32_t SandboxManagerProxy::CheckPersistPolicy(uint32_t tokenId, const std::vector<PolicyInfo> &policy,
490     std::vector<bool> &result)
491 {
492     MessageParcel data;
493     if (!data.WriteInterfaceToken(ISandboxManager::GetDescriptor())) {
494         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write descriptor fail");
495         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
496     }
497     if (!data.WriteUint32(tokenId)) {
498         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write tokenId fail");
499         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
500     }
501 
502     PolicyInfoVectorParcel policyInfoVectorParcel;
503     policyInfoVectorParcel.policyVector = policy;
504     if (!data.WriteParcelable(&policyInfoVectorParcel)) {
505         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write policyInfoVectorParcel fail");
506         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
507     }
508 
509     MessageParcel reply;
510     int32_t requestRet = SendRequest(SandboxManagerInterfaceCode::CHECK_PERSIST_PERMISSION, data, reply);
511     if (requestRet != SANDBOX_MANAGER_OK) {
512         SANDBOXMANAGER_LOG_ERROR(LABEL, "remote fail");
513         return requestRet;
514     }
515 
516     int32_t remoteRet;
517     if (!reply.ReadInt32(remoteRet)) {
518         SANDBOXMANAGER_LOG_ERROR(LABEL, "read ret fail");
519         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
520     }
521 
522     if (remoteRet == SANDBOX_MANAGER_OK && !reply.ReadBoolVector(&result)) {
523         SANDBOXMANAGER_LOG_ERROR(LABEL, "read result fail");
524         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
525     }
526     return remoteRet;
527 }
528 
StartAccessingByTokenId(uint32_t tokenId,uint64_t timestamp)529 int32_t SandboxManagerProxy::StartAccessingByTokenId(uint32_t tokenId, uint64_t timestamp)
530 {
531     MessageParcel data;
532     if (!data.WriteInterfaceToken(ISandboxManager::GetDescriptor())) {
533         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write descriptor fail.");
534         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
535     }
536     if (!data.WriteUint32(tokenId)) {
537         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write tokenId fail.");
538         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
539     }
540 
541     if (!data.WriteUint64(timestamp)) {
542         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write timestamp fail.");
543         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
544     }
545 
546     MessageParcel reply;
547     MessageOption option(MessageOption::TF_ASYNC);
548     int32_t requestRet = SendRequest(SandboxManagerInterfaceCode::START_ACCESSING_BY_TOKEN, data, reply, option);
549     if (requestRet != SANDBOX_MANAGER_OK) {
550         SANDBOXMANAGER_LOG_ERROR(LABEL, "Remote fail, requestRet = %{public}d.", requestRet);
551         return SANDBOX_MANAGER_SERVICE_REMOTE_ERR;
552     }
553     return SANDBOX_MANAGER_OK;
554 }
555 
UnSetAllPolicyByToken(uint32_t tokenId,uint64_t timestamp)556 int32_t SandboxManagerProxy::UnSetAllPolicyByToken(uint32_t tokenId, uint64_t timestamp)
557 {
558     MessageParcel data;
559     if (!data.WriteInterfaceToken(ISandboxManager::GetDescriptor())) {
560         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write descriptor fail.");
561         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
562     }
563     if (!data.WriteUint32(tokenId)) {
564         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write tokenId fail.");
565         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
566     }
567 
568     if (!data.WriteUint64(timestamp)) {
569         SANDBOXMANAGER_LOG_ERROR(LABEL, "Write timestamp failed.");
570         return SANDBOX_MANAGER_SERVICE_PARCEL_ERR;
571     }
572 
573     MessageParcel reply;
574     MessageOption option(MessageOption::TF_ASYNC);
575     int32_t requestRet = SendRequest(SandboxManagerInterfaceCode::UNSET_ALL_POLICY_BY_TOKEN, data, reply, option);
576     if (requestRet != SANDBOX_MANAGER_OK) {
577         SANDBOXMANAGER_LOG_ERROR(LABEL, "Remote fail, requestRet = %{public}d.", requestRet);
578         return SANDBOX_MANAGER_SERVICE_REMOTE_ERR;
579     }
580     return SANDBOX_MANAGER_OK;
581 }
582 } // namespace SandboxManager
583 } // namespace AccessControl
584 } // namespace OHOS