More settings binded

This commit is contained in:
Sylvain Berfini 2013-10-11 15:30:38 +02:00
parent cbb8641c91
commit 5a03fb1cd6
6 changed files with 139 additions and 52 deletions

View file

@ -20,7 +20,6 @@ package org.linphone;
import static android.content.Intent.ACTION_MAIN; import static android.content.Intent.ACTION_MAIN;
import org.linphone.compatibility.Compatibility;
import org.linphone.mediastream.Log; import org.linphone.mediastream.Log;
import org.linphone.tutorials.TutorialLauncherActivity; import org.linphone.tutorials.TutorialLauncherActivity;
@ -59,10 +58,6 @@ public class LinphoneLauncherActivity extends Activity {
mHandler = new Handler(); mHandler = new Handler();
if (getResources().getBoolean(R.bool.enable_push_id)) {
Compatibility.initPushNotificationService(this);
}
if (LinphoneService.isReady()) { if (LinphoneService.isReady()) {
onServiceReady(); onServiceReady();
} else { } else {

View file

@ -536,6 +536,10 @@ public class LinphoneManager implements LinphoneCoreListener {
initLiblinphone(c); initLiblinphone(c);
if (mServiceContext.getResources().getBoolean(R.bool.enable_push_id)) {
Compatibility.initPushNotificationService(mServiceContext);
}
IntentFilter lFilter = new IntentFilter(Intent.ACTION_SCREEN_ON); IntentFilter lFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
lFilter.addAction(Intent.ACTION_SCREEN_OFF); lFilter.addAction(Intent.ACTION_SCREEN_OFF);
mServiceContext.registerReceiver(mKeepAliveReceiver, lFilter); mServiceContext.registerReceiver(mKeepAliveReceiver, lFilter);
@ -644,7 +648,7 @@ public class LinphoneManager implements LinphoneCoreListener {
} }
} else if (eventInfo.getState() == NetworkInfo.State.CONNECTED){ } else if (eventInfo.getState() == NetworkInfo.State.CONNECTED){
manageTunnelServer(eventInfo); manageTunnelServer(eventInfo);
boolean wifiOnly = LinphonePreferences.instance().shouldOnlyRegisterOnWifiNetwork(); boolean wifiOnly = LinphonePreferences.instance().isWifiOnlyEnabled();
if ((eventInfo.getTypeName().equals("WIFI")) || (!eventInfo.getTypeName().equals("WIFI") && !wifiOnly)) { if ((eventInfo.getTypeName().equals("WIFI")) || (!eventInfo.getTypeName().equals("WIFI") && !wifiOnly)) {
if (!isNetworkReachable) { if (!isNetworkReachable) {
isNetworkReachable = true; isNetworkReachable = true;

View file

@ -2,11 +2,14 @@ package org.linphone;
import org.linphone.core.LinphoneAuthInfo; import org.linphone.core.LinphoneAuthInfo;
import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCore.FirewallPolicy;
import org.linphone.core.LinphoneCore.MediaEncryption; import org.linphone.core.LinphoneCore.MediaEncryption;
import org.linphone.core.LinphoneCore.Transports; import org.linphone.core.LinphoneCore.Transports;
import org.linphone.core.LinphoneCoreException; import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneCoreFactory; import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LinphoneProxyConfig; import org.linphone.core.LinphoneProxyConfig;
import org.linphone.core.LpConfig;
import org.linphone.mediastream.Log;
import android.content.Context; import android.content.Context;
@ -59,24 +62,36 @@ public class LinphonePreferences {
return LinphoneManager.getLcIfManagerNotDestroyedOrNull(); return LinphoneManager.getLcIfManagerNotDestroyedOrNull();
} }
private LpConfig getConfig() {
LinphoneCore lc = getLc();
if (lc != null)
return lc.getConfig();
return LinphoneCoreFactory.instance().createLpConfig(LinphoneManager.getInstance().mLinphoneConfigFile);
}
public boolean isFirstLaunch() { public boolean isFirstLaunch() {
return getLc().getConfig().getBool("app", "first_launch", true); return getConfig().getBool("app", "first_launch", true);
} }
public void firstLaunchSuccessful() { public void firstLaunchSuccessful() {
getLc().getConfig().setBool("app", "first_launch", false); getConfig().setBool("app", "first_launch", false);
}
public void setDebugEnabled(boolean enabled) {
getConfig().setBool("app", "debug", enabled);
} }
public boolean isDebugEnabled() { public boolean isDebugEnabled() {
return true; //TODO return getConfig().getBool("app", "debug", false);
} }
public void setRemoteProvisioningUrl(String url) { public void setRemoteProvisioningUrl(String url) {
getLc().getConfig().setString("app", "remote_provisioning", url); getConfig().setString("app", "remote_provisioning", url);
} }
public String getRemoteProvisioningUrl() { public String getRemoteProvisioningUrl() {
return LinphoneCoreFactory.instance().createLpConfig(LinphoneManager.getInstance().mLinphoneConfigFile).getString("app", "remote_provisioning", null); return getConfig().getString("app", "remote_provisioning", null);
} }
public String getTunnelMode() { public String getTunnelMode() {
@ -99,48 +114,40 @@ public class LinphonePreferences {
return false; //TODO return false; //TODO
} }
public void setPushNotificationRegistrationID(String regId) {
//TODO
}
public String getPushNotificationRegistrationID() {
return null; //TODO
}
public boolean isAutoStartEnabled() { public boolean isAutoStartEnabled() {
return getLc().getConfig().getBool("app", "auto_start", false); return getConfig().getBool("app", "auto_start", false);
} }
public void setAutoStart(boolean autoStartEnabled) { public void setAutoStart(boolean autoStartEnabled) {
getLc().getConfig().setBool("app", "auto_start", autoStartEnabled); getConfig().setBool("app", "auto_start", autoStartEnabled);
} }
public String getSharingPictureServerUrl() { public String getSharingPictureServerUrl() {
return getLc().getConfig().getString("app", "sharing_server", null); return getConfig().getString("app", "sharing_server", null);
} }
public void setSharingPictureServerUrl(String url) { public void setSharingPictureServerUrl(String url) {
getLc().getConfig().setString("app", "sharing_server", url); getConfig().setString("app", "sharing_server", url);
} }
public boolean shouldUseLinphoneToStoreChatHistory() { public void setAnimationsEnabled(boolean enabled) {
return false; //TODO getConfig().setBool("app", "animations", enabled);
} }
public boolean areAnimationsEnabled() { public boolean areAnimationsEnabled() {
return false; //TODO return getConfig().getBool("app", "animations", false);
} }
public boolean shouldAutomaticallyAcceptFriendsRequests() { public boolean shouldAutomaticallyAcceptFriendsRequests() {
return false; //TODO return false; //TODO
} }
public boolean isBackgroundModeEnabled() { public void setBackgroundModeEnabled(boolean enabled) {
return false; //TODO getConfig().setBool("app", "background_mode", enabled);
} }
public boolean shouldOnlyRegisterOnWifiNetwork() { public boolean isBackgroundModeEnabled() {
return false; //TODO return getConfig().getBool("app", "background_mode", true);
} }
public boolean shouldUseSoftvolume() { public boolean shouldUseSoftvolume() {
@ -148,11 +155,14 @@ public class LinphonePreferences {
} }
public String getRingtone(String defaultRingtone) { public String getRingtone(String defaultRingtone) {
return defaultRingtone; //TODO String ringtone = getLc().getRing();
if (ringtone == null || ringtone.length() == 0)
ringtone = defaultRingtone;
return ringtone;
} }
public void setRingtone(String ringtone) { public void setRingtone(String ringtone) {
//TODO getLc().setRing(ringtone);
} }
// Accounts // Accounts
@ -176,6 +186,7 @@ public class LinphonePreferences {
private String tempDomain; private String tempDomain;
private String tempProxy; private String tempProxy;
private boolean tempOutboundProxy; private boolean tempOutboundProxy;
private String tempContactsParams;
/** /**
* Creates a new account using values previously set using setNew* functions * Creates a new account using values previously set using setNew* functions
@ -188,6 +199,9 @@ public class LinphonePreferences {
String route = tempOutboundProxy ? tempProxy : null; String route = tempOutboundProxy ? tempProxy : null;
LinphoneProxyConfig prxCfg = LinphoneCoreFactory.instance().createProxyConfig(identity, proxy, route, true); LinphoneProxyConfig prxCfg = LinphoneCoreFactory.instance().createProxyConfig(identity, proxy, route, true);
if (tempContactsParams != null)
prxCfg.setContactParameters(tempContactsParams);
LinphoneAuthInfo authInfo = LinphoneCoreFactory.instance().createAuthInfo(tempUsername, tempUserId, tempPassword, null, null); LinphoneAuthInfo authInfo = LinphoneCoreFactory.instance().createAuthInfo(tempUsername, tempUserId, tempPassword, null, null);
getLc().addProxyConfig(prxCfg); getLc().addProxyConfig(prxCfg);
@ -202,6 +216,7 @@ public class LinphonePreferences {
tempDomain = null; tempDomain = null;
tempProxy = null; tempProxy = null;
tempOutboundProxy = false; tempOutboundProxy = false;
tempContactsParams = null;
} }
public void setNewAccountUsername(String username) { public void setNewAccountUsername(String username) {
@ -272,6 +287,10 @@ public class LinphonePreferences {
//TODO //TODO
} }
public void setNewAccountContactParameters(String contactParams) {
tempContactsParams = contactParams;
}
public boolean isAccountOutboundProxySet(int n) { public boolean isAccountOutboundProxySet(int n) {
return getProxyConfig(n).getRoute() != null; return getProxyConfig(n).getRoute() != null;
} }
@ -284,6 +303,9 @@ public class LinphonePreferences {
public int getDefaultAccountIndex() { public int getDefaultAccountIndex() {
LinphoneProxyConfig defaultPrxCfg = getLc().getDefaultProxyConfig(); LinphoneProxyConfig defaultPrxCfg = getLc().getDefaultProxyConfig();
if (defaultPrxCfg == null)
return 0;
LinphoneProxyConfig[] prxCfgs = getLc().getProxyConfigList(); LinphoneProxyConfig[] prxCfgs = getLc().getProxyConfigList();
for (int i = 0; i < prxCfgs.length; i++) { for (int i = 0; i < prxCfgs.length; i++) {
if (defaultPrxCfg.getIdentity().equals(prxCfgs[i].getIdentity())) { if (defaultPrxCfg.getIdentity().equals(prxCfgs[i].getIdentity())) {
@ -294,7 +316,7 @@ public class LinphonePreferences {
} }
public int getAccountCount() { public int getAccountCount() {
return getLc().getProxyConfigList().length; return Math.min(getLc().getProxyConfigList().length, getLc().getAuthInfosList().length);
} }
public void setAccountEnabled(int n, boolean disabled) { public void setAccountEnabled(int n, boolean disabled) {
@ -312,7 +334,12 @@ public class LinphonePreferences {
} }
public void deleteAccount(int n) { public void deleteAccount(int n) {
//TODO LinphoneProxyConfig proxyCfg = getProxyConfig(n);
if (proxyCfg != null)
getLc().removeProxyConfig(proxyCfg);
LinphoneAuthInfo authInfo = getAuthInfo(n);
if (authInfo != null)
getLc().removeAuthInfo(authInfo);
} }
// End of Accounts // End of Accounts
@ -413,29 +440,62 @@ public class LinphonePreferences {
} }
public void setIceEnabled(boolean enabled) { public void setIceEnabled(boolean enabled) {
//TODO if (enabled) {
getLc().setFirewallPolicy(FirewallPolicy.UseIce);
} else {
String stun = getStunServer();
if (stun != null && stun.length() > 0) {
getLc().setFirewallPolicy(FirewallPolicy.UseStun);
} else {
getLc().setFirewallPolicy(FirewallPolicy.NoFirewall);
}
}
} }
public boolean isIceEnabled() { public boolean isIceEnabled() {
return false; //TODO return getLc().getFirewallPolicy() == FirewallPolicy.UseIce;
} }
public void setUpnpEnabled(boolean enabled) { public void setUpnpEnabled(boolean enabled) {
//TODO if (enabled) {
if (isIceEnabled()) {
Log.e("Cannot have both ice and upnp enabled, disabling upnp");
} else {
getLc().setFirewallPolicy(FirewallPolicy.UseUpnp);
}
}
else {
String stun = getStunServer();
if (stun != null && stun.length() > 0) {
getLc().setFirewallPolicy(FirewallPolicy.UseStun);
} else {
getLc().setFirewallPolicy(FirewallPolicy.NoFirewall);
}
}
} }
public boolean isUpnpEnabled() { public boolean isUpnpEnabled() {
return false; //TODO return getLc().upnpAvailable() && getLc().getFirewallPolicy() == FirewallPolicy.UseUpnp;
} }
public void setPushNotificationEnabled(boolean b) { // Push Notifications
//TODO public void setPushNotificationEnabled(boolean enable) {
getConfig().setBool("app", "push_notification", enable);
} }
public boolean isPushNotificationEnabled() { public boolean isPushNotificationEnabled() {
return false; //TODO return getConfig().getBool("app", "push_notification", false);
} }
public void setPushNotificationRegistrationID(String regId) {
getConfig().setString("app", "push_notification_regid", regId);
}
public String getPushNotificationRegistrationID() {
return getConfig().getString("app", "push_notification_regid", null);
}
// End of Push Notifications
public void useRandomPort(boolean enabled) { public void useRandomPort(boolean enabled) {
//TODO //TODO
} }
@ -444,19 +504,19 @@ public class LinphonePreferences {
return false; //TODO return false; //TODO
} }
public void useIpv6(Boolean newValue) { public void useIpv6(Boolean enable) {
//TODO getLc().enableIpv6(enable);
} }
public boolean isUsingIpv6() { public boolean isUsingIpv6() {
return false; //TODO return false; //TODO
} }
public void setWifiOnlyEnabled(Boolean newValue) { public void setWifiOnlyEnabled(Boolean enable) {
//TODO getConfig().setBool("app", "wifi_only", enable);
} }
public boolean isWifiOnlyEnabled() { public boolean isWifiOnlyEnabled() {
return false; //TODO return getConfig().getBool("app", "wifi_only", false);
} }
} }

View file

@ -331,8 +331,19 @@ public class SettingsFragment extends PreferencesListFragment implements EcCalib
initializeTransportPreferences((ListPreference) findPreference(getString(R.string.pref_transport_key))); initializeTransportPreferences((ListPreference) findPreference(getString(R.string.pref_transport_key)));
((CheckBoxPreference) findPreference(getString(R.string.pref_wifi_only_key))).setChecked(mPrefs.isWifiOnlyEnabled()); ((CheckBoxPreference) findPreference(getString(R.string.pref_wifi_only_key))).setChecked(mPrefs.isWifiOnlyEnabled());
((CheckBoxPreference) findPreference(getString(R.string.pref_ice_enable_key))).setChecked(mPrefs.isIceEnabled());
((CheckBoxPreference) findPreference(getString(R.string.pref_upnp_enable_key))).setChecked(mPrefs.isUpnpEnabled()); // Disable UPnP if ICE si enabled, or disable ICE if UPnP is enabled
CheckBoxPreference ice = (CheckBoxPreference) findPreference(getString(R.string.pref_ice_enable_key));
CheckBoxPreference upnp = (CheckBoxPreference) findPreference(getString(R.string.pref_upnp_enable_key));
ice.setChecked(mPrefs.isIceEnabled());
if (mPrefs.isIceEnabled()) {
upnp.setEnabled(false);
} else {
upnp.setChecked(mPrefs.isUpnpEnabled());
if (mPrefs.isUpnpEnabled()) {
ice.setEnabled(false);
}
}
CheckBoxPreference randomPort = (CheckBoxPreference) findPreference(getString(R.string.pref_transport_use_random_ports_key)); CheckBoxPreference randomPort = (CheckBoxPreference) findPreference(getString(R.string.pref_transport_use_random_ports_key));
randomPort.setChecked(mPrefs.isUsingRandomPort()); randomPort.setChecked(mPrefs.isUsingRandomPort());
@ -372,6 +383,10 @@ public class SettingsFragment extends PreferencesListFragment implements EcCalib
findPreference(getString(R.string.pref_ice_enable_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() { findPreference(getString(R.string.pref_ice_enable_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
CheckBoxPreference upnp = (CheckBoxPreference) findPreference(getString(R.string.pref_upnp_enable_key));
boolean value = (Boolean) newValue;
upnp.setChecked(false);
upnp.setEnabled(!value);
mPrefs.setIceEnabled((Boolean) newValue); mPrefs.setIceEnabled((Boolean) newValue);
return true; return true;
} }
@ -380,7 +395,11 @@ public class SettingsFragment extends PreferencesListFragment implements EcCalib
findPreference(getString(R.string.pref_upnp_enable_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() { findPreference(getString(R.string.pref_upnp_enable_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.setUpnpEnabled((Boolean) newValue); CheckBoxPreference ice = (CheckBoxPreference) findPreference(getString(R.string.pref_ice_enable_key));
boolean value = (Boolean) newValue;
ice.setChecked(false);
ice.setEnabled(!value);
mPrefs.setUpnpEnabled(value);
return true; return true;
} }
}); });

View file

@ -302,6 +302,15 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
} }
} }
if (getResources().getBoolean(R.bool.enable_push_id)) {
String regId = mPrefs.getPushNotificationRegistrationID();
String appId = getString(R.string.push_sender_id);
if (regId != null && mPrefs.isPushNotificationEnabled()) {
String contactInfos = "app-id=" + appId + ";pn-type=google;pn-tok=" + regId + ";pn-msg-str=IM_MSG;pn-call-str=IC_MSG;pn-call-snd=ring.caf;pn-msg-snd=msg.caf";
mPrefs.setNewAccountContactParameters(contactInfos);
}
}
try { try {
mPrefs.saveNewAccount(); mPrefs.saveNewAccount();
accountCreated = true; accountCreated = true;

@ -1 +1 @@
Subproject commit c344f32c1e0db5da3d596f741a330dea28fc5639 Subproject commit bcd22f8a741f83a78631b547c71ead9d26d065bb