Add to get bluetooth state 89/31189/2
authorChengyi Zhao <chengyi1.zhao@archermind.com>
Tue, 2 Dec 2014 03:38:15 +0000 (11:38 +0800)
committerChengyi Zhao <chengyi1.zhao@archermind.com>
Wed, 3 Dec 2014 01:55:18 +0000 (09:55 +0800)
There is no need to check 'tethering' status
to get this bluetooth state.

Change-Id: I1472b4a1c09c74cb6d588fc8037391757f5abaf2
Signed-off-by: Chengyi Zhao <chengyi1.zhao@archermind.com>
src/libnetwork.c

index 63389032ff8958088902d495309bef5d933cc0fa..db7633215ef600d41b87056103c460f4c989ec4f 100755 (executable)
@@ -374,40 +374,25 @@ bool _connection_libnet_get_ethernet_state(connection_ethernet_state_e* state)
 
 bool _connection_libnet_get_bluetooth_state(connection_bt_state_e* state)
 {
-       int i = 0;
-       struct _profile_list_s bluetooth_profiles = {0, 0, NULL};
-       /*
-       TODO:
-       net_get_profile_list(NET_DEVICE_BLUETOOTH, &bluetooth_profiles.profiles, &bluetooth_profiles.count);
-        */
+       struct connman_technology *technology;
+       bool powered;
+       bool connected;
 
-       if (bluetooth_profiles.count == 0) {
-               *state = CONNECTION_BT_STATE_DEACTIVATED;
-               return true;
-       }
+       technology = connman_get_technology(TECH_TYPE_BLUETOOTH);
+       if (technology == NULL)
+               return false;
 
-       for (; i < bluetooth_profiles.count; i++) {
-               switch (bluetooth_profiles.profiles[i].ProfileState) {
-               case NET_STATE_TYPE_ONLINE:
-               case NET_STATE_TYPE_READY:
+       *state = CONNECTION_BT_STATE_DEACTIVATED;
+       powered = connman_get_technology_powered(technology);
+
+       if (powered) {
+               connected = connman_get_technology_connected(technology);
+               if (connected)
                        *state = CONNECTION_BT_STATE_CONNECTED;
-                       goto done;
-               case NET_STATE_TYPE_IDLE:
-               case NET_STATE_TYPE_FAILURE:
-               case NET_STATE_TYPE_ASSOCIATION:
-               case NET_STATE_TYPE_CONFIGURATION:
-               case NET_STATE_TYPE_DISCONNECT:
+               else
                        *state = CONNECTION_BT_STATE_DISCONNECTED;
-                       break;
-               default:
-                       __libnet_clear_profile_list(&bluetooth_profiles);
-                       return false;
-               }
        }
 
-done:
-       __libnet_clear_profile_list(&bluetooth_profiles);
-
        return true;
 }