1 /*
2 * Copyright (c) 2023 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 #define LOG_TAG "UriPermissionManager"
16
17 #include "uri_permission_manager.h"
18
19 #include "want.h"
20 #include "uri.h"
21 #include "uri_permission_manager_client.h"
22
23 #include "log_print.h"
24
25 namespace OHOS {
26 namespace UDMF {
GetInstance()27 UriPermissionManager &UriPermissionManager::GetInstance()
28 {
29 static UriPermissionManager instance;
30 return instance;
31 }
32
GrantUriPermission(const std::string & path,const std::string & bundleName)33 Status UriPermissionManager::GrantUriPermission(const std::string &path, const std::string &bundleName)
34 {
35 Uri uri(path);
36 auto status = AAFwk::UriPermissionManagerClient::GetInstance().GrantUriPermission(
37 uri, AAFwk::Want::FLAG_AUTH_READ_URI_PERMISSION, bundleName);
38 if (status != ERR_OK) {
39 ZLOGE("GrantUriPermission failed, %{public}d", status);
40 return E_ERROR;
41 }
42 return E_OK;
43 }
44 } // namespace UDMF
45 } // namespace OHOS
46