diff --git a/AndroidManifest.xml b/AndroidManifest.xml index c241a7282..6d4730203 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -3,15 +3,19 @@ package="org.linphone" android:versionCode="1" android:versionName="1.0"> - + - - + + + + + + diff --git a/res/drawable/green.png b/res/drawable/green.png new file mode 100644 index 000000000..0005537ca Binary files /dev/null and b/res/drawable/green.png differ diff --git a/res/drawable/linphone.png b/res/drawable/linphone.png new file mode 100644 index 000000000..06cf18315 Binary files /dev/null and b/res/drawable/linphone.png differ diff --git a/res/drawable/linphone2.png b/res/drawable/linphone2.png new file mode 100644 index 000000000..d1bf1ab63 Binary files /dev/null and b/res/drawable/linphone2.png differ diff --git a/res/drawable/red.png b/res/drawable/red.png new file mode 100644 index 000000000..e6136b3ff Binary files /dev/null and b/res/drawable/red.png differ diff --git a/res/layout/main.xml b/res/layout/main.xml index 6c4a48182..08dfa960c 100644 --- a/res/layout/main.xml +++ b/res/layout/main.xml @@ -5,20 +5,34 @@ android:layout_height="fill_parent" > - + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + diff --git a/res/menu/linphone_activity_menu.xml b/res/menu/linphone_activity_menu.xml new file mode 100644 index 000000000..eba6385cd --- /dev/null +++ b/res/menu/linphone_activity_menu.xml @@ -0,0 +1,5 @@ + + + + diff --git a/res/values/non_localizable_strings.xml b/res/values/non_localizable_strings.xml new file mode 100644 index 000000000..04591bc94 --- /dev/null +++ b/res/values/non_localizable_strings.xml @@ -0,0 +1,7 @@ + + + pref_proxy_key + pref_domain_key + pref_passwd_key + pref_username_key + diff --git a/res/values/strings.xml b/res/values/strings.xml index 1b02d5367..250dc8b7e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1,5 +1,14 @@ + Settings + Proxy + Domain* + Password* + Username* Hello World, Linphone! Linphone + SIP Account + Enter a user name +Enter a password +Enter a domain diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml new file mode 100644 index 000000000..2912fbaa9 --- /dev/null +++ b/res/xml/preferences.xml @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/src/org/linphone/Linphone.java b/src/org/linphone/Linphone.java index 22281a218..2d306b7bf 100644 --- a/src/org/linphone/Linphone.java +++ b/src/org/linphone/Linphone.java @@ -1,83 +1,118 @@ +/* +Linphone.java +Copyright (C) 2010 Belledonne Communications, Grenoble, France + +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 2 +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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ package org.linphone; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.net.URI; import java.util.Timer; import java.util.TimerTask; import org.linphone.core.LinphoneAuthInfo; import org.linphone.core.LinphoneCore; +import org.linphone.core.LinphoneCoreException; import org.linphone.core.LinphoneCoreFactory; import org.linphone.core.LinphoneCoreListener; import org.linphone.core.LinphoneProxyConfig; -import org.linphone.core.LinphoneCore.GeneralState; import android.app.Activity; +import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; +import android.preference.PreferenceManager; import android.util.Log; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.widget.Toast; public class Linphone extends Activity implements LinphoneCoreListener { - static final String TAG="Linphone"; - /** Called when the activity is first created. */ + static final public String TAG="Linphone"; + /** Called when the activity is first created. */ private static String LINPHONE_FACTORY_RC = "/data/data/org.linphone/files/linphonerc"; private static String LINPHONE_RC = "/data/data/org.linphone/files/.linphonerc"; private static String RING_SND = "/data/data/org.linphone/files/oldphone_mono.wav"; private static String RINGBACK_SND = "/data/data/org.linphone/files/ringback.wav"; + private static Linphone theLinphone; private LinphoneCore mLinphoneCore; - private LinphoneProxyConfig mProxyConfig; - private LinphoneAuthInfo mAuthInfo; + private SharedPreferences mPref; Timer mTimer = new Timer("Linphone scheduler"); - + + static Linphone getLinphone() { + if (theLinphone == null) { + throw new RuntimeException("LinphoneActivity not instanciated yet"); + } else { + return theLinphone; + } + } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.main); - try { + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + theLinphone = this; + mPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + try { copyAssetsFromPackage(); - - mLinphoneCore = LinphoneCoreFactory.instance().createLinphoneCore( this - , new File(LINPHONE_RC) - , new File(LINPHONE_FACTORY_RC) - , null); - mAuthInfo = LinphoneCoreFactory.instance().createAuthInfo("jehan", "223299"); - mLinphoneCore.addAuthInfo(mAuthInfo); - mProxyConfig = mLinphoneCore.createProxyConfig("sip:jehan@sip.antisip.com", "sip:sip.antisip.com",null); - mProxyConfig.enableRegister(true); - mLinphoneCore.addtProxyConfig(mProxyConfig); - mLinphoneCore.setDefaultProxyConfig(mProxyConfig); - - TimerTask lTask = new TimerTask() { + mLinphoneCore = LinphoneCoreFactory.instance().createLinphoneCore( this + , new File(LINPHONE_RC) + , new File(LINPHONE_FACTORY_RC) + , null); - @Override - public void run() { - mLinphoneCore.iterate(); - - } + initFromConf(); - }; - mTimer.scheduleAtFixedRate(lTask, 0, 100); - - - + TimerTask lTask = new TimerTask() { + + @Override + public void run() { + mLinphoneCore.iterate(); + + } + + }; + mTimer.scheduleAtFixedRate(lTask, 0, 100); + } catch (Exception e) { Log.e(TAG,"Cannot start linphone",e); } - - } - public void copyAssetsFromPackage() throws IOException { - copyIfNotExist(R.raw.oldphone_mono,RING_SND); - copyIfNotExist(R.raw.ringback,RINGBACK_SND); - copyIfNotExist(R.raw.linphonerc,LINPHONE_FACTORY_RC); - } - private void copyIfNotExist(int ressourceId,String target) throws IOException { - File lFileToCopy = new File(target); + + } + + + @Override + protected void onStop() { + // TODO Auto-generated method stub + super.onStop(); + //finish(); + } + + + private void copyAssetsFromPackage() throws IOException { + copyIfNotExist(R.raw.oldphone_mono,RING_SND); + copyIfNotExist(R.raw.ringback,RINGBACK_SND); + copyIfNotExist(R.raw.linphonerc,LINPHONE_FACTORY_RC); + } + private void copyIfNotExist(int ressourceId,String target) throws IOException { + File lFileToCopy = new File(target); if (!lFileToCopy.exists()) { FileOutputStream lOutputStream = openFileOutput (lFileToCopy.getName(), 0); InputStream lInputStream = getResources().openRawResource(ressourceId); @@ -90,44 +125,129 @@ public class Linphone extends Activity implements LinphoneCoreListener { lOutputStream.close(); lInputStream.close(); } - - } + + } public void authInfoRequested(LinphoneCore lc, String realm, String username) { // TODO Auto-generated method stub - + } public void byeReceived(LinphoneCore lc, String from) { // TODO Auto-generated method stub - + } public void displayMessage(LinphoneCore lc, String message) { // TODO Auto-generated method stub - + } public void displayStatus(LinphoneCore lc, String message) { Log.i(TAG, message); - + } public void displayWarning(LinphoneCore lc, String message) { // TODO Auto-generated method stub - + } public void generalState(LinphoneCore lc, LinphoneCore.GeneralState state) { Log.i(TAG, "new state ["+state+"]"); switch(state) { case GSTATE_REG_OK: { - mLinphoneCore.invite("simon.morlat"); + //mLinphoneCore.invite("simon.morlat"); } } } public void inviteReceived(LinphoneCore lc, String from) { // TODO Auto-generated method stub - + } public void show(LinphoneCore lc) { // TODO Auto-generated method stub + + } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the currently selected menu XML resource. + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.linphone_activity_menu, menu); + + + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_settings: + startprefActivity(); + return true; + default: + Log.e(TAG, "Unknown menu item ["+item+"]"); + break; + } + + return false; + } + + public void initFromConf() throws LinphoneCoreException { + //1 read proxy config from preferences + String lUserName = mPref.getString(getString(R.string.pref_username_key), null); + if (lUserName == null) { + Toast toast = Toast.makeText(this, this.getString(R.string.enter_username), Toast.LENGTH_LONG); + toast.show(); + startprefActivity(); + return; + } + + String lPasswd = mPref.getString(getString(R.string.pref_passwd_key), null); + if (lPasswd == null) { + Toast toast = Toast.makeText(this, this.getString(R.string.enter_passwd), Toast.LENGTH_LONG); + toast.show(); + startprefActivity(); + return; + } + + String lDomain = mPref.getString(getString(R.string.pref_domain_key), null); + if (lDomain == null) { + Toast toast = Toast.makeText(this, this.getString(R.string.enter_domain), Toast.LENGTH_LONG); + toast.show(); + startprefActivity(); + return; + } + + + //auth + mLinphoneCore.clearAuthInfos(); + LinphoneAuthInfo lAuthInfo = LinphoneCoreFactory.instance().createAuthInfo(lUserName, lPasswd); + mLinphoneCore.addAuthInfo(lAuthInfo); + + + //proxy + String lProxy = mPref.getString(getString(R.string.pref_proxy_key), "sip:"+lDomain); + + //get Default proxy if any + LinphoneProxyConfig lDefaultProxyConfig = mLinphoneCore.getDefaultProxyConfig(); + String lIdentity = "sip:"+lUserName+"@"+lDomain; + if (lDefaultProxyConfig == null) { + lDefaultProxyConfig = mLinphoneCore.createProxyConfig(lIdentity, lProxy, null,true); + mLinphoneCore.addtProxyConfig(lDefaultProxyConfig); + mLinphoneCore.setDefaultProxyConfig(lDefaultProxyConfig); + + } else { + lDefaultProxyConfig.edit(); + lDefaultProxyConfig.setIdentity(lIdentity); + lDefaultProxyConfig.setProxy(lProxy); + lDefaultProxyConfig.enableRegister(true); + lDefaultProxyConfig.done(); + } + } + + private void startprefActivity() { + Intent intent = new Intent(Intent.ACTION_MAIN); + intent.setClass(Linphone.this, LinphonePreferencesActivity.class); + startActivity(intent); + } + } \ No newline at end of file diff --git a/src/org/linphone/LinphoneException.java b/src/org/linphone/LinphoneException.java new file mode 100644 index 000000000..e24708d5e --- /dev/null +++ b/src/org/linphone/LinphoneException.java @@ -0,0 +1,43 @@ +/* +LinphoneCoreException.java +Copyright (C) 2010 Belledonne Communications, Grenoble, France + +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 2 +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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +package org.linphone; + +@SuppressWarnings("serial") +public class LinphoneException extends Exception { + + public LinphoneException() { + // TODO Auto-generated constructor stub + } + + public LinphoneException(String detailMessage) { + super(detailMessage); + // TODO Auto-generated constructor stub + } + + public LinphoneException(Throwable throwable) { + super(throwable); + // TODO Auto-generated constructor stub + } + + public LinphoneException(String detailMessage, Throwable throwable) { + super(detailMessage, throwable); + // TODO Auto-generated constructor stub + } + +} diff --git a/src/org/linphone/LinphonePreferencesActivity.java b/src/org/linphone/LinphonePreferencesActivity.java new file mode 100644 index 000000000..31c70191b --- /dev/null +++ b/src/org/linphone/LinphonePreferencesActivity.java @@ -0,0 +1,45 @@ +/* +LinphonePreferencesActivity.java +Copyright (C) 2010 Belledonne Communications, Grenoble, France + +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 2 +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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +package org.linphone; +import org.linphone.core.LinphoneCoreException; + +import android.os.Bundle; +import android.preference.PreferenceActivity; +import android.util.Log; + +public class LinphonePreferencesActivity extends PreferenceActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // Load the preferences from an XML resource + addPreferencesFromResource(R.xml.preferences); + } + + @Override + protected void onStop() { + super.onStop(); + try { + Linphone.getLinphone().initFromConf(); + } catch (LinphoneCoreException e) { + Log.e(Linphone.TAG, "cannot update config",e); + } + } + +} diff --git a/src/org/linphone/core/LinphoneCore.java b/src/org/linphone/core/LinphoneCore.java index 8df865468..4e608452c 100644 --- a/src/org/linphone/core/LinphoneCore.java +++ b/src/org/linphone/core/LinphoneCore.java @@ -61,18 +61,28 @@ public interface LinphoneCore { * @param identity sip uri sip:jehan@linphone.org * @param proxy sip uri (sip:linphone.org) * @param route optionnal sip usi (sip:linphone.org) + * @param register should be initiated * @return */ - public LinphoneProxyConfig createProxyConfig(String identity,String proxy,String route) throws LinphoneCoreException; + public LinphoneProxyConfig createProxyConfig(String identity,String proxy,String route,boolean enableRegister) throws LinphoneCoreException; + /** + * clear all added proxy config + */ + public void clearProxyConfigs(); public void addtProxyConfig(LinphoneProxyConfig proxyCfg) throws LinphoneCoreException; public void setDefaultProxyConfig(LinphoneProxyConfig proxyCfg); /** - * @return null if no default proxyconfig + * @return null if no default proxy config */ - public LinphoneProxyConfig getDefaultProxyConfig(); + public LinphoneProxyConfig getDefaultProxyConfig() ; + + /** + * clear all the added auth info + */ + void clearAuthInfos(); void addAuthInfo(LinphoneAuthInfo info); diff --git a/src/org/linphone/core/LinphoneCoreImpl.java b/src/org/linphone/core/LinphoneCoreImpl.java index 444091ac8..2cc292911 100644 --- a/src/org/linphone/core/LinphoneCoreImpl.java +++ b/src/org/linphone/core/LinphoneCoreImpl.java @@ -28,8 +28,13 @@ class LinphoneCoreImpl implements LinphoneCore { private final long nativePtr; private native long newLinphoneCore(LinphoneCoreListener listener,String userConfig,String factoryConfig,Object userdata); private native void iterate(long nativePtr); + private native long getDefaultProxyConfig(long nativePtr); + private native void setDefaultProxyConfig(long nativePtr,long proxyCfgNativePtr); private native int addProxyConfig(long nativePtr,long proxyCfgNativePtr); + private native void clearAuthInfos(long nativePtr); + + private native void clearProxyConfigs(long nativePtr); private native void addAuthInfo(long nativePtr,long authInfoNativePtr); private native void invite(long nativePtr,String uri); LinphoneCoreImpl(LinphoneCoreListener listener, File userConfig,File factoryConfig,Object userdata) throws IOException { @@ -41,12 +46,17 @@ class LinphoneCoreImpl implements LinphoneCore { addAuthInfo(nativePtr,((LinphoneAuthInfoImpl)info).nativePtr); } - public LinphoneProxyConfig createProxyConfig(String identity, String proxy,String route) throws LinphoneCoreException { - return new LinphoneProxyConfigImpl(identity, proxy, route); + public LinphoneProxyConfig createProxyConfig(String identity, String proxy,String route,boolean enableRegister) throws LinphoneCoreException { + return new LinphoneProxyConfigImpl(identity, proxy, route,enableRegister); } public LinphoneProxyConfig getDefaultProxyConfig() { - throw new RuntimeException("not implemenetd yet"); + long lNativePtr = getDefaultProxyConfig(nativePtr); + if (lNativePtr!=0) { + return new LinphoneProxyConfigImpl(lNativePtr); + } else { + return null; + } } public void invite(String uri) { @@ -65,6 +75,13 @@ class LinphoneCoreImpl implements LinphoneCore { throw new LinphoneCoreException("bad proxy config"); } } + public void clearAuthInfos() { + clearAuthInfos(nativePtr); + + } + public void clearProxyConfigs() { + clearProxyConfigs(nativePtr); + } } diff --git a/src/org/linphone/core/LinphoneProxyConfig.java b/src/org/linphone/core/LinphoneProxyConfig.java index b4b5fd8b8..17085de82 100644 --- a/src/org/linphone/core/LinphoneProxyConfig.java +++ b/src/org/linphone/core/LinphoneProxyConfig.java @@ -20,7 +20,31 @@ package org.linphone.core; public interface LinphoneProxyConfig { - void enableRegister(boolean value); + /** + * Unregister proxy config a enable edition + */ + public void edit(); + /** + * Validate proxy config changes. Start registration in case + */ + public void done(); + /** + * sip user made by sip:username@domain + */ + public void setIdentity(String identity) throws LinphoneCoreException; + /** + * Set proxy uri, like sip:linphone.org:5060 + * @param proxyUri + * @throws LinphoneCoreException + */ + public void setProxy(String proxyUri) throws LinphoneCoreException; + /** + * Enable register for this proxy config. + * Register message is issued after call to {@link #done()} + * @param value + * @throws LinphoneCoreException + */ + public void enableRegister(boolean value) throws LinphoneCoreException; } diff --git a/src/org/linphone/core/LinphoneProxyConfigImpl.java b/src/org/linphone/core/LinphoneProxyConfigImpl.java index 0fa1a85b7..f1de9707b 100644 --- a/src/org/linphone/core/LinphoneProxyConfigImpl.java +++ b/src/org/linphone/core/LinphoneProxyConfigImpl.java @@ -18,28 +18,37 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package org.linphone.core; +import org.linphone.Linphone; + +import android.util.Log; + class LinphoneProxyConfigImpl implements LinphoneProxyConfig { protected final long nativePtr; - protected LinphoneProxyConfigImpl(String identity,String proxy,String route) throws LinphoneCoreException { + boolean ownPtr = false; + protected LinphoneProxyConfigImpl(String identity,String proxy,String route, boolean enableRegister) throws LinphoneCoreException { nativePtr = newLinphoneProxyConfig(); - setIdentity(nativePtr,identity); - if (setProxy(nativePtr,proxy)!=0) { - throw new LinphoneCoreException("Bad proxy address ["+proxy+"]"); - } + setIdentity(identity); + setProxy(proxy); + enableRegister(enableRegister); + ownPtr=true; + Log.w(Linphone.TAG, "route ["+route+"] not used yet"); + } + protected LinphoneProxyConfigImpl(long aNativePtr) { + nativePtr = aNativePtr; + ownPtr=false; } - protected void finalize() throws Throwable { - delete(nativePtr); + if (ownPtr) delete(nativePtr); } private native long newLinphoneProxyConfig(); private native void delete(long ptr); - //private native void edit(long ptr); - //private native void done(long ptr); + private native void edit(long ptr); + private native void done(long ptr); private native void setIdentity(long ptr,String identity); private native int setProxy(long ptr,String proxy); @@ -47,9 +56,24 @@ class LinphoneProxyConfigImpl implements LinphoneProxyConfig { private native void enableRegister(long ptr,boolean value); public void enableRegister(boolean value) { - //edit(nativePtr); enableRegister(nativePtr,value); - //done(nativePtr); } + public void done() { + done(nativePtr); + } + + public void edit() { + edit(nativePtr); + } + + public void setIdentity(String identity) throws LinphoneCoreException { + setIdentity(nativePtr,identity); + } + + public void setProxy(String proxyUri) throws LinphoneCoreException { + if (setProxy(nativePtr,proxyUri)!=0) { + throw new LinphoneCoreException("Bad proxy address ["+proxyUri+"]"); + } + } }