Implement connection establishment functionality 45/316845/6
authorAkash Kumar <akash1.kumar@samsung.com>
Wed, 18 Dec 2024 09:59:53 +0000 (15:29 +0530)
committerAkash Kumar <akash1.kumar@samsung.com>
Tue, 24 Dec 2024 10:14:22 +0000 (15:44 +0530)
Change-Id: I84cbeaeb283555536fdac7a9a2e1d0d2a63f85de
Signed-off-by: Akash Kumar <akash1.kumar@samsung.com>
SettingWiFiDirect/SettingWiFiDirect/SettingWiFiDirect.cs
SettingWiFiDirect/SettingWiFiDirect/SettingWiFiDirect.csproj
SettingWiFiDirect/SettingWiFiDirect/TextResources/Resources.Designer.cs
SettingWiFiDirect/SettingWiFiDirect/TextResources/Resources.en-US.resx
SettingWiFiDirect/SettingWiFiDirect/TextResources/Resources.ko-KR.resx
SettingWiFiDirect/SettingWiFiDirect/TextResources/Resources.resx
SettingWiFiDirect/SettingWiFiDirect/controller/WiFiDirect.cs
SettingWiFiDirect/SettingWiFiDirect/model/Peer.cs
SettingWiFiDirect/SettingWiFiDirect/view/WiFiDirectDeviceView.cs
packaging/org.tizen.cssetting-wifi-direct-1.0.3.rpk

index bba16b295d42845ee23d03732f676a07f8bca131..ed8045391c2920f16e15f860e54e11e93f6348ab 100644 (file)
@@ -55,7 +55,7 @@ namespace SettingWiFiDirect
 
         protected override View OnCreate()
         {
-            Debug("+");
+            Debug("MainPage: " + this.GetHashCode());
             base.OnCreate();
             ResourceManager.TextResourceManager = this;
             mPeerSource = new PeerSource();
@@ -63,6 +63,17 @@ namespace SettingWiFiDirect
             return CreateComponents();
         }
 
+        protected override void OnDestroy()
+        {
+            Debug("+");
+            base.OnDestroy();
+        }
+
+        ~MainPage()
+        {
+            Debug("+");
+        }
+
         internal View CreateLoadingIcon()
         {
             var lottieAnimationView = new LottieAnimationView()
@@ -135,7 +146,7 @@ namespace SettingWiFiDirect
 
         private void OnWFDStateChanged(Object sender, WFDStateChangedEventArgs e)
         {
-            Debug("State: " + e.State);
+            Debug("State: " + e.State + " MainPage addrees: " + this.GetHashCode());
             switch (e.State)
             {
                 case WFDState.Discovering:
@@ -145,6 +156,9 @@ namespace SettingWiFiDirect
                     UpdateDeviceList();
                     mPeerSource.SetScanningState(false);
                     break;
+                case WFDState.Connected:
+                    ShowConnectedDevice();
+                    break;
                 //TODO: update for further states.
             }
         }
@@ -192,6 +206,8 @@ namespace SettingWiFiDirect
                 //item.Extra = GetInfoButton();
                 item.IsSelectable = false;
                 item.SizeWidth = mScanList.SizeWidth;
+
+                item.Clicked += OnPeerClicked;
                 return item;
             });
         }
@@ -217,6 +233,13 @@ namespace SettingWiFiDirect
             }
         }
 
+        private void ShowConnectedDevice()
+        {
+            Debug("+");
+            List<Peer> peerList = mWifiDirect.GetConnectedDevices();
+            mPeerSource.ShowConnectedPeer(peerList);
+        }
+
         private TextLabel GetHeader()
         {
             Debug("+");
@@ -227,5 +250,22 @@ namespace SettingWiFiDirect
 
             return header;
         }
+
+        private void OnPeerClicked(object sender, ClickedEventArgs e)
+        {
+            Debug("this: " + this.GetHashCode());
+            DefaultLinearItem listItem = (DefaultLinearItem)sender;
+            var peer = listItem.BindingContext as Peer;
+            Info("Name: " + peer.Name + " Address: " + peer.Address);
+            if(!peer.IsConnected())
+            {
+                Debug("Devices is not already connected.");
+                peer.Connect();
+            }else
+            {
+                Debug("Disconnect");
+                peer.Disconnect();
+            }
+        }
     }
 }
