Handle connection request from peer 46/321746/3
authorSaksham Grover <s.grover@partner.samsung.com>
Wed, 26 Mar 2025 09:11:32 +0000 (14:41 +0530)
committerSaksham Grover <s.grover@partner.samsung.com>
Thu, 3 Apr 2025 09:40:20 +0000 (15:10 +0530)
This patch:
- Updates popup functionality and adds logic for buttons on popup
- Updates scan-stop button functionality
- Adds logic during the process of disconnecting from a peer

Change-Id: Ifd7925968c7869b6d80e5abaca1a83aaf41cecfe
Signed-off-by: Saksham Grover <s.grover@partner.samsung.com>
SettingWiFiDirect/SettingWiFiDirect/SettingWiFiDirect.cs
SettingWiFiDirect/SettingWiFiDirect/SettingWiFiDirect.csproj
SettingWiFiDirect/SettingWiFiDirect/controller/WiFiDirect.cs
SettingWiFiDirect/SettingWiFiDirect/tizen-manifest.xml
SettingWiFiDirect/SettingWiFiDirect/view/ConnectionPopup.cs
SettingWiFiDirect/SettingWiFiDirect/view/WiFiDirectDeviceView.cs
packaging/org.tizen.cssetting-wifi-direct-1.0.3.rpk [deleted file]
packaging/org.tizen.cssetting-wifi-direct-1.0.4.rpk [new file with mode: 0644]
packaging/org.tizen.setting-wifi-direct.spec

index 5f731341d02a4bc751a39656adf19038b22e64f8..05a2b28f833d8dcc7756dacb1633855a8b66eb4b 100644 (file)
@@ -18,7 +18,7 @@ namespace SettingWiFiDirect
         private CollectionView mScanList;
         private Button mScanButton;
         bool mNeedScanning;
-        public override string ProvideTitle() => NUIGadgetResourceManager.GetString(nameof(Resources.IDS_WIFI_BODY_WI_FI_DIRECT_ABB));
+        public override string ProvideTitle() => GetText(nameof(Resources.IDS_WIFI_BODY_WI_FI_DIRECT_ABB));
 
         protected override void OnCustomizationUpdate(IEnumerable<MenuCustomizationItem> items)
         {
@@ -32,7 +32,7 @@ namespace SettingWiFiDirect
 
             mScanButton = new Button()
             {
-                Text = ResourceManager.TextResourceManager.NUIGadgetResourceManager.GetString(nameof(Resources.IDS_WIFI_SK_STOP))
+                Text = GetText(nameof(Resources.IDS_WIFI_SK_STOP))
             };
             mScanButton.Clicked += OnScanStopButtonClicked;
             mScanButton.ApplyStyle(viewStyle);
@@ -40,16 +40,6 @@ namespace SettingWiFiDirect
             return new View[] { mScanButton };
         }
 
