1 /*
2 * Copyright (c) 2022 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 "uri_permission_manager_stub.h"
17
18 #include "hilog_wrapper.h"
19
20 namespace OHOS {
21 namespace AAFwk {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)22 int UriPermissionManagerStub::OnRemoteRequest(
23 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
24 {
25 if (data.ReadInterfaceToken() != IUriPermissionManager::GetDescriptor()) {
26 HILOG_ERROR("InterfaceToken not equal IUriPermissionManager's descriptor.");
27 return ERR_INVALID_VALUE;
28 }
29 ErrCode errCode = ERR_OK;
30 switch (code) {
31 case UriPermMgrCmd::ON_GRANT_URI_PERMISSION : {
32 std::unique_ptr<Uri> uri(data.ReadParcelable<Uri>());
33 if (!uri) {
34 errCode = ERR_DEAD_OBJECT;
35 HILOG_ERROR("To read uri failed.");
36 break;
37 }
38 auto flag = data.ReadInt32();
39 auto fromTokenId = data.ReadInt32();
40 auto targetTokenId = data.ReadInt32();
41 auto ret = GrantUriPermission(*uri, flag, fromTokenId, targetTokenId);
42 reply.WriteBool(ret);
43 break;
44 }
45 case UriPermMgrCmd::ON_VERIFY_URI_PERMISSION : {
46 std::unique_ptr<Uri> uri(data.ReadParcelable<Uri>());
47 if (!uri) {
48 errCode = ERR_DEAD_OBJECT;
49 HILOG_ERROR("To read uri failed.");
50 break;
51 }
52 auto flag = data.ReadInt32();
53 auto tokenId = data.ReadInt32();
54 if (!VerifyUriPermission(*uri, flag, tokenId)) {
55 errCode = ERR_INVALID_OPERATION;
56 HILOG_ERROR("To check uri permission failed.");
57 }
58 break;
59 }
60 case UriPermMgrCmd::ON_REMOVE_URI_PERMISSION : {
61 auto tokenId = data.ReadInt32();
62 RemoveUriPermission(tokenId);
63 break;
64 }
65 default:
66 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
67 }
68 return errCode;
69 }
70 } // namespace AAFwk
71 } // namespace OHOS
72