add first start configuration checking

This commit is contained in:
Jehan Monnier 2010-03-23 17:41:30 +01:00
parent 4749970d5c
commit 838be51880
9 changed files with 80 additions and 29 deletions

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.linphone"
android:versionCode="104"
android:versionName="1.04">
android:versionCode="106"
android:versionName="1.06">
<uses-sdk android:minSdkVersion="3" />
<application android:icon="@drawable/linphone2" android:label="@string/app_name" android:debuggable = "true">

BIN
libs/armeabi/liblinphone.so Executable file

Binary file not shown.

View file

@ -5,4 +5,6 @@
<string name="pref_domain_key">pref_domain_key</string>
<string name="pref_passwd_key">pref_passwd_key</string>
<string name="pref_username_key">pref_username_key</string>
<string name="pref_debug_key">pref_debug_key</string>
</resources>

View file

@ -1,20 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="about_text">Linphone %s SIP (rfc 3261) Compatible Internet phone \n http://www.linphone.org</string>
<string name="menu_about">About</string>
<string name="pref_audio">Audio</string>
<string name="menu_exit">Exit</string>
<string name="pref_prefix">Prefix</string>
<string name="pref_advanced">Advanced</string>
<string name="menu_settings">Settings</string>
<string name="pref_proxy">Proxy</string>
<string name="pref_domain">Domain*</string>
<string name="pref_passwd">Password*</string>
<string name="pref_username">Username*</string>
<string name="hello">Hello World, Linphone!</string>
<string name="app_name">Linphone</string>
<string name="pref_sipaccount">SIP Account</string>
<string name="wrong_username">wrong user name</string>
<string name="pref_debug">Debug</string>
<string name="about_text">Linphone %s SIP (rfc 3261) Compatible Internet phone \n http://www.linphone.org</string>
<string name="menu_about">About</string>
<string name="pref_audio">Audio</string>
<string name="menu_exit">Exit</string>
<string name="pref_prefix">Prefix</string>
<string name="pref_advanced">Advanced</string>
<string name="menu_settings">Settings</string>
<string name="pref_proxy">Proxy</string>
<string name="pref_domain">Domain*</string>
<string name="pref_passwd">Password*</string>
<string name="pref_username">Username*</string>
<string name="hello">Hello World, Linphone!</string>
<string name="app_name">Linphone</string>
<string name="pref_sipaccount">SIP Account</string>
<string name="wrong_username">wrong user name</string>
<string name="wrong_passwd">wrong password</string>
<string name="wrong_domain">Wrong domain</string>
<string name="wrong_settings">Wrong settings</string>
@ -23,7 +24,9 @@
<string name="call_error">Cannot call %s</string>
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="never_remind">Never remind me</string>
<string name="config_error">%s, do you want to return to the settings page ?</string>
<string name="initial_config_error">No initial config found, do you want to return to the settings page ?</string>
<string name="warning_already_incall">Cannot initiate a new call because a call is already engaged</string>
<string name="tab_history">History</string>
<string name="warning_wrong_destination_address">Cannot build destination address from [%s]</string>

View file

@ -13,6 +13,8 @@
<PreferenceCategory android:title="@string/pref_advanced">
<EditTextPreference android:title="@string/pref_prefix"
android:key="@string/pref_prefix_key"></EditTextPreference>
</PreferenceCategory>
<CheckBoxPreference android:key="@string/pref_debug_key" android:title="@string/pref_debug" android:enabled="true"></CheckBoxPreference>
</PreferenceCategory>
</PreferenceScreen>

View file

