Show our own devices in security view

This commit is contained in:
Sylvain Berfini 2019-06-27 16:14:13 +02:00
parent 3f7d43aa2a
commit 795bd0b04d
5 changed files with 75 additions and 108 deletions

View file

@ -18,6 +18,11 @@ Group changes to describe their impact on the project, as follows:
- Added sample application to help developpers getting started with our SDK
- Added picture in picture feature if supported instead of video overlay
- Added camera preview as dialer's background on tablets
- Contact section in the settings
## Changed
- Call statistics are now available for each call & conference
- Added our own devices in LIME encrypted chatrooms' security view
## [4.1.0] - 2019-05-03
@ -173,6 +178,3 @@ Group changes to describe their impact on the project, as follows:
- Crashes Android 6/7 at starting
- Permissions issues
- Layout of tablet views
### Changed
- management of the view for displaying call statistics

View file

@ -71,10 +71,10 @@ public class CallStatsAdapter extends BaseExpandableListAdapter {
view = inflater.inflate(R.layout.call_stats_child, viewGroup, false);
}
// filling the view
holder = new CallStatsChildViewHolder(view, mContext);
view.setTag(holder);
holder.setCall(mCalls.get(groupPosition));
// filling the view
holder = new CallStatsChildViewHolder(view, mContext);
view.setTag(holder);
holder.setCall(mCalls.get(groupPosition));
return view;
}

View file

