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