-        public string GetButtonText()
-        {
-            if(WiFiDirect.IsDiscoverable())
-            {
-                return ResourceManager.TextResourceManager.NUIGadgetResourceManager.GetString(nameof
-                       (Resources.IDS_WIFI_SK_STOP));
-            }
-            return ResourceManager.TextResourceManager.NUIGadgetResourceManager.GetString(nameof(Resources.IDS_WIFI_SK4_SCAN));
-        }
-
         private ViewStyle GetButtonViewStyle()
         {
             ViewStyle viewStyle = new ViewStyle();
@@ -92,7 +82,6 @@ namespace SettingWiFiDirect
         protected override View OnCreate()
         {
             WiFiDirect.WFDStateChanged += OnWFDStateChanged;
-            WiFiDirect.WFDStatusChanged += OnConnectionStatusChanged;
 
             Debug("MainPage: " + this.GetHashCode());
             base.OnCreate();
@@ -106,7 +95,6 @@ namespace SettingWiFiDirect
         {
             Debug("+");
             WiFiDirect.WFDStateChanged -= OnWFDStateChanged;
-            WiFiDirect.WFDStatusChanged -= OnConnectionStatusChanged;
             base.OnDestroy();
         }
 
@@ -190,24 +178,32 @@ namespace SettingWiFiDirect
             switch (e.State)
             {
                 case WFDState.Discovering:
+                    UpdateScanButton(true);
                     ChangeScanningState(true);
+                    WiFiDirect.WFDStatusChanged += OnConnectionStatusChanged;
                     break;
                 case WFDState.Activated:
                     if (mNeedScanning)
                     {
                         StartScan();
+                        UpdateScanButton(true);
+                        ChangeScanningState(true);
                     }else
                     {
                         UpdateDeviceList();
+                        UpdateScanButton(true);
                         ChangeScanningState(false);
                     }
                     break;
                 case WFDState.Connected:
+                    UpdateScanButton(false);
                     ChangeScanningState(false);
                     ShowConnectedDevice();
                     break;
                 case WFDState.Disconnecting:
                     mNeedScanning = true;
+                    mPeerSource.UpdateTitle();
+                    WiFiDirect.WFDStatusChanged -= OnConnectionStatusChanged;
                     break;
                 //TODO: update for further states.
 
@@ -222,25 +218,33 @@ namespace SettingWiFiDirect
             {
                 case WiFiDirectConnectionState.ConnectionRequest:
 
-                    OnConnectionRequest();
-                    break;
+                    var connectingPeer = WiFiDirect.GetConnectingPeer();
+                    if (connectingPeer != null)
+                    {
+                        Debug("Connecting Peer macAddress : " + connectingPeer.Address);
+                    }
+                    else
+                    {
+                        Debug("Connecting Peer is NULL");
+                        return;
+                    }
 
+                    OnConnectionRequest(connectingPeer);
+                    break;
                 default:
                     break;
             }
-
         }
 
-        private void OnConnectionRequest()
+        private void OnConnectionRequest(Peer connectingPeer)
         {
             try
             {
-                ConnectionPopup connectionPopup = new ConnectionPopup();
-                var page = connectionPopup.ConnectionPopupPage();
+                var page = new ConnectionPopup(connectingPeer);
                 if (page != null)
                 {
                     NUIApplication.GetDefaultWindow().GetDefaultNavigator().Add(page);
-                    connectionPopup.SetPopupPage(page);
+                    page.SetPopupPage(page);
                 }
                 else
                 {
@@ -318,7 +322,6 @@ namespace SettingWiFiDirect
                 Debug("Discovery started");
                 mNeedScanning = false;
                 ChangeScanningState(true);
-                mScanButton.Text = GetButtonText();
             }
             Debug("-");
         }
@@ -347,8 +350,7 @@ namespace SettingWiFiDirect
         private TextLabel GetHeader()
         {
             Debug("+");
-            string headerString = NUIGadgetResourceManager.GetString(
-                nameof(Resources.IDS_WIFI_BODY_YOUR_DEVICE_HPS_IS_CURRENTLY_VISIBLE_TO_NEARBY_DEVICES));
+            string headerString = GetText(nameof(Resources.IDS_WIFI_BODY_YOUR_DEVICE_HPS_IS_CURRENTLY_VISIBLE_TO_NEARBY_DEVICES));
             string label = string.Format(headerString, WiFiDirect.getDeviceName());
             TextLabel header = new TextLabel(label);
 
@@ -388,15 +390,33 @@ namespace SettingWiFiDirect
         private void StopDiscovery()
         {
             Debug("+");
+            WiFiDirect.WFDStatusChanged -= OnConnectionStatusChanged;
             bool discoveryStopped = WiFiDirect.StopDiscovery();
             if (discoveryStopped)
             {
                 Debug("Discovery stopped");
                 mNeedScanning = false;
                 ChangeScanningState(false);
-                mScanButton.Text = GetButtonText();
             }
             Debug("-");
         }
+
+        private void UpdateScanButton(bool visible)
+        {
+            mScanButton.IsEnabled = visible;
+            if (WiFiDirect.IsDiscoverable())
+            {
+                mScanButton.Text = GetText(nameof(Resources.IDS_WIFI_SK_STOP));
+            }
+            else
+            {
+                mScanButton.Text = GetText(nameof(Resources.IDS_WIFI_SK4_SCAN));
+            }
+        }
+
+        string GetText(string str)
+        {
+            return ResourceManager.TextResourceManager.NUIGadgetResourceManager.GetString(str);
+        }
     }
 }
index fc91e745c8909db54a56f3cd066c325fb5835aec..3ab8bf20af907f144eae37d8b2e57c11995108f5 100644 (file)
@@ -14,7 +14,8 @@
 
        <ItemGroup>
                <PackageReference Include="SettingCore" Version="1.0.435" />
-               <PackageReference Include="Tizen.NET" Version="13.0.0.18570" />
+               <PackageReference Include="Tizen.NET" Version="13.0.0.18726" />
+               <PackageReference Include="Tizen.NET.API13" Version="13.0.0.18726" />
        </ItemGroup>
 
        <ItemGroup>
index fa9af637873c30bb56212977851882fed573eb66..77dae14ed10ae2910c461354622f307e93c9a2ae 100644 (file)
@@ -231,6 +231,48 @@ namespace SettingWiFiDirect
             return true;
         }
 
+        static public Peer GetConnectingPeer()
+        {
+            Debug("+");
+            try
+            {
+                WiFiDirectPeer wfdpeer = WiFiDirectManager.GetConnectingPeer();
+                Peer connectingPeer = CreatePeer(wfdpeer);
+                return connectingPeer;
+            }
+            catch (Exception e)
+            {
+                Error("Error: " + e.Message + "\n" + e.StackTrace);
+            }
+
+            return null;
+        }
+
+        static public void RejectConnection(string macAddress)
+        {
+            Debug("+");
+            try
+            {
+                WiFiDirectManager.RejectConnection(macAddress);
+            }
+            catch (Exception e)
+            {
+                Error("Error: " + e.Message + "\n" + e.StackTrace);
+            }
+        }
+
+        static public void AcceptConnection(string macAddress)
+        {
+            Debug("+");
+            try
+            {
+                WiFiDirectManager.AcceptConnection(macAddress);
+            }
+            catch (Exception e)
+            {
+                Error("Error: " + e.Message + "\n" + e.StackTrace);
+            }
+        }
     }
 
     internal class WFDStateChangedEventArgs
