Loading android/app/src/com/android/bluetooth/mapclient/MapClientService.java +5 −2 Original line number Diff line number Diff line Loading @@ -172,8 +172,11 @@ public class MapClientService extends ProfileService { // When creating a new statemachine, its state is set to CONNECTING - which will trigger // connect. MceStateMachine mapStateMachine; if (mSmLooper != null) mapStateMachine = new MceStateMachine(this, device, mSmLooper); else mapStateMachine = new MceStateMachine(this, device); if (mSmLooper != null) { mapStateMachine = new MceStateMachine(this, device, mSmLooper); } else { mapStateMachine = new MceStateMachine(this, device); } mMapInstanceMap.put(device, mapStateMachine); } Loading android/app/src/com/android/bluetooth/mapclient/MceStateMachine.java +31 −35 Original line number Diff line number Diff line Loading @@ -14,18 +14,28 @@ * limitations under the License. */ /** * Bluetooth MAP MCE StateMachine (Disconnected) | ^ CONNECT | | DISCONNECTED V | (Connecting) * (Disconnecting) | ^ CONNECTED | | DISCONNECT V | (Connected) * * <p>Valid Transitions: State + Event -> Transition: * * <p>Disconnected + CONNECT -> Connecting Connecting + CONNECTED -> Connected Connecting + TIMEOUT * -> Disconnecting Connecting + DISCONNECT/CONNECT -> Defer Message Connected + DISCONNECT -> * Disconnecting Connected + CONNECT -> Disconnecting + Defer Message Disconnecting + DISCONNECTED * -> (Safe) Disconnected Disconnecting + TIMEOUT -> (Force) Disconnected Disconnecting + * DISCONNECT/CONNECT : Defer Message */ // Bluetooth MAP MCE StateMachine // (Disconnected) // | ^ // CONNECT | | DISCONNECTED // V | // (Connecting) (Disconnecting) // | ^ // CONNECTED | | DISCONNECT // V | // (Connected) // Valid Transitions: State + Event -> Transition: // Disconnected + CONNECT -> Connecting // Connecting + CONNECTED -> Connected // Connecting + TIMEOUT -> Disconnecting // Connecting + DISCONNECT/CONNECT -> Defer Message // Connected + DISCONNECT -> Disconnecting // Connected + CONNECT -> Disconnecting + Defer Message // Disconnecting + DISCONNECTED -> (Safe) Disconnected // Disconnecting + TIMEOUT -> (Force) Disconnected // Disconnecting + DISCONNECT/CONNECT : Defer Message package com.android.bluetooth.mapclient; import static android.Manifest.permission.BLUETOOTH_CONNECT; Loading Loading @@ -64,6 +74,7 @@ import com.android.vcard.VCardConstants; import com.android.vcard.VCardEntry; import com.android.vcard.VCardProperty; import java.time.Duration; import java.time.Instant; import java.util.Calendar; import java.util.HashMap; Loading Loading @@ -100,8 +111,8 @@ class MceStateMachine extends StateMachine { // Bluetooth, to work with the default Car Messenger. This may need to be set to false if the // messaging app takes that responsibility. private static final Boolean SAVE_OUTBOUND_MESSAGES = true; private static final int DISCONNECT_TIMEOUT = 3000; private static final int CONNECT_TIMEOUT = 10000; @VisibleForTesting static final Duration DISCONNECT_TIMEOUT = Duration.ofSeconds(3); private static final Duration CONNECT_TIMEOUT = Duration.ofSeconds(10); private static final int MAX_MESSAGES = 20; private static final int MSG_CONNECT = 1; private static final int MSG_DISCONNECT = 2; Loading Loading @@ -215,27 +226,16 @@ class MceStateMachine extends StateMachine { new ConcurrentHashMap<String, MessageMetadata>(); MceStateMachine(MapClientService service, BluetoothDevice device) { this(service, device, null, null); super(TAG); // Create a state machine with its own separate thread mService = service; mDevice = device; initStateMachine(); } MceStateMachine(MapClientService service, BluetoothDevice device, Looper looper) { this(service, device, null, null, looper); } @VisibleForTesting MceStateMachine( MapClientService service, BluetoothDevice device, MasClient masClient, MapClientContent database) { super(TAG); mService = service; mMasClient = masClient; mDevice = device; mDatabase = database; initStateMachine(); } @VisibleForTesting MceStateMachine( MapClientService service, Loading Loading @@ -552,7 +552,7 @@ class MceStateMachine extends StateMachine { // When commanded to connect begin SDP to find the MAS server. mDevice.sdpSearch(BluetoothUuid.MAS); sendMessageDelayed(MSG_CONNECTING_TIMEOUT, CONNECT_TIMEOUT); sendMessageDelayed(MSG_CONNECTING_TIMEOUT, CONNECT_TIMEOUT.toMillis()); Log.i(TAG, Utils.getLoggableAddress(mDevice) + " [Connecting]: Await SDP results"); } Loading Loading @@ -1270,7 +1270,7 @@ class MceStateMachine extends StateMachine { if (mMasClient != null) { mMasClient.makeRequest(new RequestSetNotificationRegistration(false)); mMasClient.shutdown(); sendMessageDelayed(MSG_DISCONNECTING_TIMEOUT, DISCONNECT_TIMEOUT); sendMessageDelayed(MSG_DISCONNECTING_TIMEOUT, DISCONNECT_TIMEOUT.toMillis()); } else { // MAP was never connected transitionTo(mDisconnected); Loading Loading @@ -1345,10 +1345,6 @@ class MceStateMachine extends StateMachine { return "MSG_GET_MESSAGE_LISTING"; case MSG_SET_MESSAGE_STATUS: return "MSG_SET_MESSAGE_STATUS"; case DISCONNECT_TIMEOUT: return "DISCONNECT_TIMEOUT"; case CONNECT_TIMEOUT: return "CONNECT_TIMEOUT"; case MSG_CONNECT: return "MSG_CONNECT"; case MSG_DISCONNECT: Loading android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java +142 −277 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
android/app/src/com/android/bluetooth/mapclient/MapClientService.java +5 −2 Original line number Diff line number Diff line Loading @@ -172,8 +172,11 @@ public class MapClientService extends ProfileService { // When creating a new statemachine, its state is set to CONNECTING - which will trigger // connect. MceStateMachine mapStateMachine; if (mSmLooper != null) mapStateMachine = new MceStateMachine(this, device, mSmLooper); else mapStateMachine = new MceStateMachine(this, device); if (mSmLooper != null) { mapStateMachine = new MceStateMachine(this, device, mSmLooper); } else { mapStateMachine = new MceStateMachine(this, device); } mMapInstanceMap.put(device, mapStateMachine); } Loading
android/app/src/com/android/bluetooth/mapclient/MceStateMachine.java +31 −35 Original line number Diff line number Diff line Loading @@ -14,18 +14,28 @@ * limitations under the License. */ /** * Bluetooth MAP MCE StateMachine (Disconnected) | ^ CONNECT | | DISCONNECTED V | (Connecting) * (Disconnecting) | ^ CONNECTED | | DISCONNECT V | (Connected) * * <p>Valid Transitions: State + Event -> Transition: * * <p>Disconnected + CONNECT -> Connecting Connecting + CONNECTED -> Connected Connecting + TIMEOUT * -> Disconnecting Connecting + DISCONNECT/CONNECT -> Defer Message Connected + DISCONNECT -> * Disconnecting Connected + CONNECT -> Disconnecting + Defer Message Disconnecting + DISCONNECTED * -> (Safe) Disconnected Disconnecting + TIMEOUT -> (Force) Disconnected Disconnecting + * DISCONNECT/CONNECT : Defer Message */ // Bluetooth MAP MCE StateMachine // (Disconnected) // | ^ // CONNECT | | DISCONNECTED // V | // (Connecting) (Disconnecting) // | ^ // CONNECTED | | DISCONNECT // V | // (Connected) // Valid Transitions: State + Event -> Transition: // Disconnected + CONNECT -> Connecting // Connecting + CONNECTED -> Connected // Connecting + TIMEOUT -> Disconnecting // Connecting + DISCONNECT/CONNECT -> Defer Message // Connected + DISCONNECT -> Disconnecting // Connected + CONNECT -> Disconnecting + Defer Message // Disconnecting + DISCONNECTED -> (Safe) Disconnected // Disconnecting + TIMEOUT -> (Force) Disconnected // Disconnecting + DISCONNECT/CONNECT : Defer Message package com.android.bluetooth.mapclient; import static android.Manifest.permission.BLUETOOTH_CONNECT; Loading Loading @@ -64,6 +74,7 @@ import com.android.vcard.VCardConstants; import com.android.vcard.VCardEntry; import com.android.vcard.VCardProperty; import java.time.Duration; import java.time.Instant; import java.util.Calendar; import java.util.HashMap; Loading Loading @@ -100,8 +111,8 @@ class MceStateMachine extends StateMachine { // Bluetooth, to work with the default Car Messenger. This may need to be set to false if the // messaging app takes that responsibility. private static final Boolean SAVE_OUTBOUND_MESSAGES = true; private static final int DISCONNECT_TIMEOUT = 3000; private static final int CONNECT_TIMEOUT = 10000; @VisibleForTesting static final Duration DISCONNECT_TIMEOUT = Duration.ofSeconds(3); private static final Duration CONNECT_TIMEOUT = Duration.ofSeconds(10); private static final int MAX_MESSAGES = 20; private static final int MSG_CONNECT = 1; private static final int MSG_DISCONNECT = 2; Loading Loading @@ -215,27 +226,16 @@ class MceStateMachine extends StateMachine { new ConcurrentHashMap<String, MessageMetadata>(); MceStateMachine(MapClientService service, BluetoothDevice device) { this(service, device, null, null); super(TAG); // Create a state machine with its own separate thread mService = service; mDevice = device; initStateMachine(); } MceStateMachine(MapClientService service, BluetoothDevice device, Looper looper) { this(service, device, null, null, looper); } @VisibleForTesting MceStateMachine( MapClientService service, BluetoothDevice device, MasClient masClient, MapClientContent database) { super(TAG); mService = service; mMasClient = masClient; mDevice = device; mDatabase = database; initStateMachine(); } @VisibleForTesting MceStateMachine( MapClientService service, Loading Loading @@ -552,7 +552,7 @@ class MceStateMachine extends StateMachine { // When commanded to connect begin SDP to find the MAS server. mDevice.sdpSearch(BluetoothUuid.MAS); sendMessageDelayed(MSG_CONNECTING_TIMEOUT, CONNECT_TIMEOUT); sendMessageDelayed(MSG_CONNECTING_TIMEOUT, CONNECT_TIMEOUT.toMillis()); Log.i(TAG, Utils.getLoggableAddress(mDevice) + " [Connecting]: Await SDP results"); } Loading Loading @@ -1270,7 +1270,7 @@ class MceStateMachine extends StateMachine { if (mMasClient != null) { mMasClient.makeRequest(new RequestSetNotificationRegistration(false)); mMasClient.shutdown(); sendMessageDelayed(MSG_DISCONNECTING_TIMEOUT, DISCONNECT_TIMEOUT); sendMessageDelayed(MSG_DISCONNECTING_TIMEOUT, DISCONNECT_TIMEOUT.toMillis()); } else { // MAP was never connected transitionTo(mDisconnected); Loading Loading @@ -1345,10 +1345,6 @@ class MceStateMachine extends StateMachine { return "MSG_GET_MESSAGE_LISTING"; case MSG_SET_MESSAGE_STATUS: return "MSG_SET_MESSAGE_STATUS"; case DISCONNECT_TIMEOUT: return "DISCONNECT_TIMEOUT"; case CONNECT_TIMEOUT: return "CONNECT_TIMEOUT"; case MSG_CONNECT: return "MSG_CONNECT"; case MSG_DISCONNECT: Loading
android/app/tests/unit/src/com/android/bluetooth/mapclient/MapClientStateMachineTest.java +142 −277 File changed.Preview size limit exceeded, changes collapsed. Show changes