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