index d0594e5271076372d6c5117a6debe6b730610f5f..2f1f9b793dbb98b2a843227f0beea494b070f37b 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns="http://tizen.org/ns/packages" api-version="7.0"
-  package="org.tizen.cssetting-wifi-direct" version="1.0.3"
+  package="org.tizen.cssetting-wifi-direct" version="1.0.4"
   res-type="org.tizen.appfw.gadget.setting-wifi-direct" res-version="1.0.0">
        <allowed-package id="org.tizen.*">
                <required-privileges>
index a88e66e098d611cb3ac4b10f27428d1ea378ee9f..892c15000ebeef058883bffa6198493515ce7894 100644 (file)
@@ -6,14 +6,21 @@ using static SettingWiFiDirect.Logger;
 
 namespace SettingWiFiDirect
 {
-    internal class ConnectionPopup:ContentPage
+    internal class ConnectionPopup : DialogPage
     {
         private Timer mTimer;
         private Progress mProgress;
-        private ContentPage mContentPage = null;
+        private ConnectionPopup mAlertPage = null;
         private const int MaxDuration = 120;
+        private Peer mConnectingPeer = null;
 
-        internal ContentPage ConnectionPopupPage()
+        public ConnectionPopup(Peer connectingPeer)
+        {
+            mConnectingPeer = connectingPeer;
+            CreateComponents();
+        }
+
+        internal void CreateComponents()
         {
             var connectionRequestView = new View()
             {
@@ -30,9 +37,8 @@ namespace SettingWiFiDirect
             connectionRequestView.Add(item);
 
             int timeout = 120;
-            string message = ResourceManager.TextResourceManager.NUIGadgetResourceManager.GetString(
-                nameof(Resources.IDS_WIFI_POP_CONNECT_TO_PS_IN_PD_SECONDS));
-            string label = string.Format(message, WiFiDirect.getDeviceName(), timeout);
+            string message = GetText(nameof(Resources.IDS_WIFI_POP_CONNECT_TO_PS_IN_PD_SECONDS));
+            string label = string.Format(message, mConnectingPeer.Name, timeout);
 
             var messageItem = new TextLabel(label)
             {
@@ -47,18 +53,12 @@ namespace SettingWiFiDirect
             var cancelButton = CreateCancelButton();
             var okButton = CreateOkButton();
 
-            ContentPage page = new ContentPage()
+            Content = new AlertDialog()
             {
-                Content = new AlertDialog()
-                {
-                    Title = ResourceManager.TextResourceManager.NUIGadgetResourceManager.GetString(
-                        nameof(Resources.IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB)),
-                    Content = connectionRequestView,
-                    Actions = new View[] { cancelButton, okButton },
-                },
+                Title = GetText(nameof(Resources.IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB)),
+                Content = connectionRequestView,
+                Actions = new View[] { cancelButton, okButton },
             };
-
-            return page;
         }
 
         private bool OnTimerTick()
@@ -67,9 +67,9 @@ namespace SettingWiFiDirect
 
             if (mProgress.CurrentValue == MaxDuration)
             {
-                if (mContentPage != null)
+                if (mAlertPage != null)
                 {
-                    NUIApplication.GetDefaultWindow().GetDefaultNavigator().Remove(mContentPage);
+                    NUIApplication.GetDefaultWindow().GetDefaultNavigator().Remove(mAlertPage);
                 }
                 return false;
             }
@@ -81,9 +81,11 @@ namespace SettingWiFiDirect
         {
             Debug("+");
             mTimer.Stop();
-            if (mContentPage != null)
+            string macAddress = mConnectingPeer.Address;
+            WiFiDirect.RejectConnection(macAddress);
+            if (mAlertPage != null)
             {
-                NUIApplication.GetDefaultWindow().GetDefaultNavigator().Remove(mContentPage);
+                NUIApplication.GetDefaultWindow().GetDefaultNavigator().Remove(mAlertPage);
             }
         }
 
@@ -91,8 +93,7 @@ namespace SettingWiFiDirect
         {
             var okButton = new Button()
             {
-                Text = ResourceManager.TextResourceManager.NUIGadgetResourceManager.GetString(
-                    nameof(Resources.IDS_WIFI_SK2_OK)),
+                Text = GetText(nameof(Resources.IDS_WIFI_SK2_OK)),
                 WidthSpecification = 300,
                 HeightSpecification = 80,
             };
@@ -104,8 +105,7 @@ namespace SettingWiFiDirect
         {
             var cancelButton = new Button()
             {
-                Text = ResourceManager.TextResourceManager.NUIGadgetResourceManager.GetString(
-                    nameof(Resources.IDS_WIFI_SK_CANCEL)),
+                Text = GetText(nameof(Resources.IDS_WIFI_SK_CANCEL)),
                 WidthSpecification = 300,
                 HeightSpecification = 80,
             };
@@ -134,16 +134,23 @@ namespace SettingWiFiDirect
         private void OnOkConfirmed(object source, ClickedEventArgs args)
         {
             Debug("+");
-            if (mContentPage != null)
+            string macAddress = mConnectingPeer.Address;
+            WiFiDirect.AcceptConnection(macAddress);
+            if (mAlertPage != null)
             {
-                NUIApplication.GetDefaultWindow().GetDefaultNavigator().Remove(mContentPage);
-            }  //TODO
+                NUIApplication.GetDefaultWindow().GetDefaultNavigator().Remove(mAlertPage);
+            }
         }
 
-        public void SetPopupPage(ContentPage page)
+        public void SetPopupPage(ConnectionPopup page)
         {
             Debug("+");
-            mContentPage = page;
+            mAlertPage = page;
+        }
+
+        string GetText(string str)
+        {
+            return ResourceManager.TextResourceManager.NUIGadgetResourceManager.GetString(str);
         }
 
     }
index 2761e55d2202cc979c705d0e5a05195edda0e5eb..d8c20ccf1403d387b4ba770e5c03cf575712e696 100644 (file)
@@ -123,6 +123,12 @@ namespace SettingWiFiDirect
             }
         }
 
+        public void UpdateTitle()
+        {
+            Debug("+");
+            mPeerCollection.Title = mAvailableGroupTitle;
+        }
+
         private void AddConnectedDevice()
         {
             Debug("+");
diff --git a/packaging/org.tizen.cssetting-wifi-direct-1.0.3.rpk b/packaging/org.tizen.cssetting-wifi-direct-1.0.3.rpk
deleted file mode 100644 (file)
index 61482cf..0000000
Binary files a/packaging/org.tizen.cssetting-wifi-direct-1.0.3.rpk and /dev/null differ
diff --git a/packaging/org.tizen.cssetting-wifi-direct-1.0.4.rpk b/packaging/org.tizen.cssetting-wifi-direct-1.0.4.rpk
new file mode 100644 (file)
index 0000000..c2d4b9e
Binary files /dev/null and b/packaging/org.tizen.cssetting-wifi-direct-1.0.4.rpk differ
index eed40b22d1945f5165aca93951a7d4699b00eae3..b54e636ae31b4057c89e4f3680a1b38014df2077 100644 (file)
@@ -1,6 +1,6 @@
 Name:          org.tizen.setting-wifi-direct
 summary:       NUI wifi-direct setting application
-Version:       1.0.3
+Version:       1.0.4
 Release:       1
 Provides:      org.tizen.setting-wifi-direct = %{version}-%{release}
 Group:         Applications/Security