1 /* 2 * Copyright (c) 2024 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 AUTHORIZATION_DIALOG_H 17 #define AUTHORIZATION_DIALOG_H 18 19 #include <mutex> 20 21 #include "ability_connect_callback_stub.h" 22 #include "ffrt_inner.h" 23 #include "singleton.h" 24 25 namespace OHOS { 26 namespace MMI { 27 class AuthorizationDialog final { 28 DECLARE_SINGLETON(AuthorizationDialog); 29 public: 30 DISALLOW_MOVE(AuthorizationDialog); 31 bool ConnectSystemUi(); GetBundleName()32 static std::string GetBundleName() 33 { 34 return bundleName_; 35 } 36 GetAbilityName()37 static std::string GetAbilityName() 38 { 39 return abilityName_; 40 } 41 GetUiExtensionType()42 static std::string GetUiExtensionType() 43 { 44 return uiExtensionType_; 45 } 46 void CloseDialog(); 47 private: 48 class DialogAbilityConnection : public OHOS::AAFwk::AbilityConnectionStub { 49 public: 50 void OnAbilityConnectDone( 51 const AppExecFwk::ElementName& element, const sptr<IRemoteObject>& remoteObject, int resultCode) override; 52 void OnAbilityDisconnectDone(const AppExecFwk::ElementName& element, int resultCode) override; 53 void CloseDialog(); 54 bool DialogIsOpen(); 55 void OpenDialog(); 56 bool IsConnected(); 57 58 private: 59 std::mutex mutex_; 60 std::atomic_bool isDialogShow_ { false }; 61 sptr<IRemoteObject> remoteObject_ { nullptr }; 62 }; 63 64 sptr<DialogAbilityConnection> dialogConnectionCallback_ { nullptr }; 65 static std::string bundleName_; 66 static std::string abilityName_; 67 static std::string uiExtensionType_; 68 }; 69 70 #define AUTH_DIALOG ::OHOS::Singleton<AuthorizationDialog>::GetInstance() 71 } // namespace MMI 72 } // namespace OHOS 73 74 #endif // AUTHORIZATION_DIALOG_H