@ -25,11 +25,15 @@ import org.linphone.core.LinphoneCoreListener;
import org.linphone.core.LinphoneCore.GeneralState;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
@ -81,7 +85,9 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
private String mDisplayName;
private AudioManager mAudioManager;
private PowerManager.WakeLock mWakeLock;
private SharedPreferences mPref;
String PREF_CHECK_CONFIG = "pref_check_config";
/**
*
* @return null if not ready yet
@ -103,7 +109,7 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
mAudioManager = ((AudioManager)getSystemService(Context.AUDIO_SERVICE));
PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"Linphone");
mPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
try {
@ -329,6 +335,34 @@ public class DialerActivity extends Activity implements LinphoneCoreListener {
case GSTATE_POWER_ON:
mCall.setEnabled(!lc.isIncall());
mHangup.setEnabled(!mCall.isEnabled());
try{
LinphoneService.instance().initFromConf();
} catch (LinphoneConfigException ec) {
Log.w(LinphoneService.TAG,"no valid settings found",ec);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(getString(R.string.initial_config_error))
.setCancelable(false)
.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
LinphoneActivity.instance().startprefActivity();
}
}).setNeutralButton(getString(R.string.no), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
}).setNegativeButton(getString(R.string.never_remind), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mPref.edit().putBoolean(PREF_CHECK_CONFIG, true).commit();
dialog.cancel();
}
});
if (mPref.getBoolean(PREF_CHECK_CONFIG, false) == false) {
builder.create().show();
}
} catch (Exception e ) {
Log.e(LinphoneService.TAG,"Cannot get initial config", e);
}
break;
case GSTATE_REG_OK: {
break;

View file

@ -172,7 +172,7 @@ public class LinphoneActivity extends TabActivity implements SensorEventListener
return false;
}
private void startprefActivity() {
protected void startprefActivity() {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClass(this, LinphonePreferencesActivity.class);
startActivity(intent);

View file

@ -35,8 +35,10 @@ import org.linphone.core.LinphoneProxyConfig;
import org.linphone.core.LinphoneCore.GeneralState;
import android.app.AlertDialog;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
@ -86,11 +88,7 @@ public class LinphoneService extends Service implements LinphoneCoreListener {
, null);
mLinphoneCore.setSoftPlayLevel(3);
try {
initFromConf();
} catch (LinphoneConfigException ec) {
Log.w(TAG,"no valid settings found",ec);
}
TimerTask lTask = new TimerTask() {
@Override
public void run() {
@ -189,6 +187,10 @@ public class LinphoneService extends Service implements LinphoneCoreListener {
public void initFromConf() throws LinphoneConfigException, LinphoneException {
//traces
boolean lIsDebug = mPref.getBoolean(getString(R.string.pref_debug_key), false);
LinphoneCoreFactory.instance().setDebugMode(lIsDebug);
//1 read proxy config from preferences
String lUserName = mPref.getString(getString(R.string.pref_username_key), null);
if (lUserName == null || lUserName.length()==0) {
@ -213,8 +215,10 @@ public class LinphoneService extends Service implements LinphoneCoreListener {
//proxy
String lProxy = mPref.getString(getString(R.string.pref_proxy_key), "sip:"+lDomain);
String lProxy = mPref.getString(getString(R.string.pref_proxy_key),null);
if (lProxy == null || lProxy.length() == 0) {
lProxy = "sip:"+lDomain;
}
//get Default proxy if any
LinphoneProxyConfig lDefaultProxyConfig = mLinphoneCore.getDefaultProxyConfig();
String lIdentity = "sip:"+lUserName+"@"+lDomain;
@ -247,7 +251,7 @@ public class LinphoneService extends Service implements LinphoneCoreListener {
mLinphoneCore.setNetworkStateReachable(lConnectivityManager.getActiveNetworkInfo().getState() ==NetworkInfo.State.CONNECTED);
} catch (LinphoneCoreException e) {
throw new LinphoneConfigException(getString(R.string.wrong_settings));
throw new LinphoneConfigException(getString(R.string.wrong_settings),e);
}
}

View file

@ -22,6 +22,7 @@ import java.io.File;
import java.io.IOException;
public class LinphoneCoreFactory {
static {
System.loadLibrary("linphone");
}
@ -42,6 +43,11 @@ public class LinphoneCoreFactory {
public LinphoneAddress createLinphoneAddress(String username,String domain,String displayName) {
return new LinphoneAddressImpl(username,domain,displayName);
}
/**
* Enable verbose traces
* @param enable
*/
public native void setDebugMode(boolean enable);
}