1 /* 2 * Copyright (c) 2022 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 ACCESSTOKEN_MANAGER_CLIENT_H 17 #define ACCESSTOKEN_MANAGER_CLIENT_H 18 19 #include <string> 20 #include <mutex> 21 #include <condition_variable> 22 23 #include "access_token.h" 24 #include "hap_token_info.h" 25 #include "i_token_sync_manager.h" 26 #include "nocopyable.h" 27 28 namespace OHOS { 29 namespace Security { 30 namespace AccessToken { 31 class TokenSyncManagerClient final { 32 public: 33 static const int TOKEN_SYNC_LOAD_SA_TIMEOUT_MS = 60000; 34 35 static TokenSyncManagerClient& GetInstance(); 36 37 virtual ~TokenSyncManagerClient(); 38 39 int GetRemoteHapTokenInfo(const std::string& deviceID, AccessTokenID tokenID); 40 int DeleteRemoteHapTokenInfo(AccessTokenID tokenID); 41 int UpdateRemoteHapTokenInfo(const HapTokenInfoForSync& tokenInfo); 42 void LoadTokenSync(); 43 void FinishStartSASuccess(const sptr<IRemoteObject>& remoteObject); 44 void FinishStartSAFailed(); 45 void SetRemoteObject(const sptr<IRemoteObject>& remoteObject); 46 sptr<IRemoteObject> GetRemoteObject(); 47 void OnRemoteDiedHandle(); 48 49 private: 50 std::condition_variable tokenSyncCon_; 51 std::mutex tokenSyncMutex_; 52 std::mutex remoteMutex_; 53 bool ready_ = false; 54 sptr<IRemoteObject> remoteObject_ = nullptr; 55 56 TokenSyncManagerClient(); 57 58 DISALLOW_COPY_AND_MOVE(TokenSyncManagerClient); 59 60 sptr<ITokenSyncManager> GetProxy(); 61 }; 62 } // namespace AccessToken 63 } // namespace Security 64 } // namespace OHOS 65 #endif // ACCESSTOKEN_MANAGER_CLIENT_H 66