• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 "SystemApiCheckHandler"
17 
18 #include "system_api_check_handler.h"
19 
20 #include "delete_permanently_operations_uri.h"
21 #include "medialibrary_operation.h"
22 #include "permission_utils.h"
23 #include "userfilemgr_uri.h"
24 #include "album_operation_uri.h"
25 #include "data_secondary_directory_uri.h"
26 
27 namespace OHOS::Media {
28 
29 static const std::unordered_set<std::string> SYSTEM_API_URIS = {
30     PAH_DELETE_PHOTO_ALBUM,
31     PAH_DELETE_PHOTOS,
32     PAH_RECOVER_PHOTOS,
33     PAH_SYS_CREATE_PHOTO,
34     PAH_SYS_TRASH_PHOTO,
35     UFM_DELETE_PHOTO_ALBUM,
36     PAH_REMOVE_FORM_MAP,
37     PAH_CREATE_APP_URI_PERMISSION,
38     PAH_SET_LOCATION,
39     URI_DELETE_PHOTOS_COMPLETED,
40     PAH_DISMISS_ASSET,
41     PAH_GROUP_ANAALBUM_DISMISS,
42     UFM_QUERY_HIDDEN_ALBUM,
43     PAH_QUERY_HIDDEN_ALBUM,
44     PAH_HIDE_PHOTOS,
45     PAH_BATCH_UPDATE_OWNER_ALBUM_ID,
46 };
47 
ExecuteCheckPermission(MediaLibraryCommand & cmd,PermParam & permParam)48 int32_t SystemApiCheckHandler::ExecuteCheckPermission(MediaLibraryCommand &cmd, PermParam &permParam)
49 {
50     std::string uri = cmd.GetUriStringWithoutSegment();
51     OperationObject obj = cmd.GetOprnObject();
52     OperationType type = cmd.GetOprnType();
53     if (SYSTEM_API_URIS.find(uri) == SYSTEM_API_URIS.end()) {
54         return E_SUCCESS;
55     }
56     if (!PermissionUtils::IsSystemApp()) {
57         MEDIA_ERR_LOG("not system app, uri:%{public}s obj:%{public}d, type:%{public}d", uri.c_str(), obj, type);
58         return -E_CHECK_SYSTEMAPP_FAIL;
59     }
60     return E_SUCCESS;
61 }
62 
63 } // namespace OHOS::Media