Fixed crash if trying to create a chat room from contact or history without proxy config

This commit is contained in:
Sylvain Berfini 2019-12-05 15:16:24 +01:00
parent 807c279e88
commit b0407645e7
3 changed files with 70 additions and 36 deletions

View file

@ -88,7 +88,7 @@ android {
defaultConfig { defaultConfig {
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 29 targetSdkVersion 29
versionCode 4211 versionCode 4212
versionName "${project.version}" versionName "${project.version}"
applicationId getPackageName() applicationId getPackageName()
multiDexEnabled true multiDexEnabled true

View file

@ -364,6 +364,8 @@ public class ContactDetailsFragment extends Fragment implements ContactsUpdatedL
private void goToChat(String tag, boolean isSecured) { private void goToChat(String tag, boolean isSecured) {
Core core = LinphoneManager.getCore(); Core core = LinphoneManager.getCore();
if (core == null) return;
Address participant = Factory.instance().createAddress(tag); Address participant = Factory.instance().createAddress(tag);
ProxyConfig defaultProxyConfig = core.getDefaultProxyConfig(); ProxyConfig defaultProxyConfig = core.getDefaultProxyConfig();
@ -409,6 +411,18 @@ public class ContactDetailsFragment extends Fragment implements ContactsUpdatedL
} }
} }
} }
} else {
if (isSecured) {
Log.e(
"[Contact Details Fragment] Can't create a secured chat room without proxy config");
return;
}
ChatRoom room = core.getChatRoom(participant);
if (room != null) {
((ContactsActivity) getActivity())
.showChatRoom(room.getLocalAddress(), room.getPeerAddress());
}
} }
} }
} }

View file

@ -160,7 +160,7 @@ public class HistoryDetailFragment extends Fragment {
mWaitLayout.setVisibility(View.GONE); mWaitLayout.setVisibility(View.GONE);
((HistoryActivity) getActivity()).displayChatRoomError(); ((HistoryActivity) getActivity()).displayChatRoomError();
Log.e( Log.e(
"Group mChat room for address " "[History Detail Fragment] Group mChat room for address "
+ cr.getPeerAddress() + cr.getPeerAddress()
+ " has failed !"); + " has failed !");
} }
@ -257,24 +257,29 @@ public class HistoryDetailFragment extends Fragment {
private void goToChat(boolean isSecured) { private void goToChat(boolean isSecured) {
Core core = LinphoneManager.getCore(); Core core = LinphoneManager.getCore();
if (core == null) return;
Address participant = Factory.instance().createAddress(mSipUri); Address participant = Factory.instance().createAddress(mSipUri);
ProxyConfig defaultProxyConfig = core.getDefaultProxyConfig();
if (defaultProxyConfig != null) {
ChatRoom room = ChatRoom room =
core.findOneToOneChatRoom( core.findOneToOneChatRoom(
core.getDefaultProxyConfig().getContact(), participant, isSecured); defaultProxyConfig.getContact(), participant, isSecured);
if (room != null) { if (room != null) {
((HistoryActivity) getActivity()) ((HistoryActivity) getActivity())
.showChatRoom(room.getLocalAddress(), room.getPeerAddress()); .showChatRoom(room.getLocalAddress(), room.getPeerAddress());
} else { } else {
ProxyConfig lpc = core.getDefaultProxyConfig(); if (defaultProxyConfig.getConferenceFactoryUri() != null
if (lpc != null && (isSecured
&& lpc.getConferenceFactoryUri() != null || !LinphonePreferences.instance().useBasicChatRoomFor1To1())) {
&& (isSecured || !LinphonePreferences.instance().useBasicChatRoomFor1To1())) {
mWaitLayout.setVisibility(View.VISIBLE); mWaitLayout.setVisibility(View.VISIBLE);
ChatRoomParams params = core.createDefaultChatRoomParams(); ChatRoomParams params = core.createDefaultChatRoomParams();
params.enableEncryption(isSecured); params.enableEncryption(isSecured);
params.enableGroup(false); params.enableGroup(false);
// We don't want a basic chat room // We don't want a basic chat room,
// so if isSecured is false we have to set this manually
params.setBackend(ChatRoomBackend.FlexisipChat); params.setBackend(ChatRoomBackend.FlexisipChat);
Address[] participants = new Address[1]; Address[] participants = new Address[1];
@ -282,7 +287,9 @@ public class HistoryDetailFragment extends Fragment {
mChatRoom = mChatRoom =
core.createChatRoom( core.createChatRoom(
params, getString(R.string.dummy_group_chat_subject), participants); params,
getString(R.string.dummy_group_chat_subject),
participants);
if (mChatRoom != null) { if (mChatRoom != null) {
mChatRoom.addListener(mChatRoomCreationListener); mChatRoom.addListener(mChatRoomCreationListener);
} else { } else {
@ -297,5 +304,18 @@ public class HistoryDetailFragment extends Fragment {
} }
} }
} }
} else {
if (isSecured) {
Log.e(
"[History Detail Fragment] Can't create a secured chat room without proxy config");
return;
}
ChatRoom room = core.getChatRoom(participant);
if (room != null) {
((HistoryActivity) getActivity())
.showChatRoom(room.getLocalAddress(), room.getPeerAddress());
}
}
} }
} }