• 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 
25 namespace OHOS::Media {
26 
27 static const std::unordered_set<std::string> SYSTEM_API_URIS = {
28     PAH_DELETE_PHOTO_ALBUM,
29     PAH_DELETE_PHOTOS,
30     PAH_RECOVER_PHOTOS,
31     PAH_SYS_CREATE_PHOTO,
32     PAH_SYS_TRASH_PHOTO,
33     UFM_DELETE_PHOTO_ALBUM,
34     PAH_REMOVE_FORM_MAP,
35     PAH_CREATE_APP_URI_PERMISSION,
36     PAH_SET_LOCATION,
37     URI_DELETE_PHOTOS_COMPLETED,
38     PAH_DISMISS_ASSET,
39     PAH_GROUP_ANAALBUM_DISMISS,
40     UFM_QUERY_HIDDEN_ALBUM,
41     PAH_QUERY_HIDDEN_ALBUM,
42     PAH_HIDE_PHOTOS,
43     PAH_BATCH_UPDATE_OWNER_ALBUM_ID,
44 };
45 
ExecuteCheckPermission(MediaLibraryCommand & cmd,PermParam & permParam)46 int32_t SystemApiCheckHandler::ExecuteCheckPermission(MediaLibraryCommand &cmd, PermParam &permParam)
47 {
48     std::string uri = cmd.GetUriStringWithoutSegment();
49     OperationObject obj = cmd.GetOprnObject();
50     OperationType type = cmd.GetOprnType();
51     if (SYSTEM_API_URIS.find(uri) == SYSTEM_API_URIS.end()) {
52         return E_SUCCESS;
53     }
54     if (!PermissionUtils::IsSystemApp()) {
55         MEDIA_ERR_LOG("not system app, uri:%{public}s obj:%{public}d, type:%{public}d", uri.c_str(), obj, type);
56         return E_CHECK_SYSTEMAPP_FAIL;
57     }
58     return E_SUCCESS;
59 }
60 
61 } // namespace OHOS::Media