@ -157,9 +157,11 @@ public class ChatMessagesFragment extends Fragment
if (mChatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) {
ParticipantDevice[] devices =
mChatRoom.getParticipants()[0].getDevices();
if (devices.length == 1) {
oneParticipantOneDevice = true;
}
// Only start a call automatically if both ourselves and the remote
// have 1 device exactly, otherwise show devices list.
oneParticipantOneDevice =
devices.length == 1
&& mChatRoom.getMe().getDevices().length == 1;
}
if (LinphonePreferences.instance().isLimeSecurityPopupEnabled()) {

View file

@ -39,16 +39,13 @@ import org.linphone.views.ContactAvatar;
class DevicesAdapter extends BaseExpandableListAdapter {
private final Context mContext;
private List<Participant> mParticipants;
private boolean mOnlyDisplayChildsAsGroups;
public DevicesAdapter(Context context) {
mContext = context;
mParticipants = new ArrayList<>();
mOnlyDisplayChildsAsGroups = false;
}
public void updateListItems(List<Participant> participants, boolean childsAsGroups) {
mOnlyDisplayChildsAsGroups = childsAsGroups;
public void updateListItems(List<Participant> participants) {
mParticipants = participants;
notifyDataSetChanged();
}
@ -56,26 +53,48 @@ class DevicesAdapter extends BaseExpandableListAdapter {
@Override
public View getGroupView(
int groupPosition, boolean isExpanded, View view, ViewGroup viewGroup) {
if (mOnlyDisplayChildsAsGroups) {
ParticipantDevice device = (ParticipantDevice) getGroup(groupPosition);
Participant participant = (Participant) getGroup(groupPosition);
DeviceChildViewHolder holder = null;
if (view != null) {
Object possibleHolder = view.getTag();
if (possibleHolder instanceof DeviceChildViewHolder) {
holder = (DeviceChildViewHolder) possibleHolder;
}
} else {
LayoutInflater inflater = LayoutInflater.from(mContext);
view = inflater.inflate(R.layout.chat_device_cell_as_group, viewGroup, false);
}
if (holder == null) {
holder = new DeviceChildViewHolder(view);
view.setTag(holder);
// Group position 0 is reserved for ME participant & devices
DeviceGroupViewHolder holder = null;
if (view != null) {
Object possibleHolder = view.getTag();
if (possibleHolder instanceof DeviceGroupViewHolder) {
holder = (DeviceGroupViewHolder) possibleHolder;
}
} else {
LayoutInflater inflater = LayoutInflater.from(mContext);
view = inflater.inflate(R.layout.chat_device_group, viewGroup, false);
}
if (holder == null) {
holder = new DeviceGroupViewHolder(view);
view.setTag(holder);
}
holder.deviceName.setText(device.getName());
Address participantAddress = participant.getAddress();
LinphoneContact contact =
ContactsManager.getInstance().findContactFromAddress(participantAddress);
if (contact != null) {
ContactAvatar.displayAvatar(
contact, participant.getSecurityLevel(), holder.avatarLayout);
holder.participantName.setText(contact.getFullName());
} else {
String displayName = LinphoneUtils.getAddressDisplayName(participantAddress);
ContactAvatar.displayAvatar(
displayName, participant.getSecurityLevel(), holder.avatarLayout);
holder.participantName.setText(displayName);
}
holder.sipUri.setText(participantAddress.asStringUriOnly());
if (!mContext.getResources().getBoolean(R.bool.show_sip_uri_in_chat)) {
holder.sipUri.setVisibility(View.GONE);
}
if (getChildrenCount(groupPosition) == 1) {
holder.securityLevel.setVisibility(View.VISIBLE);
holder.groupExpander.setVisibility(View.GONE);
ParticipantDevice device = (ParticipantDevice) getChild(groupPosition, 0);
ChatRoomSecurityLevel level = device.getSecurityLevel();
switch (level) {
case Safe:
@ -91,67 +110,10 @@ class DevicesAdapter extends BaseExpandableListAdapter {
break;
}
} else {
Participant participant = (Participant) getGroup(groupPosition);
DeviceGroupViewHolder holder = null;
if (view != null) {
Object possibleHolder = view.getTag();
if (possibleHolder instanceof DeviceGroupViewHolder) {
holder = (DeviceGroupViewHolder) possibleHolder;
}
} else {
LayoutInflater inflater = LayoutInflater.from(mContext);
view = inflater.inflate(R.layout.chat_device_group, viewGroup, false);
}
if (holder == null) {
holder = new DeviceGroupViewHolder(view);
view.setTag(holder);
}
Address participantAddress = participant.getAddress();
LinphoneContact contact =
ContactsManager.getInstance().findContactFromAddress(participantAddress);
if (contact != null) {
ContactAvatar.displayAvatar(
contact, participant.getSecurityLevel(), holder.avatarLayout);
holder.participantName.setText(contact.getFullName());
} else {
String displayName = LinphoneUtils.getAddressDisplayName(participantAddress);
ContactAvatar.displayAvatar(
displayName, participant.getSecurityLevel(), holder.avatarLayout);
holder.participantName.setText(displayName);
}
holder.sipUri.setText(participantAddress.asStringUriOnly());
if (!mContext.getResources().getBoolean(R.bool.show_sip_uri_in_chat)) {
holder.sipUri.setVisibility(View.GONE);
}
if (getChildrenCount(groupPosition) == 1) {
holder.securityLevel.setVisibility(View.VISIBLE);
holder.groupExpander.setVisibility(View.GONE);
ParticipantDevice device = (ParticipantDevice) getChild(groupPosition, 0);
ChatRoomSecurityLevel level = device.getSecurityLevel();
switch (level) {
case Safe:
holder.securityLevel.setImageResource(R.drawable.security_2_indicator);
break;
case Encrypted:
holder.securityLevel.setImageResource(R.drawable.security_1_indicator);
break;
case ClearText:
case Unsafe:
default:
holder.securityLevel.setImageResource(R.drawable.security_alert_indicator);
break;
}
} else {
holder.securityLevel.setVisibility(View.GONE);
holder.groupExpander.setVisibility(View.VISIBLE);
holder.groupExpander.setImageResource(
isExpanded ? R.drawable.chevron_list_open : R.drawable.chevron_list_close);
}
holder.securityLevel.setVisibility(View.GONE);
holder.groupExpander.setVisibility(View.VISIBLE);
holder.groupExpander.setImageResource(
isExpanded ? R.drawable.chevron_list_open : R.drawable.chevron_list_close);
}
return view;
@ -199,32 +161,27 @@ class DevicesAdapter extends BaseExpandableListAdapter {
@Override
public int getGroupCount() {
if (mParticipants.isEmpty()) return 0;
return mOnlyDisplayChildsAsGroups
? mParticipants.get(0).getDevices().length
: mParticipants.size();
return mParticipants.size();
}
@Override
public int getChildrenCount(int groupPosition) {
if (mParticipants.isEmpty()) return 0;
return mOnlyDisplayChildsAsGroups
? 0
: mParticipants.get(groupPosition).getDevices().length;
if (groupPosition >= mParticipants.size()) return 0;
return mParticipants.get(groupPosition).getDevices().length;
}
@Override
public Object getGroup(int groupPosition) {
if (mParticipants.isEmpty()) return null;
return mOnlyDisplayChildsAsGroups
? mParticipants.get(0).getDevices()[groupPosition]
: mParticipants.get(groupPosition);
if (groupPosition >= mParticipants.size()) return null;
return mParticipants.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
if (mParticipants.isEmpty()) return null;
return mParticipants.get(groupPosition).getDevices()[childPosition];
if (groupPosition >= mParticipants.size()) return null;
ParticipantDevice[] devices = mParticipants.get(groupPosition).getDevices();
if (devices.length == 0 || childPosition >= devices.length) return null;
return devices[childPosition];
}
@Override

View file

@ -28,7 +28,7 @@ import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.Nullable;
import java.util.Arrays;
import java.util.ArrayList;
import org.linphone.LinphoneManager;
import org.linphone.R;
import org.linphone.contacts.ContactsManager;
@ -38,6 +38,7 @@ import org.linphone.core.ChatRoom;
import org.linphone.core.ChatRoomCapabilities;
import org.linphone.core.Core;
import org.linphone.core.Factory;
import org.linphone.core.Participant;
import org.linphone.core.ParticipantDevice;
import org.linphone.utils.LinphoneUtils;
@ -173,8 +174,13 @@ public class DevicesFragment extends Fragment {
}
if (mRoom != null && mRoom.getNbParticipants() > 0) {
mOnlyDisplayChilds = mRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt());
mAdapter.updateListItems(Arrays.asList(mRoom.getParticipants()), mOnlyDisplayChilds);
ArrayList<Participant> participantLists = new ArrayList<>();
// Group position 0 is reserved for ME participant & devices
participantLists.add(mRoom.getMe());
for (Participant participant : mRoom.getParticipants()) {
participantLists.add(participant);
}
mAdapter.updateListItems(participantLists);
}
}
}