• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 inline const std::u16string ABILITY_MGR_DESCRIPTOR = u"ohos.aafwk.AbilityManager";
30 inline const std::string WIFI_EVENT_TAP_NOTIFICATION = "ohos.event.notification.wifi.TAP_NOTIFICATION";
31 inline const std::string WIFI_EVENT_DIALOG_ACCEPT = "ohos.event.wifi.DIALOG_ACCEPT";
32 inline const std::string WIFI_EVENT_DIALOG_REJECT = "ohos.event.wifi.DIALOG_REJECT";
33 inline const std::string EVENT_SETTINGS_WLAN_KEEP_CONNECTED = "event.settings.wlan.keep_connected";
34 enum WifiNotificationId {
35     WIFI_PORTAL_NOTIFICATION_ID = 101000,
36     WIFI_5G_CONN_NOTIFICATION_ID = 101001
37 };
38 
39 enum WifiNotificationStatus {
40     WIFI_PORTAL_CONNECTED = 0,
41     WIFI_PORTAL_TIMEOUT = 1,
42     WIFI_PORTAL_FOUND = 2,
43     WIFI_5G_CONN_FOUND = 3
44 };
45 
46 enum WifiNotificationOpetationType {
47     CANCEL = 0,
48     PUBLISH = 1
49 };
50 
51 enum WifiDialogType {
52     CDD = 0,
53     THREE_VAP = 1,
54     CANDIDATE_CONNECT = 2,
55     AUTO_IDENTIFY_CONN = 3,
56     P2P_WSC_PBC_DIALOG = 4,
57     SETTINGS_AUTO_IDENTIFY_CONN = 5
58 };
59 
60 class WifiNotificationUtil {
61 public:
62     static WifiNotificationUtil& GetInstance(void);
63 
64     void PublishWifiNotification(WifiNotificationId notificationId, std::string& ssid, WifiNotificationStatus status);
65 
66     void CancelWifiNotification(WifiNotificationId notificationId);
67 
68     void DisplaySettingWlanPage(std::string bundleName, std::string abilityName, std::string navEntryKey);
69 
70     int32_t StartAbility(OHOS::AAFwk::Want& want);
71 
72     void ShowDialog(WifiDialogType type, std::string comInfo = "");
73 
74     void ShowSettingsDialog(WifiDialogType type, std::string settings);
75 
76 private:
77     std::atomic<bool> isPortalNtfPublished {false};
78     std::atomic<bool> is5gConnNtfPublished {false};
79 
80     WifiNotificationUtil();
81     ~WifiNotificationUtil();
82 };
83 
84 class UIExtensionAbilityConnection : public AAFwk::AbilityConnectionStub {
85 public:
UIExtensionAbilityConnection(const std::string commandStr,const std::string bundleName,const std::string abilityName)86     UIExtensionAbilityConnection(
87         const std::string commandStr, const std::string bundleName, const std::string abilityName)
88         : commandStr_(commandStr), bundleName_(bundleName), abilityName_(abilityName)
89     {}
90 
91     virtual ~UIExtensionAbilityConnection() = default;
92 
93     void OnAbilityConnectDone(
94         const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int32_t resultCode) override;
95     void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int32_t resultCode) override;
96 
97 private:
98     std::string commandStr_;
99     std::string bundleName_;
100     std::string abilityName_;
101 };
102 }  // namespace Wifi
103 }  // namespace OHOS
104 #endif