Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 03da5270 authored by Gaurav Asati's avatar Gaurav Asati Committed by Linux Build Service Account
Browse files

Delay connection time-out.

This change delays the auto connect of
audio profiles to make sure that all the
clients of the Bluetooth Audio services
are ready. This handles a corner case
of BT OFF-ON and auto connect.

Change-Id: I14b5ebc37617847f87387dfee501b59427c9d14a
parent 8e27fc66
Loading
Loading
Loading
Loading
+31 −13
Original line number Diff line number Diff line
@@ -615,6 +615,8 @@ public class AdapterService extends Service {
    private static final int MESSAGE_PROFILE_INIT_PRIORITIES=40;
    private static final int CONNECT_OTHER_PROFILES_TIMEOUT= 6000;
    private static final int CONNECT_OTHER_PROFILES_TIMEOUT_DELAYED = 10000;
    private static final int MESSAGE_AUTO_CONNECT_PROFILES = 50;
    private static final int AUTO_CONNECT_PROFILES_TIMEOUT= 500;

    private final Handler mHandler = new Handler() {
        @Override
@@ -647,6 +649,11 @@ public class AdapterService extends Service {
                    processConnectOtherProfiles((BluetoothDevice) msg.obj,msg.arg1);
                }
                    break;
                case MESSAGE_AUTO_CONNECT_PROFILES: {
                    if (DBG) debugLog( "MESSAGE_AUTO_CONNECT_PROFILES");
                    autoConnectProfilesDelayed();
                    break;
                }
            }
        }
    };
@@ -1524,19 +1531,30 @@ public class AdapterService extends Service {
          return mQuietmode;
     }

    // Delaying Auto Connect to make sure that all clients
    // are up and running, specially BluetoothHeadset.
    public void autoConnect() {
        debugLog( "delay auto connect by 500 ms");
        if ((mHandler.hasMessages(MESSAGE_AUTO_CONNECT_PROFILES) == false) &&
            (isQuietModeEnabled()== false)) {
            Message m = mHandler.obtainMessage(MESSAGE_AUTO_CONNECT_PROFILES);
            mHandler.sendMessageDelayed(m,AUTO_CONNECT_PROFILES_TIMEOUT);
        }
    }

    private void autoConnectProfilesDelayed(){
        if (getState() != BluetoothAdapter.STATE_ON){
             errorLog("autoConnect() - BT is not ON. Exiting autoConnect");
            errorLog("BT is not ON. Exiting autoConnect");
            return;
        }
        if (isQuietModeEnabled() == false) {
             debugLog( "autoConnect() - Initiate auto connection on BT on...");
            debugLog("Initiate auto connection on BT on...");
            autoConnectHeadset();
            autoConnectA2dp();
            autoConnectA2dpSink();
        }
        else {
             debugLog( "autoConnect() - BT is in quiet mode. Not initiating auto connections");
            debugLog("BT is in Quiet mode. No auto connections");
        }
    }