[RCS] Fix incorrect source ip in Iwlan
Bug: 180706349
Test: manual
Change-Id: I11a9dc39f10750ea652be9be8b2f9a66727da297
diff --git a/testapps/TestRcsApp/aosp_test_rcsclient/src/com/android/libraries/rcs/simpleclient/protocol/msrp/MsrpManager.java b/testapps/TestRcsApp/aosp_test_rcsclient/src/com/android/libraries/rcs/simpleclient/protocol/msrp/MsrpManager.java
index 5943f09..81abe89 100644
--- a/testapps/TestRcsApp/aosp_test_rcsclient/src/com/android/libraries/rcs/simpleclient/protocol/msrp/MsrpManager.java
+++ b/testapps/TestRcsApp/aosp_test_rcsclient/src/com/android/libraries/rcs/simpleclient/protocol/msrp/MsrpManager.java
@@ -25,6 +25,7 @@
import com.google.common.util.concurrent.MoreExecutors;
import java.io.IOException;
+import java.net.InetAddress;
import java.net.Socket;
/** Provides creating and managing {@link MsrpSession} */
@@ -36,9 +37,10 @@
}
private static MsrpSession createMsrpSession(ConnectivityManager manager,
- Network network, String host, int port, MsrpSessionListener listener)
- throws IOException {
- Socket socket = network.getSocketFactory().createSocket(host, port);
+ Network network, String host, int port, String localIp, int localPort,
+ MsrpSessionListener listener) throws IOException {
+ Socket socket = network.getSocketFactory().createSocket(host, port,
+ InetAddress.getByName(localIp), localPort);
MsrpSession msrpSession = new MsrpSession(manager,
network, socket, listener);
Thread thread = new Thread(msrpSession::run);
@@ -47,14 +49,14 @@
}
public ListenableFuture<MsrpSession> createMsrpSession(
- String host, int port, MsrpSessionListener listener) {
+ String host, int port, String localIp, int localPort, MsrpSessionListener listener) {
return Futures.transformAsync(
imsPdnNetworkFetcher.getImsPdnNetwork(),
network -> {
if (network != null) {
return Futures.immediateFuture(
createMsrpSession(imsPdnNetworkFetcher.getConnectivityManager(),
- network, host, port, listener));
+ network, host, port, localIp, localPort, listener));
} else {
return Futures.immediateFailedFuture(
new IllegalStateException("Network is null"));
diff --git a/testapps/TestRcsApp/aosp_test_rcsclient/src/com/android/libraries/rcs/simpleclient/service/chat/SimpleChatSession.java b/testapps/TestRcsApp/aosp_test_rcsclient/src/com/android/libraries/rcs/simpleclient/service/chat/SimpleChatSession.java
index 6813c91..ebccbde 100644
--- a/testapps/TestRcsApp/aosp_test_rcsclient/src/com/android/libraries/rcs/simpleclient/service/chat/SimpleChatSession.java
+++ b/testapps/TestRcsApp/aosp_test_rcsclient/src/com/android/libraries/rcs/simpleclient/service/chat/SimpleChatSession.java
@@ -402,10 +402,11 @@
private void startMsrpSession(SimpleSdpMessage remoteSdp) {
Log.d(TAG, "Start MSRP session: " + remoteSdp);
if (remoteSdp.getAddress().isPresent() && remoteSdp.getPort().isPresent()) {
+ String localIp = getLocalIp();
Futures.addCallback(
mMsrpManager.createMsrpSession(
- remoteSdp.getAddress().get(), remoteSdp.getPort().getAsInt(),
- this::receiveMsrpChunk),
+ remoteSdp.getAddress().get(), remoteSdp.getPort().getAsInt(), localIp,
+ 0 /* localPort */, this::receiveMsrpChunk),
new FutureCallback<MsrpSession>() {
@Override
public void onSuccess(MsrpSession result) {
@@ -430,6 +431,11 @@
}
}
+ private String getLocalIp() {
+ SipSessionConfiguration configuration = mContext.getSipSession().getSessionConfiguration();
+ return configuration.getLocalIpAddress();
+ }
+
private void receiveMsrpChunk(MsrpChunk chunk) {
Log.d(TAG, "Received msrp= " + chunk + " conversation=" + mConversationId);