payload init, data paths, armv7 detection, typos

Fix: payload initialization in PreferenceActivity
Fix: paths to application data by using Android facilities
Detect ARMv7 by looking at Build.CPU_ABI through reflection
Fix: crash on registration change after LinphoneActivity was killed by Android
This commit is contained in:
Guillaume Beraudo 2011-03-11 11:36:48 +01:00
parent 441fb13047
commit 6c3e6fe464
7 changed files with 107 additions and 70 deletions

View file

@ -7,7 +7,7 @@
<string name="pref_transport_udp">UDP</string>
<string name="pref_transport_tcp">TCP</string>
<string name="pref_transport_tls">TLS</string>
<string name="pref_transport_use_standard_ports">Don\'t use random ports</string>
<string name="pref_transport_use_standard_ports">Use standard ports</string>
<string name="at_least_a_protocol">At least one item is required</string>

View file

@ -44,23 +44,25 @@
<CheckBoxPreference android:key="@string/pref_echo_cancellation_key"
android:title="@string/pref_echo_cancellation" android:summary="@string/pref_echo_cancellation_summary"></CheckBoxPreference>
<CheckBoxPreference android:key="@string/pref_echo_canceller_calibration_key" android:title="@string/pref_echo_canceller_calibration" android:defaultValue="false"></CheckBoxPreference><PreferenceScreen android:title="@string/pref_codecs"
<CheckBoxPreference android:key="@string/pref_echo_canceller_calibration_key"
android:title="@string/pref_echo_canceller_calibration" />
<PreferenceScreen android:title="@string/pref_codecs"
android:key="@string/pref_codecs_key">
<CheckBoxPreference android:key="@string/pref_codec_speex16_key"
android:title="@string/pref_codec_speex16" android:defaultValue="true"
android:enabled="false"></CheckBoxPreference>
android:title="@string/pref_codec_speex16"/>
<CheckBoxPreference android:key="@string/pref_codec_speex8_key"
android:title="@string/pref_codec_speex8" android:defaultValue="true"></CheckBoxPreference>
android:title="@string/pref_codec_speex8"/>
<CheckBoxPreference android:key="@string/pref_codec_ilbc_key"
android:title="@string/pref_codec_ilbc" android:enabled="false"
android:shouldDisableView="true" android:defaultValue="true"
android:summary="@string/pref_ilbc_summary"></CheckBoxPreference>
android:title="@string/pref_codec_ilbc"
android:shouldDisableView="true"
android:summary="@string/pref_ilbc_summary"/>
<CheckBoxPreference android:key="@string/pref_codec_gsm_key"
android:title="@string/pref_codec_gsm" android:defaultValue="true"></CheckBoxPreference>
android:title="@string/pref_codec_gsm"/>
<CheckBoxPreference android:key="@string/pref_codec_pcmu_key"
android:title="@string/pref_codec_pcmu" android:defaultValue="true"></CheckBoxPreference>
android:title="@string/pref_codec_pcmu"/>
<CheckBoxPreference android:key="@string/pref_codec_pcma_key"
android:title="@string/pref_codec_pcma" android:defaultValue="true"></CheckBoxPreference>
android:title="@string/pref_codec_pcma"/>
</PreferenceScreen>
</PreferenceCategory>
@ -118,7 +120,8 @@
android:title="@string/pref_transport_udp" android:defaultValue="true"/>
<CheckBoxPreference android:key="@string/pref_transport_tcp_key"
android:title="@string/pref_transport_tcp" />
<CheckBoxPreference android:key="@string/pref_transport_tls_key" android:title="@string/pref_transport_tls" />
<!-- <CheckBoxPreference android:key="@string/pref_transport_tls_key"-->
<!-- android:title="@string/pref_transport_tls" />-->
<CheckBoxPreference android:key="@string/pref_transport_use_standard_ports_key"
android:title="@string/pref_transport_use_standard_ports"/>
</PreferenceScreen>

View file

