• 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 "system_ability_definition.h"
22 
23 namespace OHOS {
24 namespace StorageManager {
GetStorageManagerProxy(void)25 sptr<IStorageManager> StorageManagerClient::GetStorageManagerProxy(void)
26 {
27     auto samgr = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
28     if (samgr == nullptr) {
29         LOGE("samgr empty error");
30         return nullptr;
31     }
32 
33     sptr<IRemoteObject> object = samgr->GetSystemAbility(OHOS::STORAGE_MANAGER_MANAGER_ID);
34     if (object == nullptr) {
35         LOGE("storage manager client samgr ablity empty error");
36         return nullptr;
37     }
38 
39     return iface_cast<IStorageManager>(object);
40 }
41 
PrepareAddUser(uint32_t userId,const std::string & volumId,uint32_t flags)42 int32_t StorageManagerClient::PrepareAddUser(uint32_t userId, const std::string &volumId, uint32_t flags)
43 {
44     sptr<IStorageManager> client = GetStorageManagerProxy();
45     if (client == nullptr) {
46         LOGE("get storage manager service failed");
47         return -EFAULT;
48     }
49 
50     return client->PrepareAddUser(userId, flags);
51 }
52 
RemoveUser(uint32_t userId,const std::string & volumId,uint32_t flags)53 int32_t StorageManagerClient::RemoveUser(uint32_t userId, const std::string &volumId, uint32_t flags)
54 {
55     sptr<IStorageManager> client = GetStorageManagerProxy();
56     if (client == nullptr) {
57         LOGE("get storage manager service failed");
58         return -EFAULT;
59     }
60 
61     return client->RemoveUser(userId, flags);
62 }
63 
GenerateUserKeys(uint32_t userId,uint32_t flags)64 int32_t StorageManagerClient::GenerateUserKeys(uint32_t userId, uint32_t flags)
65 {
66     sptr<IStorageManager> client = GetStorageManagerProxy();
67     if (client == nullptr) {
68         LOGE("get storage manager service failed");
69         return -EFAULT;
70     }
71 
72     return client->GenerateUserKeys(userId, flags);
73 }
74 
DeleteUserKeys(uint32_t userId)75 int32_t StorageManagerClient::DeleteUserKeys(uint32_t userId)
76 {
77     sptr<IStorageManager> client = GetStorageManagerProxy();
78     if (client == nullptr) {
79         LOGE("get storage manager service failed");
80         return -EFAULT;
81     }
82 
83     return client->DeleteUserKeys(userId);
84 }
85 
UpdateUserAuth(uint32_t userId,std::string auth,std::string compSecret)86 int32_t StorageManagerClient::UpdateUserAuth(uint32_t userId, std::string auth, std::string compSecret)
87 {
88     sptr<IStorageManager> client = GetStorageManagerProxy();
89     if (client == nullptr) {
90         LOGE("get storage manager service failed");
91         return -EFAULT;
92     }
93 
94     return client->UpdateUserAuth(userId, auth, compSecret);
95 }
96 
ActiveUserKey(uint32_t userId,std::string auth,std::string compSecret)97 int32_t StorageManagerClient::ActiveUserKey(uint32_t userId, std::string auth, std::string compSecret)
98 {
99     sptr<IStorageManager> client = GetStorageManagerProxy();
100     if (client == nullptr) {
101         LOGE("get storage manager service failed");
102         return -EFAULT;
103     }
104 
105     return client->ActiveUserKey(userId, auth, compSecret);
106 }
107 
InactiveUserKey(uint32_t userId)108 int32_t StorageManagerClient::InactiveUserKey(uint32_t userId)
109 {
110     sptr<IStorageManager> client = GetStorageManagerProxy();
111     if (client == nullptr) {
112         LOGE("get storage manager service failed");
113         return -EFAULT;
114     }
115 
116     return client->InactiveUserKey(userId);
117 }
118 
UpdateKeyContext(uint32_t userId)119 int32_t StorageManagerClient::UpdateKeyContext(uint32_t userId)
120 {
121     sptr<IStorageManager> client = GetStorageManagerProxy();
122     if (client == nullptr) {
123         LOGE("get storage manager service failed");
124         return -EFAULT;
125     }
126 
127     return client->UpdateKeyContext(userId);
128 }
129 }
130 }