• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "client/storage_manager_client.h"
16 
17 #include "iremote_object.h"
18 #include "iremote_proxy.h"
19 #include "iservice_registry.h"
20 #include "storage_service_log.h"
21 #include "storage_service_errno.h"
22 #include "system_ability_definition.h"
23 
24 namespace OHOS {
25 namespace StorageManager {
GetStorageManagerProxy(void)26 sptr<IStorageManager> StorageManagerClient::GetStorageManagerProxy(void)
27 {
28     auto samgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
29     if (samgr == nullptr) {
30         LOGE("samgr empty error");
31         return nullptr;
32     }
33 
34     sptr<IRemoteObject> object = samgr->GetSystemAbility(OHOS::STORAGE_MANAGER_MANAGER_ID);
35     if (object == nullptr) {
36         LOGE("storage manager client samgr ablity empty error");
37         return nullptr;
38     }
39 
40     return iface_cast<IStorageManager>(object);
41 }
42 
PrepareAddUser(uint32_t userId,uint32_t flags)43 int32_t StorageManagerClient::PrepareAddUser(uint32_t userId, uint32_t flags)
44 {
45     sptr<IStorageManager> client = GetStorageManagerProxy();
46     if (client == nullptr) {
47         LOGE("get storage manager service failed");
48         return -EFAULT;
49     }
50 
51     return client->PrepareAddUser(userId, flags);
52 }
53 
RemoveUser(uint32_t userId,uint32_t flags)54 int32_t StorageManagerClient::RemoveUser(uint32_t userId, uint32_t flags)
55 {
56     sptr<IStorageManager> client = GetStorageManagerProxy();
57     if (client == nullptr) {
58         LOGE("get storage manager service failed");
59         return -EFAULT;
60     }
61 
62     return client->RemoveUser(userId, flags);
63 }
64 
GenerateUserKeys(uint32_t userId,uint32_t flags)65 int32_t StorageManagerClient::GenerateUserKeys(uint32_t userId, uint32_t flags)
66 {
67     sptr<IStorageManager> client = GetStorageManagerProxy();
68     if (client == nullptr) {
69         LOGE("get storage manager service failed");
70         return -EFAULT;
71     }
72 
73     return client->GenerateUserKeys(userId, flags);
74 }
75 
DeleteUserKeys(uint32_t userId)76 int32_t StorageManagerClient::DeleteUserKeys(uint32_t userId)
77 {
78     sptr<IStorageManager> client = GetStorageManagerProxy();
79     if (client == nullptr) {
80         LOGE("get storage manager service failed");
81         return -EFAULT;
82     }
83 
84     return client->DeleteUserKeys(userId);
85 }
86 
UpdateUserAuth(uint32_t userId,uint64_t secureUid,const std::vector<uint8_t> & token,const std::vector<uint8_t> & oldSecret,const std::vector<uint8_t> & newSecret)87 int32_t StorageManagerClient::UpdateUserAuth(uint32_t userId, uint64_t secureUid,
88                                              const std::vector<uint8_t> &token,
89                                              const std::vector<uint8_t> &oldSecret,
90                                              const std::vector<uint8_t> &newSecret)
91 {
92     sptr<IStorageManager> client = GetStorageManagerProxy();
93     if (client == nullptr) {
94         LOGE("get storage manager service failed");
95         return -EFAULT;
96     }
97 
98     return client->UpdateUserAuth(userId, secureUid, token, oldSecret, newSecret);
99 }
100 
ActiveUserKey(uint32_t userId,const std::vector<uint8_t> & token,const std::vector<uint8_t> & secret)101 int32_t StorageManagerClient::ActiveUserKey(uint32_t userId,
102                                             const std::vector<uint8_t> &token,
103                                             const std::vector<uint8_t> &secret)
104 {
105     sptr<IStorageManager> client = GetStorageManagerProxy();
106     if (client == nullptr) {
107         LOGE("get storage manager service failed");
108         return -EFAULT;
109     }
110 
111     return client->ActiveUserKey(userId, token, secret);
112 }
113 
InactiveUserKey(uint32_t userId)114 int32_t StorageManagerClient::InactiveUserKey(uint32_t userId)
115 {
116     sptr<IStorageManager> client = GetStorageManagerProxy();
117     if (client == nullptr) {
118         LOGE("get storage manager service failed");
119         return -EFAULT;
120     }
121 
122     return client->InactiveUserKey(userId);
123 }
124 
UpdateKeyContext(uint32_t userId)125 int32_t StorageManagerClient::UpdateKeyContext(uint32_t userId)
126 {
127     sptr<IStorageManager> client = GetStorageManagerProxy();
128     if (client == nullptr) {
129         LOGE("get storage manager service failed");
130         return -EFAULT;
131     }
132 
133     return client->UpdateKeyContext(userId);
134 }
135 
LockUserScreen(uint32_t userId)136 int32_t StorageManagerClient::LockUserScreen(uint32_t userId)
137 {
138     sptr<IStorageManager> client = GetStorageManagerProxy();
139     if (client == nullptr) {
140         LOGE("get storage manager service failed");
141         return E_SA_IS_NULLPTR;
142     }
143 
144     return client->LockUserScreen(userId);
145 }
146 
UnlockUserScreen(uint32_t userId,const std::vector<uint8_t> & token,const std::vector<uint8_t> & secret)147 int32_t StorageManagerClient::UnlockUserScreen(uint32_t userId,
148                                                const std::vector<uint8_t> &token,
149                                                const std::vector<uint8_t> &secret)
150 {
151     sptr<IStorageManager> client = GetStorageManagerProxy();
152     if (client == nullptr) {
153         LOGE("get storage manager service failed");
154         return -EFAULT;
155     }
156 
157     return client->UnlockUserScreen(userId, token, secret);
158 }
159 
GetFileEncryptStatus(uint32_t userId,bool & isEncrypted,bool needCheckDirMount)160 int32_t StorageManagerClient::GetFileEncryptStatus(uint32_t userId, bool &isEncrypted, bool needCheckDirMount)
161 {
162     sptr<IStorageManager> client = GetStorageManagerProxy();
163     if (client == nullptr) {
164         LOGE("get storage manager service failed");
165         return -EFAULT;
166     }
167 
168     return client->GetFileEncryptStatus(userId, isEncrypted, needCheckDirMount);
169 }
170 
GetUserNeedActiveStatus(uint32_t userId,bool & needActive)171 int32_t StorageManagerClient::GetUserNeedActiveStatus(uint32_t userId, bool &needActive)
172 {
173     sptr<IStorageManager> client = GetStorageManagerProxy();
174     if (client == nullptr) {
175         LOGE("get storage manager service failed");
176         return E_SA_IS_NULLPTR;
177     }
178 
179     return client->GetUserNeedActiveStatus(userId, needActive);
180 }
181 
GetLockScreenStatus(uint32_t userId,bool & lockScreenStatus)182 int32_t StorageManagerClient::GetLockScreenStatus(uint32_t userId, bool &lockScreenStatus)
183 {
184     sptr<IStorageManager> client = GetStorageManagerProxy();
185     if (client == nullptr) {
186         LOGE("get storage manager service failed");
187         return -EFAULT;
188     }
189 
190     return client->GetLockScreenStatus(userId, lockScreenStatus);
191 }
192 
MountDfsDocs(int32_t userId,const std::string & relativePath,const std::string & networkId,const std::string & deviceId)193 int32_t StorageManagerClient::MountDfsDocs(int32_t userId, const std::string &relativePath,
194     const std::string &networkId, const std::string &deviceId)
195 {
196     sptr<IStorageManager> client = GetStorageManagerProxy();
197     if (client == nullptr) {
198         LOGE("get storage manager service failed");
199         return -EFAULT;
200     }
201 
202     return client->MountDfsDocs(userId, relativePath, networkId, deviceId);
203 }
204 
UMountDfsDocs(int32_t userId,const std::string & relativePath,const std::string & networkId,const std::string & deviceId)205 int32_t StorageManagerClient::UMountDfsDocs(int32_t userId, const std::string &relativePath,
206     const std::string &networkId, const std::string &deviceId)
207 {
208     sptr<IStorageManager> client = GetStorageManagerProxy();
209     if (client == nullptr) {
210         LOGE("get storage manager service failed");
211         return -EFAULT;
212     }
213 
214     return client->UMountDfsDocs(userId, relativePath, networkId, deviceId);
215 }
216 }
217 }
218