Added class to migrate old fashioned settings to new ones
This commit is contained in:
parent
3c5d0bea3e
commit
a2cb36ff8f
7 changed files with 235 additions and 37 deletions
4
Makefile
4
Makefile
|
@ -36,13 +36,13 @@ BUILD_REMOTE_PROVISIONING=1
|
|||
BUILD_X264=1
|
||||
BUILD_AMRNB=full # 0, light or full
|
||||
BUILD_AMRWB=0
|
||||
BUILD_GPLV3_ZRTP=0
|
||||
BUILD_GPLV3_ZRTP=1
|
||||
BUILD_SILK=1
|
||||
BUILD_G729=0
|
||||
BUILD_TUNNEL=0
|
||||
BUILD_WEBRTC_AECM=1
|
||||
BUILD_OPUS=1
|
||||
BUILD_FOR_X86=1
|
||||
BUILD_FOR_X86=0
|
||||
USE_JAVAH=1
|
||||
BUILD_TLS=1
|
||||
BUILD_SQLITE=1
|
||||
|
|
|
@ -536,6 +536,11 @@ public class LinphoneManager implements LinphoneCoreListener {
|
|||
|
||||
initLiblinphone(c);
|
||||
|
||||
PreferencesMigrator prefMigrator = new PreferencesMigrator(mServiceContext);
|
||||
if (prefMigrator.isMigrationNeeded()) {
|
||||
prefMigrator.doMigration();
|
||||
}
|
||||
|
||||
if (mServiceContext.getResources().getBoolean(R.bool.enable_push_id)) {
|
||||
Compatibility.initPushNotificationService(mServiceContext);
|
||||
}
|
||||
|
@ -864,7 +869,9 @@ public class LinphoneManager implements LinphoneCoreListener {
|
|||
return InCallActivity.instance();
|
||||
else if (IncomingCallActivity.isInstanciated())
|
||||
return IncomingCallActivity.instance();
|
||||
else
|
||||
else if (mServiceContext != null)
|
||||
return mServiceContext;
|
||||
else if (LinphoneService.isReady())
|
||||
return LinphoneService.instance().getApplicationContext();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -1,21 +1,8 @@
|
|||
package org.linphone;
|
||||
|
||||
import org.linphone.core.LinphoneAuthInfo;
|
||||
import org.linphone.core.LinphoneCore;
|
||||
import org.linphone.core.LinphoneCore.FirewallPolicy;
|
||||
import org.linphone.core.LinphoneCore.MediaEncryption;
|
||||
import org.linphone.core.LinphoneCore.Transports;
|
||||
import org.linphone.core.LinphoneCoreException;
|
||||
import org.linphone.core.LinphoneCoreFactory;
|
||||
import org.linphone.core.LinphoneProxyConfig;
|
||||
import org.linphone.core.LpConfig;
|
||||
import org.linphone.mediastream.Log;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/*
|
||||
ChatListFragment.java
|
||||
Copyright (C) 2012 Belledonne Communications, Grenoble, France
|
||||
LinphonePreferences.java
|
||||
Copyright (C) 2013 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
|
||||
|
@ -32,6 +19,20 @@ along with this program; if not, write to the Free Software
|
|||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
import org.linphone.core.LinphoneAddress;
|
||||
import org.linphone.core.LinphoneAuthInfo;
|
||||
import org.linphone.core.LinphoneCore;
|
||||
import org.linphone.core.LinphoneCore.FirewallPolicy;
|
||||
import org.linphone.core.LinphoneCore.MediaEncryption;
|
||||
import org.linphone.core.LinphoneCore.Transports;
|
||||
import org.linphone.core.LinphoneCoreException;
|
||||
import org.linphone.core.LinphoneCoreFactory;
|
||||
import org.linphone.core.LinphoneProxyConfig;
|
||||
import org.linphone.core.LpConfig;
|
||||
import org.linphone.mediastream.Log;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* @author Sylvain Berfini
|
||||
*/
|
||||
|
@ -53,7 +54,7 @@ public class LinphonePreferences {
|
|||
|
||||
private String getString(int key) {
|
||||
if (mContext == null) {
|
||||
mContext = LinphoneService.instance();
|
||||
mContext = LinphoneManager.getInstance().getContext();
|
||||
}
|
||||
|
||||
return mContext.getString(key);
|
||||
|
@ -71,6 +72,10 @@ public class LinphonePreferences {
|
|||
return LinphoneCoreFactory.instance().createLpConfig(LinphoneManager.getInstance().mLinphoneConfigFile);
|
||||
}
|
||||
|
||||
public void removePreviousVersionAuthInfoRemoval() {
|
||||
getConfig().setBool("sip", "store_auth_info", true);
|
||||
}
|
||||
|
||||
// App settings
|
||||
public boolean isFirstLaunch() {
|
||||
return getConfig().getBool("app", "first_launch", true);
|
||||
|
@ -110,8 +115,18 @@ public class LinphonePreferences {
|
|||
|
||||
private LinphoneAuthInfo getAuthInfo(int n) {
|
||||
LinphoneAuthInfo[] authsInfos = getLc().getAuthInfosList();
|
||||
if (n < 0 || n >= authsInfos.length)
|
||||
// In case you have multiple proxy configs with same auth info
|
||||
if (n > 0 && n >= authsInfos.length) {
|
||||
LinphoneProxyConfig prxCfg = getProxyConfig(n);
|
||||
try {
|
||||
LinphoneAddress addr = LinphoneCoreFactory.instance().createLinphoneAddress(prxCfg.getIdentity());
|
||||
return getLc().findAuthInfo(addr.getUserName(), null);
|
||||
} catch (LinphoneCoreException e) { }
|
||||
return null;
|
||||
}
|
||||
else if (n < 0) {
|
||||
return null;
|
||||
}
|
||||
return authsInfos[n];
|
||||
}
|
||||
|
||||
|
@ -170,7 +185,8 @@ public class LinphonePreferences {
|
|||
}
|
||||
|
||||
public String getAccountUsername(int n) {
|
||||
return getAuthInfo(n).getUsername();
|
||||
LinphoneAuthInfo authInfo = getAuthInfo(n);
|
||||
return authInfo == null ? null : authInfo.getUsername();
|
||||
}
|
||||
|
||||
public void setNewAccountUserId(String userId) {
|
||||
|
@ -182,7 +198,8 @@ public class LinphonePreferences {
|
|||
}
|
||||
|
||||
public String getAccountUserId(int n) {
|
||||
return getAuthInfo(n).getUserId();
|
||||
LinphoneAuthInfo authInfo = getAuthInfo(n);
|
||||
return authInfo == null ? null : authInfo.getUserId();
|
||||
}
|
||||
|
||||
public void setNewAccountPassword(String password) {
|
||||
|
@ -194,7 +211,8 @@ public class LinphonePreferences {
|
|||
}
|
||||
|
||||
public String getAccountPassword(int n) {
|
||||
return getAuthInfo(n).getPassword();
|
||||
LinphoneAuthInfo authInfo = getAuthInfo(n);
|
||||
return authInfo == null ? null : authInfo.getPassword();
|
||||
}
|
||||
|
||||
public void setNewAccountDomain(String domain) {
|
||||
|
@ -294,7 +312,7 @@ public class LinphonePreferences {
|
|||
}
|
||||
|
||||
public int getAccountCount() {
|
||||
return Math.min(getLc().getProxyConfigList().length, getLc().getAuthInfosList().length);
|
||||
return getLc().getProxyConfigList().length;
|
||||
}
|
||||
|
||||
public void setAccountEnabled(int n, boolean disabled) {
|
||||
|
@ -461,14 +479,20 @@ public class LinphonePreferences {
|
|||
}
|
||||
|
||||
public void useRandomPort(boolean enabled) {
|
||||
useRandomPort(enabled, true);
|
||||
}
|
||||
|
||||
public void useRandomPort(boolean enabled, boolean apply) {
|
||||
getConfig().setBool("app", "random_port", enabled);
|
||||
if (enabled) {
|
||||
setSipPort(LINPHONE_CORE_RANDOM_PORT);
|
||||
} else {
|
||||
if (getTransport().equals(getString(R.string.pref_transport_tls)))
|
||||
setSipPort(5061);
|
||||
else
|
||||
setSipPort(5060);
|
||||
if (apply) {
|
||||
if (enabled) {
|
||||
setSipPort(LINPHONE_CORE_RANDOM_PORT);
|
||||
} else {
|
||||
if (getTransport().equals(getString(R.string.pref_transport_tls)))
|
||||
setSipPort(5061);
|
||||
else
|
||||
setSipPort(5060);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -611,10 +611,6 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
|
|||
void onCallStateChanged(LinphoneCall call, State state, String message);
|
||||
}
|
||||
|
||||
public void changeRingtone(String ringtone) {
|
||||
LinphonePreferences.instance().setRingtone(ringtone);
|
||||
}
|
||||
|
||||
public void onRingerPlayerCreated(MediaPlayer mRingerPlayer) {
|
||||
String uriString = LinphonePreferences.instance().getRingtone(android.provider.Settings.System.DEFAULT_RINGTONE_URI.toString());
|
||||
try {
|
||||
|
|
149
src/org/linphone/PreferencesMigrator.java
Normal file
149
src/org/linphone/PreferencesMigrator.java
Normal file
|
@ -0,0 +1,149 @@
|
|||
package org.linphone;
|
||||
|
||||
/*
|
||||
PreferencesMigrator.java
|
||||
Copyright (C) 2013 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.
|
||||
*/
|
||||
|
||||
import org.linphone.core.LinphoneCore;
|
||||
import org.linphone.core.LinphoneCoreException;
|
||||
import org.linphone.mediastream.Log;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.content.res.Resources;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
/**
|
||||
* @author Sylvain Berfini
|
||||
*/
|
||||
public class PreferencesMigrator {
|
||||
private LinphonePreferences mNewPrefs;
|
||||
private SharedPreferences mOldPrefs;
|
||||
private Resources mResources;
|
||||
|
||||
public PreferencesMigrator(Context context) {
|
||||
mNewPrefs = LinphonePreferences.instance();
|
||||
mResources = context.getResources();
|
||||
mOldPrefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
}
|
||||
|
||||
public boolean isMigrationNeeded() {
|
||||
int accountNumber = mOldPrefs.getInt(getString(R.string.pref_extra_accounts), -1);
|
||||
boolean migrationNeeded = accountNumber != -1;
|
||||
Log.w("Preference migration needed ? " + migrationNeeded);
|
||||
return migrationNeeded;
|
||||
}
|
||||
|
||||
public void doMigration() {
|
||||
mNewPrefs.firstLaunchSuccessful(); // If migration is needed, it is safe to assume Linphone has already been started once.
|
||||
mNewPrefs.removePreviousVersionAuthInfoRemoval(); // Remove flag in linphonerc asking core not to store auths infos
|
||||
|
||||
mNewPrefs.setFrontCamAsDefault(getPrefBoolean(R.string.pref_video_use_front_camera_key, true));
|
||||
mNewPrefs.setWifiOnlyEnabled(getPrefBoolean(R.string.pref_wifi_only_key, false));
|
||||
mNewPrefs.useRandomPort(getPrefBoolean(R.string.pref_transport_use_random_ports_key, true), false);
|
||||
mNewPrefs.setPushNotificationEnabled(getPrefBoolean(R.string.pref_push_notification_key, false));
|
||||
mNewPrefs.setPushNotificationRegistrationID(getPrefString(R.string.push_reg_id_key, null));
|
||||
mNewPrefs.setDebugEnabled(getPrefBoolean(R.string.pref_debug_key, false));
|
||||
mNewPrefs.setBackgroundModeEnabled(getPrefBoolean(R.string.pref_background_mode_key, true));
|
||||
mNewPrefs.setAnimationsEnabled(getPrefBoolean(R.string.pref_animation_enable_key, false));
|
||||
mNewPrefs.setAutoStart(getPrefBoolean(R.string.pref_autostart_key, false));
|
||||
mNewPrefs.setSharingPictureServerUrl(getPrefString(R.string.pref_image_sharing_server_key, null));
|
||||
mNewPrefs.setRemoteProvisioningUrl(getPrefString(R.string.pref_remote_provisioning_key, null));
|
||||
|
||||
doAccountsMigration();
|
||||
deleteAllOldPreferences();
|
||||
}
|
||||
|
||||
private void doAccountsMigration() {
|
||||
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
|
||||
lc.clearAuthInfos();
|
||||
lc.clearProxyConfigs();
|
||||
|
||||
for (int i = 0; i < mOldPrefs.getInt(getString(R.string.pref_extra_accounts), 1); i++) {
|
||||
doAccountMigration(i, i == getPrefInt(R.string.pref_default_account_key, 0));
|
||||
}
|
||||
}
|
||||
|
||||
private void doAccountMigration(int index, boolean isDefaultAccount) {
|
||||
String key = index == 0 ? "" : String.valueOf(index);
|
||||
|
||||
String username = getPrefString(getString(R.string.pref_username_key) + key, null);
|
||||
String userid = getPrefString(getString(R.string.pref_auth_userid_key) + key, null);
|
||||
String password = getPrefString(getString(R.string.pref_passwd_key) + key, null);
|
||||
String domain = getPrefString(getString(R.string.pref_domain_key) + key, null);
|
||||
if (username != null && username.length() > 0 && password != null) {
|
||||
mNewPrefs.setNewAccountUsername(username);
|
||||
mNewPrefs.setNewAccountUserId(userid);
|
||||
mNewPrefs.setNewAccountDomain(domain);
|
||||
mNewPrefs.setNewAccountPassword(password);
|
||||
|
||||
String proxy = getPrefString(getString(R.string.pref_proxy_key) + key, null);
|
||||
mNewPrefs.setNewAccountProxy(proxy);
|
||||
String expire = getPrefString(R.string.pref_expire_key, null);
|
||||
mNewPrefs.setNewAccountExpires(expire);
|
||||
|
||||
if (getPrefBoolean(getString(R.string.pref_enable_outbound_proxy_key) + key, false)) {
|
||||
mNewPrefs.setNewAccountOutboundProxyEnabled(true);
|
||||
}
|
||||
if (mResources.getBoolean(R.bool.enable_push_id)) {
|
||||
String regId = mNewPrefs.getPushNotificationRegistrationID();
|
||||
String appId = getString(R.string.push_sender_id);
|
||||
if (regId != null && mNewPrefs.isPushNotificationEnabled()) {
|
||||
String contactInfos = "app-id=" + appId + ";pn-type=google;pn-tok=" + regId;
|
||||
mNewPrefs.setNewAccountContactParameters(contactInfos);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
mNewPrefs.saveNewAccount();
|
||||
} catch (LinphoneCoreException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (isDefaultAccount) {
|
||||
mNewPrefs.setDefaultAccount(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteAllOldPreferences() {
|
||||
Editor editor = mOldPrefs.edit();
|
||||
editor.clear();
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
private String getString(int key) {
|
||||
return mResources.getString(key);
|
||||
}
|
||||
private boolean getPrefBoolean(int key, boolean defaultValue) {
|
||||
return mOldPrefs.getBoolean(mResources.getString(key), defaultValue);
|
||||
}
|
||||
private boolean getPrefBoolean(String key, boolean defaultValue) {
|
||||
return mOldPrefs.getBoolean(key, defaultValue);
|
||||
}
|
||||
private String getPrefString(int key, String defaultValue) {
|
||||
return mOldPrefs.getString(mResources.getString(key), defaultValue);
|
||||
}
|
||||
private int getPrefInt(int key, int defaultValue) {
|
||||
return mOldPrefs.getInt(mResources.getString(key), defaultValue);
|
||||
}
|
||||
private String getPrefString(String key, String defaultValue) {
|
||||
return mOldPrefs.getString(key, defaultValue);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,24 @@
|
|||
package org.linphone;
|
||||
|
||||
/*
|
||||
SettingsFragment.java
|
||||
Copyright (C) 2013 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.
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -31,6 +50,9 @@ import android.preference.Preference.OnPreferenceClickListener;
|
|||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceScreen;
|
||||
|
||||
/**
|
||||
* @author Sylvain Berfini
|
||||
*/
|
||||
public class SettingsFragment extends PreferencesListFragment implements EcCalibrationListener {
|
||||
private static final int WIZARD_INTENT = 1;
|
||||
private LinphonePreferences mPrefs;
|
||||
|
@ -53,7 +75,7 @@ public class SettingsFragment extends PreferencesListFragment implements EcCalib
|
|||
|
||||
// Inits the values or the listener on some settings
|
||||
private void initSettings() {
|
||||
//initAccounts(); Init accounts on Resume instead of on Create to update the account list when coming back from wizard
|
||||
//Init accounts on Resume instead of on Create to update the account list when coming back from wizard
|
||||
|
||||
initAudioSettings();
|
||||
initVideoSettings();
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 08c59397cbb5e34786f6cfb8187675ad501929ea
|
||||
Subproject commit 712dd480ca6d9ce3c28e4089d3fe1ed5ee437e61
|
Loading…
Reference in a new issue