From: Wootak Jung Date: Thu, 13 Oct 2022 05:02:31 +0000 (+0900) Subject: Add discovery auto start function X-Git-Tag: accepted/tizen/unified/20221111.105330~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e60d7ac0f55a8506f110cdb48200614830ca5653;p=profile%2Fiot%2Fapps%2Fdotnet%2Fsetting-bluetooth.git Add discovery auto start function get bonded devices when bt enabled start discovery when bt enabled start discovery when enter the app Change-Id: Iec6536719f821979c0e1ad67930a0ea8acf1f02d Signed-off-by: Wootak Jung --- diff --git a/SettingBluetooth/SettingBluetooth/Controller/AdapterController.cs b/SettingBluetooth/SettingBluetooth/Controller/AdapterController.cs index fce381c..5a7c426 100644 --- a/SettingBluetooth/SettingBluetooth/Controller/AdapterController.cs +++ b/SettingBluetooth/SettingBluetooth/Controller/AdapterController.cs @@ -45,5 +45,11 @@ namespace SettingBluetooth.Controller BtModel.StartDiscovery(); } } + + internal static void AutoStart() + { + Log.Info(Program.LogTag, "Start discovery"); + BtModel.StartDiscovery(); + } } } diff --git a/SettingBluetooth/SettingBluetooth/Controller/DeviceController.cs b/SettingBluetooth/SettingBluetooth/Controller/DeviceController.cs index d6c06e4..0548985 100644 --- a/SettingBluetooth/SettingBluetooth/Controller/DeviceController.cs +++ b/SettingBluetooth/SettingBluetooth/Controller/DeviceController.cs @@ -112,6 +112,10 @@ namespace SettingBluetooth.Controller ConnectHid(device.BtDevice); } } + else + { + Log.Info(Program.LogTag, "No available profile"); + } } else { diff --git a/SettingBluetooth/SettingBluetooth/Model/BtModel.cs b/SettingBluetooth/SettingBluetooth/Model/BtModel.cs index 75c3ba1..39a9972 100644 --- a/SettingBluetooth/SettingBluetooth/Model/BtModel.cs +++ b/SettingBluetooth/SettingBluetooth/Model/BtModel.cs @@ -44,6 +44,11 @@ namespace SettingBluetooth.Model BtModelImpl.Instance.StopDiscovery(); } + internal static void GetBondedDevices() + { + BtModelImpl.Instance.GetBondedDevices(); + } + internal static event EventHandler OperationStateChanged { add diff --git a/SettingBluetooth/SettingBluetooth/Model/BtModelImpl.cs b/SettingBluetooth/SettingBluetooth/Model/BtModelImpl.cs index 2a63eff..31a4051 100644 --- a/SettingBluetooth/SettingBluetooth/Model/BtModelImpl.cs +++ b/SettingBluetooth/SettingBluetooth/Model/BtModelImpl.cs @@ -55,24 +55,28 @@ namespace SettingBluetooth.Model mOperationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Searched)); } + internal void GetBondedDevices() + { + IEnumerable devices; + BtDevice btDevice; + BtDeviceChangedEventArgs args; + devices = BluetoothAdapter.GetBondedDevices(); + + foreach (BluetoothDevice device in devices) + { + Log.Info(Program.LogTag, "GetBondedDevices. Address: " + device.Address + ", Name: " + device.Name); + btDevice = new BtDevice(device, BtDeviceState.Paired); + args = new BtDeviceChangedEventArgs(btDevice); + mDeviceChanged?.Invoke(null, args); + } + } + private void AdapterStateChanged(object obj, StateChangedEventArgs ev) { if (ev.BTState == BluetoothState.Enabled) { mOperationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Activated)); - - IEnumerable devices; - BtDevice btDevice; - BtDeviceChangedEventArgs args; - - devices = BluetoothAdapter.GetBondedDevices(); - foreach (BluetoothDevice device in devices) - { - Log.Info(Program.LogTag, "GetBondedDevices. Address: " + device.Address + ", Name: " + device.Name); - btDevice = new BtDevice(device, BtDeviceState.Paired); - args = new BtDeviceChangedEventArgs(btDevice); - mDeviceChanged?.Invoke(null, args); - } + GetBondedDevices(); } else { diff --git a/SettingBluetooth/SettingBluetooth/View/BtDeviceView.cs b/SettingBluetooth/SettingBluetooth/View/BtDeviceView.cs index f7e798e..1c2e100 100644 --- a/SettingBluetooth/SettingBluetooth/View/BtDeviceView.cs +++ b/SettingBluetooth/SettingBluetooth/View/BtDeviceView.cs @@ -406,6 +406,15 @@ namespace SettingBluetooth view.Add(mScanButton); } + internal static void AddDeviceView(View view) + { + Log.Info(Program.LogTag, "Add device view"); + AddPairedDeviceView(view); + AddSearchedDeviceView(view); + BtModel.GetBondedDevices(); + AdapterController.AutoStart(); + } + internal static void RemovePairedDeviceView(View view) { if (mPairedDeviceView) diff --git a/SettingBluetooth/SettingBluetooth/View/BtMainView.cs b/SettingBluetooth/SettingBluetooth/View/BtMainView.cs index 1855467..e6749ee 100644 --- a/SettingBluetooth/SettingBluetooth/View/BtMainView.cs +++ b/SettingBluetooth/SettingBluetooth/View/BtMainView.cs @@ -32,9 +32,7 @@ namespace SettingBluetooth case BtOperationState.Deactivating: break; case BtOperationState.Activated: - Log.Info(Program.LogTag, "Add initial view"); - BtDeviceView.AddPairedDeviceView(mMainView); - BtDeviceView.AddSearchedDeviceView(mMainView); + BtDeviceView.AddDeviceView(mMainView); break; case BtOperationState.Activating: break; @@ -91,6 +89,11 @@ namespace SettingBluetooth BtModel.OperationStateChanged += BtModelOperationStateChanged; BtModel.DeviceChanged += BtDeviceView.BtModelDeviceChanged; + if (BtModel.IsEnabled) + { + BtDeviceView.AddDeviceView(mMainView); + } + mMainPage = new ContentPage() { AppBar = appBar, diff --git a/packaging/org.tizen.cssetting-bluetooth-1.0.0.tpk b/packaging/org.tizen.cssetting-bluetooth-1.0.0.tpk index 2b53b8e..ff55c71 100644 Binary files a/packaging/org.tizen.cssetting-bluetooth-1.0.0.tpk and b/packaging/org.tizen.cssetting-bluetooth-1.0.0.tpk differ