index d6f24ba6f7c721d1440c2df61e5c209f7b0010b2..fc91e745c8909db54a56f3cd066c325fb5835aec 100644 (file)
@@ -13,8 +13,8 @@
        </PropertyGroup>
 
        <ItemGroup>
-               <PackageReference Include="SettingCore" Version="1.0.346" />
-               <PackageReference Include="Tizen.NET" Version="12.0.0.18043" />
+               <PackageReference Include="SettingCore" Version="1.0.435" />
+               <PackageReference Include="Tizen.NET" Version="13.0.0.18570" />
        </ItemGroup>
 
        <ItemGroup>
index cd88a28bebac3a54b29e5918f3f08d1da460b34a..34a7637ad9117df8f8cb8a07d13b2e7377a41b8f 100644 (file)
@@ -10,8 +10,8 @@
 
 namespace SettingWiFiDirect.TextResources {
     using System;
-
-
+    
+    
     /// <summary>
     ///   A strongly-typed resource class, for looking up localized strings, etc.
     /// </summary>
@@ -22,13 +22,12 @@ namespace SettingWiFiDirect.TextResources {
     [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
     [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
     [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
-    public class Resources
-    {
-
+    public class Resources {
+        
         private static global::System.Resources.ResourceManager resourceMan;
-
+        
         private static global::System.Globalization.CultureInfo resourceCulture;
-
+        
         [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
 
         static private string mResourcePath = "";
@@ -41,44 +40,38 @@ namespace SettingWiFiDirect.TextResources {
         {
             return mResourcePath;
         }
-        internal Resources()
-        {
-        }
 
+        internal Resources() {
+        }
+        
         /// <summary>
         ///   Returns the cached ResourceManager instance used by this class.
         /// </summary>
         [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
-        public static global::System.Resources.ResourceManager ResourceManager
-        {
-            get
-            {
-                if (object.ReferenceEquals(resourceMan, null))
-                {
+        public static global::System.Resources.ResourceManager ResourceManager {
+            get {
+                if (object.ReferenceEquals(resourceMan, null)) {
                     global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SettingWiFiDirect.TextResources.Resources", typeof(Resources).Assembly);
                     resourceMan = temp;
                 }
                 return resourceMan;
             }
         }
-
+        
         /// <summary>
         ///   Overrides the current thread's CurrentUICulture property for all
         ///   resource lookups using this strongly typed resource class.
         /// </summary>
         [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
-        public static global::System.Globalization.CultureInfo Culture
-        {
-            get
-            {
+        public static global::System.Globalization.CultureInfo Culture {
+            get {
                 return resourceCulture;
             }
-            set
-            {
+            set {
                 resourceCulture = value;
             }
         }
-
+        
         /// <summary>
         ///   Looks up a localized string similar to Available.
         /// </summary>
@@ -88,6 +81,42 @@ namespace SettingWiFiDirect.TextResources {
             }
         }
         
+        /// <summary>
+        ///   Looks up a localized string similar to Connection failed.
+        /// </summary>
+        public static string IDS_CHATON_HEADER_CONNECTION_FAILED_ABB2 {
+            get {
+                return ResourceManager.GetString("IDS_CHATON_HEADER_CONNECTION_FAILED_ABB2", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to Connected.
+        /// </summary>
+        public static string IDS_COM_BODY_CONNECTED_M_STATUS {
+            get {
+                return ResourceManager.GetString("IDS_COM_BODY_CONNECTED_M_STATUS", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to Connected devices.
+        /// </summary>
+        public static string IDS_ST_HEADER_CONNECTED_DEVICES {
+            get {
+                return ResourceManager.GetString("IDS_ST_HEADER_CONNECTED_DEVICES", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to Connecting....
+        /// </summary>
+        public static string IDS_WIFI_BODY_CONNECTING_ING {
+            get {
+                return ResourceManager.GetString("IDS_WIFI_BODY_CONNECTING_ING", resourceCulture);
+            }
+        }
+        
         /// <summary>
         ///   Looks up a localized string similar to Wi-Fi Direct.
         /// </summary>
@@ -98,7 +127,7 @@ namespace SettingWiFiDirect.TextResources {
         }
         
         /// <summary>
-        ///   Looks up a localized string similar to Your device (%s) is currently visible to nearby devices..
+        ///   Looks up a localized string similar to Your device ({0}) is currently visible to nearby devices..
         /// </summary>
         public static string IDS_WIFI_BODY_YOUR_DEVICE_HPS_IS_CURRENTLY_VISIBLE_TO_NEARBY_DEVICES {
             get {
@@ -114,5 +143,23 @@ namespace SettingWiFiDirect.TextResources {
                 return ResourceManager.GetString("IDS_WIFI_HEADER_AVAILABLE_DEVICES_ABB", resourceCulture);
             }
         }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to Cancel.
+        /// </summary>
+        public static string IDS_WIFI_SK_CANCEL {
+            get {
+                return ResourceManager.GetString("IDS_WIFI_SK_CANCEL", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to Disconnect.
+        /// </summary>
+        public static string IDS_WIFI_SK_DISCONNECT {
+            get {
+                return ResourceManager.GetString("IDS_WIFI_SK_DISCONNECT", resourceCulture);
+            }
+        }
     }
 }
index a137c542bb6ca37c2d52dfe9c91cef9c2ba16650..1ba258e116c2bcc68b92177465b726166730834f 100644 (file)
   <data name="IDS_CHATON_BODY_AVAILABLE" xml:space="preserve">
     <value>Available</value>
   </data>
+  <data name="IDS_CHATON_HEADER_CONNECTION_FAILED_ABB2" xml:space="preserve">
+    <value>Connection failed</value>
+  </data>
+  <data name="IDS_COM_BODY_CONNECTED_M_STATUS" xml:space="preserve">
+    <value>Connected</value>
+  </data>
+  <data name="IDS_ST_HEADER_CONNECTED_DEVICES" xml:space="preserve">
+    <value>Connected devices</value>
+  </data>
+  <data name="IDS_WIFI_BODY_CONNECTING_ING" xml:space="preserve">
+    <value>Connecting...</value>
+  </data>
   <data name="IDS_WIFI_BODY_WI_FI_DIRECT_ABB" xml:space="preserve">
     <value>Wi-Fi Direct</value>
   </data>
   <data name="IDS_WIFI_HEADER_AVAILABLE_DEVICES_ABB" xml:space="preserve">
     <value>Available devices</value>
   </data>
-</root>
+  <data name="IDS_WIFI_SK_CANCEL" xml:space="preserve">
+    <value>Cancel</value>
+  </data>
+  <data name="IDS_WIFI_SK_DISCONNECT" xml:space="preserve">
+    <value>Disconnect</value>
+  </data>
+</root>
\ No newline at end of file
index 6db77055228fa0b5635e9e86fde43d0fa6a94208..a9f38fe349345c2403e786cf132ac9f698d939a4 100644 (file)
   <data name="IDS_CHATON_BODY_AVAILABLE" xml:space="preserve">
     <value>가능</value>
   </data>
+  <data name="IDS_CHATON_HEADER_CONNECTION_FAILED_ABB2" xml:space="preserve">
+    <value>연결 안 됨</value>
+  </data>
+  <data name="IDS_COM_BODY_CONNECTED_M_STATUS" xml:space="preserve">
+    <value>연결됨</value>
+  </data>
+  <data name="IDS_ST_HEADER_CONNECTED_DEVICES" xml:space="preserve">
+    <value>연결된 디바이스</value>
+  </data>
+  <data name="IDS_WIFI_BODY_CONNECTING_ING" xml:space="preserve">
+    <value>연결 중...</value>
+  </data>
   <data name="IDS_WIFI_BODY_WI_FI_DIRECT_ABB" xml:space="preserve">
     <value>Wi-Fi 다이렉트</value>
   </data>
   <data name="IDS_WIFI_HEADER_AVAILABLE_DEVICES_ABB" xml:space="preserve">
     <value>사용 가능한 디바이스</value>
   </data>
-</root>
+  <data name="IDS_WIFI_SK_CANCEL" xml:space="preserve">
+    <value>취소</value>
+  </data>
+  <data name="IDS_WIFI_SK_DISCONNECT" xml:space="preserve">
+    <value>연결 해제</value>
+  </data>
+</root>
\ No newline at end of file
index a137c542bb6ca37c2d52dfe9c91cef9c2ba16650..1ba258e116c2bcc68b92177465b726166730834f 100644 (file)
   <data name="IDS_CHATON_BODY_AVAILABLE" xml:space="preserve">
     <value>Available</value>
   </data>
+  <data name="IDS_CHATON_HEADER_CONNECTION_FAILED_ABB2" xml:space="preserve">
+    <value>Connection failed</value>
+  </data>
+  <data name="IDS_COM_BODY_CONNECTED_M_STATUS" xml:space="preserve">
+    <value>Connected</value>
+  </data>
+  <data name="IDS_ST_HEADER_CONNECTED_DEVICES" xml:space="preserve">
+    <value>Connected devices</value>
+  </data>
+  <data name="IDS_WIFI_BODY_CONNECTING_ING" xml:space="preserve">
+    <value>Connecting...</value>
+  </data>
   <data name="IDS_WIFI_BODY_WI_FI_DIRECT_ABB" xml:space="preserve">
     <value>Wi-Fi Direct</value>
   </data>
   <data name="IDS_WIFI_HEADER_AVAILABLE_DEVICES_ABB" xml:space="preserve">
     <value>Available devices</value>
   </data>
-</root>
+  <data name="IDS_WIFI_SK_CANCEL" xml:space="preserve">
+    <value>Cancel</value>
+  </data>
+  <data name="IDS_WIFI_SK_DISCONNECT" xml:space="preserve">
+    <value>Disconnect</value>
+  </data>
+</root>
\ No newline at end of file
index 741d19da94ef8d09e844cd61708565d1046d9652..24fad90d299979978e67c39a01b432c2607ee91d 100644 (file)
@@ -143,6 +143,22 @@ namespace SettingWiFiDirect
             return null;
         }
 
+        public List<Peer> GetConnectedDevices()
+        {
+            Debug("+");
+            try
+            {
+                mFoundDeviceList = WiFiDirectManager.GetConnectedPeers();
+                return GetPeerList();
+            }
+            catch (Exception e)
+            {
+                Debug("Fail to get connected peers " + e.ToString());
+            }
+
+            return null;
+        }
+
         public List<Peer> GetPeerList()
         {
             Debug("+");
index 3f11e309d9ad2acf4ef4e3d1ada304eb90d693fe..73b20aa5fb1d85599abd6713f6f2084049f0ebeb 100644 (file)
@@ -21,7 +21,36 @@ namespace SettingWiFiDirect
             Name = peer.Name;
             Address = peer.MacAddress;
             mRssi = peer.Rssi;
-            mStateInfo = "Available"; //TODO
+            mStateInfo = GetStateInfo();
+            mWfdPeer.ConnectionStateChanged += ConnectionStateChanged;
+        }
+
+        private void ConnectionStateChanged(object sender, ConnectionStateChangedEventArgs e)
+        {
+            Debug(this.GetHashCode() + " State: " + e.State + " Address: " + e.MacAddress);
+            if (e.MacAddress == mAddress)
+            {
+                Debug("+");
+                switch (e.State)
+                {
+                    case WiFiDirectConnectionState.ConnectionRsp:
+                        Debug("Update stateInfo");
+                        StateInfo = "Connected";
+                        break;
+                    case WiFiDirectConnectionState.ConnectionWpsRequest:
+                        break;
+                    case WiFiDirectConnectionState.DisconnectRsp:
+                        Debug("Update stateInfo");
+                        StateInfo = "Available";
+                        break;
+                    case WiFiDirectConnectionState.DisconnectInd:
+                        Debug("Update stateInfo");
+                        StateInfo = "Available";
+                        break;
+
+                }
+            }
+            Debug("StateInfo " + StateInfo);
         }
 
         private void OnPropertyChanged(string propertyName)
@@ -89,10 +118,66 @@ namespace SettingWiFiDirect
                 OnPropertyChanged("StateInfo");
             }
         }
+
         private string GetStateInfo(WiFiDirectConnectionState state)
         {
             //TODO: update
-            return "Available";
+            if (mWfdPeer.IsConnected)
+            {
+                return "Connected";
+            }else
+            {
+                return "Available";
+            }
+        }
+
+        private string GetStateInfo()
+        {
+            //TODO: update
+            if (mWfdPeer.IsConnected)
+            {
+                return "Connected";
+            }
+            else
+            {
+                return "Available";
+            }
+        }
+        public void Connect()
+        {
+            Debug("this: " + this.GetHashCode());
+            try
+            {
+                Debug("+");
+                mWfdPeer.Connect();
+                StateInfo = "Connecting...";
+                Debug("-");
+            }
+            catch (Exception e)
+            {
+                Error("Error in connecting peer. " + e.Message);
+            }
+
+        }
+
+        public void Disconnect()
+        {
+            Debug("this: " + this.GetHashCode());
+            try
+            {
+                mWfdPeer.Disconnect();
+                StateInfo = "Disconnecting...";
+            }
+            catch (Exception e)
+            {
+                Error("Error in disconnecting. " + e.Message);
+            }
+        }
+
+        public bool IsConnected() 
+        {
+            Debug ("Connected?: " + mWfdPeer.IsConnected);
+            return mWfdPeer.IsConnected;
         }
     }
 }
index 9f759ca74cd7b4324d98d2803a8c8b2ca075c73d..8992342fb9bc3a548860993b6de0a9cb9c910a5e 100644 (file)
@@ -74,7 +74,7 @@ namespace SettingWiFiDirect
     public class PeerSource : ObservableCollection<DeviceCollection>
     {
         private DeviceCollection mAvailable;
-        private DeviceCollection mPaired;
+        private DeviceCollection mConnected;
 
         public PeerSource()
         {
@@ -95,6 +95,7 @@ namespace SettingWiFiDirect
         internal void AddFoundPeers(List<Peer> peerList)
         {
             Debug("Size: " + peerList.Count);
+            mAvailable.Clear();
             foreach (var item in peerList)
             {
                 mAvailable.AddDevice(item);
@@ -105,5 +106,47 @@ namespace SettingWiFiDirect
         {
             mAvailable.IconOpacity = isScanning ? 1.0f : 0.0f;
         }
+
+        public void ShowConnectedPeer(List<Peer> peerList)
+        {
+            Debug("+");
+
+            string groupTitle = ResourceManager.TextResourceManager.NUIGadgetResourceManager.GetString(
+                nameof(Resources.IDS_ST_HEADER_CONNECTED_DEVICES));
+
+            try
+            {
+                mConnected = new DeviceCollection(groupTitle);
+                Debug("Count: " + this.Count);
+                this.Clear();
+                Debug("Count: " + this.Count);
+                this.Add(mConnected);
+                Debug("Count: " + this.Count);
+            }
+            catch (Exception e)
+            {
+                Error(e.Message + "\n" + e.StackTrace);
+            }
+            Debug("Size: " + peerList.Count);
+            mConnected.Clear();
+            foreach (var item in peerList)
+            {
+                mConnected.AddDevice(item);
+            }
+        }
+
+        private void AddConnectedDevice()
+        {
+            Debug("+");
+            foreach (Peer peer in mAvailable)
+            {
+                Debug(peer.Name + " : " + peer.Address);
+                if (peer.IsConnected())
+                {
+                    Debug("+" + peer.Name + "Connected.");
+                    mConnected.AddDevice(peer);
+                }
+            }
+        }
     }
 }
index 136ea9588aeab37e7e3830d21f1da08b7bdde8bf..05e5da77ae43e6c27369b541921b0b0b14bac71a 100644 (file)
Binary files a/packaging/org.tizen.cssetting-wifi-direct-1.0.3.rpk and b/packaging/org.tizen.cssetting-wifi-direct-1.0.3.rpk differ