public static final String TAG = "SapMessage";
public static final boolean DEBUG = SapService.DEBUG;
public static final boolean VERBOSE = SapService.VERBOSE;
- public static final boolean TEST = SapService.PTS_TEST;
+ public static final boolean TEST = false;
/* Message IDs - SAP specification */
public static final int ID_CONNECT_REQ = 0x00;
case ID_DISCONNECT_REQ: /* No params */
break;
default:
- if(TEST == false) {
- Log.e(TAG, "Unknown request type");
- return null;
- }
+ Log.e(TAG, "Unknown request type");
+ return null;
}
return newMessage;
}
}
break;
case PARAM_CONNECTION_STATUS_ID:
- // not needed - server -> client
- if(TEST) {
- if(paramLength != PARAM_CONNECTION_STATUS_LENGTH) {
- Log.e(TAG, "Received PARAM_CONNECTION_STATUS with wrong length: " +
- paramLength + " skipping this parameter.");
- skip(is, paramLength + skipLen);
- success = false;
- } else {
- mConnectionStatus = is.read();
- skip(is, 4 - PARAM_CONNECTION_STATUS_LENGTH);
- }
- break;
- } // Fall through if TEST == false
+ // not needed for server role, but used for module test
+ if(paramLength != PARAM_CONNECTION_STATUS_LENGTH) {
+ Log.e(TAG, "Received PARAM_CONNECTION_STATUS with wrong length: " +
+ paramLength + " skipping this parameter.");
+ skip(is, paramLength + skipLen);
+ success = false;
+ } else {
+ mConnectionStatus = is.read();
+ skip(is, 4 - PARAM_CONNECTION_STATUS_LENGTH);
+ }
+ break;
case PARAM_CARD_READER_STATUS_ID:
- // not needed - server -> client
- if(TEST) {
- if(paramLength != PARAM_CARD_READER_STATUS_LENGTH) {
- Log.e(TAG, "Received PARAM_CARD_READER_STATUS with wrong length: " +
- paramLength + " skipping this parameter.");
- skip(is, paramLength + skipLen);
- success = false;
- } else {
- mCardReaderStatus = is.read();
- skip(is, 4 - PARAM_CARD_READER_STATUS_LENGTH);
- }
- break;
- } // Fall through if TEST == false
+ // not needed for server role, but used for module test
+ if(paramLength != PARAM_CARD_READER_STATUS_LENGTH) {
+ Log.e(TAG, "Received PARAM_CARD_READER_STATUS with wrong length: " +
+ paramLength + " skipping this parameter.");
+ skip(is, paramLength + skipLen);
+ success = false;
+ } else {
+ mCardReaderStatus = is.read();
+ skip(is, 4 - PARAM_CARD_READER_STATUS_LENGTH);
+ }
+ break;
case PARAM_STATUS_CHANGE_ID:
- // not needed - server -> client
- if(TEST) {
- if(paramLength != PARAM_STATUS_CHANGE_LENGTH) {
- Log.e(TAG, "Received PARAM_STATUS_CHANGE with wrong length: " +
- paramLength + " skipping this parameter.");
- skip(is, paramLength + skipLen);
- success = false;
- } else {
- mStatusChange = is.read();
- skip(is, 4 - PARAM_STATUS_CHANGE_LENGTH);
- }
- break;
- } // Fall through if TEST == false
+ // not needed for server role, but used for module test
+ if(paramLength != PARAM_STATUS_CHANGE_LENGTH) {
+ Log.e(TAG, "Received PARAM_STATUS_CHANGE with wrong length: " +
+ paramLength + " skipping this parameter.");
+ skip(is, paramLength + skipLen);
+ success = false;
+ } else {
+ mStatusChange = is.read();
+ skip(is, 4 - PARAM_STATUS_CHANGE_LENGTH);
+ }
+ break;
case PARAM_RESULT_CODE_ID:
- // not needed - server -> client
- if(TEST) {
- if(paramLength != PARAM_RESULT_CODE_LENGTH) {
- Log.e(TAG, "Received PARAM_RESULT_CODE with wrong length: " +
- paramLength + " skipping this parameter.");
- skip(is, paramLength + skipLen);
- success = false;
- } else {
- mResultCode = is.read();
- skip(is, 4 - PARAM_RESULT_CODE_LENGTH);
- }
- break;
- } // Fall through if TEST == false
+ // not needed for server role, but used for module test
+ if(paramLength != PARAM_RESULT_CODE_LENGTH) {
+ Log.e(TAG, "Received PARAM_RESULT_CODE with wrong length: " +
+ paramLength + " skipping this parameter.");
+ skip(is, paramLength + skipLen);
+ success = false;
+ } else {
+ mResultCode = is.read();
+ skip(is, 4 - PARAM_RESULT_CODE_LENGTH);
+ }
+ break;
case PARAM_DISCONNECT_TYPE_ID:
- // not needed - server -> client
- if(TEST) {
- if(paramLength != PARAM_DISCONNECT_TYPE_LENGTH) {
- Log.e(TAG, "Received PARAM_DISCONNECT_TYPE_ID with wrong length: " +
- paramLength + " skipping this parameter.");
- skip(is, paramLength + skipLen);
- success = false;
- } else {
- mDisconnectionType = is.read();
- skip(is, 4 - PARAM_DISCONNECT_TYPE_LENGTH);
- }
- break;
- } // Fall through if TEST == false
+ // not needed for server role, but used for module test
+ if(paramLength != PARAM_DISCONNECT_TYPE_LENGTH) {
+ Log.e(TAG, "Received PARAM_DISCONNECT_TYPE_ID with wrong length: " +
+ paramLength + " skipping this parameter.");
+ skip(is, paramLength + skipLen);
+ success = false;
+ } else {
+ mDisconnectionType = is.read();
+ skip(is, 4 - PARAM_DISCONNECT_TYPE_LENGTH);
+ }
+ break;
case PARAM_RESPONSE_APDU_ID:
- // not needed - server -> client
- if(TEST) {
- mApduResp = new byte[paramLength];
- read(is, mApduResp);
- skip(is, skipLen);
- break;
- } // Fall through if TEST == false
+ // not needed for server role, but used for module test
+ mApduResp = new byte[paramLength];
+ read(is, mApduResp);
+ skip(is, skipLen);
+ break;
case PARAM_ATR_ID:
- // not needed - server -> client
- if(TEST) {
- mAtr = new byte[paramLength];
- read(is, mAtr);
- skip(is, skipLen);
- break;
- } // Fall through if TEST == false
+ // not needed for server role, but used for module test
+ mAtr = new byte[paramLength];
+ read(is, mAtr);
+ skip(is, skipLen);
+ break;
default:
Log.e(TAG, "Received unknown parameter ID: " + paramId + " length: " +
paramLength + " skipping this parameter.");
writeParameter(os, PARAM_RESULT_CODE_ID, mResultCode,
PARAM_RESULT_CODE_LENGTH);
}
- if(mDisconnectionType != INVALID_VALUE && TEST) {
+ if(mDisconnectionType != INVALID_VALUE) {
writeParameter(os, PARAM_DISCONNECT_TYPE_ID, mDisconnectionType,
PARAM_DISCONNECT_TYPE_LENGTH);
}
writeParameter(os, PARAM_STATUS_CHANGE_ID, mStatusChange,
PARAM_STATUS_CHANGE_LENGTH);
}
- if(mTransportProtocol != INVALID_VALUE && TEST) {
+ if(mTransportProtocol != INVALID_VALUE) {
writeParameter(os, PARAM_TRANSPORT_PROTOCOL_ID, mTransportProtocol,
PARAM_TRANSPORT_PROTOCOL_LENGTH);
}
- if(mApdu != null && TEST) {
+ if(mApdu != null) {
writeParameter(os, PARAM_COMMAND_APDU_ID, mApdu);
}
- if(mApdu7816 != null && TEST) {
+ if(mApdu7816 != null) {
writeParameter(os, PARAM_COMMAND_APDU7816_ID, mApdu7816);
}
if(mApduResp != null) {
break;
}
default:
- if(TEST == false) {
- Log.e(TAG, "Unknown request type");
- throw new IllegalArgumentException();
- }
+ Log.e(TAG, "Unknown request type");
+ throw new IllegalArgumentException();
}
/* Update the ongoing requests queue */
if(mClearRilQueue == true) {
public static String getMsgTypeName(int msgType) {
- if(TEST || VERBOSE) {
+ if(DEBUG || VERBOSE) {
switch (msgType)
{
case ID_CONNECT_REQ: return "ID_CONNECT_REQ";
import java.util.concurrent.CountDownLatch;
import com.android.bluetooth.R;
+
import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.os.Message;
import android.os.Parcel;
import android.os.SystemClock;
+import android.os.SystemProperties;
import android.telephony.TelephonyManager;
import android.util.Log;
+
//import com.android.internal.telephony.RIL;
import com.google.protobuf.micro.CodedOutputStreamMicro;
private static final String TAG_HANDLER = "SapServerHandler";
public static final boolean DEBUG = SapService.DEBUG;
public static final boolean VERBOSE = SapService.VERBOSE;
- public static final boolean PTS_TEST = SapService.PTS_TEST;
private enum SAP_STATE {
DISCONNECTED, CONNECTING, CONNECTING_CALL_ONGOING, CONNECTED,
String title, text, button, ticker;
Notification notification;
if(VERBOSE) Log.i(TAG, "setNotification type: " + type);
+ /* For PTS TC_SERVER_DCN_BV_03_I we need to expose the option to send immediate disconnect
+ * without first sending a graceful disconnect.
+ * To enable this option set
+ * bt.sap.pts="true" */
+ String pts_enabled = SystemProperties.get("bt.sap.pts");
+ Boolean pts_test = Boolean.parseBoolean(pts_enabled);
+
/* put notification up for the user to be able to disconnect from the client*/
Intent sapDisconnectIntent = new Intent(SapServer.SAP_DISCONNECT_ACTION);
if(type == SapMessage.DISC_GRACEFULL){
text = mContext.getString(R.string.bluetooth_sap_notif_disconnecting);
ticker = mContext.getString(R.string.bluetooth_sap_notif_ticker);
}
- if(!PTS_TEST)
+ if(!pts_test)
{
sapDisconnectIntent.putExtra(SapServer.SAP_DISCONNECT_TYPE_EXTRA, type);
PendingIntent pIntentDisconnect = PendingIntent.getBroadcast(mContext, type,
if(VERBOSE) Log.i(TAG_HANDLER, "sendRilMessage() - "
+ SapMessage.getMsgTypeName(sapMsg.getMsgType()));
try {
- if (mRilBtOutStream != null)
+ if(mRilBtOutStream != null) {
sapMsg.writeReqToStream(mRilBtOutStream);
+ } /* Else SAP was enabled on a build that did not support SAP, which we will not
+ * handle. */
} catch (IOException e) {
Log.e(TAG_HANDLER, "Unable to send message to RIL", e);
SapMessage errorReply = new SapMessage(SapMessage.ID_ERROR_RESP);
sendClientMessage(errorReply);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG_HANDLER, "Unable encode message", e);
+ SapMessage errorReply = new SapMessage(SapMessage.ID_ERROR_RESP);
+ sendClientMessage(errorReply);
}
}