13e5483f6Sopenharmony_ci/* 23e5483f6Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 33e5483f6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 43e5483f6Sopenharmony_ci * you may not use this file except in compliance with the License. 53e5483f6Sopenharmony_ci * You may obtain a copy of the License at 63e5483f6Sopenharmony_ci * 73e5483f6Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 83e5483f6Sopenharmony_ci * 93e5483f6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 103e5483f6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 113e5483f6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 123e5483f6Sopenharmony_ci * See the License for the specific language governing permissions and 133e5483f6Sopenharmony_ci * limitations under the License. 143e5483f6Sopenharmony_ci */ 153e5483f6Sopenharmony_ci#define MLOG_TAG "RingtonePrivacyManager" 163e5483f6Sopenharmony_ci 173e5483f6Sopenharmony_ci#include "ringtone_privacy_manager.h" 183e5483f6Sopenharmony_ci 193e5483f6Sopenharmony_ci#include "ringtone_errno.h" 203e5483f6Sopenharmony_ci#include "ringtone_file_utils.h" 213e5483f6Sopenharmony_ci#include "ringtone_log.h" 223e5483f6Sopenharmony_ci#include "ringtone_type.h" 233e5483f6Sopenharmony_ci 243e5483f6Sopenharmony_cinamespace OHOS { 253e5483f6Sopenharmony_cinamespace Media { 263e5483f6Sopenharmony_ciusing namespace std; 273e5483f6Sopenharmony_ciusing PrivacyRanges = vector<pair<uint32_t, uint32_t>>; 283e5483f6Sopenharmony_ciRingtonePrivacyManager::RingtonePrivacyManager(const string &path, const string &mode) : path_(path), mode_(mode) 293e5483f6Sopenharmony_ci{} 303e5483f6Sopenharmony_ci 313e5483f6Sopenharmony_ciRingtonePrivacyManager::~RingtonePrivacyManager() 323e5483f6Sopenharmony_ci{} 333e5483f6Sopenharmony_ci 343e5483f6Sopenharmony_ciconst vector<string> EXIF_SUPPORTED_EXTENSION = { 353e5483f6Sopenharmony_ci RINGTONE_CONTAINER_TYPE_MP3, 363e5483f6Sopenharmony_ci RINGTONE_CONTAINER_TYPE_OGG 373e5483f6Sopenharmony_ci}; 383e5483f6Sopenharmony_ci 393e5483f6Sopenharmony_cistatic bool IsTargetExtension(const string &path) 403e5483f6Sopenharmony_ci{ 413e5483f6Sopenharmony_ci const string ext = RingtoneFileUtils::GetExtensionFromPath(path); 423e5483f6Sopenharmony_ci bool ret = find(EXIF_SUPPORTED_EXTENSION.begin(), EXIF_SUPPORTED_EXTENSION.end(), ext) != 433e5483f6Sopenharmony_ci EXIF_SUPPORTED_EXTENSION.end(); 443e5483f6Sopenharmony_ci if (!ret) { 453e5483f6Sopenharmony_ci RINGTONE_ERR_LOG("invalid target extension:%{public}s", ext.c_str()); 463e5483f6Sopenharmony_ci } 473e5483f6Sopenharmony_ci return ret; 483e5483f6Sopenharmony_ci} 493e5483f6Sopenharmony_ci 503e5483f6Sopenharmony_ci/* Caller is responsible to close the returned fd */ 513e5483f6Sopenharmony_cistatic int32_t OpenOriginFd(const string &path, const string &mode) 523e5483f6Sopenharmony_ci{ 533e5483f6Sopenharmony_ci return RingtoneFileUtils::OpenFile(path, mode); 543e5483f6Sopenharmony_ci} 553e5483f6Sopenharmony_ci 563e5483f6Sopenharmony_ciint32_t RingtonePrivacyManager::Open() 573e5483f6Sopenharmony_ci{ 583e5483f6Sopenharmony_ci if (!IsTargetExtension(path_)) { 593e5483f6Sopenharmony_ci return E_INVALID_PATH; 603e5483f6Sopenharmony_ci } 613e5483f6Sopenharmony_ci return OpenOriginFd(path_, mode_); 623e5483f6Sopenharmony_ci} 633e5483f6Sopenharmony_ci} // namespace Media 643e5483f6Sopenharmony_ci} // namespace OHOS 65