diff --git a/src/org/sflphone/client/HomeActivity.java b/src/org/sflphone/client/HomeActivity.java index 7abceb50a4af863b8d84dd406d2b5991574c41fc..47ab996e59bb3593ee23a9eb75d5adb7f91a6d5a 100644 --- a/src/org/sflphone/client/HomeActivity.java +++ b/src/org/sflphone/client/HomeActivity.java @@ -90,7 +90,7 @@ import android.widget.RelativeLayout; import android.widget.Toast; public class HomeActivity extends FragmentActivity implements DialingFragment.Callbacks, AccountsManagementFragment.Callbacks, - ContactListFragment.Callbacks, CallListFragment.Callbacks, HistoryFragment.Callbacks, CallInterface, MenuFragment.Callbacks { + ContactListFragment.Callbacks, CallListFragment.Callbacks, HistoryFragment.Callbacks, MenuFragment.Callbacks { static final String TAG = HomeActivity.class.getSimpleName(); @@ -107,7 +107,6 @@ public class HomeActivity extends FragmentActivity implements DialingFragment.Ca private DrawerLayout mNavigationDrawer; private ActionBarDrawerToggle mDrawerToggle; - CallReceiver callReceiver; private boolean isClosing = false; private Timer t = new Timer(); @@ -125,7 +124,6 @@ public class HomeActivity extends FragmentActivity implements DialingFragment.Ca public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - callReceiver = new CallReceiver(this); setContentView(R.layout.activity_home); @@ -300,12 +298,6 @@ public class HomeActivity extends FragmentActivity implements DialingFragment.Ca @Override protected void onResume() { super.onResume(); - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction(CallManagerCallBack.INCOMING_CALL); - intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT); - intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED); - registerReceiver(callReceiver, intentFilter); - } @Override @@ -356,7 +348,7 @@ public class HomeActivity extends FragmentActivity implements DialingFragment.Ca @Override protected void onPause() { super.onPause(); - unregisterReceiver(callReceiver); + if (mBound) { unbindService(mConnection); mBound = false; @@ -456,36 +448,6 @@ public class HomeActivity extends FragmentActivity implements DialingFragment.Ca return service; } - /** - * Interface implemented to handle incoming events - */ - @Override - public void incomingCall(Intent call) { - SipCall infos = call.getParcelableExtra("newcall"); - - launchCallActivity(infos); - - } - - @Override - public void callStateChanged(Intent callState) { - Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); - String cID = b.getString("CallID"); - String state = b.getString("State"); - Log.i(TAG, "callStateChanged" + cID + " " + state); - // mSectionsPagerAdapter.updateHome(); - - } - - @Override - public void incomingText(Intent msg) { - Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext"); - b.getString("CallID"); - String from = b.getString("From"); - String mess = b.getString("Msg"); - Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show(); - } - @Override public void onTextContact(final CallContact c) { // TODO @@ -640,30 +602,6 @@ public class HomeActivity extends FragmentActivity implements DialingFragment.Ca mContactDrawer.expandPane(); } - @Override - public void confCreated(Intent intent) { - // TODO Auto-generated method stub - - } - - @Override - public void confRemoved(Intent intent) { - // TODO Auto-generated method stub - - } - - @Override - public void confChanged(Intent intent) { - // TODO Auto-generated method stub - - } - - @Override - public void recordingChanged(Intent intent) { - // TODO Auto-generated method stub - - } - @Override public void selectedCall(Conference c) { Intent intent = new Intent().setClass(this, CallActivity.class); diff --git a/src/org/sflphone/fragments/CallFragment.java b/src/org/sflphone/fragments/CallFragment.java index 0a098f600ab9638eb313587ee40187d9490cb2bc..60f33a7c32064ba24e4a352c564fb4049d9603c1 100644 --- a/src/org/sflphone/fragments/CallFragment.java +++ b/src/org/sflphone/fragments/CallFragment.java @@ -511,7 +511,7 @@ public class CallFragment extends Fragment implements Callback { } try { if (conf.getParticipants().get(0).isOutGoing() - && mCallbacks.getService().getCall(conf.getParticipants().get(0).getCallId()) == null) { + && mCallbacks.getService().getConference(conf.getId()) == null) { mCallbacks.getService().placeCall(conf.getParticipants().get(0)); initOutGoingCallDisplay(); } else if (conf.getParticipants().get(0).isOutGoing() && conf.getParticipants().get(0).isRinging()) { diff --git a/src/org/sflphone/fragments/CallListFragment.java b/src/org/sflphone/fragments/CallListFragment.java index 7bfa23f37b58fc2881ce913bbf307410bc959a47..1264e54aa4668a6926fed49e945bd9d5e1d80559 100644 --- a/src/org/sflphone/fragments/CallListFragment.java +++ b/src/org/sflphone/fragments/CallListFragment.java @@ -35,10 +35,13 @@ import java.util.HashMap; import java.util.Observable; import java.util.Observer; +import android.content.IntentFilter; import org.sflphone.R; +import org.sflphone.interfaces.CallInterface; import org.sflphone.model.CallTimer; import org.sflphone.model.Conference; -import org.sflphone.model.SipCall; +import org.sflphone.receivers.CallReceiver; +import org.sflphone.service.CallManagerCallBack; import org.sflphone.service.ISipService; import android.app.Activity; @@ -68,13 +71,14 @@ import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; -public class CallListFragment extends Fragment { +public class CallListFragment extends Fragment implements CallInterface{ private static final String TAG = CallListFragment.class.getSimpleName(); private Callbacks mCallbacks = sDummyCallbacks; private TextView nb_calls, nb_confs; CallListAdapter confs_adapter, calls_adapter; CallTimer timer; + CallReceiver callReceiver; public static final int REQUEST_TRANSFER = 10; public static final int REQUEST_CONF = 20; @@ -95,9 +99,59 @@ public class CallListFragment extends Fragment { } }; + @Override + public void incomingCall(Intent call) { + + } + + @Override + public void callStateChanged(Intent callState) { + Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); + String cID = b.getString("CallID"); + String state = b.getString("State"); + Log.i(TAG, "callStateChanged" + cID + " " + state); + try { + updateLists(); + } catch (RemoteException e) { + e.printStackTrace(); + } + } + + @Override + public void incomingText(Intent msg) { + Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext"); + b.getString("CallID"); + String from = b.getString("From"); + String mess = b.getString("Msg"); + Toast.makeText(getActivity(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show(); + } + + @Override + public void confCreated(Intent intent) { + try { + updateLists(); + } catch (RemoteException e) { + e.printStackTrace(); + } + } + + @Override + public void confRemoved(Intent intent) { + + } + + @Override + public void confChanged(Intent intent) { + + } + + @Override + public void recordingChanged(Intent intent) { + + } + /** * The Activity calling this fragment has to implement this interface - * */ public interface Callbacks { @@ -138,6 +192,11 @@ public class CallListFragment extends Fragment { @Override public void onResume() { super.onResume(); + IntentFilter intentFilter = new IntentFilter(); + intentFilter.addAction(CallManagerCallBack.INCOMING_CALL); + intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT); + intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED); + getActivity().registerReceiver(callReceiver, intentFilter); if (mCallbacks.getService() != null) { try { updateLists(); @@ -155,34 +214,30 @@ public class CallListFragment extends Fragment { @SuppressWarnings("unchecked") // No proper solution with HashMap runtime cast public void updateLists() throws RemoteException { - HashMap<String, SipCall> calls = (HashMap<String, SipCall>) mCallbacks.getService().getCallList(); HashMap<String, Conference> confs = (HashMap<String, Conference>) mCallbacks.getService().getConferenceList(); - - updateCallList(calls); - updateConferenceList(confs); + Log.i(TAG, "There are " + confs.size()); + sortConferences(confs); } - private void updateConferenceList(HashMap<String, Conference> confs) { - nb_confs.setText("" + confs.size()); - confs_adapter.updateDataset(new ArrayList<Conference>(confs.values())); - } + private void sortConferences(HashMap<String, Conference> conferences) { - private void updateCallList(HashMap<String, SipCall> calls) { - nb_calls.setText("" + calls.size()); - ArrayList<Conference> conferences = new ArrayList<Conference>(); - for (SipCall call : calls.values()) { - Conference confOne = new Conference("-1"); - confOne.getParticipants().add(call); - conferences.add(confOne); + ArrayList<Conference> multiConfs = new ArrayList<Conference>(); + ArrayList<Conference> oneToOneConfs = new ArrayList<Conference>(); + for (Conference conf : conferences.values()) { + if (conf.hasMultipleParticipants()) + multiConfs.add(conf); + else + oneToOneConfs.add(conf); } - calls_adapter.updateDataset(conferences); - + nb_confs.setText("" + multiConfs.size()); + nb_calls.setText("" + oneToOneConfs.size()); + confs_adapter.updateDataset(new ArrayList<Conference>(multiConfs)); + calls_adapter.updateDataset(oneToOneConfs); } @Override public void onDetach() { - super.onDetach(); mCallbacks = sDummyCallbacks; @@ -191,26 +246,19 @@ public class CallListFragment extends Fragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + callReceiver = new CallReceiver(this); } @Override public void onPause() { super.onPause(); mHandler.removeCallbacks(mUpdateTimeTask); + getActivity().unregisterReceiver(callReceiver); } @Override public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - // Give some text to display if there is no data. In a real - // application this would come from a resource. - // setEmptyText("No phone numbers"); - - // We have a menu item to show in action bar. - setHasOptionsMenu(true); - } @Override @@ -345,51 +393,51 @@ public class CallListFragment extends Fragment { @Override public boolean onDrag(View v, DragEvent event) { switch (event.getAction()) { - case DragEvent.ACTION_DRAG_STARTED: - // Do nothing - // Log.w(TAG, "ACTION_DRAG_STARTED"); - break; - case DragEvent.ACTION_DRAG_ENTERED: - // Log.w(TAG, "ACTION_DRAG_ENTERED"); - v.setBackgroundColor(Color.GREEN); - break; - case DragEvent.ACTION_DRAG_EXITED: - // Log.w(TAG, "ACTION_DRAG_EXITED"); - v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_generic_selector)); - break; - case DragEvent.ACTION_DROP: - // Log.w(TAG, "ACTION_DROP"); - View view = (View) event.getLocalState(); - - Item i = event.getClipData().getItemAt(0); - Intent intent = i.getIntent(); - intent.setExtrasClassLoader(Conference.class.getClassLoader()); - - Conference initial = (Conference) view.getTag(); - Conference target = (Conference) v.getTag(); - - if (initial == target) { - return true; - } - - DropActionsChoice dialog = DropActionsChoice.newInstance(); - Bundle b = new Bundle(); - b.putParcelable("call_initial", initial); - b.putParcelable("call_targeted", target); - dialog.setArguments(b); - dialog.setTargetFragment(CallListFragment.this, 0); - dialog.show(getChildFragmentManager(), "dialog"); - - // view.setBackgroundColor(Color.WHITE); - // v.setBackgroundColor(Color.BLACK); - break; - case DragEvent.ACTION_DRAG_ENDED: - // Log.w(TAG, "ACTION_DRAG_ENDED"); - View view1 = (View) event.getLocalState(); - view1.setVisibility(View.VISIBLE); - v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_generic_selector)); - default: - break; + case DragEvent.ACTION_DRAG_STARTED: + // Do nothing + // Log.w(TAG, "ACTION_DRAG_STARTED"); + break; + case DragEvent.ACTION_DRAG_ENTERED: + // Log.w(TAG, "ACTION_DRAG_ENTERED"); + v.setBackgroundColor(Color.GREEN); + break; + case DragEvent.ACTION_DRAG_EXITED: + // Log.w(TAG, "ACTION_DRAG_EXITED"); + v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_generic_selector)); + break; + case DragEvent.ACTION_DROP: + // Log.w(TAG, "ACTION_DROP"); + View view = (View) event.getLocalState(); + + Item i = event.getClipData().getItemAt(0); + Intent intent = i.getIntent(); + intent.setExtrasClassLoader(Conference.class.getClassLoader()); + + Conference initial = (Conference) view.getTag(); + Conference target = (Conference) v.getTag(); + + if (initial == target) { + return true; + } + + DropActionsChoice dialog = DropActionsChoice.newInstance(); + Bundle b = new Bundle(); + b.putParcelable("call_initial", initial); + b.putParcelable("call_targeted", target); + dialog.setArguments(b); + dialog.setTargetFragment(CallListFragment.this, 0); + dialog.show(getChildFragmentManager(), "dialog"); + + // view.setBackgroundColor(Color.WHITE); + // v.setBackgroundColor(Color.BLACK); + break; + case DragEvent.ACTION_DRAG_ENDED: + // Log.w(TAG, "ACTION_DRAG_ENDED"); + View view1 = (View) event.getLocalState(); + view1.setVisibility(View.VISIBLE); + v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_generic_selector)); + default: + break; } return true; } @@ -402,50 +450,50 @@ public class CallListFragment extends Fragment { Conference transfer = null; if (requestCode == REQUEST_TRANSFER) { switch (resultCode) { - case 0: - Conference c = data.getParcelableExtra("target"); - transfer = data.getParcelableExtra("transfer"); - try { - - mCallbacks.getService().attendedTransfer(transfer.getParticipants().get(0).getCallId(), c.getParticipants().get(0).getCallId()); - calls_adapter.remove(transfer); - calls_adapter.remove(c); - calls_adapter.notifyDataSetChanged(); - } catch (RemoteException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - Toast.makeText(getActivity(), getString(R.string.home_transfer_complet), Toast.LENGTH_LONG).show(); - break; - - case 1: - String to = data.getStringExtra("to_number"); - transfer = data.getParcelableExtra("transfer"); - try { - Toast.makeText(getActivity(), getString(R.string.home_transfering,transfer.getParticipants().get(0).getContact().getmDisplayName(),to), - Toast.LENGTH_SHORT).show(); - mCallbacks.getService().transfer(transfer.getParticipants().get(0).getCallId(), to); - mCallbacks.getService().hangUp(transfer.getParticipants().get(0).getCallId()); - } catch (RemoteException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - break; - - default: - break; + case 0: + Conference c = data.getParcelableExtra("target"); + transfer = data.getParcelableExtra("transfer"); + try { + + mCallbacks.getService().attendedTransfer(transfer.getParticipants().get(0).getCallId(), c.getParticipants().get(0).getCallId()); + calls_adapter.remove(transfer); + calls_adapter.remove(c); + calls_adapter.notifyDataSetChanged(); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Toast.makeText(getActivity(), getString(R.string.home_transfer_complet), Toast.LENGTH_LONG).show(); + break; + + case 1: + String to = data.getStringExtra("to_number"); + transfer = data.getParcelableExtra("transfer"); + try { + Toast.makeText(getActivity(), getString(R.string.home_transfering, transfer.getParticipants().get(0).getContact().getmDisplayName(), to), + Toast.LENGTH_SHORT).show(); + mCallbacks.getService().transfer(transfer.getParticipants().get(0).getCallId(), to); + mCallbacks.getService().hangUp(transfer.getParticipants().get(0).getCallId()); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + break; + + default: + break; } } else if (requestCode == REQUEST_CONF) { switch (resultCode) { - case 0: - Conference call_to_add = data.getParcelableExtra("transfer"); - Conference call_target = data.getParcelableExtra("target"); + case 0: + Conference call_to_add = data.getParcelableExtra("transfer"); + Conference call_target = data.getParcelableExtra("target"); - bindCalls(call_to_add, call_target); - break; + bindCalls(call_to_add, call_target); + break; - default: - break; + default: + break; } } } @@ -453,6 +501,8 @@ public class CallListFragment extends Fragment { private void bindCalls(Conference call_to_add, Conference call_target) { try { + Log.i(TAG, "joining calls:"+ call_to_add.getId() + " and " + call_target.getId()); + if (call_target.hasMultipleParticipants() && !call_to_add.hasMultipleParticipants()) { mCallbacks.getService().addParticipant(call_to_add.getParticipants().get(0), call_target.getId()); diff --git a/src/org/sflphone/history/HistoryCall.java b/src/org/sflphone/history/HistoryCall.java index af029bbcab5e351249c9009b291e5ddd70c787bc..05d35919f6f446caee908fcdf42130047a2caa67 100644 --- a/src/org/sflphone/history/HistoryCall.java +++ b/src/org/sflphone/history/HistoryCall.java @@ -81,19 +81,6 @@ public class HistoryCall implements Parcelable { @DatabaseField long callID; - public HistoryCall(HashMap<String, String> entry) { - call_end = Long.parseLong(entry.get(ServiceConstants.history.TIMESTAMP_STOP_KEY)); - call_start = Long.parseLong(entry.get(ServiceConstants.history.TIMESTAMP_START_KEY)); - accountID = entry.get(ServiceConstants.history.ACCOUNT_ID_KEY); - - direction = entry.get(ServiceConstants.history.DIRECTION_KEY); - missed = entry.get(ServiceConstants.history.MISSED_KEY).contentEquals("true"); - - recordPath = entry.get(ServiceConstants.history.RECORDING_PATH_KEY); - number = entry.get(ServiceConstants.history.PEER_NUMBER_KEY); - timeFormatted = HistoryTimeModel.timeToHistoryConst(call_start); - } - /* Needed by ORMLite */ public HistoryCall() { } @@ -188,7 +175,7 @@ public class HistoryCall implements Parcelable { } public boolean isIncoming() { - return direction.contentEquals(ServiceConstants.history.INCOMING_STRING); + return true; } public boolean isMissed() { diff --git a/src/org/sflphone/model/Conference.java b/src/org/sflphone/model/Conference.java index 0047f3b62e3333466f0ea43612c53a3ef93a8423..3c30c9b0fcaf66b0dc92f5d20ab884a98f98851c 100644 --- a/src/org/sflphone/model/Conference.java +++ b/src/org/sflphone/model/Conference.java @@ -39,11 +39,21 @@ import android.os.Parcelable; public class Conference implements Parcelable { private String id; - private String state = ""; + private int mConfState; private ArrayList<SipCall> participants; private boolean recording; private ArrayList<SipMessage> messages; + public static String DEFAULT_ID = "-1"; + + public boolean isRinging() { + return participants.get(0).isRinging(); + } + + public void removeParticipant(String toRemove) { + participants.remove(toRemove); + } + public interface state { int ACTIVE_ATTACHED = 0; int ACTIVE_DETACHED = 1; @@ -53,6 +63,30 @@ public class Conference implements Parcelable { int HOLD_REC = 5; } + public void setCallState(String callID, int newState) { + if(id.contentEquals(callID)) + mConfState = newState; + else { + getCallById(callID).setCallState(newState); + } + } + + public void setCallState(String confID, String newState) { + if (newState.equals("ACTIVE_ATTACHED")) { + setCallState(confID, state.ACTIVE_ATTACHED); + } else if (newState.equals("ACTIVE_DETACHED")) { + setCallState(confID, state.ACTIVE_DETACHED); + } else if (newState.equals("ACTIVE_ATTACHED_REC")) { + setCallState(confID, state.ACTIVE_ATTACHED_REC); + } else if (newState.equals("ACTIVE_DETACHED_REC")) { + setCallState(confID, state.ACTIVE_DETACHED_REC); + } else if (newState.equals("HOLD")) { + setCallState(confID, state.HOLD); + } else if (newState.equals("HOLD_REC")) { + setCallState(confID, state.HOLD_REC); + } + } + @Override public int describeContents() { return 0; @@ -61,7 +95,7 @@ public class Conference implements Parcelable { @Override public void writeToParcel(Parcel out, int flags) { out.writeString(id); - out.writeString(state); + out.writeInt(mConfState); out.writeTypedList(participants); out.writeByte((byte) (recording ? 1 : 0)); out.writeTypedList(messages); @@ -80,13 +114,18 @@ public class Conference implements Parcelable { private Conference(Parcel in) { participants = new ArrayList<SipCall>(); id = in.readString(); - state = in.readString(); + mConfState = in.readInt(); in.readTypedList(participants, SipCall.CREATOR); recording = in.readByte() == 1 ? true : false; messages = new ArrayList<SipMessage>(); in.readTypedList(messages, SipMessage.CREATOR); } + public Conference(SipCall call) { + this(DEFAULT_ID); + participants.add(call); + } + public Conference(String cID) { id = cID; participants = new ArrayList<SipCall>(); @@ -96,7 +135,7 @@ public class Conference implements Parcelable { public Conference(Conference c) { id = c.id; - state = c.state; + mConfState = c.mConfState; participants = new ArrayList<SipCall>(c.participants); recording = c.recording; messages = new ArrayList<SipMessage>(); @@ -113,11 +152,37 @@ public class Conference implements Parcelable { if (participants.size() == 1) { return participants.get(0).getCallStateString(); } - return state; + return getConferenceStateString(); } - public void setState(String state) { - this.state = state; + public String getConferenceStateString() { + + String text_state; + + switch (mConfState) { + case state.ACTIVE_ATTACHED: + text_state = "ACTIVE_ATTACHED"; + break; + case state.ACTIVE_DETACHED: + text_state = "ACTIVE_DETACHED"; + break; + case state.ACTIVE_ATTACHED_REC: + text_state = "ACTIVE_ATTACHED_REC"; + break; + case state.ACTIVE_DETACHED_REC: + text_state = "ACTIVE_DETACHED_REC"; + break; + case state.HOLD: + text_state = "HOLD"; + break; + case state.HOLD_REC: + text_state = "HOLD_REC"; + break; + default: + text_state = "NULL"; + } + + return text_state; } public ArrayList<SipCall> getParticipants() { @@ -132,7 +197,7 @@ public class Conference implements Parcelable { return false; } - public SipCall getCall(String callID) { + public SipCall getCallById(String callID) { for (int i = 0; i < participants.size(); ++i) { if (participants.get(i).getCallId().contentEquals(callID)) return participants.get(i); @@ -169,9 +234,16 @@ public class Conference implements Parcelable { public boolean isOnHold() { if (participants.size() == 1 && participants.get(0).isOnHold()) return true; - return state.contentEquals("HOLD"); + return getConferenceStateString().contentEquals("HOLD"); + } + + public boolean isIncoming() { + if (participants.size() == 1 && participants.get(0).isIncoming()) + return true; + return false; } + public void setRecording(boolean b) { recording = b; } @@ -192,15 +264,15 @@ public class Conference implements Parcelable { } public ArrayList<SipMessage> getMessages() { - if (hasMultipleParticipants()) - return messages; - else - return participants.get(0).getMessages(); - + return messages; } public void addSipMessage(SipMessage sipMessage) { messages.add(sipMessage); } + public void addParticipant(SipCall part) { + participants.add(part); + } + } diff --git a/src/org/sflphone/model/SipCall.java b/src/org/sflphone/model/SipCall.java index 184ab7d2e314dd6562fa7230b53e5e949a7c7cf6..a8574a4b4dc55aa47ceaa56fa2565c2b5e556705 100644 --- a/src/org/sflphone/model/SipCall.java +++ b/src/org/sflphone/model/SipCall.java @@ -54,8 +54,6 @@ public class SipCall implements Parcelable { private int mCallType = state.CALL_TYPE_UNDETERMINED; private int mCallState = state.CALL_STATE_NONE; private int mMediaState = state.MEDIA_STATE_NONE; - - ArrayList<SipMessage> messages; /************************ * Construtors @@ -71,10 +69,7 @@ public class SipCall implements Parcelable { mCallState = in.readInt(); mMediaState = in.readInt(); timestamp_start = in.readLong(); - - messages = new ArrayList<SipMessage>(); - in.readTypedList(messages, SipMessage.CREATOR); - } + } public SipCall(String id, Account account, int call_type, int call_state, int media_state, CallContact c) { mCallID = id; @@ -83,7 +78,6 @@ public class SipCall implements Parcelable { mCallState = call_state; mMediaState = media_state; contact = c; - messages = new ArrayList<SipMessage>(); } public interface state { @@ -125,8 +119,6 @@ public class SipCall implements Parcelable { out.writeInt(mCallState); out.writeInt(mMediaState); out.writeLong(timestamp_start); - - out.writeTypedList(messages); } public static final Parcelable.Creator<SipCall> CREATOR = new Parcelable.Creator<SipCall>() { @@ -418,13 +410,4 @@ public class SipCall implements Parcelable { public boolean isCurrent() { return mCallState == state.CALL_STATE_CURRENT; } - - public void addSipMessage(SipMessage message) { - messages.add(message); - } - - public ArrayList<SipMessage> getMessages() { - return messages; - } - } diff --git a/src/org/sflphone/service/CallManagerCallBack.java b/src/org/sflphone/service/CallManagerCallBack.java index 8126c8b91284e6bc3e7511bf3a54050a846d4c19..5ba0d67d5eeab9d3073052f1fc8c58d29a4903a2 100644 --- a/src/org/sflphone/service/CallManagerCallBack.java +++ b/src/org/sflphone/service/CallManagerCallBack.java @@ -2,22 +2,20 @@ package org.sflphone.service; import android.content.Intent; import android.os.Bundle; -import android.os.RemoteException; import android.support.v4.content.LocalBroadcastManager; import android.util.Log; import org.sflphone.client.CallActivity; import org.sflphone.model.*; +import org.sflphone.utils.SwigNativeConverter; import java.util.ArrayList; -import java.util.HashMap; import java.util.Iterator; import java.util.Map; public class CallManagerCallBack extends Callback { - + private static final String TAG = "CallManagerCallBack"; - private final ISipService.Stub mBinder; - private SipService mService; + private SipService mService; static public final String CALL_STATE_CHANGED = "call-state-changed"; static public final String INCOMING_CALL = "incoming-call"; @@ -28,14 +26,13 @@ public class CallManagerCallBack extends Callback { static public final String RECORD_STATE_CHANGED = "record_state"; - public CallManagerCallBack(SipService context, ISipService.Stub bind) { + public CallManagerCallBack(SipService context) { mService = context; - mBinder = bind; } @Override public void on_call_state_changed(String callID, String newState) { - Log.d(TAG, "on_call_state_changed : (" + callID + ", " + newState + ")"); + Log.d(TAG, "on_call_state_changed : (" + callID + ", " + newState + ")"); Bundle bundle = new Bundle(); bundle.putString("CallID", callID); bundle.putString("State", newState); @@ -52,23 +49,23 @@ public class CallManagerCallBack extends Callback { if (newState.equals("INCOMING")) { - mService.getCurrentCalls().get(callID).setCallState(SipCall.state.CALL_STATE_INCOMING); + mService.getCurrentConfs().get(callID).setCallState(callID, SipCall.state.CALL_STATE_INCOMING); } else if (newState.equals("RINGING")) { try { - mService.getCurrentCalls().get(callID).setCallState(SipCall.state.CALL_STATE_RINGING); + mService.getCurrentConfs().get(callID).setCallState(callID, SipCall.state.CALL_STATE_RINGING); } catch (NullPointerException e) { - if (mService.getCurrentCalls() == null) { + if (mService.getCurrentConfs() == null) { return; } - if (mService.getCurrentCalls().get(callID) == null) { + if (mService.getCurrentConfs().get(callID) == null) { Log.e(TAG, "call for " + callID + " is null"); return; } } } else if (newState.equals("CURRENT")) { - if (mService.getCurrentCalls().get(callID) != null) { - mService.getCurrentCalls().get(callID).setCallState(SipCall.state.CALL_STATE_CURRENT); + if (mService.getCurrentConfs().get(callID) != null) { + mService.getCurrentConfs().get(callID).setCallState(callID, SipCall.state.CALL_STATE_CURRENT); } else { // Check if call is in a conference Iterator<Map.Entry<String, Conference>> it = mService.getCurrentConfs().entrySet().iterator(); @@ -84,11 +81,11 @@ public class CallManagerCallBack extends Callback { } else if (newState.equals("HUNGUP")) { Log.d(TAG, "Hanging up " + callID); - if (mService.getCurrentCalls().get(callID) != null) { - if (mService.getCurrentCalls().get(callID).isRinging() - && mService.getCurrentCalls().get(callID).isIncoming()) - mService.notificationManager.publishMissedCallNotification(mService.getCurrentCalls().get(callID)); - mService.getCurrentCalls().remove(callID); + if (mService.getCurrentConfs().get(callID) != null) { + if (mService.getCurrentConfs().get(callID).isRinging() + && mService.getCurrentConfs().get(callID).isIncoming()) + mService.notificationManager.publishMissedCallNotification(mService.getCurrentConfs().get(callID)); + mService.getCurrentConfs().remove(callID); } else { ArrayList<Conference> it = new ArrayList<Conference>(mService.getCurrentConfs().values()); @@ -109,15 +106,13 @@ public class CallManagerCallBack extends Callback { } } - mService.sendBroadcast(intent); - } else if (newState.equals("BUSY")) { - mService.getCurrentCalls().remove(callID); + mService.getCurrentConfs().remove(callID); } else if (newState.equals("FAILURE")) { - mService.getCurrentCalls().remove(callID); + mService.getCurrentConfs().remove(callID); } else if (newState.equals("HOLD")) { - if (mService.getCurrentCalls().get(callID) != null) { - mService.getCurrentCalls().get(callID).setCallState(SipCall.state.CALL_STATE_HOLD); + if (mService.getCurrentConfs().get(callID) != null) { + mService.getCurrentConfs().get(callID).setCallState(callID, SipCall.state.CALL_STATE_HOLD); } else { // Check if call is in a conference Iterator<Map.Entry<String, Conference>> it = mService.getCurrentConfs().entrySet().iterator(); @@ -131,8 +126,8 @@ public class CallManagerCallBack extends Callback { } } else if (newState.equals("UNHOLD")) { - if (mService.getCurrentCalls().get(callID) != null) { - mService.getCurrentCalls().get(callID).setCallState(SipCall.state.CALL_STATE_CURRENT); + if (mService.getCurrentConfs().get(callID) != null) { + mService.getCurrentConfs().get(callID).setCallState(callID, SipCall.state.CALL_STATE_CURRENT); } else { // Check if call is in a conference Iterator<Map.Entry<String, Conference>> it = mService.getCurrentConfs().entrySet().iterator(); @@ -145,7 +140,7 @@ public class CallManagerCallBack extends Callback { } } } else { - mService.getCurrentCalls().get(callID).setCallState(SipCall.state.CALL_STATE_NONE); + mService.getCurrentConfs().get(callID).setCallState(callID, SipCall.state.CALL_STATE_NONE); } @@ -160,10 +155,9 @@ public class CallManagerCallBack extends Callback { SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance(); try { - HashMap<String, String> details = (HashMap<String, String>) mBinder.getAccountDetails(accountID); - ArrayList<HashMap<String, String>> credentials = (ArrayList<HashMap<String, String>>) mBinder - .getCredentials(accountID); - Account acc = new Account(accountID, details, credentials); + StringMap details = mService.getConfigurationManagerJNI().getAccountDetails(accountID); + VectMap credentials = mService.getConfigurationManagerJNI().getCredentials(accountID); + Account acc = new Account(accountID, SwigNativeConverter.convertAccountToNative(details), SwigNativeConverter.convertCredentialsToNative(credentials)); callBuilder.startCallCreation(callID).setAccount(acc).setCallState(SipCall.state.CALL_STATE_RINGING) .setCallType(SipCall.state.CALL_TYPE_INCOMING); callBuilder.setContact(CallContact.ContactBuilder.buildUnknownContact(from)); @@ -174,99 +168,116 @@ public class CallManagerCallBack extends Callback { SipCall newCall = callBuilder.build(); toSend.putExtra("newcall", newCall); - HashMap<String, String> callDetails = (HashMap<String, String>) mBinder.getCallDetails(callID); + StringMap callDetails = mService.getCallManagerJNI().getCallDetails(callID); newCall.setTimestamp_start(Long.parseLong(callDetails.get(ServiceConstants.call.TIMESTAMP_START))); - mService.getCurrentCalls().put(newCall.getCallId(), newCall); - Bundle bundle = new Bundle(); - Conference tmp = new Conference("-1"); + Conference toAdd = new Conference(newCall); - tmp.getParticipants().add(newCall); + mService.getCurrentConfs().put(toAdd.getId(), toAdd); - bundle.putParcelable("conference", tmp); + Bundle bundle = new Bundle(); + + bundle.putParcelable("conference", toAdd); toSend.putExtra("resuming", false); toSend.putExtras(bundle); mService.startActivity(toSend); mService.mediaManager.startRing(""); mService.mediaManager.obtainAudioFocus(true); - } catch (RemoteException e1) { - e1.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } - + @Override - public void on_transfer_state_changed(String result){ - Log.w(TAG,"TRANSFER STATE CHANGED:"+result); + public void on_transfer_state_changed(String result) { + Log.w(TAG, "TRANSFER STATE CHANGED:" + result); } - + @Override - public void on_conference_created(String confID){ - Log.w(TAG,"CONFERENCE CREATED:"+confID); + public void on_conference_created(final String confID) { + Log.w(TAG, "CONFERENCE CREATED:" + confID); Intent intent = new Intent(CONF_CREATED); Conference created = new Conference(confID); - try { - ArrayList<String> all_participants = (ArrayList<String>) mBinder.getParticipantList(intent.getStringExtra("confID")); - for (String participant : all_participants) { - created.getParticipants().add(mService.getCurrentCalls().get(participant)); - mService.getCurrentCalls().remove(participant); + StringVect all_participants = mService.getCallManagerJNI().getParticipantList(confID); + Log.w(TAG, "all_participants:" + all_participants.size()); + for (int i = 0; i < all_participants.size(); ++i) { + if (mService.getCurrentConfs().get(all_participants.get(i)) != null) { + created.addParticipant(mService.getCurrentConfs().get(all_participants.get(i)).getCallById(all_participants.get(i))); + mService.getCurrentConfs().remove(all_participants.get(i)); + } else { + Iterator<Map.Entry<String, Conference>> it = mService.getCurrentConfs().entrySet().iterator(); + while (it.hasNext()) { + Conference tmp = it.next().getValue(); + for (SipCall c : tmp.getParticipants()) { + if (c.getCallId().contentEquals(all_participants.get(i))) { + created.addParticipant(c); + mService.getCurrentConfs().get(tmp.getId()).removeParticipant(c.getCallId()); + } + } + } } - intent.putExtra("newconf", created); - mService.getCurrentConfs().put(confID, created); - mService.sendBroadcast(intent); - } catch (RemoteException e1) { - e1.printStackTrace(); } - Log.i(TAG, "current_confs size " + mService.getCurrentConfs().size()); + intent.putExtra("newconf", created); + mService.getCurrentConfs().put(created.getId(), created); + mService.sendBroadcast(intent); } - + @Override - public void on_incoming_message(String ID, String from, String msg){ - Log.w(TAG,"on_incoming_message:"+msg); + public void on_incoming_message(String ID, String from, String msg) { + Log.w(TAG, "on_incoming_message:" + msg); Bundle bundle = new Bundle(); bundle.putString("CallID", ID); bundle.putString("From", from); bundle.putString("Msg", msg); - Intent intent = new Intent(INCOMING_TEXT); + Intent intent = new Intent(INCOMING_TEXT); intent.putExtra("com.savoirfairelinux.sflphone.service.newtext", bundle); - if (mService.getCurrentCalls().get(ID) != null) { - mService.getCurrentCalls().get(ID).addSipMessage(new SipMessage(true, msg)); - } else if (mService.getCurrentConfs().get(ID) != null) { + if (mService.getCurrentConfs().get(ID) != null) { mService.getCurrentConfs().get(ID).addSipMessage(new SipMessage(true, msg)); - } else - return; + } else { + Iterator<Map.Entry<String, Conference>> it = mService.getCurrentConfs().entrySet().iterator(); + while (it.hasNext()) { + Conference tmp = it.next().getValue(); + for (SipCall c : tmp.getParticipants()) { + if (c.getCallId().contentEquals(ID)) { + mService.getCurrentConfs().get(tmp.getId()).addSipMessage(new SipMessage(true, msg)); + } + } + } + + } mService.sendBroadcast(intent); } - + @Override - public void on_conference_removed(String confID){ + public void on_conference_removed(String confID) { Intent intent = new Intent(CONF_REMOVED); intent.putExtra("confID", confID); - Conference toDestroy = mService.getCurrentConfs().get(confID); - for (int i = 0; i < toDestroy.getParticipants().size(); ++i) { + Conference toReInsert = mService.getCurrentConfs().get(confID); + /*for (int i = 0; i < toDestroy.getParticipants().size(); ++i) { mService.getCurrentCalls().put(toDestroy.getParticipants().get(i).getCallId(), toDestroy.getParticipants().get(i)); - } + }*/ mService.getCurrentConfs().remove(confID); + mService.getCurrentConfs().put(toReInsert.getId(), toReInsert); mService.sendBroadcast(intent); } - + @Override - public void on_conference_state_changed(String confID, String state){ + public void on_conference_state_changed(String confID, String state) { + Intent intent = new Intent(CONF_CHANGED); intent.putExtra("confID", confID); intent.putExtra("State", state); ArrayList<String> all_participants; - try { +/* try { all_participants = (ArrayList<String>) mBinder.getParticipantList(intent.getStringExtra("confID")); for (String participant : all_participants) { if (mService.getCurrentConfs().get(confID).getParticipants().size() < all_participants.size() @@ -281,17 +292,17 @@ public class CallManagerCallBack extends Callback { } } catch (RemoteException e) { e.printStackTrace(); - } + }*/ Log.i(TAG, "Received" + intent.getAction()); if (mService.getCurrentConfs().get(confID) != null) { - mService.getCurrentConfs().get(confID).setState(intent.getStringExtra("State")); + mService.getCurrentConfs().get(confID).setCallState(confID, state); mService.sendBroadcast(intent); } } - + @Override - public void on_record_playback_filepath(String id, String filename){ + public void on_record_playback_filepath(String id, String filename) { Intent intent = new Intent(RECORD_STATE_CHANGED); intent.putExtra("id", id); intent.putExtra("file", filename); diff --git a/src/org/sflphone/service/ConfigurationManagerCallback.java b/src/org/sflphone/service/ConfigurationManagerCallback.java index 0a02925e6be25218c9f92de98435509853ab8075..32c2e9c7732ece49beef421301218278b369a9c1 100644 --- a/src/org/sflphone/service/ConfigurationManagerCallback.java +++ b/src/org/sflphone/service/ConfigurationManagerCallback.java @@ -22,21 +22,17 @@ */ package org.sflphone.service; -import android.content.Context; import android.content.Intent; -import android.support.v4.content.LocalBroadcastManager; public class ConfigurationManagerCallback extends ConfigurationCallback { // private static final String TAG = "ConfigurationManagerCallback"; -private final ISipService.Stub mBinder; private SipService mService; static public final String ACCOUNTS_CHANGED = "accounts-changed"; static public final String ACCOUNT_STATE_CHANGED = "account-state-changed"; - public ConfigurationManagerCallback(SipService context, ISipService.Stub bind) { + public ConfigurationManagerCallback(SipService context) { mService = context; - mBinder = bind; } @Override diff --git a/src/org/sflphone/service/ISipService.aidl b/src/org/sflphone/service/ISipService.aidl index c4c5e186ffaed67c404afca33b9442de7a15104b..cb8b64c67775fa6f3c052963b39acc454d20e942 100644 --- a/src/org/sflphone/service/ISipService.aidl +++ b/src/org/sflphone/service/ISipService.aidl @@ -74,16 +74,13 @@ interface ISipService { void unholdConference(in String confID); boolean isConferenceParticipant(in String callID); Map getConferenceList(); - Map getCallList(); List getParticipantList(in String confID); String getConferenceId(in String callID); String getConferenceDetails(in String callID); Conference getCurrentCall(); List getConcurrentCalls(); - - - /* */ - - SipCall getCall(String callID); + + Conference getConference(in String id); + } diff --git a/src/org/sflphone/service/SipService.java b/src/org/sflphone/service/SipService.java index c76ad979185ce58bc0daa0a082c87055e3ffe093..bfc6ac2bf8232b38b1b557443b4db844eabd4c02 100644 --- a/src/org/sflphone/service/SipService.java +++ b/src/org/sflphone/service/SipService.java @@ -49,7 +49,6 @@ import android.os.IBinder; import android.os.Looper; import android.os.Message; import android.os.RemoteException; -import android.support.v4.content.LocalBroadcastManager; import android.util.Log; public class SipService extends Service { @@ -57,9 +56,19 @@ public class SipService extends Service { static final String TAG = "SipService"; private SipServiceExecutor mExecutor; private static HandlerThread executorThread; + + public CallManager getCallManagerJNI() { + return callManagerJNI; + } + private CallManager callManagerJNI; private ManagerImpl managerImpl; private CallManagerCallBack callManagerCallBack; + + public ConfigurationManager getConfigurationManagerJNI() { + return configurationManagerJNI; + } + private ConfigurationManager configurationManagerJNI; private ConfigurationManagerCallback configurationManagerCallback; private boolean isPjSipStackStarted = false; @@ -67,16 +76,16 @@ public class SipService extends Service { public SipNotifications notificationManager; public MediaManager mediaManager; - private HashMap<String, SipCall> current_calls = new HashMap<String, SipCall>(); + /*private HashMap<String, SipCall> current_calls = new HashMap<String, SipCall>();*/ private HashMap<String, Conference> current_confs = new HashMap<String, Conference>(); public HashMap<String, Conference> getCurrentConfs() { return current_confs; } - public HashMap<String, SipCall> getCurrentCalls() { + /*public HashMap<String, SipCall> getCurrentCalls() { return current_calls; - } + }*/ @Override public boolean onUnbind(Intent i) { @@ -144,28 +153,27 @@ public class SipService extends Service { public SipServiceExecutor getExecutor() { // create mExecutor lazily if (mExecutor == null) { - mExecutor = new SipServiceExecutor(this); + mExecutor = new SipServiceExecutor(); } return mExecutor; } // Executes immediate tasks in a single executorThread. public static class SipServiceExecutor extends Handler { - WeakReference<SipService> handlerService; - SipServiceExecutor(SipService s) { + SipServiceExecutor() { super(createLooper()); - handlerService = new WeakReference<SipService>(s); } public void execute(Runnable task) { // TODO: add wakelock - Message.obtain(this, 0/* don't care */, task).sendToTarget(); + Message.obtain(SipServiceExecutor.this, 0/* don't care */, task).sendToTarget(); Log.w(TAG, "SenT!"); } @Override public void handleMessage(Message msg) { + Log.w(TAG, "handleMessage"); if (msg.obj instanceof Runnable) { executeInternal((Runnable) msg.obj); } else { @@ -216,11 +224,11 @@ public class SipService extends Service { // managerImpl.setPath(getApplication().getFilesDir().getAbsolutePath()); callManagerJNI = new CallManager(); - callManagerCallBack = new CallManagerCallBack(this, mBinder); + callManagerCallBack = new CallManagerCallBack(this); SFLPhoneservice.setCallbackObject(callManagerCallBack); configurationManagerJNI = new ConfigurationManager(); - configurationManagerCallback = new ConfigurationManagerCallback(this, mBinder); + configurationManagerCallback = new ConfigurationManagerCallback(this); SFLPhoneservice.setConfigurationCallbackObject(configurationManagerCallback); managerImpl.init(""); @@ -255,7 +263,7 @@ public class SipService extends Service { Object obj = null; boolean done = false; - protected abstract Object doRun() throws SameThreadException; + protected abstract Object doRun() throws SameThreadException, RemoteException; public Object getVal() { return obj; @@ -273,6 +281,8 @@ public class SipService extends Service { done = true; } catch (SameThreadException e) { Log.e(TAG, "Not done from same thread"); + } catch (RemoteException e) { + Log.e(TAG, e.toString()); } } } @@ -311,7 +321,8 @@ public class SipService extends Service { HashMap<String, String> details = SwigNativeConverter.convertCallDetailsToNative(callManagerJNI.getCallDetails(call.getCallId())); // watchout timestamp stored by sflphone is in seconds call.setTimestamp_start(Long.parseLong(details.get(ServiceConstants.call.TIMESTAMP_START))); - getCurrentCalls().put(call.getCallId(), call); + Conference toAdd = new Conference(call); + current_confs.put(toAdd.getId(), toAdd); mediaManager.obtainAudioFocus(false); } }); @@ -647,7 +658,7 @@ public class SipService extends Service { // Generate a CONF_CREATED callback } }); - + Log.i(TAG, "After joining participants"); } @Override @@ -688,7 +699,8 @@ public class SipService extends Service { Conference tmp = it.next().getValue(); Log.i(TAG, "conf has " + tmp.getParticipants().size() + " participants"); if (tmp.contains(callID)) { - current_calls.put(callID, tmp.getCall(callID)); + Conference toDetach = new Conference(tmp.getCallById(callID)); + current_confs.put(toDetach.getId(), toDetach); Log.i(TAG, "Call found and put in current_calls"); } } @@ -796,7 +808,7 @@ public class SipService extends Service { class PartList extends SipRunnableWithReturn { @Override protected StringVect doRun() throws SameThreadException { - Log.i(TAG, "SipService.getAccountList() thread running..."); + Log.i(TAG, "SipService.getParticipantList() thread running..."); return callManagerJNI.getParticipantList(confID); } } @@ -804,10 +816,10 @@ public class SipService extends Service { PartList runInstance = new PartList(); getExecutor().execute(runInstance); while (!runInstance.isDone()) { - // Log.w(TAG, "Waiting for getConferenceList"); + Log.w(TAG, "getParticipantList"); } StringVect swigvect = (StringVect) runInstance.getVal(); - + Log.w(TAG, "After that"); ArrayList<String> nativelist = new ArrayList<String>(); for (int i = 0; i < swigvect.size(); i++) @@ -873,17 +885,14 @@ public class SipService extends Service { Log.i(TAG, "SipService.toggleRecordingCall() thread running..."); boolean result = callManagerJNI.toggleRecording(id); - if (getCurrentCalls().containsKey(id)) { - getCurrentCalls().get(id).setRecording(result); - } else if (getCurrentConfs().containsKey(id)) { + if (getCurrentConfs().containsKey(id)) { getCurrentConfs().get(id).setRecording(result); } else { - // A call in a conference has been put on hold Iterator<Conference> it = getCurrentConfs().values().iterator(); while (it.hasNext()) { Conference c = it.next(); - if (c.getCall(id) != null) - c.getCall(id).setRecording(result); + if (c.getCallById(id) != null) + c.getCallById(id).setRecording(result); } } return result; @@ -940,9 +949,7 @@ public class SipService extends Service { protected void doRun() throws SameThreadException, RemoteException { Log.i(TAG, "SipService.sendTextMessage() thread running..."); callManagerJNI.sendTextMessage(callID, message.comment); - if (getCurrentCalls().get(callID) != null) - getCurrentCalls().get(callID).addSipMessage(message); - else if (getCurrentConfs().get(callID) != null) + if (getCurrentConfs().get(callID) != null) getCurrentConfs().get(callID).addSipMessage(message); } }); @@ -964,10 +971,6 @@ public class SipService extends Service { results.add(new Codec(active_payloads.get(i), configurationManagerJNI.getAudioCodecDetails(active_payloads.get(i)), true)); } - - // if (results.get(active_payloads.get(i)) != null) { - // results.get(active_payloads.get(i)).setEnabled(true); - IntVect payloads = configurationManagerJNI.getAudioCodecList(); for (int i = 0; i < payloads.size(); ++i) { @@ -984,11 +987,6 @@ public class SipService extends Service { } - // if (!results.containsKey(payloads.get(i))) { - // results.put(payloads.get(i), new Codec(payloads.get(i), configurationManagerJNI.getAudioCodecDetails(payloads.get(i)), false)); - // Log.i(TAG, "Other, Adding:" + results.get((payloads.get(i))).getName()); - // } - return results; } } @@ -1040,84 +1038,46 @@ public class SipService extends Service { }); } - @Override - public HashMap<String, SipCall> getCallList() throws RemoteException { - // class CallList extends SipRunnableWithReturn { - // - // @Override - // protected StringVect doRun() throws SameThreadException { - // Log.i(TAG, "SipService.getCallList() thread running...incoming"); - // return callManagerJNI.getCallList(); - // } - // } - // - // CallList runInstance = new CallList(); - // getExecutor().execute(runInstance); - // while (!runInstance.isDone()) { - // Log.w(TAG, "Waiting for getAudioCodecList"); - // } - // StringVect swigmap = (StringVect) runInstance.getVal(); - // - // ArrayList<String> nativemap = new ArrayList<String>(); - // for (int i = 0; i < swigmap.size(); ++i) { - // - // String t = swigmap.get(i); - // nativemap.add(t); - // } - // if(callManagerJNI == null) - // return new HashMap<String, SipCall>(); - // - // - // HashMap<String, SipCall> results = new HashMap<String, SipCall>(); - // StringVect calls = callManagerJNI.getCallList(); - // for(int i = 0 ; i < calls.size(); ++i){ - // results.put(calls.get(i), new SipCall(calls.get(i), callManagerJNI.getCallDetails(calls.get(i)))); - // } - - return getCurrentCalls(); - } - - @Override - public SipCall getCall(String callID) throws RemoteException { - return getCurrentCalls().get(callID); - } +/* @Override + public Conference getCallById(String callID) throws RemoteException { + if(current_confs.containsKey(callID)) + return current_confs.get(callID); + else{ + Iterator<Conference> it = getCurrentConfs().values().iterator(); + while (it.hasNext()) { + Conference c = it.next(); + if (c.getCallById(callID) != null) + return c; + } + } + return null; + }*/ /*********************** * Notification API ***********************/ @Override public void createNotification() throws RemoteException { - notificationManager.makeNotification(getCurrentCalls()); } @Override public void destroyNotification() throws RemoteException { - notificationManager.removeNotification(); } @Override public Conference getCurrentCall() throws RemoteException { - for (SipCall i : current_calls.values()) { - - // Incoming >> Ongoing - if (i.isIncoming()) { - Conference tmp = new Conference("-1"); - tmp.getParticipants().add(i); - return tmp; - } - - if (i.isOngoing()) { - Conference tmp = new Conference("-1"); - tmp.getParticipants().add(i); - return tmp; - } + for (Conference conf : current_confs.values()) { + if (conf.isIncoming()) + return conf; } - if (!current_confs.isEmpty()) { - return (Conference) current_confs.values().toArray()[0]; + for (Conference conf : current_confs.values()) { + if (conf.isOnGoing()) + return conf; } + return null; } @@ -1134,19 +1094,12 @@ public class SipService extends Service { @Override public List getConcurrentCalls() throws RemoteException { - ArrayList<Conference> toReturn = new ArrayList<Conference>(); - - for (SipCall sip : current_calls.values()) { - if (!sip.isCurrent()) { - Conference tmp = new Conference("-1"); - tmp.getParticipants().add(sip); - toReturn.add(tmp); - } - } - - Log.i(TAG, "toReturn SIZE " + toReturn.size()); + return new ArrayList(current_confs.values()); + } - return toReturn; + @Override + public Conference getConference(String id) throws RemoteException { + return current_confs.get(id); } @Override diff --git a/src/org/sflphone/utils/SipNotifications.java b/src/org/sflphone/utils/SipNotifications.java index eaf9fb0f2e778948824562febaf861d190a97877..47961cccc4379b238d06f0e45c1e1ce02dee7bdd 100644 --- a/src/org/sflphone/utils/SipNotifications.java +++ b/src/org/sflphone/utils/SipNotifications.java @@ -38,6 +38,7 @@ import java.util.Random; import org.sflphone.R; import org.sflphone.client.HomeActivity; +import org.sflphone.model.Conference; import org.sflphone.model.SipCall; import android.app.Notification; @@ -145,7 +146,7 @@ public class SipNotifications { cancelVoicemails(); } - public void publishMissedCallNotification(SipCall sipCall) { + public void publishMissedCallNotification(Conference missedConf) { CharSequence tickerText = context.getString(R.string.notif_missed_call_title); long when = System.currentTimeMillis(); @@ -157,7 +158,7 @@ public class SipNotifications { nb.setTicker(tickerText); nb.setWhen(when); nb.setContentTitle(context.getString(R.string.notif_missed_call_title)); - nb.setContentText(context.getString(R.string.notif_missed_call_content, sipCall.getContact().getmDisplayName())); + nb.setContentText(context.getString(R.string.notif_missed_call_content, missedConf.getParticipants().get(0).getContact().getmDisplayName())); Intent notificationIntent = new Intent(context, HomeActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);