1 /*
2 * Copyright (C) 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 #define MLOG_TAG "MediaToolPermissionHandler"
17
18 #include "media_tool_permission_handler.h"
19 #include "mediatool_uri.h"
20
21 namespace OHOS::Media {
22
IsMediaToolOperation(MediaLibraryCommand & cmd,PermParam & permParam)23 static bool IsMediaToolOperation(MediaLibraryCommand &cmd, PermParam &permParam)
24 {
25 if (permParam.isOpenFile) {
26 return cmd.GetQuerySetParam(IS_TOOL_OPEN) == TOOL_OPEN_TRUE;
27 }
28 return IsMediatoolOperation(cmd);
29 }
30
UnifyOprnObject(MediaLibraryCommand & cmd)31 static void UnifyOprnObject(MediaLibraryCommand &cmd)
32 {
33 static const std::unordered_map<OperationObject, OperationObject> UNIFY_OP_OBJECT_MAP = {
34 { OperationObject::TOOL_PHOTO, OperationObject::FILESYSTEM_PHOTO },
35 { OperationObject::TOOL_AUDIO, OperationObject::FILESYSTEM_AUDIO },
36 { OperationObject::TOOL_ALBUM, OperationObject::PHOTO_ALBUM },
37 };
38
39 OperationObject obj = cmd.GetOprnObject();
40 if (UNIFY_OP_OBJECT_MAP.find(obj) != UNIFY_OP_OBJECT_MAP.end()) {
41 cmd.SetOprnObject(UNIFY_OP_OBJECT_MAP.at(obj));
42 }
43 }
44
ExecuteCheckPermission(MediaLibraryCommand & cmd,PermParam & permParam)45 int32_t MediaToolPermissionHandler::ExecuteCheckPermission(MediaLibraryCommand &cmd, PermParam &permParam)
46 {
47 MEDIA_DEBUG_LOG("MediaToolPermissionHandler enter");
48 if (IsMediaToolOperation(cmd, permParam)) {
49 // 转换tooloperation
50 UnifyOprnObject(cmd);
51 return ConvertPermResult(IsDeveloperMediaTool(cmd, permParam.openFileNode));
52 } else {
53 return E_PERMISSION_DENIED;
54 }
55 }
56
57 } // namespace name