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 "PermissionHandlerCommon" 17 18 #include "permission_common.h" 19 20 #include <cstdlib> 21 22 #include "medialibrary_bundle_manager.h" 23 #include "medialibrary_operation.h" 24 #include "parameters.h" 25 #include "permission_utils.h" 26 27 using namespace std; 28 29 namespace OHOS::Media { 30 GetClientAppId()31string GetClientAppId() 32 { 33 string bundleName = MediaLibraryBundleManager::GetInstance()->GetClientBundleName(); 34 return PermissionUtils::GetAppIdByBundleName(bundleName); 35 } 36 IsMediatoolOperation(MediaLibraryCommand & cmd)37bool IsMediatoolOperation(MediaLibraryCommand &cmd) 38 { 39 return cmd.GetOprnObject() == OperationObject::TOOL_PHOTO || cmd.GetOprnObject() == OperationObject::TOOL_AUDIO || 40 cmd.GetOprnObject() == OperationObject::TOOL_ALBUM || cmd.GetOprnType() == Media::OperationType::DELETE_TOOL; 41 } 42 IsDeveloperMediaTool(MediaLibraryCommand & cmd)43bool IsDeveloperMediaTool(MediaLibraryCommand &cmd) 44 { 45 if (!PermissionUtils::IsRootShell() && 46 !(PermissionUtils::IsHdcShell() && cmd.GetOprnType() == Media::OperationType::TOOL_QUERY_BY_DISPLAY_NAME)) { 47 MEDIA_ERR_LOG("Mediatool permission check failed: target is not root"); 48 return false; 49 } 50 if (!OHOS::system::GetBoolParameter("const.security.developermode.state", true)) { 51 MEDIA_ERR_LOG("Mediatool permission check failed: target is not in developer mode"); 52 return false; 53 } 54 return true; 55 } 56 ConvertPermResult(bool isPermSuccess)57int32_t ConvertPermResult(bool isPermSuccess) 58 { 59 return isPermSuccess ? E_SUCCESS : E_PERMISSION_DENIED; 60 } 61 62 } // namespace name 63 64