1 /*
2 * Copyright (c) 2022-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 #include "copy_uri_handler.h"
16 
17 #include <fcntl.h>
18 #include <unistd.h>
19 
20 #include "errors.h"
21 #include "os_account_manager.h"
22 #include "pasteboard_hilog.h"
23 #include "remote_file_share.h"
24 namespace OHOS::MiscServices {
25 using namespace OHOS::AppFileService::ModuleRemoteFileShare;
CopyUriHandler()26 CopyUriHandler::CopyUriHandler()
27 {
28     isPaste_ = false;
29 }
ToUri(int32_t fd)30 std::string CopyUriHandler::ToUri(int32_t fd)
31 {
32     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "begin, fd:%{public}d", fd);
33     std::vector<int32_t> ids;
34     auto ret = AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids);
35     if (ret != ERR_OK || ids.empty()) {
36         PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "query active user failed errCode=%{public}d", ret);
37         return uri_;
38     }
39     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "fd: %{public}d, user:%{public}d", fd, ids[0]);
40     ret = RemoteFileShare::CreateSharePath(fd, uri_, ids[0]);
41     if (ret != 0 && ret != FILE_EXIST) {
42         PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, " create share path failed, %{public}d ", ret);
43         return uri_;
44     }
45     return uri_;
46 }
47 } // namespace OHOS::MiscServices
48