Loading android/app/src/com/android/bluetooth/sap/SapService.java +6 −11 Original line number Diff line number Diff line Loading @@ -113,27 +113,22 @@ public class SapService extends ProfileService { for (int i = 0; i < CREATE_RETRY_TIME && !mInterrupted; i++) { initSocketOK = true; try { // // It is mandatory for MSE to support initiation of bonding and // encryption. // // TODO: Consider reusing the mServerSocket - it is intended // to be reused for multiple connections. // mServerSocket = mAdapter. listenUsingRfcommOn(BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP); int channel = mServerSocket.getChannel(); // It is mandatory for MSE to support initiation of bonding and encryption. // TODO: Consider reusing the mServerSocket - it is indented to be reused // for multiple connections. mServerSocket = mAdapter.listenUsingRfcommOn( BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP, true); if (mSdpHandle >= 0) { SdpManager.getDefaultManager().removeSdpRecord(mSdpHandle); if (VERBOSE) Log.d(TAG, "Removing SDP record"); } mSdpHandle = SdpManager.getDefaultManager().createSapsRecord(SDP_SAP_SERVICE_NAME, mServerSocket.getChannel(), SDP_SAP_VERSION); } catch (IOException e) { Log.e(TAG, "Error create RfcommServerSocket ", e); initSocketOK = false; } if (!initSocketOK) { // Need to break out of this loop if BT is being turned off. if (mAdapter == null) break; Loading android/app/tests/src/com/android/bluetooth/tests/SecurityTest.java 0 → 100644 +35 −0 Original line number Diff line number Diff line package com.android.bluetooth.tests; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothUuid; import android.test.AndroidTestCase; import android.util.Log; import java.io.IOException; public class SecurityTest extends AndroidTestCase { static final String TAG = "SecurityTest"; public void connectSapNoSec() { BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter(); if(bt == null) { Log.e(TAG,"No Bluetooth Device!"); assertTrue(false); } BluetoothTestUtils.enableBt(bt); BluetoothDevice serverDevice = bt.getRemoteDevice(ObexTest.SERVER_ADDRESS); try { serverDevice.createInsecureRfcommSocketToServiceRecord(BluetoothUuid.SAP.getUuid()); } catch (IOException e) { Log.e(TAG, "Failed to create connection", e); } try { Thread.sleep(1000); } catch (InterruptedException e) { Log.w(TAG, "Sleep interrupted", e); } } } Loading
android/app/src/com/android/bluetooth/sap/SapService.java +6 −11 Original line number Diff line number Diff line Loading @@ -113,27 +113,22 @@ public class SapService extends ProfileService { for (int i = 0; i < CREATE_RETRY_TIME && !mInterrupted; i++) { initSocketOK = true; try { // // It is mandatory for MSE to support initiation of bonding and // encryption. // // TODO: Consider reusing the mServerSocket - it is intended // to be reused for multiple connections. // mServerSocket = mAdapter. listenUsingRfcommOn(BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP); int channel = mServerSocket.getChannel(); // It is mandatory for MSE to support initiation of bonding and encryption. // TODO: Consider reusing the mServerSocket - it is indented to be reused // for multiple connections. mServerSocket = mAdapter.listenUsingRfcommOn( BluetoothAdapter.SOCKET_CHANNEL_AUTO_STATIC_NO_SDP, true); if (mSdpHandle >= 0) { SdpManager.getDefaultManager().removeSdpRecord(mSdpHandle); if (VERBOSE) Log.d(TAG, "Removing SDP record"); } mSdpHandle = SdpManager.getDefaultManager().createSapsRecord(SDP_SAP_SERVICE_NAME, mServerSocket.getChannel(), SDP_SAP_VERSION); } catch (IOException e) { Log.e(TAG, "Error create RfcommServerSocket ", e); initSocketOK = false; } if (!initSocketOK) { // Need to break out of this loop if BT is being turned off. if (mAdapter == null) break; Loading
android/app/tests/src/com/android/bluetooth/tests/SecurityTest.java 0 → 100644 +35 −0 Original line number Diff line number Diff line package com.android.bluetooth.tests; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothUuid; import android.test.AndroidTestCase; import android.util.Log; import java.io.IOException; public class SecurityTest extends AndroidTestCase { static final String TAG = "SecurityTest"; public void connectSapNoSec() { BluetoothAdapter bt = BluetoothAdapter.getDefaultAdapter(); if(bt == null) { Log.e(TAG,"No Bluetooth Device!"); assertTrue(false); } BluetoothTestUtils.enableBt(bt); BluetoothDevice serverDevice = bt.getRemoteDevice(ObexTest.SERVER_ADDRESS); try { serverDevice.createInsecureRfcommSocketToServiceRecord(BluetoothUuid.SAP.getUuid()); } catch (IOException e) { Log.e(TAG, "Failed to create connection", e); } try { Thread.sleep(1000); } catch (InterruptedException e) { Log.w(TAG, "Sleep interrupted", e); } } }