diff options
author | Casper Bonde <c.bonde@samsung.com> | 2015-04-16 15:24:00 +0200 |
---|---|---|
committer | Andre Eisenbach <eisenbach@google.com> | 2015-06-02 17:01:06 -0700 |
commit | 1f1103e93ba7ebd48c57c9627dc7b262c6f01c77 (patch) | |
tree | fd4d5b6bd8e24234ecfb6b1f0246663d4cd0bcd0 /tests | |
parent | 7ac99a6ff9b5389948eec70d2afa96bb255feedd (diff) | |
download | android_packages_apps_Bluetooth-1f1103e93ba7ebd48c57c9627dc7b262c6f01c77.tar.gz android_packages_apps_Bluetooth-1f1103e93ba7ebd48c57c9627dc7b262c6f01c77.tar.bz2 android_packages_apps_Bluetooth-1f1103e93ba7ebd48c57c9627dc7b262c6f01c77.zip |
SAP: Change to use new SDP Api (2/4)
Added support for Sim Access Profile (SAP) in the SDPManager.
To make it easier to test, both SDP record creation and seach
is added.
Change-Id: I871eb762389e3717b8bd6bc37a8ffc09fff6f589
Signed-off-by: Casper Bonde <c.bonde@samsung.com>
Diffstat (limited to 'tests')
3 files changed, 92 insertions, 32 deletions
diff --git a/tests/src/com/android/bluetooth/tests/SapServerTest.java b/tests/src/com/android/bluetooth/tests/SapServerTest.java index f0dc084dc..3de3240a2 100644 --- a/tests/src/com/android/bluetooth/tests/SapServerTest.java +++ b/tests/src/com/android/bluetooth/tests/SapServerTest.java @@ -30,8 +30,9 @@ import com.android.bluetooth.sap.SapServer; public class SapServerTest extends AndroidTestCase { protected static String TAG = "SapServerTest"; protected static final boolean D = true; - private static final boolean rilTestModeEnabled = false; /* Set the RIL driver in test mode, where request stubs are used in stead of forwarding to the modem/sim */ - + // Set the RIL driver in test mode, where request stubs are used instead + // of forwarding to the Modem/SIM. + private static final boolean rilTestModeEnabled = false; private Context mContext = null; public SapServerTest() { @@ -176,16 +177,20 @@ public class SapServerTest extends AndroidTestCase { } sequencer.addStep(apdu7816Req, apdu7816Resp); - SapMessage transferCardReaderStatusReq = new SapMessage(SapMessage.ID_TRANSFER_CARD_READER_STATUS_REQ); + SapMessage transferCardReaderStatusReq = + new SapMessage(SapMessage.ID_TRANSFER_CARD_READER_STATUS_REQ); - SapMessage transferCardReaderStatusResp = new SapMessage(SapMessage.ID_TRANSFER_CARD_READER_STATUS_RESP); + SapMessage transferCardReaderStatusResp = + new SapMessage(SapMessage.ID_TRANSFER_CARD_READER_STATUS_RESP); transferCardReaderStatusResp.setResultCode(SapMessage.RESULT_OK); sequencer.addStep(transferCardReaderStatusReq, transferCardReaderStatusResp); - SapMessage setTransportProtocolReq = new SapMessage(SapMessage.ID_SET_TRANSPORT_PROTOCOL_REQ); + SapMessage setTransportProtocolReq = + new SapMessage(SapMessage.ID_SET_TRANSPORT_PROTOCOL_REQ); setTransportProtocolReq.setTransportProtocol(0x01); // T=1 - SapMessage setTransportProtocolResp = new SapMessage(SapMessage.ID_SET_TRANSPORT_PROTOCOL_RESP); + SapMessage setTransportProtocolResp = + new SapMessage(SapMessage.ID_SET_TRANSPORT_PROTOCOL_RESP); setTransportProtocolResp.setResultCode(SapMessage.RESULT_OK); sequencer.addStep(setTransportProtocolReq, setTransportProtocolResp); @@ -222,8 +227,12 @@ public class SapServerTest extends AndroidTestCase { SapMessage apduReq = new SapMessage(SapMessage.ID_TRANSFER_APDU_REQ); apduReq.setApdu(dummyBytes); - SapMessage apduResp = null; /* expect no response as we send a SIM_RESET before the write APDU completes - TODO: Consider adding a real response, and add an optional flag. */ + // + // Expect no response as we send a SIM_RESET before the write APDU + // completes. + // TODO: Consider adding a real response, and add an optional flag. + // + SapMessage apduResp = null; index = sequencer.addStep(apduReq, apduResp); SapMessage resetReq = new SapMessage(SapMessage.ID_RESET_SIM_REQ); @@ -249,7 +258,8 @@ public class SapServerTest extends AndroidTestCase { */ public void testSapServerTimeouts() { Intent sapDisconnectIntent = new Intent(SapServer.SAP_DISCONNECT_ACTION); - sapDisconnectIntent.putExtra(SapServer.SAP_DISCONNECT_TYPE_EXTRA, SapMessage.DISC_IMMEDIATE); + sapDisconnectIntent.putExtra( + SapServer.SAP_DISCONNECT_TYPE_EXTRA, SapMessage.DISC_IMMEDIATE); mContext = this.getContext(); try { @@ -298,7 +308,8 @@ public class SapServerTest extends AndroidTestCase { public class SeqStep { public ArrayList<SapMessage> requests = null; public ArrayList<SapMessage> responses = null; - public int index = 0; /* requests with same index are executed in parallel (without waiting for a response) */ + public int index = 0; // Requests with same index are executed in + // parallel without waiting for a response public SeqStep(SapMessage request, SapMessage response) { requests = new ArrayList<SapMessage>(); responses = new ArrayList<SapMessage>(); @@ -328,7 +339,8 @@ public class SapServerTest extends AndroidTestCase { public SapSequencer() throws IOException { /* Setup the looper thread to handle messages */ - handlerThread = new HandlerThread("SapTestTimeoutHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND); + handlerThread = new HandlerThread("SapTestTimeoutHandler", + android.os.Process.THREAD_PRIORITY_BACKGROUND); handlerThread.start(); Looper testLooper = handlerThread.getLooper(); messageHandler = new Handler(testLooper, this); @@ -339,7 +351,8 @@ public class SapServerTest extends AndroidTestCase { /* Create a SapServer. Fake the BtSocket using piped input/output streams*/ inStream = new PipedInputStream(8092); outStream = new PipedOutputStream(); - sapServer = new SapServer(null, mContext, new PipedInputStream(outStream, 8092), new PipedOutputStream(inStream)); + sapServer = new SapServer(null, mContext, new PipedInputStream(outStream, 8092), + new PipedOutputStream(inStream)); sapServer.start(); } @@ -364,15 +377,16 @@ public class SapServerTest extends AndroidTestCase { * @param response The response to EXPECT from the SAP server * @return The created step index, which can be used when adding events or actions. */ - public int addStep(SapMessage request, SapMessage response) { // TODO: should we add a step trigger? (in stead of just executing in sequence) + public int addStep(SapMessage request, SapMessage response) { + // TODO: should we add a step trigger? (in stead of just executing in sequence) SeqStep newStep = new SeqStep(request, response); sequence.add(newStep); return sequence.indexOf(newStep); } /** - * Add a sub-step to a sequencer step. All requests added to the same index will be send to the - * SapServer in the order added before listening for the response. + * Add a sub-step to a sequencer step. All requests added to the same index will be send to + * the SapServer in the order added before listening for the response. * The response order is not validated - hence for each response received the entire list of * responses in the step will be searched for a match. * @param index the index returned from addStep() to which the sub-step is to be added. @@ -399,8 +413,9 @@ public class SapServerTest extends AndroidTestCase { if(step.requests != null) { for(SapMessage request : step.requests) { if(request != null) { - Log.i(TAG, "Writing request: " + SapMessage.getMsgTypeName(request.getMsgType())); - writeSapMessage(request, false); /* write the message without flushing */ + Log.i(TAG, "Writing request: " + + SapMessage.getMsgTypeName(request.getMsgType())); + writeSapMessage(request, false); // write the message without flushing } } writeSapMessage(null, true); /* flush the pipe */ @@ -414,11 +429,13 @@ public class SapServerTest extends AndroidTestCase { while(!done) { for(SapMessage response : step.responses) { if(response != null) - Log.i(TAG, "Waiting for the response: " + SapMessage.getMsgTypeName(response.getMsgType())); + Log.i(TAG, "Waiting for the response: " + + SapMessage.getMsgTypeName(response.getMsgType())); } inMsg = readSapMessage(); if(inMsg != null) - Log.i(TAG, "Read message: " + SapMessage.getMsgTypeName(inMsg.getMsgType())); + Log.i(TAG, "Read message: " + + SapMessage.getMsgTypeName(inMsg.getMsgType())); else assertTrue("Failed to read message.", false); @@ -465,19 +482,21 @@ public class SapServerTest extends AndroidTestCase { */ private boolean compareSapMessages(SapMessage received, SapMessage expected) { boolean retVal = true; - if(expected.getCardReaderStatus() != -1 && received.getCardReaderStatus() != expected.getCardReaderStatus()) { + if(expected.getCardReaderStatus() != -1 && + received.getCardReaderStatus() != expected.getCardReaderStatus()) { Log.i(TAG, "received.getCardReaderStatus() != expected.getCardReaderStatus() " - + received.getCardReaderStatus() +" != " + expected.getCardReaderStatus()); + + received.getCardReaderStatus() + " != " + expected.getCardReaderStatus()); retVal = false; } if(received.getConnectionStatus() != expected.getConnectionStatus()) { Log.i(TAG, "received.getConnectionStatus() != expected.getConnectionStatus() " - + received.getConnectionStatus() +" != " + expected.getConnectionStatus()); + + received.getConnectionStatus() + " != " + expected.getConnectionStatus()); retVal = false; } if(received.getDisconnectionType() != expected.getDisconnectionType()) { Log.i(TAG, "received.getDisconnectionType() != expected.getDisconnectionType() " - + received.getDisconnectionType() +" != " + expected.getDisconnectionType()); + + received.getDisconnectionType() + " != " + + expected.getDisconnectionType()); retVal = false; } if(received.getMaxMsgSize() != expected.getMaxMsgSize()) { @@ -492,37 +511,43 @@ public class SapServerTest extends AndroidTestCase { } if(received.getResultCode() != expected.getResultCode()) { Log.i(TAG, "received.getResultCode() != expected.getResultCode() " - + received.getResultCode() +" != " + expected.getResultCode()); + + received.getResultCode() + " != " + expected.getResultCode()); retVal = false; } if(received.getStatusChange() != expected.getStatusChange()) { Log.i(TAG, "received.getStatusChange() != expected.getStatusChange() " - + received.getStatusChange() +" != " + expected.getStatusChange()); + + received.getStatusChange() + " != " + expected.getStatusChange()); retVal = false; } if(received.getTransportProtocol() != expected.getTransportProtocol()) { Log.i(TAG, "received.getTransportProtocol() != expected.getTransportProtocol() " - + received.getTransportProtocol() +" != " + expected.getTransportProtocol()); + + received.getTransportProtocol() + " != " + + expected.getTransportProtocol()); retVal = false; } if(!Arrays.equals(received.getApdu(), expected.getApdu())) { Log.i(TAG, "received.getApdu() != expected.getApdu() " - + Arrays.toString(received.getApdu()) +" != " + Arrays.toString(expected.getApdu())); + + Arrays.toString(received.getApdu()) + " != " + + Arrays.toString(expected.getApdu())); retVal = false; } if(!Arrays.equals(received.getApdu7816(), expected.getApdu7816())) { Log.i(TAG, "received.getApdu7816() != expected.getApdu7816() " - + Arrays.toString(received.getApdu7816()) +" != " + Arrays.toString(expected.getApdu7816())); + + Arrays.toString(received.getApdu7816()) + " != " + + Arrays.toString(expected.getApdu7816())); retVal = false; } - if(expected.getApduResp() != null && !Arrays.equals(received.getApduResp(), expected.getApduResp())) { + if(expected.getApduResp() != null && !Arrays.equals(received.getApduResp(), + expected.getApduResp())) { Log.i(TAG, "received.getApduResp() != expected.getApduResp() " - + Arrays.toString(received.getApduResp()) +" != " + Arrays.toString(expected.getApduResp())); + + Arrays.toString(received.getApduResp()) + " != " + + Arrays.toString(expected.getApduResp())); retVal = false; } if(expected.getAtr() != null && !Arrays.equals(received.getAtr(), expected.getAtr())) { Log.i(TAG, "received.getAtr() != expected.getAtr() " - + Arrays.toString(received.getAtr()) +" != " + Arrays.toString(expected.getAtr())); + + Arrays.toString(received.getAtr()) + " != " + + Arrays.toString(expected.getAtr())); retVal = false; } return retVal; diff --git a/tests/src/com/android/bluetooth/tests/SdpManagerTest.java b/tests/src/com/android/bluetooth/tests/SdpManagerTest.java index 2b7310d1d..6ff395443 100644 --- a/tests/src/com/android/bluetooth/tests/SdpManagerTest.java +++ b/tests/src/com/android/bluetooth/tests/SdpManagerTest.java @@ -110,6 +110,12 @@ public class SdpManagerTest extends AndroidTestCase { Log.i(TAG, " Added record_handle=" + handles[record_id]); assertTrue(handles[record_id]>=0); if(record_id == count) break; + + handles[++record_id] = mManager.createSapsRecord(SDP_SERVER_NAME, + record_id, SDP_VERSION); + Log.i(TAG, " Added record_handle=" + handles[record_id]); + assertTrue(handles[record_id]>=0); + if (record_id == count) break; } } @@ -159,7 +165,8 @@ public class SdpManagerTest extends AndroidTestCase { final String[] uuids = {BluetoothUuid.MAS.toString(), BluetoothUuid.MNS.toString(), BluetoothUuid.PBAP_PSE.toString(), - BluetoothUuid.ObexObjectPush.toString()}; + BluetoothUuid.ObexObjectPush.toString(), + BluetoothUuid.SAP.toString()}; final String uuids_str; final StringBuilder sb = new StringBuilder(uuids.length*2-1); for(String str : uuids) { diff --git a/tests/src/com/android/bluetooth/tests/SdpManagerTestServer.java b/tests/src/com/android/bluetooth/tests/SdpManagerTestServer.java index 19e01bea4..05783908e 100644 --- a/tests/src/com/android/bluetooth/tests/SdpManagerTestServer.java +++ b/tests/src/com/android/bluetooth/tests/SdpManagerTestServer.java @@ -16,6 +16,7 @@ import android.bluetooth.SdpMasRecord; import android.bluetooth.SdpMnsRecord; import android.bluetooth.SdpOppOpsRecord; import android.bluetooth.SdpPseRecord; +import android.bluetooth.SdpSapsRecord; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -145,6 +146,7 @@ public class SdpManagerTestServer extends ServerRequestHandler { boolean hasMas = false; boolean hasMns = false; boolean hasOppServer = false; + boolean hasSapServer = false; boolean hasPse = false; final CountDownLatch mLatch; @@ -158,6 +160,8 @@ public class SdpManagerTestServer extends ServerRequestHandler { hasPse = true; if(uuid.toString().equals(BluetoothUuid.ObexObjectPush.toString())) hasOppServer = true; + if(uuid.toString().equals(BluetoothUuid.SAP.toString())) + hasSapServer = true; } mLatch = latch; } @@ -261,6 +265,28 @@ public class SdpManagerTestServer extends ServerRequestHandler { Log.i(TAG, "Wrong service name (" + record.getServiceName() + ") received, still waiting..."); } + } else if (hasSapServer && uuid.toString().equals(BluetoothUuid.SAP.toString())) { + Log.v(TAG, " -> SAP Server UUID in result."); + int status = intent.getIntExtra(BluetoothDevice.EXTRA_SDP_SEARCH_STATUS, -1); + Assert.assertEquals(AbstractionLayer.BT_STATUS_SUCCESS, status); /* BT_STATUS_SUCCESS == 0 - but status is not documented... */ + Log.v(TAG, " -> status: "+status); + SdpSapsRecord record = intent.getParcelableExtra(BluetoothDevice.EXTRA_SDP_RECORD); + Assert.assertNotNull(record); + Log.v(TAG, " -> Record: " + record); + /* As the normal profiles are also running, we filter out these records */ + if (record.getServiceName().equals(SdpManagerTest.SDP_SERVER_NAME)) { + Assert.assertEquals(record.getProfileVersion(), SdpManagerTest.SDP_VERSION); + Assert.assertEquals(record.getServiceName(), SdpManagerTest.SDP_SERVER_NAME); + int rfcommChannel = record.getRfcommCannelNumber(); + /* We set RFCOMM-channel to record_id and the l2cap PSM to + * iteration*record_id. + * As SAP does not carry a L2CAP PSM, we cannot validate the RFCOMM value + Assert.assertEquals(mOperationIndex+rfcommChannel, l2capPsm); */ + mLatch.countDown(); + } else { + Log.i(TAG, "Wrong service name (" + record.getServiceName() + + ") received, still waiting..."); + } } else { Log.i(TAG, "Wrong UUID received, still waiting..."); } @@ -289,6 +315,8 @@ public class SdpManagerTestServer extends ServerRequestHandler { serverDevice.sdpSearch(BluetoothUuid.PBAP_PSE); if(uuid.toString().equals(BluetoothUuid.ObexObjectPush.toString())) serverDevice.sdpSearch(BluetoothUuid.ObexObjectPush); + if(uuid.toString().equals(BluetoothUuid.SAP.toString())) + serverDevice.sdpSearch(BluetoothUuid.SAP); } // Await results |