@ -55,6 +55,7 @@ import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
import android.widget.Toast;
@ -86,7 +87,9 @@ public class LinphoneActivity extends TabActivity {
private boolean checkAccount;
static final boolean isInstanciated() {
return instance != null;
}
static final LinphoneActivity instance() {
if (instance != null) return instance;
@ -148,7 +151,7 @@ public class LinphoneActivity extends TabActivity {
if (requestCode == FIRST_LOGIN_ACTIVITY) {
if (resultCode == RESULT_OK) {
Toast.makeText(this, getString(R.string.ec_calibration_launch_message), Toast.LENGTH_LONG).show();
LinphoneManager.getInstance().initializePayloads();
try {
LinphoneManager.getInstance().startEcCalibration(new EcCalibrationListener() {
public void onEcCalibrationStatus(EcCalibratorStatus status, int delayMs) {
@ -173,7 +176,9 @@ public class LinphoneActivity extends TabActivity {
}
private void fillTabHost() {
private synchronized void fillTabHost() {
if (((TabWidget) findViewById(android.R.id.tabs)).getChildCount() != 0) return;
TabHost lTabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Reusable TabSpec for each tab
Drawable tabDrawable; // Drawable for a tab
@ -343,9 +348,7 @@ public class LinphoneActivity extends TabActivity {
.setCancelable(false)
.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent intent = new Intent(ACTION_MAIN);
intent.setClass(getApplicationContext(), LinphonePreferencesActivity.class);
startActivity(intent);
startprefActivity();
}
})
.setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
@ -390,7 +393,8 @@ public class LinphoneActivity extends TabActivity {
.setCancelable(false)
.setPositiveButton(getString(R.string.cont), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
LinphoneActivity.instance().startprefActivity();
LinphoneManager.getInstance().initializePayloads();
startprefActivity();
checkAccount = false;
}
});
@ -410,7 +414,7 @@ public class LinphoneActivity extends TabActivity {
.setCancelable(false)
.setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
LinphoneActivity.instance().startprefActivity();
startprefActivity();
checkAccount = false;
}
}).setNeutralButton(getString(R.string.no), new DialogInterface.OnClickListener() {

View file

@ -18,8 +18,21 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.linphone;
import static android.media.AudioManager.*;
import static org.linphone.core.LinphoneCall.State.*;
import static android.media.AudioManager.MODE_IN_CALL;
import static android.media.AudioManager.MODE_NORMAL;
import static android.media.AudioManager.MODE_RINGTONE;
import static android.media.AudioManager.ROUTE_SPEAKER;
import static android.media.AudioManager.STREAM_RING;
import static android.media.AudioManager.STREAM_VOICE_CALL;
import static android.media.AudioManager.VIBRATE_TYPE_RINGER;
import static org.linphone.R.string.pref_codec_ilbc_key;
import static org.linphone.R.string.pref_codec_speex16_key;
import static org.linphone.R.string.pref_codec_speex32_key;
import static org.linphone.R.string.pref_echo_cancellation_key;
import static org.linphone.core.LinphoneCall.State.CallEnd;
import static org.linphone.core.LinphoneCall.State.Error;
import static org.linphone.core.LinphoneCall.State.IncomingReceived;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@ -39,6 +52,7 @@ import org.linphone.core.LinphoneCoreListener;
import org.linphone.core.LinphoneFriend;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.core.PayloadType;
import org.linphone.core.Version;
import org.linphone.core.LinphoneCall.State;
import org.linphone.core.LinphoneCore.EcCalibratorStatus;
import org.linphone.core.LinphoneCore.FirewallPolicy;
@ -53,6 +67,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Resources;
import android.hardware.Camera;
import android.media.AudioManager;
@ -98,6 +113,12 @@ public final class LinphoneManager implements LinphoneCoreListener {
private LinphoneManager(final Context c) {
String basePath = c.getFilesDir().getAbsolutePath();
linphoneInitialConfigFile = basePath + "/linphonerc";
linphoneConfigFile = basePath + "/.linphonerc";
ringSoundFile = basePath + "/oldphone_mono.wav";
ringbackSoundFile = basePath + "/ringback.wav";
mAudioManager = ((AudioManager) c.getSystemService(Context.AUDIO_SERVICE));
mVibrator = (Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE);
mPref = PreferenceManager.getDefaultSharedPreferences(c);
@ -135,10 +156,10 @@ public final class LinphoneManager implements LinphoneCoreListener {
public static final String TAG="Linphone";
/** Called when the activity is first created. */
private static final String LINPHONE_FACTORY_RC = "/data/data/org.linphone/files/linphonerc";
private static final String LINPHONE_RC = "/data/data/org.linphone/files/.linphonerc";
private static final String RING_SND = "/data/data/org.linphone/files/oldphone_mono.wav";
private static final String RINGBACK_SND = "/data/data/org.linphone/files/ringback.wav";
private final String linphoneInitialConfigFile;
private final String linphoneConfigFile;
private final String ringSoundFile;
private final String ringbackSoundFile;
private Timer mTimer = new Timer("Linphone scheduler");
@ -306,7 +327,7 @@ public final class LinphoneManager implements LinphoneCoreListener {
copyAssetsFromPackage(context);
mLc = LinphoneCoreFactory.instance().createLinphoneCore(
this, LINPHONE_RC, LINPHONE_FACTORY_RC, null);
this, linphoneConfigFile, linphoneInitialConfigFile, null);
mLc.setPlaybackGain(3);
mLc.setRing(null);
@ -335,9 +356,9 @@ public final class LinphoneManager implements LinphoneCoreListener {
}
private void copyAssetsFromPackage(Context context) throws IOException {
copyIfNotExist(context, R.raw.oldphone_mono,RING_SND);
copyIfNotExist(context, R.raw.ringback,RINGBACK_SND);
copyFromPackage(context, R.raw.linphonerc, new File(LINPHONE_FACTORY_RC).getName());
copyIfNotExist(context, R.raw.oldphone_mono,ringSoundFile);
copyIfNotExist(context, R.raw.ringback,ringbackSoundFile);
copyFromPackage(context, R.raw.linphonerc, new File(linphoneInitialConfigFile).getName());
}
private void copyIfNotExist(Context context, int ressourceId,String target) throws IOException {
File lFileToCopy = new File(target);
@ -761,4 +782,25 @@ public final class LinphoneManager implements LinphoneCoreListener {
/* ops */
}
}
public void initializePayloads() {
Log.i(TAG, "Initializing supported payloads");
Editor e = mPref.edit();
boolean fastCpu = Version.isArmv7();
e.putBoolean(getString(pref_echo_cancellation_key), fastCpu);
e.putBoolean(getString(R.string.pref_codec_gsm_key), true);
e.putBoolean(getString(R.string.pref_codec_pcma_key), true);
e.putBoolean(getString(R.string.pref_codec_pcmu_key), true);
e.putBoolean(getString(R.string.pref_codec_speex8_key), true);
e.putBoolean(getString(pref_codec_speex16_key), fastCpu);
e.putBoolean(getString(pref_codec_speex32_key), fastCpu);
boolean ilbc = LinphoneService.isReady() && LinphoneManager.getLc()
.findPayloadType("iLBC", 8000)!=null;
e.putBoolean(getString(pref_codec_ilbc_key), ilbc);
e.commit();
}
}

View file

@ -24,8 +24,6 @@ import static org.linphone.R.string.ec_calibrating;
import static org.linphone.R.string.ec_calibration_launch_message;
import static org.linphone.R.string.pref_codec_ilbc_key;
import static org.linphone.R.string.pref_codec_speex16_key;
import static org.linphone.R.string.pref_codec_speex32_key;
import static org.linphone.R.string.pref_echo_cancellation_key;
import static org.linphone.R.string.pref_echo_canceller_calibration_key;
import static org.linphone.R.string.pref_video_enable_key;
@ -43,14 +41,12 @@ import android.os.Handler;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.util.Log;
import android.widget.Toast;
public class LinphonePreferencesActivity extends PreferenceActivity implements EcCalibrationListener {
private boolean mIsLowEndCpu = true;
private Handler mHandler = new Handler();
private CheckBoxPreference ecPref;
@ -70,23 +66,6 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
addTransportChecboxesListener();
boolean enableIlbc=false;
if (LinphoneService.isReady()) {
// if not ilbc, we are on low end cpu.
enableIlbc = LinphoneManager.getLc().findPayloadType("iLBC", 8000)!=null?true:false;
mIsLowEndCpu=!enableIlbc;
if (!mIsLowEndCpu && !prefs().contains(getString(pref_echo_cancellation_key))) {
writeBoolean(pref_echo_cancellation_key, true);
}
if (mIsLowEndCpu) {
writeBoolean(pref_codec_ilbc_key, false);
writeBoolean(pref_codec_speex16_key, false);
writeBoolean(pref_codec_speex32_key, false);
}
}
ecPref = (CheckBoxPreference) findPreference(pref_echo_canceller_calibration_key);
ecPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
@ -95,38 +74,37 @@ public class LinphonePreferencesActivity extends PreferenceActivity implements E
}
});
if (!mIsLowEndCpu) {
findPreference(pref_codec_ilbc_key).setEnabled(enableIlbc);
findPreference(pref_codec_speex16_key).setEnabled(enableIlbc);
boolean fastCpu = Version.isArmv7();
if (fastCpu) {
boolean ilbc = LinphoneService.isReady() && LinphoneManager.getLc().findPayloadType("iLBC", 8000)!=null;
findPreference(pref_codec_ilbc_key).setEnabled(ilbc);
findPreference(pref_codec_speex16_key).setEnabled(true);
//findPreference(pref_codec_speex32_key)).setEnabled(enableIlbc);
}
// Force disable video
if (Version.sdkStrictlyBelow(5) || !enableIlbc || !LinphoneManager.getInstance().hasCamera()) {
// No video
if (Version.sdkStrictlyBelow(5) || !fastCpu || !LinphoneManager.getInstance().hasCamera()) {
disableCheckbox(pref_video_enable_key);
}
if (prefs().getBoolean(LinphoneActivity.PREF_FIRST_LAUNCH,true)) {
if (!mIsLowEndCpu ) {
if (fastCpu) {
Toast.makeText(this, getString(ec_calibration_launch_message), Toast.LENGTH_LONG).show();
startEcCalibration();
}
}
prefs().edit().putBoolean(LinphoneActivity.PREF_FIRST_LAUNCH, false).commit();
}
}
}
private List<CheckBoxPreference> findTransportCb() {
return Arrays.asList(
findCheckbox(R.string.pref_transport_udp_key),
findCheckbox(R.string.pref_transport_tcp_key),
findCheckbox(R.string.pref_transport_tls_key));
}
private void addTransportChecboxesListener() {
final List<CheckBoxPreference> checkboxes = findTransportCb();
final List<CheckBoxPreference> checkboxes = Arrays.asList(
findCheckbox(R.string.pref_transport_udp_key)
,findCheckbox(R.string.pref_transport_tcp_key)
// ,findCheckbox(R.string.pref_transport_tls_key)
);
OnPreferenceChangeListener changedListener = new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {

View file

@ -201,7 +201,8 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
if (state == RegistrationState.RegistrationOk || state == RegistrationState.RegistrationFailed) {
mHandler.post(new Runnable() {
public void run() {
LinphoneActivity.instance().onRegistrationStateChanged(state, message);
if (LinphoneActivity.isInstanciated())
LinphoneActivity.instance().onRegistrationStateChanged(state, message);
}
});
}

View file

@ -42,4 +42,13 @@ public class Version {
return buildVersion;
}
public static boolean isArmv7() {
try {
return sdkAboveOrEqual(4)
&& Build.class.getField("CPU_ABI").get(null).toString().startsWith("armeabi-v7");
} catch (Throwable e) {}
return false;
}
}