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 WIFI_NOTIFICATION_UTIL_H 17 #define WIFI_NOTIFICATION_UTIL_H 18 #include "ability_connect_callback_stub.h" 19 #include "ipc_skeleton.h" 20 #include "want.h" 21 #include "want_params_wrapper.h" 22 #include <atomic> 23 #include <string> 24 25 namespace OHOS { 26 namespace Wifi { 27 constexpr int DEFAULT_INVAL_VALUE = -1; 28 constexpr int32_t SIGNAL_NUM = 3; 29 const std::u16string ABILITY_MGR_DESCRIPTOR = u"ohos.aafwk.AbilityManager"; 30 const std::string WIFI_EVENT_TAP_NOTIFICATION = "ohos.event.notification.wifi.TAP_NOTIFICATION"; 31 const std::string WIFI_EVENT_DIALOG_ACCEPT = "ohos.event.wifi.DIALOG_ACCEPT"; 32 const std::string WIFI_EVENT_DIALOG_REJECT = "ohos.event.wifi.DIALOG_REJECT"; 33 const std::string EVENT_SETTINGS_WLAN_KEEP_CONNECTED = "event.settings.wlan.keep_connected"; 34 enum WifiNotificationId { 35 WIFI_PORTAL_NOTIFICATION_ID = 101000 36 }; 37 38 enum WifiNotificationStatus { 39 WIFI_PORTAL_CONNECTED = 0, 40 WIFI_PORTAL_TIMEOUT = 1, 41 WIFI_PORTAL_FOUND = 2 42 }; 43 44 enum WifiNotificationOpetationType { 45 CANCEL = 0, 46 PUBLISH = 1 47 }; 48 49 enum WifiDialogType { 50 CDD = 0, 51 THREE_VAP = 1, 52 CANDIDATE_CONNECT = 2 53 }; 54 55 class WifiNotificationUtil { 56 public: 57 static WifiNotificationUtil& GetInstance(void); 58 59 void PublishWifiNotification(WifiNotificationId notificationId, std::string& ssid, WifiNotificationStatus status); 60 61 void CancelWifiNotification(WifiNotificationId notificationId); 62 63 int32_t StartAbility(OHOS::AAFwk::Want& want); 64 65 void ShowDialog(WifiDialogType type); 66 67 void ShowSettingsDialog(WifiDialogType type, std::string settings); 68 69 private: 70 std::atomic<bool> isNtfPublished {false}; 71 72 WifiNotificationUtil(); 73 ~WifiNotificationUtil(); 74 }; 75 76 class UIExtensionAbilityConnection : public AAFwk::AbilityConnectionStub { 77 public: UIExtensionAbilityConnection(const std::string commandStr,const std::string bundleName,const std::string abilityName)78 UIExtensionAbilityConnection( 79 const std::string commandStr, const std::string bundleName, const std::string abilityName) 80 : commandStr_(commandStr), bundleName_(bundleName), abilityName_(abilityName) 81 {} 82 83 virtual ~UIExtensionAbilityConnection() = default; 84 85 void OnAbilityConnectDone( 86 const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int32_t resultCode) override; 87 void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int32_t resultCode) override; 88 89 private: 90 std::string commandStr_; 91 std::string bundleName_; 92 std::string abilityName_; 93 }; 94 } 95 } 96 #endif