Loading android/app/src/com/android/bluetooth/sap/SapMessage.java +2 −1 Original line number Original line Diff line number Diff line Loading @@ -15,6 +15,7 @@ import org.android.btsap.SapApi; import org.android.btsap.SapApi.*; import org.android.btsap.SapApi.*; import com.google.protobuf.micro.*; import com.google.protobuf.micro.*; import android.os.RemoteException; import android.util.Log; import android.util.Log; /** /** Loading Loading @@ -720,7 +721,7 @@ public class SapMessage { /** /** * Send the message by calling corresponding ISap api. * Send the message by calling corresponding ISap api. */ */ public void send(ISap sapProxy) throws Exception { public void send(ISap sapProxy) throws RemoteException, RuntimeException { int rilSerial = sNextSerial.getAndIncrement(); int rilSerial = sNextSerial.getAndIncrement(); Log.e(TAG, "callISapReq: called for mMsgType " + mMsgType + " rilSerial " + rilSerial); Log.e(TAG, "callISapReq: called for mMsgType " + mMsgType + " rilSerial " + rilSerial); Loading android/app/src/com/android/bluetooth/sap/SapRilReceiver.java +34 −3 Original line number Original line Diff line number Diff line Loading @@ -4,6 +4,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStream; import java.util.ArrayList; import java.util.ArrayList; import java.util.List; import java.util.List; import java.util.concurrent.atomic.AtomicLong; import org.android.btsap.SapApi.MsgHeader; import org.android.btsap.SapApi.MsgHeader; Loading @@ -16,7 +17,9 @@ import android.hardware.radio.V1_0.ISapCallback; import android.net.LocalSocket; import android.net.LocalSocket; import android.net.LocalSocketAddress; import android.net.LocalSocketAddress; import android.os.Handler; import android.os.Handler; import android.os.HwBinder; import android.os.Message; import android.os.Message; import android.os.RemoteException; import android.util.Log; import android.util.Log; public class SapRilReceiver implements Runnable { public class SapRilReceiver implements Runnable { Loading @@ -34,7 +37,9 @@ public class SapRilReceiver implements Runnable { InputStream mRilBtInStream = null; InputStream mRilBtInStream = null; SapCallback mSapCallback; SapCallback mSapCallback; ISap mSapProxy; volatile ISap mSapProxy = null; final AtomicLong mSapProxyCookie = new AtomicLong(0); final SapProxyDeathRecipient mSapProxyDeathRecipient; private Handler mSapServerMsgHandler = null; private Handler mSapServerMsgHandler = null; private Handler mSapServiceHandler = null; private Handler mSapServiceHandler = null; Loading @@ -42,6 +47,19 @@ public class SapRilReceiver implements Runnable { public static final int RIL_MAX_COMMAND_BYTES = (8 * 1024); public static final int RIL_MAX_COMMAND_BYTES = (8 * 1024); byte[] buffer = new byte[RIL_MAX_COMMAND_BYTES]; byte[] buffer = new byte[RIL_MAX_COMMAND_BYTES]; final class SapProxyDeathRecipient implements HwBinder.DeathRecipient { @Override public void serviceDied(long cookie) { // Deal with service going away Log.d(TAG, "serviceDied"); // todo: temp hack to send delayed message so that rild is back up by then // mSapHandler.sendMessage(mSapHandler.obtainMessage(EVENT_SAP_PROXY_DEAD, cookie)); mSapServerMsgHandler.sendMessageDelayed( mSapServerMsgHandler.obtainMessage(SapServer.SAP_PROXY_DEAD, cookie), SapServer.ISAP_GET_SERVICE_DELAY_MILLIS); } } private void sendSapMessage(SapMessage sapMessage) { private void sendSapMessage(SapMessage sapMessage) { if (sapMessage.getMsgType() < SapMessage.ID_RIL_BASE) { if (sapMessage.getMsgType() < SapMessage.ID_RIL_BASE) { sendClientMessage(sapMessage); sendClientMessage(sapMessage); Loading Loading @@ -185,21 +203,34 @@ public class SapRilReceiver implements Runnable { mSapProxy = ISap.getService(SOCKET_NAME_RIL_BT); mSapProxy = ISap.getService(SOCKET_NAME_RIL_BT); if (mSapProxy != null) { if (mSapProxy != null) { Log.d(TAG, "getSapProxy: mSapProxy != null; calling setCallback()"); Log.d(TAG, "getSapProxy: mSapProxy != null; calling setCallback()"); // todo(b/31632518): need to do this again if remote process crashes/restarts mSapProxy.linkToDeath(mSapProxyDeathRecipient, mSapProxyCookie.incrementAndGet()); mSapProxy.setCallback(mSapCallback); mSapProxy.setCallback(mSapCallback); } else { } else { Log.e(TAG, "getSapProxy: mSapProxy == null"); Log.e(TAG, "getSapProxy: mSapProxy == null"); } } } catch (Exception e) { } catch (RemoteException | RuntimeException e) { mSapProxy = null; // if service is not up, treat it like death notification to try to get service again mSapServerMsgHandler.sendMessageDelayed( mSapServerMsgHandler.obtainMessage( SapServer.SAP_PROXY_DEAD, mSapProxyCookie.get()), SapServer.ISAP_GET_SERVICE_DELAY_MILLIS); Log.e(TAG, "getSapProxy: exception", e); Log.e(TAG, "getSapProxy: exception", e); } } return mSapProxy; return mSapProxy; } } public void resetSapProxy() { mSapProxy = null; } public SapRilReceiver(Handler SapServerMsgHandler, Handler sapServiceHandler) { public SapRilReceiver(Handler SapServerMsgHandler, Handler sapServiceHandler) { mSapServerMsgHandler = SapServerMsgHandler; mSapServerMsgHandler = SapServerMsgHandler; mSapServiceHandler = sapServiceHandler; mSapServiceHandler = sapServiceHandler; mSapCallback = new SapCallback(); mSapCallback = new SapCallback(); mSapProxyDeathRecipient = new SapProxyDeathRecipient(); mSapProxy = getSapProxy(); mSapProxy = getSapProxy(); } } Loading android/app/src/com/android/bluetooth/sap/SapServer.java +18 −7 Original line number Original line Diff line number Diff line Loading @@ -15,6 +15,7 @@ import android.os.Handler.Callback; import android.os.HandlerThread; import android.os.HandlerThread; import android.os.Looper; import android.os.Looper; import android.os.Message; import android.os.Message; import android.os.RemoteException; import android.os.SystemClock; import android.os.SystemClock; import android.os.SystemProperties; import android.os.SystemProperties; import android.telephony.TelephonyManager; import android.telephony.TelephonyManager; Loading Loading @@ -77,12 +78,14 @@ public class SapServer extends Thread implements Callback { public static final int SAP_MSG_RIL_REQ = 0x02; public static final int SAP_MSG_RIL_REQ = 0x02; public static final int SAP_MSG_RIL_IND = 0x03; public static final int SAP_MSG_RIL_IND = 0x03; public static final int SAP_RIL_SOCK_CLOSED = 0x04; public static final int SAP_RIL_SOCK_CLOSED = 0x04; public static final int SAP_PROXY_DEAD = 0x05; public static final String SAP_DISCONNECT_ACTION = public static final String SAP_DISCONNECT_ACTION = "com.android.bluetooth.sap.action.DISCONNECT_ACTION"; "com.android.bluetooth.sap.action.DISCONNECT_ACTION"; public static final String SAP_DISCONNECT_TYPE_EXTRA = public static final String SAP_DISCONNECT_TYPE_EXTRA = "com.android.bluetooth.sap.extra.DISCONNECT_TYPE"; "com.android.bluetooth.sap.extra.DISCONNECT_TYPE"; public static final int NOTIFICATION_ID = android.R.drawable.stat_sys_data_bluetooth; public static final int NOTIFICATION_ID = android.R.drawable.stat_sys_data_bluetooth; public static final int ISAP_GET_SERVICE_DELAY_MILLIS = 3 * 1000; private static final int DISCONNECT_TIMEOUT_IMMEDIATE = 5000; /* ms */ private static final int DISCONNECT_TIMEOUT_IMMEDIATE = 5000; /* ms */ private static final int DISCONNECT_TIMEOUT_RFCOMM = 2000; /* ms */ private static final int DISCONNECT_TIMEOUT_RFCOMM = 2000; /* ms */ private PendingIntent pDiscIntent = null; // Holds a reference to disconnect timeout intents private PendingIntent pDiscIntent = null; // Holds a reference to disconnect timeout intents Loading Loading @@ -635,6 +638,13 @@ public class SapServer extends Thread implements Callback { sendDisconnectInd(SapMessage.DISC_IMMEDIATE); sendDisconnectInd(SapMessage.DISC_IMMEDIATE); startDisconnectTimer(SapMessage.DISC_RFCOMM, DISCONNECT_TIMEOUT_RFCOMM); startDisconnectTimer(SapMessage.DISC_RFCOMM, DISCONNECT_TIMEOUT_RFCOMM); break; break; case SAP_PROXY_DEAD: if ((long) msg.obj == mRilBtReceiver.mSapProxyCookie.get()) { mRilBtReceiver.resetSapProxy(); // todo: rild should be back up since message was sent with a delay. this is a hack. mRilBtReceiver.getSapProxy(); } default: default: /* Message not handled */ /* Message not handled */ return false; return false; Loading Loading @@ -849,21 +859,22 @@ public class SapServer extends Thread implements Callback { ISap sapProxy = mRilBtReceiver.getSapProxy(); ISap sapProxy = mRilBtReceiver.getSapProxy(); if (sapProxy == null) { if (sapProxy == null) { Log.e(TAG_HANDLER, "sendRilMessage: Unable to send message to RIL; sapProxy is null"); Log.e(TAG_HANDLER, "sendRilMessage: Unable to send message to RIL; sapProxy is null"); SapMessage errorReply = new SapMessage(SapMessage.ID_ERROR_RESP); sendClientMessage(new SapMessage(SapMessage.ID_ERROR_RESP)); sendClientMessage(errorReply); return; return; } } try { try { sapMsg.send(sapProxy); sapMsg.send(sapProxy); if (VERBOSE) { if (VERBOSE) { Log.d(TAG_HANDLER, "sendRilMessage: sapMsg.callISapReq called " Log.d(TAG_HANDLER, "sendRilMessage: sapMsg.callISapReq called successfully"); + "successfully"); } } } catch (Exception e) { } catch (IllegalArgumentException e) { Log.e(TAG_HANDLER, "sendRilMessage: IllegalArgumentException", e); sendClientMessage(new SapMessage(SapMessage.ID_ERROR_RESP)); } catch (RemoteException | RuntimeException e) { Log.e(TAG_HANDLER, "sendRilMessage: Unable to send message to RIL", e); Log.e(TAG_HANDLER, "sendRilMessage: Unable to send message to RIL", e); SapMessage errorReply = new SapMessage(SapMessage.ID_ERROR_RESP); sendClientMessage(new SapMessage(SapMessage.ID_ERROR_RESP)); sendClientMessage(errorReply); mRilBtReceiver.resetSapProxy(); } } } } Loading Loading
android/app/src/com/android/bluetooth/sap/SapMessage.java +2 −1 Original line number Original line Diff line number Diff line Loading @@ -15,6 +15,7 @@ import org.android.btsap.SapApi; import org.android.btsap.SapApi.*; import org.android.btsap.SapApi.*; import com.google.protobuf.micro.*; import com.google.protobuf.micro.*; import android.os.RemoteException; import android.util.Log; import android.util.Log; /** /** Loading Loading @@ -720,7 +721,7 @@ public class SapMessage { /** /** * Send the message by calling corresponding ISap api. * Send the message by calling corresponding ISap api. */ */ public void send(ISap sapProxy) throws Exception { public void send(ISap sapProxy) throws RemoteException, RuntimeException { int rilSerial = sNextSerial.getAndIncrement(); int rilSerial = sNextSerial.getAndIncrement(); Log.e(TAG, "callISapReq: called for mMsgType " + mMsgType + " rilSerial " + rilSerial); Log.e(TAG, "callISapReq: called for mMsgType " + mMsgType + " rilSerial " + rilSerial); Loading
android/app/src/com/android/bluetooth/sap/SapRilReceiver.java +34 −3 Original line number Original line Diff line number Diff line Loading @@ -4,6 +4,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStream; import java.util.ArrayList; import java.util.ArrayList; import java.util.List; import java.util.List; import java.util.concurrent.atomic.AtomicLong; import org.android.btsap.SapApi.MsgHeader; import org.android.btsap.SapApi.MsgHeader; Loading @@ -16,7 +17,9 @@ import android.hardware.radio.V1_0.ISapCallback; import android.net.LocalSocket; import android.net.LocalSocket; import android.net.LocalSocketAddress; import android.net.LocalSocketAddress; import android.os.Handler; import android.os.Handler; import android.os.HwBinder; import android.os.Message; import android.os.Message; import android.os.RemoteException; import android.util.Log; import android.util.Log; public class SapRilReceiver implements Runnable { public class SapRilReceiver implements Runnable { Loading @@ -34,7 +37,9 @@ public class SapRilReceiver implements Runnable { InputStream mRilBtInStream = null; InputStream mRilBtInStream = null; SapCallback mSapCallback; SapCallback mSapCallback; ISap mSapProxy; volatile ISap mSapProxy = null; final AtomicLong mSapProxyCookie = new AtomicLong(0); final SapProxyDeathRecipient mSapProxyDeathRecipient; private Handler mSapServerMsgHandler = null; private Handler mSapServerMsgHandler = null; private Handler mSapServiceHandler = null; private Handler mSapServiceHandler = null; Loading @@ -42,6 +47,19 @@ public class SapRilReceiver implements Runnable { public static final int RIL_MAX_COMMAND_BYTES = (8 * 1024); public static final int RIL_MAX_COMMAND_BYTES = (8 * 1024); byte[] buffer = new byte[RIL_MAX_COMMAND_BYTES]; byte[] buffer = new byte[RIL_MAX_COMMAND_BYTES]; final class SapProxyDeathRecipient implements HwBinder.DeathRecipient { @Override public void serviceDied(long cookie) { // Deal with service going away Log.d(TAG, "serviceDied"); // todo: temp hack to send delayed message so that rild is back up by then // mSapHandler.sendMessage(mSapHandler.obtainMessage(EVENT_SAP_PROXY_DEAD, cookie)); mSapServerMsgHandler.sendMessageDelayed( mSapServerMsgHandler.obtainMessage(SapServer.SAP_PROXY_DEAD, cookie), SapServer.ISAP_GET_SERVICE_DELAY_MILLIS); } } private void sendSapMessage(SapMessage sapMessage) { private void sendSapMessage(SapMessage sapMessage) { if (sapMessage.getMsgType() < SapMessage.ID_RIL_BASE) { if (sapMessage.getMsgType() < SapMessage.ID_RIL_BASE) { sendClientMessage(sapMessage); sendClientMessage(sapMessage); Loading Loading @@ -185,21 +203,34 @@ public class SapRilReceiver implements Runnable { mSapProxy = ISap.getService(SOCKET_NAME_RIL_BT); mSapProxy = ISap.getService(SOCKET_NAME_RIL_BT); if (mSapProxy != null) { if (mSapProxy != null) { Log.d(TAG, "getSapProxy: mSapProxy != null; calling setCallback()"); Log.d(TAG, "getSapProxy: mSapProxy != null; calling setCallback()"); // todo(b/31632518): need to do this again if remote process crashes/restarts mSapProxy.linkToDeath(mSapProxyDeathRecipient, mSapProxyCookie.incrementAndGet()); mSapProxy.setCallback(mSapCallback); mSapProxy.setCallback(mSapCallback); } else { } else { Log.e(TAG, "getSapProxy: mSapProxy == null"); Log.e(TAG, "getSapProxy: mSapProxy == null"); } } } catch (Exception e) { } catch (RemoteException | RuntimeException e) { mSapProxy = null; // if service is not up, treat it like death notification to try to get service again mSapServerMsgHandler.sendMessageDelayed( mSapServerMsgHandler.obtainMessage( SapServer.SAP_PROXY_DEAD, mSapProxyCookie.get()), SapServer.ISAP_GET_SERVICE_DELAY_MILLIS); Log.e(TAG, "getSapProxy: exception", e); Log.e(TAG, "getSapProxy: exception", e); } } return mSapProxy; return mSapProxy; } } public void resetSapProxy() { mSapProxy = null; } public SapRilReceiver(Handler SapServerMsgHandler, Handler sapServiceHandler) { public SapRilReceiver(Handler SapServerMsgHandler, Handler sapServiceHandler) { mSapServerMsgHandler = SapServerMsgHandler; mSapServerMsgHandler = SapServerMsgHandler; mSapServiceHandler = sapServiceHandler; mSapServiceHandler = sapServiceHandler; mSapCallback = new SapCallback(); mSapCallback = new SapCallback(); mSapProxyDeathRecipient = new SapProxyDeathRecipient(); mSapProxy = getSapProxy(); mSapProxy = getSapProxy(); } } Loading
android/app/src/com/android/bluetooth/sap/SapServer.java +18 −7 Original line number Original line Diff line number Diff line Loading @@ -15,6 +15,7 @@ import android.os.Handler.Callback; import android.os.HandlerThread; import android.os.HandlerThread; import android.os.Looper; import android.os.Looper; import android.os.Message; import android.os.Message; import android.os.RemoteException; import android.os.SystemClock; import android.os.SystemClock; import android.os.SystemProperties; import android.os.SystemProperties; import android.telephony.TelephonyManager; import android.telephony.TelephonyManager; Loading Loading @@ -77,12 +78,14 @@ public class SapServer extends Thread implements Callback { public static final int SAP_MSG_RIL_REQ = 0x02; public static final int SAP_MSG_RIL_REQ = 0x02; public static final int SAP_MSG_RIL_IND = 0x03; public static final int SAP_MSG_RIL_IND = 0x03; public static final int SAP_RIL_SOCK_CLOSED = 0x04; public static final int SAP_RIL_SOCK_CLOSED = 0x04; public static final int SAP_PROXY_DEAD = 0x05; public static final String SAP_DISCONNECT_ACTION = public static final String SAP_DISCONNECT_ACTION = "com.android.bluetooth.sap.action.DISCONNECT_ACTION"; "com.android.bluetooth.sap.action.DISCONNECT_ACTION"; public static final String SAP_DISCONNECT_TYPE_EXTRA = public static final String SAP_DISCONNECT_TYPE_EXTRA = "com.android.bluetooth.sap.extra.DISCONNECT_TYPE"; "com.android.bluetooth.sap.extra.DISCONNECT_TYPE"; public static final int NOTIFICATION_ID = android.R.drawable.stat_sys_data_bluetooth; public static final int NOTIFICATION_ID = android.R.drawable.stat_sys_data_bluetooth; public static final int ISAP_GET_SERVICE_DELAY_MILLIS = 3 * 1000; private static final int DISCONNECT_TIMEOUT_IMMEDIATE = 5000; /* ms */ private static final int DISCONNECT_TIMEOUT_IMMEDIATE = 5000; /* ms */ private static final int DISCONNECT_TIMEOUT_RFCOMM = 2000; /* ms */ private static final int DISCONNECT_TIMEOUT_RFCOMM = 2000; /* ms */ private PendingIntent pDiscIntent = null; // Holds a reference to disconnect timeout intents private PendingIntent pDiscIntent = null; // Holds a reference to disconnect timeout intents Loading Loading @@ -635,6 +638,13 @@ public class SapServer extends Thread implements Callback { sendDisconnectInd(SapMessage.DISC_IMMEDIATE); sendDisconnectInd(SapMessage.DISC_IMMEDIATE); startDisconnectTimer(SapMessage.DISC_RFCOMM, DISCONNECT_TIMEOUT_RFCOMM); startDisconnectTimer(SapMessage.DISC_RFCOMM, DISCONNECT_TIMEOUT_RFCOMM); break; break; case SAP_PROXY_DEAD: if ((long) msg.obj == mRilBtReceiver.mSapProxyCookie.get()) { mRilBtReceiver.resetSapProxy(); // todo: rild should be back up since message was sent with a delay. this is a hack. mRilBtReceiver.getSapProxy(); } default: default: /* Message not handled */ /* Message not handled */ return false; return false; Loading Loading @@ -849,21 +859,22 @@ public class SapServer extends Thread implements Callback { ISap sapProxy = mRilBtReceiver.getSapProxy(); ISap sapProxy = mRilBtReceiver.getSapProxy(); if (sapProxy == null) { if (sapProxy == null) { Log.e(TAG_HANDLER, "sendRilMessage: Unable to send message to RIL; sapProxy is null"); Log.e(TAG_HANDLER, "sendRilMessage: Unable to send message to RIL; sapProxy is null"); SapMessage errorReply = new SapMessage(SapMessage.ID_ERROR_RESP); sendClientMessage(new SapMessage(SapMessage.ID_ERROR_RESP)); sendClientMessage(errorReply); return; return; } } try { try { sapMsg.send(sapProxy); sapMsg.send(sapProxy); if (VERBOSE) { if (VERBOSE) { Log.d(TAG_HANDLER, "sendRilMessage: sapMsg.callISapReq called " Log.d(TAG_HANDLER, "sendRilMessage: sapMsg.callISapReq called successfully"); + "successfully"); } } } catch (Exception e) { } catch (IllegalArgumentException e) { Log.e(TAG_HANDLER, "sendRilMessage: IllegalArgumentException", e); sendClientMessage(new SapMessage(SapMessage.ID_ERROR_RESP)); } catch (RemoteException | RuntimeException e) { Log.e(TAG_HANDLER, "sendRilMessage: Unable to send message to RIL", e); Log.e(TAG_HANDLER, "sendRilMessage: Unable to send message to RIL", e); SapMessage errorReply = new SapMessage(SapMessage.ID_ERROR_RESP); sendClientMessage(new SapMessage(SapMessage.ID_ERROR_RESP)); sendClientMessage(errorReply); mRilBtReceiver.resetSapProxy(); } } } } Loading