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 16 #ifndef USER_IDM_SERVICE_H 17 #define USER_IDM_SERVICE_H 18 19 #include "user_idm_stub.h" 20 21 #include <memory> 22 #include <string> 23 #include <vector> 24 25 #include "system_ability.h" 26 #include "system_ability_definition.h" 27 28 #include "context.h" 29 30 namespace OHOS { 31 namespace UserIam { 32 namespace UserAuth { 33 class UserIdmService : public SystemAbility, public UserIdmStub, public NoCopyable { 34 public: 35 DECLARE_SYSTEM_ABILITY(UserIdmService); 36 explicit UserIdmService(int32_t systemAbilityId, bool runOnCreate = false); 37 ~UserIdmService() override = default; 38 int Dump(int fd, const std::vector<std::u16string> &args) override; 39 int32_t OpenSession(int32_t userId, std::vector<uint8_t> &challenge) override; 40 void CloseSession(int32_t userId) override; 41 int32_t GetCredentialInfo(int32_t userId, AuthType authType, 42 const sptr<IdmGetCredInfoCallbackInterface> &callback) override; 43 int32_t GetSecInfo(int32_t userId, const sptr<IdmGetSecureUserInfoCallbackInterface> &callback) override; 44 void AddCredential(int32_t userId, const CredentialPara &credPara, 45 const sptr<IdmCallbackInterface> &callback, bool isUpdate) override; 46 void UpdateCredential(int32_t userId, const CredentialPara &credPara, 47 const sptr<IdmCallbackInterface> &callback) override; 48 int32_t Cancel(int32_t userId) override; 49 int32_t EnforceDelUser(int32_t userId, const sptr<IdmCallbackInterface> &callback) override; 50 void DelUser(int32_t userId, const std::vector<uint8_t> authToken, 51 const sptr<IdmCallbackInterface> &callback) override; 52 void DelCredential(int32_t userId, uint64_t credentialId, const std::vector<uint8_t> &authToken, 53 const sptr<IdmCallbackInterface> &callback) override; 54 55 protected: 56 void OnStart() override; 57 void OnStop() override; 58 59 private: 60 int32_t CancelCurrentEnroll(); 61 void CancelCurrentEnrollIfExist(); 62 int32_t GetSecInfoInner(int32_t userId, SecUserInfo &secUserInfo); 63 int32_t GetCredentialInfoInner(int32_t userId, AuthType authType, std::vector<CredentialInfo> &credInfoList); 64 std::mutex mutex_; 65 }; 66 } // namespace UserAuth 67 } // namespace UserIam 68 } // namespace OHOS 69 #endif // USER_IDM_SERVICE_H