• 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 #define MLOG_TAG "Media_IPC"
16 
17 #include "user_define_ipc_client.h"
18 
19 #include "iservice_registry.h"
20 
21 namespace OHOS::Media::IPC {
22 static const std::u16string DESCRIPTOR = u"OHOS.DataShare.IDataShare";
23 static const int STORAGE_MANAGER_MANAGER_ID = 5003;
SetTraceId(const std::string & traceId)24 UserDefineIPCClient &UserDefineIPCClient::SetTraceId(const std::string &traceId)
25 {
26     this->traceId_ = traceId;
27     return *this;
28 }
29 
GetTraceId() const30 std::string UserDefineIPCClient::GetTraceId() const
31 {
32     return this->traceId_;
33 }
34 
SetUserId(const int32_t & userId)35 UserDefineIPCClient &UserDefineIPCClient::SetUserId(const int32_t &userId)
36 {
37     this->userId_ = userId;
38     return *this;
39 }
40 
GetUserId() const41 int32_t UserDefineIPCClient::GetUserId() const
42 {
43     return this->userId_;
44 }
45 
GetHeader() const46 std::unordered_map<std::string, std::string> UserDefineIPCClient::GetHeader() const
47 {
48     return this->header_;
49 }
50 
SetHeader(const std::unordered_map<std::string,std::string> & header)51 UserDefineIPCClient &UserDefineIPCClient::SetHeader(const std::unordered_map<std::string, std::string> &header)
52 {
53     this->header_ = header;
54     return *this;
55 }
56 
InitClient(const int32_t & userId)57 int32_t UserDefineIPCClient::InitClient(const int32_t &userId)
58 {
59     userId_ = userId;
60     bool errConn = UserFileClient::IsValid(userId);
61     CHECK_AND_RETURN_RET(!errConn, E_OK);
62     MEDIA_ERR_LOG("Call IPC UserFileClient::IsInValid");
63     auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
64     errConn = saManager == nullptr;
65     CHECK_AND_RETURN_RET_LOG(!errConn, E_ERR, "Get system ability mgr failed.");
66     auto remoteObj = saManager->GetSystemAbility(STORAGE_MANAGER_MANAGER_ID);
67     errConn = remoteObj == nullptr;
68     CHECK_AND_RETURN_RET_LOG(!errConn, E_ERR, "GetSystemAbility Service Failed.");
69     UserFileClient::Init(remoteObj, true, userId);
70     return E_OK;
71 }
HeaderMarshalling(MessageParcel & data)72 int32_t UserDefineIPCClient::HeaderMarshalling(MessageParcel &data)
73 {
74     bool errConn = !data.WriteInterfaceToken(DESCRIPTOR);
75     CHECK_AND_RETURN_RET_LOG(!errConn, E_FAIL, "WriteInterfaceToken failed");
76     return E_OK;
77 }
78 }  // namespace OHOS::Media::IPC