@@ -40,6 +40,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
4040 private static final String SECURE_SETTINGS_BLUETOOTH_NAME ="bluetooth_name" ;
4141 private static final int TIMEOUT_BIND_MS = 3000 ; //Maximum msec to wait for a bind
4242 private static final int TIMEOUT_SAVE_MS = 500 ; //Maximum msec to wait for a save
43+ //Maximum msec to wait for service restart
44+ private static final int SERVICE_RESTART_TIME_MS = 200 ;
4345
4446 private static final int MESSAGE_ENABLE = 1 ;
4547 private static final int MESSAGE_DISABLE = 2 ;
@@ -49,6 +51,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
4951 private static final int MESSAGE_UNREGISTER_STATE_CHANGE_CALLBACK = 31 ;
5052 private static final int MESSAGE_BLUETOOTH_SERVICE_CONNECTED = 40 ;
5153 private static final int MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED = 41 ;
54+ private static final int MESSAGE_RESTART_BLUETOOTH_SERVICE = 42 ;
5255 private static final int MESSAGE_BLUETOOTH_STATE_CHANGE =60 ;
5356 private static final int MESSAGE_TIMEOUT_BIND =100 ;
5457 private static final int MESSAGE_TIMEOUT_UNBIND =101 ;
@@ -660,8 +663,36 @@ public void handleMessage(Message msg) {
660663 {
661664 if (DBG ) Log .d (TAG , "MESSAGE_BLUETOOTH_SERVICE_DISCONNECTED" );
662665 sendBluetoothServiceDownCallback ();
666+
667+ // Send BT state broadcast to update
668+ // the BT icon correctly
669+ Message stateChangeMsg = mHandler .obtainMessage (
670+ MESSAGE_BLUETOOTH_STATE_CHANGE );
671+ stateChangeMsg .arg1 = BluetoothAdapter .STATE_ON ;
672+ stateChangeMsg .arg2 =
673+ BluetoothAdapter .STATE_TURNING_OFF ;
674+ mHandler .sendMessage (stateChangeMsg );
675+ synchronized (mConnection ) {
676+ mBluetooth = null ;
677+ }
678+ // Send a Bluetooth Restart message
679+ Message restartMsg = mHandler .obtainMessage (
680+ MESSAGE_RESTART_BLUETOOTH_SERVICE );
681+ mHandler .sendMessageDelayed (restartMsg ,
682+ SERVICE_RESTART_TIME_MS );
663683 break ;
664684 }
685+ case MESSAGE_RESTART_BLUETOOTH_SERVICE :
686+ {
687+ Log .d (TAG , "MESSAGE_RESTART_BLUETOOTH_SERVICE:"
688+ +" Restart IBluetooth service" );
689+ /* Enable without persisting the setting as
690+ it doesnt change when IBluetooth
691+ service restarts */
692+ handleEnable (false , mQuietEnable );
693+ break ;
694+ }
695+
665696 case MESSAGE_TIMEOUT_UNBIND :
666697 {
667698 Log .e (TAG , "MESSAGE_TIMEOUT_UNBIND" );
0 commit comments