diff --git a/src/org/sflphone/fragments/HistoryFragment.java b/src/org/sflphone/fragments/HistoryFragment.java index cd5f3e79cb4ce3950aa11ab7ec75b816e43e2ed7..f2366e89885d6750874d72dce1f6d4a5aa0c1f0e 100644 --- a/src/org/sflphone/fragments/HistoryFragment.java +++ b/src/org/sflphone/fragments/HistoryFragment.java @@ -40,7 +40,7 @@ import org.sflphone.adapters.ContactPictureTask; import org.sflphone.client.DetailHistoryActivity; import org.sflphone.loaders.HistoryLoader; import org.sflphone.loaders.LoaderConstants; -import org.sflphone.model.HistoryEntry; +import org.sflphone.history.HistoryEntry; import org.sflphone.service.ISipService; import android.app.Activity; @@ -117,12 +117,8 @@ public class HistoryFragment extends ListFragment implements LoaderCallbacks<Arr public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_clear_history: - try { - mCallbacks.getService().clearHistory(); + // TODO clean Database! getLoaderManager().restartLoader(LoaderConstants.HISTORY_LOADER, null, this); - } catch (RemoteException e) { - e.printStackTrace(); - } return true; default: return super.onOptionsItemSelected(item); @@ -167,8 +163,7 @@ public class HistoryFragment extends ListFragment implements LoaderCallbacks<Arr public void onStart() { super.onStart(); Log.w(TAG, "onStart"); - getActivity().supportInvalidateOptionsMenu(); - getLoaderManager().restartLoader(LoaderConstants.HISTORY_LOADER, null, this); + //getLoaderManager().restartLoader(LoaderConstants.HISTORY_LOADER, null, this); } public void makeNewCall(int position) { diff --git a/src/org/sflphone/history/DatabaseHelper.java b/src/org/sflphone/history/DatabaseHelper.java new file mode 100644 index 0000000000000000000000000000000000000000..3e52334c10e27d5ab9c53befce626fe64ef0019c --- /dev/null +++ b/src/org/sflphone/history/DatabaseHelper.java @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. + * + * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Additional permission under GNU GPL version 3 section 7: + * + * If you modify this program, or any covered work, by linking or + * combining it with the OpenSSL project's OpenSSL library (or a + * modified version of that library), containing parts covered by the + * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. + * grants you additional permission to convey the resulting work. + * Corresponding Source for a non-source form of such a combination + * shall include the source code for the parts of OpenSSL used as well + * as that of the covered work. + */ + + +package org.sflphone.history; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.util.Log; +import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper; +import com.j256.ormlite.dao.Dao; +import com.j256.ormlite.support.ConnectionSource; +import com.j256.ormlite.table.TableUtils; + +import java.sql.SQLException; + +/** + * Database helper class used to manage the creation and upgrading of your database. This class also usually provides + * the DAOs used by the other classes. + */ +public class DatabaseHelper extends OrmLiteSqliteOpenHelper { + + // name of the database file for your application -- change to something appropriate for your app + private static final String DATABASE_NAME = "history.db"; + // any time you make changes to your database objects, you may have to increase the database version + private static final int DATABASE_VERSION = 1; + + // the DAO object we use to access the SimpleData table + private Dao<HistoryCall, Integer> historyDao = null; + + public DatabaseHelper(Context context) { + super(context, DATABASE_NAME, null, DATABASE_VERSION); + } + + /** + * This is called when the database is first created. Usually you should call createTable statements here to create + * the tables that will store your data. + */ + @Override + public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) { + try { + Log.i(DatabaseHelper.class.getName(), "onCreate"); + TableUtils.createTable(connectionSource, HistoryCall.class); + } catch (SQLException e) { + Log.e(DatabaseHelper.class.getName(), "Can't create database", e); + throw new RuntimeException(e); + } + } + + /** + * This is called when your application is upgraded and it has a higher version number. This allows you to adjust + * the various data to match the new version number. + */ + @Override + public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) { + try { + Log.i(DatabaseHelper.class.getName(), "onUpgrade"); + TableUtils.dropTable(connectionSource, HistoryCall.class, true); + // after we drop the old databases, we create the new ones + onCreate(db, connectionSource); + } catch (SQLException e) { + Log.e(DatabaseHelper.class.getName(), "Can't drop databases", e); + throw new RuntimeException(e); + } + } + + /** + * Returns the Database Access Object (DAO) for our SimpleData class. It will create it or just give the cached + * value. + */ + public Dao<HistoryCall, Integer> getHistoryDao() throws SQLException { + if (historyDao == null) { + historyDao = getDao(HistoryCall.class); + } + return historyDao; + } + + /** + * Close the database connections and clear any cached DAOs. + */ + @Override + public void close() { + super.close(); + historyDao = null; + } +} diff --git a/src/org/sflphone/history/HistoryCall.java b/src/org/sflphone/history/HistoryCall.java new file mode 100644 index 0000000000000000000000000000000000000000..27b47168eac025cf529f3a3eb1ae658430203751 --- /dev/null +++ b/src/org/sflphone/history/HistoryCall.java @@ -0,0 +1,7 @@ +package org.sflphone.history; + +/** + * Created by lisional on 14/01/14. + */ +public class HistoryCall { +} diff --git a/src/org/sflphone/model/HistoryEntry.java b/src/org/sflphone/history/HistoryEntry.java similarity index 95% rename from src/org/sflphone/model/HistoryEntry.java rename to src/org/sflphone/history/HistoryEntry.java index 0866c5a4bbfd6bf41c8df7eb56b9adc8adaa9551..30037507be24c01d6851a4afe264d8cd1ca91ff5 100644 --- a/src/org/sflphone/model/HistoryEntry.java +++ b/src/org/sflphone/history/HistoryEntry.java @@ -29,7 +29,7 @@ * as that of the covered work. */ -package org.sflphone.model; +package org.sflphone.history; import java.sql.Timestamp; import java.text.SimpleDateFormat; @@ -41,8 +41,8 @@ import java.util.NavigableMap; import java.util.TimeZone; import java.util.TreeMap; +import org.sflphone.model.CallContact; import org.sflphone.service.ServiceConstants; -import org.sflphone.utils.HistoryManager; import android.os.Parcel; import android.os.Parcelable; @@ -195,9 +195,14 @@ public class HistoryEntry implements Parcelable { String timeFormatted; String displayName; + String accountID; + + long contactID; + 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"); @@ -205,7 +210,7 @@ public class HistoryEntry implements Parcelable { displayName = entry.get(ServiceConstants.history.DISPLAY_NAME_KEY); recordPath = entry.get(ServiceConstants.history.RECORDING_PATH_KEY); number = entry.get(ServiceConstants.history.PEER_NUMBER_KEY); - timeFormatted = HistoryManager.timeToHistoryConst(call_start); + timeFormatted = HistoryTimeModel.timeToHistoryConst(call_start); } public String getDirection() { @@ -265,12 +270,14 @@ public class HistoryEntry implements Parcelable { public void writeToParcel(Parcel dest, int flags) { dest.writeLong(call_start); dest.writeLong(call_end); + dest.writeString(accountID); dest.writeString(number); dest.writeByte((byte) (missed ? 1 : 0)); dest.writeString(direction); dest.writeString(recordPath); dest.writeString(timeFormatted); dest.writeString(displayName); + dest.writeLong(contactID); } public static final Parcelable.Creator<HistoryCall> CREATOR = new Parcelable.Creator<HistoryCall>() { @@ -286,12 +293,14 @@ public class HistoryEntry implements Parcelable { private HistoryCall(Parcel in) { call_start = in.readLong(); call_end = in.readLong(); + accountID = in.readString(); number = in.readString(); missed = in.readByte() == 1 ? true : false; direction = in.readString(); recordPath = in.readString(); timeFormatted = in.readString(); displayName = in.readString(); + contactID = in.readLong(); } public boolean hasRecord() { diff --git a/src/org/sflphone/history/HistoryManager.java b/src/org/sflphone/history/HistoryManager.java new file mode 100644 index 0000000000000000000000000000000000000000..25aa8530e77d714759987912513cb511cc9ee72d --- /dev/null +++ b/src/org/sflphone/history/HistoryManager.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. + * + * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Additional permission under GNU GPL version 3 section 7: + * + * If you modify this program, or any covered work, by linking or + * combining it with the OpenSSL project's OpenSSL library (or a + * modified version of that library), containing parts covered by the + * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. + * grants you additional permission to convey the resulting work. + * Corresponding Source for a non-source form of such a combination + * shall include the source code for the parts of OpenSSL used as well + * as that of the covered work. + */ + +package org.sflphone.history; + +import android.content.Context; +import com.j256.ormlite.android.apptools.OpenHelperManager; +import com.j256.ormlite.dao.Dao; + +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; +import java.util.Locale; + +public class HistoryManager { + + private Context mContext; + private DatabaseHelper historyDBHelper = null; + + public HistoryManager(Context context) { + getHelper(); + mContext = context; + } + + /** + * Retrieve helper for our DB + */ + private DatabaseHelper getHelper() { + if (historyDBHelper == null) { + historyDBHelper = OpenHelperManager.getHelper(mContext, DatabaseHelper.class); + } + return historyDBHelper; + } + + public List<HistoryCall> getAll() throws SQLException { + return getHelper().getHistoryDao().queryForAll(); + } +} diff --git a/src/org/sflphone/history/HistoryTimeModel.java b/src/org/sflphone/history/HistoryTimeModel.java new file mode 100644 index 0000000000000000000000000000000000000000..4839059ff5b3df13af34f79e7fd0734afa1861b3 --- /dev/null +++ b/src/org/sflphone/history/HistoryTimeModel.java @@ -0,0 +1,7 @@ +package org.sflphone.history; + +/** + * Created by lisional on 14/01/14. + */ +public class HistoryTimeModel { +} diff --git a/src/org/sflphone/loaders/HistoryLoader.java b/src/org/sflphone/loaders/HistoryLoader.java index 0bdb7ba3e7fa0d6faad9e9d2779a3f5171f20f4f..a8acab9c0a858e4fbb7cc2896882093a6df5c232 100644 --- a/src/org/sflphone/loaders/HistoryLoader.java +++ b/src/org/sflphone/loaders/HistoryLoader.java @@ -31,36 +31,29 @@ package org.sflphone.loaders; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - +import android.content.AsyncTaskLoader; +import android.content.Context; +import android.database.Cursor; +import android.provider.ContactsContract; +import org.sflphone.history.HistoryCall; +import org.sflphone.history.HistoryEntry; +import org.sflphone.history.HistoryManager; import org.sflphone.model.CallContact; -import org.sflphone.model.CallContact.ContactBuilder; -import org.sflphone.model.HistoryEntry; -import org.sflphone.model.HistoryEntry.HistoryCall; -import org.sflphone.service.ISipService; -import org.sflphone.service.ServiceConstants; -import android.content.Context; -import android.os.RemoteException; -import android.provider.ContactsContract.Contacts; -import android.support.v4.content.AsyncTaskLoader; -import android.util.Log; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; public class HistoryLoader extends AsyncTaskLoader<ArrayList<HistoryEntry>> { private static final String TAG = HistoryLoader.class.getSimpleName(); - private ISipService service; - HashMap<String, HistoryEntry> historyEntries; - static final String[] CONTACTS_SUMMARY_PROJECTION = new String[] { Contacts._ID, Contacts.DISPLAY_NAME, Contacts.PHOTO_ID, Contacts.LOOKUP_KEY, - Contacts.STARRED }; + ArrayList<HistoryEntry> historyEntries; + private HistoryManager historyManager = null; - public HistoryLoader(Context context, ISipService isip) { + public HistoryLoader(Context context) { super(context); - service = isip; + historyManager = new HistoryManager(context); } @SuppressWarnings("unchecked") @@ -68,11 +61,41 @@ public class HistoryLoader extends AsyncTaskLoader<ArrayList<HistoryEntry>> { @Override public ArrayList<HistoryEntry> loadInBackground() { - historyEntries = new HashMap<String, HistoryEntry>(); + historyEntries = new ArrayList<HistoryEntry>(); - if (service == null) { - return new ArrayList<HistoryEntry>(); + try { + List<HistoryCall> list = historyManager.getAll(); + + HistoryEntry tmp; + CallContact.ContactBuilder builder = CallContact.ContactBuilder.getInstance(); + for (HistoryCall call : list) { + CallContact contact; + if (call.getContactID() == 0) { + contact = CallContact.ContactBuilder.buildUnknownContact(call.getNumber()); + } else { + Cursor result = getContext().getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, + ContactsContract.Contacts._ID + " = ?", + new String[]{String.valueOf(call.getContactID())}, null); + int iID = result.getColumnIndex(ContactsContract.Contacts._ID); + int iName = result.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); + int iPhoto = result.getColumnIndex(ContactsContract.Contacts.PHOTO_ID); + int iStarred = result.getColumnIndex(ContactsContract.Contacts.STARRED); + + if (result.moveToFirst()) { + builder.startNewContact(result.getLong(iID), result.getString(iName), result.getLong(iPhoto)); + contact = builder.build(); + } else { + contact = CallContact.ContactBuilder.buildUnknownContact(call.getNumber()); + } + } + tmp = new HistoryEntry(call.getAccountID(), contact); + historyEntries.add(tmp); + } + } catch (SQLException e) { + e.printStackTrace(); } + +/* try { ArrayList<HashMap<String, String>> history = (ArrayList<HashMap<String, String>>) service.getHistory(); @@ -117,7 +140,9 @@ public class HistoryLoader extends AsyncTaskLoader<ArrayList<HistoryEntry>> { } catch (RemoteException e) { Log.i(TAG, e.toString()); - } - return new ArrayList<HistoryEntry>(historyEntries.values()); + }*/ + return historyEntries; } + + } diff --git a/src/org/sflphone/receivers/IncomingReceiver.java b/src/org/sflphone/receivers/IncomingReceiver.java deleted file mode 100644 index 9bf0fd09b3d0d7e575f996ef8bfa8cfcad05d58b..0000000000000000000000000000000000000000 --- a/src/org/sflphone/receivers/IncomingReceiver.java +++ /dev/null @@ -1,343 +0,0 @@ -/* - * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. - * - * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ -package org.sflphone.receivers; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map.Entry; - -import org.sflphone.client.CallActivity; -import org.sflphone.model.Account; -import org.sflphone.model.CallContact; -import org.sflphone.model.Conference; -import org.sflphone.model.SipCall; -import org.sflphone.model.SipMessage; -import org.sflphone.service.CallManagerCallBack; -import org.sflphone.service.ConfigurationManagerCallback; -import org.sflphone.service.ISipService.Stub; -import org.sflphone.service.ServiceConstants; -import org.sflphone.service.SipService; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.os.RemoteException; -import android.util.Log; - -public class IncomingReceiver extends BroadcastReceiver { - - static final String TAG = IncomingReceiver.class.getSimpleName(); - - SipService callback; - Stub mBinder; - - public IncomingReceiver(SipService client, Stub bind) { - callback = client; - mBinder = bind; - } - - @SuppressWarnings("unchecked") - // Hashmap runtime cast - @Override - public void onReceive(Context context, Intent intent) { - - if (intent.getAction().contentEquals(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED)) { - - Log.i(TAG, "Received" + intent.getAction()); - callback.sendBroadcast(intent); - - } else if (intent.getAction().contentEquals(ConfigurationManagerCallback.ACCOUNTS_CHANGED)) { - - Log.i(TAG, "Received" + intent.getAction()); - callback.sendBroadcast(intent); - - } else if (intent.getAction().contentEquals(CallManagerCallBack.INCOMING_TEXT)) { - - Bundle extra = intent.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext"); - Log.i(TAG, "Received" + intent.getAction()); - if (callback.getCurrent_calls().get(extra.getString("CallID")) != null) { - callback.getCurrent_calls().get(extra.get("CallID")).addSipMessage(new SipMessage(true, extra.getString("Msg"))); - } else if (callback.getCurrent_confs().get(extra.getString("CallID")) != null) { - callback.getCurrent_confs().get(extra.get("CallID")).addSipMessage(new SipMessage(true, extra.getString("Msg"))); - } else - return; - - callback.sendBroadcast(intent); - - } else if (intent.getAction().contentEquals(CallManagerCallBack.INCOMING_CALL)) { - Bundle b = intent.getBundleExtra("com.savoirfairelinux.sflphone.service.newcall"); - - SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance(); - - Account acc; - try { - HashMap<String, String> details = (HashMap<String, String>) mBinder.getAccountDetails(b.getString("AccountID")); - ArrayList<HashMap<String, String>> credentials = (ArrayList<HashMap<String, String>>) mBinder - .getCredentials(b.getString("AccountID")); - acc = new Account(b.getString("AccountID"), details, credentials); - callBuilder.startCallCreation(b.getString("CallID")).setAccount(acc).setCallState(SipCall.state.CALL_STATE_RINGING) - .setCallType(SipCall.state.CALL_TYPE_INCOMING); - callBuilder.setContact(CallContact.ContactBuilder.buildUnknownContact(b.getString("From"))); - - Intent toSend = new Intent(CallManagerCallBack.INCOMING_CALL); - toSend.setClass(callback, CallActivity.class); - toSend.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - - SipCall newCall = callBuilder.build(); - toSend.putExtra("newcall", newCall); - HashMap<String, String> callDetails = (HashMap<String, String>) mBinder.getCallDetails(b.getString("CallID")); - - newCall.setTimestamp_start(Long.parseLong(callDetails.get(ServiceConstants.call.TIMESTAMP_START))); - callback.getCurrent_calls().put(newCall.getCallId(), newCall); - // callback.sendBroadcast(toSend); - Bundle bundle = new Bundle(); - Conference tmp = new Conference("-1"); - - tmp.getParticipants().add(newCall); - - bundle.putParcelable("conference", tmp); - toSend.putExtra("resuming", false); - toSend.putExtras(bundle); - callback.startActivity(toSend); - callback.mediaManager.startRing(""); - callback.mediaManager.obtainAudioFocus(true); - } catch (RemoteException e1) { - e1.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - - } else if (intent.getAction().contentEquals(CallManagerCallBack.CALL_STATE_CHANGED)) { - - Log.i(TAG, "Received " + intent.getAction()); - Bundle b = intent.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); - String newState = b.getString("State"); - - try { - if (callback.getCurrent_calls().get(b.getString("CallID")) != null && mBinder.isConferenceParticipant(b.getString("CallID"))) { - callback.getCurrent_calls().remove(b.getString("CallID")); - } - } catch (RemoteException e1) { - e1.printStackTrace(); - } - - if (newState.equals("INCOMING")) { - callback.getCurrent_calls().get(b.getString("CallID")).setCallState(SipCall.state.CALL_STATE_INCOMING); - } else if (newState.equals("RINGING")) { - try { - callback.getCurrent_calls().get(b.getString("CallID")).setCallState(SipCall.state.CALL_STATE_RINGING); - } catch (NullPointerException e) { - if (callback.getCurrent_calls() == null) { - return; - } - if (callback.getCurrent_calls().get(b.getString("CallID")) == null) { - Log.e(TAG, "get(b.getString(callID)) null"); - return; - } - } - - } else if (newState.equals("CURRENT")) { - if (callback.getCurrent_calls().get(b.getString("CallID")) != null) { - callback.getCurrent_calls().get(b.getString("CallID")).setCallState(SipCall.state.CALL_STATE_CURRENT); - } else { - // Check if call is in a conference - Iterator<Entry<String, Conference>> it = callback.getCurrent_confs().entrySet().iterator(); - while (it.hasNext()) { - Conference tmp = it.next().getValue(); - for (SipCall c : tmp.getParticipants()) { - if (c.getCallId().contentEquals(b.getString("CallID"))) - c.setCallState(SipCall.state.CALL_STATE_CURRENT); - } - } - } - - } else if (newState.equals("HUNGUP")) { - - if (callback.getCurrent_calls().get(b.getString("CallID")) != null) { - - if (callback.getCurrent_calls().get(b.getString("CallID")).isRinging() - && callback.getCurrent_calls().get(b.getString("CallID")).isIncoming()) - callback.notificationManager.publishMissedCallNotification(callback.getCurrent_calls().get(b.getString("CallID"))); - callback.getCurrent_calls().remove(b.getString("CallID")); - } else { - ArrayList<Conference> it = new ArrayList<Conference>(callback.getCurrent_confs().values()); - - boolean found = false; - int i = 0; - while (!found && i < it.size()) { - Conference tmp = it.get(i); - - for (int j = 0; j < tmp.getParticipants().size(); ++j) { - if (tmp.getParticipants().get(j).getCallId().contentEquals(b.getString("CallID"))) { - callback.getCurrent_confs().get(tmp.getId()).getParticipants().remove(tmp.getParticipants().get(j)); - found = true; - } - - } - ++i; - - } - } - - callback.sendBroadcast(intent); - - } else if (newState.equals("BUSY")) { - callback.getCurrent_calls().remove(b.getString("CallID")); - } else if (newState.equals("FAILURE")) { - callback.getCurrent_calls().remove(b.getString("CallID")); - } else if (newState.equals("HOLD")) { - if (callback.getCurrent_calls().get(b.getString("CallID")) != null) { - callback.getCurrent_calls().get(b.getString("CallID")).setCallState(SipCall.state.CALL_STATE_HOLD); - } else { - // Check if call is in a conference - Iterator<Entry<String, Conference>> it = callback.getCurrent_confs().entrySet().iterator(); - while (it.hasNext()) { - Conference tmp = it.next().getValue(); - for (SipCall c : tmp.getParticipants()) { - if (c.getCallId().contentEquals(b.getString("CallID"))) - c.setCallState(SipCall.state.CALL_STATE_HOLD); - } - } - } - } else if (newState.equals("UNHOLD")) { - - if (callback.getCurrent_calls().get(b.getString("CallID")) != null) { - callback.getCurrent_calls().get(b.getString("CallID")).setCallState(SipCall.state.CALL_STATE_CURRENT); - } else { - // Check if call is in a conference - Iterator<Entry<String, Conference>> it = callback.getCurrent_confs().entrySet().iterator(); - while (it.hasNext()) { - Conference tmp = it.next().getValue(); - for (SipCall c : tmp.getParticipants()) { - if (c.getCallId().contentEquals(b.getString("CallID"))) - c.setCallState(SipCall.state.CALL_STATE_CURRENT); - } - } - } - } else { - callback.getCurrent_calls().get(b.getString("CallID")).setCallState(SipCall.state.CALL_STATE_NONE); - } - - callback.sendBroadcast(intent); - - } else if (intent.getAction().contentEquals(CallManagerCallBack.NEW_CALL_CREATED)) { - - Log.i(TAG, "Received" + intent.getAction()); - - } else if (intent.getAction().contentEquals(CallManagerCallBack.CONF_CREATED)) { - - Log.i(TAG, "Received" + intent.getAction()); - Conference created = new Conference(intent.getStringExtra("confID")); - - try { - ArrayList<String> all_participants = (ArrayList<String>) mBinder.getParticipantList(intent.getStringExtra("confID")); - for (String participant : all_participants) { - created.getParticipants().add(callback.getCurrent_calls().get(participant)); - callback.getCurrent_calls().remove(participant); - } - Intent toSend = new Intent(CallManagerCallBack.CONF_CREATED); - toSend.putExtra("newconf", created); - callback.getCurrent_confs().put(intent.getStringExtra("confID"), created); - callback.sendBroadcast(toSend); - } catch (RemoteException e1) { - e1.printStackTrace(); - } - Log.i(TAG, "current_confs size " + callback.getCurrent_confs().size()); - - } else if (intent.getAction().contentEquals(CallManagerCallBack.CONF_REMOVED)) { - - Log.i(TAG, "Received" + intent.getAction()); - Conference toDestroy = callback.getCurrent_confs().get(intent.getStringExtra("confID")); - for (int i = 0; i < toDestroy.getParticipants().size(); ++i) { - callback.getCurrent_calls().put(toDestroy.getParticipants().get(i).getCallId(), toDestroy.getParticipants().get(i)); - } - callback.getCurrent_confs().remove(intent.getStringExtra("confID")); - callback.sendBroadcast(intent); - - } else if (intent.getAction().contentEquals(CallManagerCallBack.CONF_CHANGED)) { - - ArrayList<String> all_participants; - try { - all_participants = (ArrayList<String>) mBinder.getParticipantList(intent.getStringExtra("confID")); - for (String participant : all_participants) { - if (callback.getCurrent_confs().get(intent.getStringExtra("confID")).getParticipants().size() < all_participants.size() - && callback.getCurrent_calls().get(participant) != null) { // We need to add the new participant to the conf - callback.getCurrent_confs().get(intent.getStringExtra("confID")).getParticipants() - .add(callback.getCurrent_calls().get(participant)); - callback.getCurrent_calls().remove(participant); - callback.getCurrent_confs().get(intent.getStringExtra("confID")).setState(intent.getStringExtra("State")); - callback.sendBroadcast(intent); - return; - } - } - } catch (RemoteException e) { - e.printStackTrace(); - } - - Log.i(TAG, "Received" + intent.getAction()); - if (callback.getCurrent_confs().get(intent.getStringExtra("confID")) != null) { - - callback.getCurrent_confs().get(intent.getStringExtra("confID")).setState(intent.getStringExtra("State")); - callback.sendBroadcast(intent); - } - - } else if (intent.getAction().contentEquals(CallManagerCallBack.RECORD_STATE_CHANGED)) { - - Log.i(TAG, "Received" + intent.getAction()); - - // try { - // if (callback.getCurrent_confs().get(intent.getStringExtra("id")) != null) { - // callback.getCurrent_confs().get(intent.getStringExtra("id")).setRecording(mBinder.isRecording(intent.getStringExtra("id"))); - // } else if (callback.getCurrent_calls().get(intent.getStringExtra("id")) != null) { - // callback.getCurrent_calls().get(intent.getStringExtra("id")).setRecording(mBinder.isRecording(intent.getStringExtra("id"))); - // } else { - // // A call in a conference has been put on hold - // Iterator<Conference> it = callback.getCurrent_confs().values().iterator(); - // while (it.hasNext()) { - // Conference c = it.next(); - // if (c.getCall(intent.getStringExtra("id")) != null) - // c.getCall(intent.getStringExtra("id")).setRecording(mBinder.isRecording(intent.getStringExtra("id"))); - // } - // } - // // Re sending the same intent to the app - // callback.sendBroadcast(intent); - // ; - // } catch (RemoteException e) { - // // TODO Auto-generated catch block - // e.printStackTrace(); - // } - - } - - } -} diff --git a/src/org/sflphone/service/ISipService.aidl b/src/org/sflphone/service/ISipService.aidl index 9d8a3268f88194c544ccb255640cede54a4a3ad5..c4c5e186ffaed67c404afca33b9442de7a15104b 100644 --- a/src/org/sflphone/service/ISipService.aidl +++ b/src/org/sflphone/service/ISipService.aidl @@ -34,16 +34,11 @@ interface ISipService { // FIXME void toggleSpeakerPhone(in boolean toggle); - - /* History */ - List getHistory(); - void clearHistory(); - + /* Notification */ void createNotification(); void destroyNotification(); - - + /* Recording */ void setRecordPath(in String path); String getRecordPath(); diff --git a/src/org/sflphone/service/SipService.java b/src/org/sflphone/service/SipService.java index 439a6ab733ef55e2c23f5d71cbfa238072f51459..5de1bc12e287ffc3c11ee599ff9e9105b58db553 100644 --- a/src/org/sflphone/service/SipService.java +++ b/src/org/sflphone/service/SipService.java @@ -604,43 +604,6 @@ public class SipService extends Service { }); } - @Override - public ArrayList<HashMap<String, String>> getHistory() throws RemoteException { - class History extends SipRunnableWithReturn { - - @Override - protected VectMap doRun() throws SameThreadException { - Log.i(TAG, "SipService.getHistory() thread running..."); - - return configurationManagerJNI.getHistory(); - } - } - - History runInstance = new History(); - getExecutor().execute(runInstance); - while (!runInstance.isDone()) { - // Log.w(TAG, "Waiting for getHistory"); - } - Log.i(TAG, "SipService.getHistory() DONE"); - VectMap swigmap = (VectMap) runInstance.getVal(); - - ArrayList<HashMap<String, String>> nativemap = SwigNativeConverter.convertHistoryToNative(swigmap); - - return nativemap; - } - - @Override - public void clearHistory() throws RemoteException { - getExecutor().execute(new SipRunnable() { - @Override - protected void doRun() throws SameThreadException { - Log.i(TAG, "SipService.clearHistory() thread running..."); - configurationManagerJNI.clearHistory(); - } - }); - - } - /************************* * Transfer related API *************************/ diff --git a/src/org/sflphone/utils/HistoryManager.java b/src/org/sflphone/utils/HistoryManager.java deleted file mode 100644 index d3fc1865bbcd945641ad9641fc45cba6e50a753f..0000000000000000000000000000000000000000 --- a/src/org/sflphone/utils/HistoryManager.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. - * - * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -package org.sflphone.utils; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Locale; - -public class HistoryManager { - - static ArrayList<String> timeCategories; - - public interface HistoryTimeCategoryModel { - String TODAY = "Today"; // 0 - String YESTERDAY = "Yesterday"; // 1 - String TWO_DAYS = HistoryManager.getDate(2, "MM/dd");// 2 - String THREE_DAYS = HistoryManager.getDate(3, "MM/dd");// 3 - String FOUR_DAYS = HistoryManager.getDate(4, "MM/dd");// 4 - String FIVE_DAYS = HistoryManager.getDate(5, "MM/dd");// 5 - String SIX_DAYS = HistoryManager.getDate(6, "MM/dd");// 6 - String LAST_WEEK = "Last week"; // 7 - String TWO_WEEKS = "Two weeks ago"; // 8 - String THREE_WEEKS = "Three weeks ago"; // 9 - String LAST_MONTH = "Last month"; // 10 - String TWO_MONTH = "Two months ago"; // 11 - String THREE_MONTH = "Three months ago"; // 12 - String FOUR_MONTH = "Four months ago"; // 13 - String FIVE_MONTH = "Five months ago"; // 14 - String SIX_MONTH = "Six months ago"; // 15 - String SEVEN_MONTH = "Seven months ago"; // 16 - String EIGHT_MONTH = "Eight months ago"; // 17 - String NINE_MONTH = "Nine months ago"; // 18 - String TEN_MONTH = "Ten months ago"; // 19 - String ELEVEN_MONTH = "Eleven months ago"; // 20 - String TWELVE_MONTH = "Twelve months ago"; // 21 - String LAST_YEAR = "Last year"; // 22 - String LONG_TIME_AGO = "Very long time ago"; // 23 - String NEVER = "Never"; // 24 - } - - private static final String TAG = HistoryManager.class.getSimpleName(); - - static Calendar removeDays(int ago) { - Calendar cal = Calendar.getInstance(Locale.getDefault()); - int currentDay = cal.get(Calendar.DAY_OF_MONTH); - // Set the date to 2 days ago - cal.set(Calendar.DAY_OF_MONTH, currentDay - ago); - return cal; - } - - static String getDate(int ago, String format) { - Calendar cal = removeDays(ago); - SimpleDateFormat objFormatter = new SimpleDateFormat(format, Locale.CANADA); - objFormatter.setTimeZone(cal.getTimeZone()); - - String result = objFormatter.format(cal.getTime()); - cal.clear(); - return result; - } - - public static String timeToHistoryConst(long time) { - - if(timeCategories == null){ - initializeCategories(); - } - - long time2 = time; - long currentTime = Calendar.getInstance(Locale.getDefault()).getTime().getTime() / 1000; // in seconds - - if (time < 0) - return HistoryTimeCategoryModel.NEVER; - - // Check if part if the current Nychthemeron - if (currentTime - time <= 3600 * 24) // The future case would be a bug, but it have to be handled anyway or it will appear in - // "very long time ago" - return HistoryTimeCategoryModel.TODAY; - - time2 -= time % (3600 * 24); // Reset to midnight - currentTime -= currentTime % (3600 * 24); // Reset to midnight - // Check for last week - if (currentTime - (6) * 3600 * 24 < time2) { - for (int i = 1; i < 7; i++) { - if (currentTime - ((i) * 3600 * 24) == time2) - return timeCategories.get(i); // Yesterday to Six_days_ago - } - } - // Check for last month - else if (currentTime - ((4) * 7 * 24 * 3600) < time2) { - for (int i = 1; i < 4; i++) { - if (currentTime - ((i + 1) * 7 * 24 * 3600) < time2) - return timeCategories.get(i + timeCategories.indexOf(HistoryTimeCategoryModel.LAST_WEEK) - 1); // Last_week to Three_weeks_ago - } - } - // Check for last year - else if (currentTime - (12) * 30.4f * 24 * 3600 < time2) { - for (int i = 1; i < 12; i++) { - if (currentTime - (i + 1) * 30.4f * 24 * 3600 < time2) // Not exact, but faster - return timeCategories.get(i + timeCategories.indexOf(HistoryTimeCategoryModel.LAST_MONTH) - 1); - ; // Last_month to Twelve_months ago - } - } - // if (QDate::currentDate().addYears(-1) >= date && QDate::currentDate().addYears(-2) < date) - else if (currentTime - 365 * 24 * 3600 < time2) - return HistoryTimeCategoryModel.LAST_YEAR; - - // Every other senario - return HistoryTimeCategoryModel.LONG_TIME_AGO; - } - - private static void initializeCategories() { - timeCategories = new ArrayList<String>(); - timeCategories.add(HistoryTimeCategoryModel.TODAY); - timeCategories.add(HistoryTimeCategoryModel.YESTERDAY); - timeCategories.add(HistoryTimeCategoryModel.TWO_DAYS); - timeCategories.add(HistoryTimeCategoryModel.THREE_DAYS); - timeCategories.add(HistoryTimeCategoryModel.FOUR_DAYS); - timeCategories.add(HistoryTimeCategoryModel.FIVE_DAYS); - timeCategories.add(HistoryTimeCategoryModel.SIX_DAYS); - timeCategories.add(HistoryTimeCategoryModel.LAST_WEEK); - timeCategories.add(HistoryTimeCategoryModel.TWO_WEEKS); - timeCategories.add(HistoryTimeCategoryModel.THREE_WEEKS); - timeCategories.add(HistoryTimeCategoryModel.LAST_MONTH); - timeCategories.add(HistoryTimeCategoryModel.TWO_MONTH); - timeCategories.add(HistoryTimeCategoryModel.THREE_MONTH); - timeCategories.add(HistoryTimeCategoryModel.FOUR_MONTH); - timeCategories.add(HistoryTimeCategoryModel.FIVE_MONTH); - timeCategories.add(HistoryTimeCategoryModel.SIX_MONTH); - timeCategories.add(HistoryTimeCategoryModel.SEVEN_MONTH); - timeCategories.add(HistoryTimeCategoryModel.EIGHT_MONTH); - timeCategories.add(HistoryTimeCategoryModel.NINE_MONTH); - timeCategories.add(HistoryTimeCategoryModel.TEN_MONTH); - timeCategories.add(HistoryTimeCategoryModel.ELEVEN_MONTH); - timeCategories.add(HistoryTimeCategoryModel.TWELVE_MONTH); - timeCategories.add(HistoryTimeCategoryModel.LAST_YEAR); - timeCategories.add(HistoryTimeCategoryModel.LONG_TIME_AGO); - timeCategories.add(HistoryTimeCategoryModel.NEVER); - } - -} diff --git a/src/org/sflphone/utils/SwigNativeConverter.java b/src/org/sflphone/utils/SwigNativeConverter.java index 634c049bf6ec62741a7627101547ff93b850dbd9..aa6fce535e7d68916e329aac90f84e4c87919528 100644 --- a/src/org/sflphone/utils/SwigNativeConverter.java +++ b/src/org/sflphone/utils/SwigNativeConverter.java @@ -80,36 +80,6 @@ public class SwigNativeConverter { return toReturn; } - /** - * Swig to Native - */ - public static ArrayList<HashMap<String, String>> convertHistoryToNative(VectMap swigmap) { - ArrayList<HashMap<String, String>> nativemap = new ArrayList<HashMap<String, String>>(); - - for (int i = 0; i < swigmap.size(); ++i) { - HashMap<String, String> entry = new HashMap<String, String>(); - - entry.put(ServiceConstants.history.ACCOUNT_ID_KEY, tryToGet(swigmap.get(i), ServiceConstants.history.ACCOUNT_ID_KEY)); - entry.put(ServiceConstants.history.CALLID_KEY, tryToGet(swigmap.get(i), ServiceConstants.history.CALLID_KEY)); - entry.put(ServiceConstants.history.CONFID_KEY, tryToGet(swigmap.get(i), ServiceConstants.history.CONFID_KEY)); - entry.put(ServiceConstants.history.DISPLAY_NAME_KEY, tryToGet(swigmap.get(i), ServiceConstants.history.DISPLAY_NAME_KEY)); - entry.put(ServiceConstants.history.PEER_NUMBER_KEY, tryToGet(swigmap.get(i), ServiceConstants.history.PEER_NUMBER_KEY)); - entry.put(ServiceConstants.history.RECORDING_PATH_KEY, tryToGet(swigmap.get(i), ServiceConstants.history.RECORDING_PATH_KEY)); - entry.put(ServiceConstants.history.DIRECTION_KEY, tryToGet(swigmap.get(i), ServiceConstants.history.DIRECTION_KEY)); - entry.put(ServiceConstants.history.MISSED_KEY, tryToGet(swigmap.get(i), ServiceConstants.history.MISSED_KEY)); - entry.put(ServiceConstants.history.TIMESTAMP_START_KEY, tryToGet(swigmap.get(i), ServiceConstants.history.TIMESTAMP_START_KEY)); - entry.put(ServiceConstants.history.TIMESTAMP_STOP_KEY, tryToGet(swigmap.get(i), ServiceConstants.history.TIMESTAMP_STOP_KEY)); - entry.put(ServiceConstants.history.AUDIO_CODEC_KEY, tryToGet(swigmap.get(i), ServiceConstants.history.AUDIO_CODEC_KEY)); - - if(entry.get(ServiceConstants.history.DIRECTION_KEY).isEmpty()) - continue; - - nativemap.add(entry); - } - - return nativemap; - } - private static String tryToGet(StringMap smap, String key) { if (smap.has_key(key)) { return smap.get(key);