Merge branch 'dev_settings'

This commit is contained in:
Sylvain Berfini 2013-10-17 12:25:38 +02:00
commit 5a392adaf4
52 changed files with 2234 additions and 1830 deletions

View file

@ -68,7 +68,7 @@
<activity android:name="org.linphone.LinphoneActivity"
android:theme="@style/NoTitle"
android:screenOrientation="nosensor"
android:screenOrientation="behind"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View file

@ -42,7 +42,7 @@ 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

View file

@ -27,7 +27,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/black" />
android:textColor="@color/text_contrast" />
</LinearLayout>

View file

@ -27,7 +27,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/black" />
android:textColor="@color/text_contrast" />
</LinearLayout>

View file

@ -36,7 +36,7 @@
android:gravity="center"
android:paddingTop="50sp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:textColor="@color/text_contrast"
android:id="@+id/AboutText"/>
<Button android:id="@+id/exit"

View file

@ -27,7 +27,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/black" />
android:textColor="@color/text_contrast" />
</LinearLayout>

View file

@ -32,14 +32,14 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/black" />
android:textColor="@color/text_contrast" />
<TextView
android:id="@+id/contactAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/black" />
android:textColor="@color/text_contrast" />
</LinearLayout>
@ -58,7 +58,7 @@
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="13sp"
android:textColor="@android:color/black" />
android:textColor="@color/text_contrast" />
<TextView
android:id="@+id/date"
@ -67,7 +67,7 @@
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textSize="13sp"
android:textColor="@android:color/black" />
android:textColor="@color/text_contrast" />
<TextView
android:id="@+id/time"
@ -79,7 +79,7 @@
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textSize="13sp"
android:textColor="@android:color/black" />
android:textColor="@color/text_contrast" />
</RelativeLayout>

View file

@ -62,7 +62,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/black" />
android:textColor="@color/text_contrast" />
</LinearLayout>

View file

@ -31,7 +31,7 @@
android:gravity="center"
android:paddingTop="50sp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:textColor="@color/text_contrast"
android:id="@+id/AboutText"/>
<Button android:id="@+id/exit"

View file

@ -27,7 +27,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/black" />
android:textColor="@color/text_contrast" />
</LinearLayout>

View file

@ -63,7 +63,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/black"
android:textColor="@color/text_contrast"
android:layout_marginLeft="10dp" />
<TextView
@ -73,7 +73,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/black"
android:textColor="@color/text_contrast"
android:layout_marginLeft="5dp" />
</LinearLayout>

View file

@ -47,7 +47,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/black" />
android:textColor="@color/text_contrast" />
</LinearLayout>

View file

@ -42,7 +42,7 @@
android:layout_toRightOf="@id/icon"
android:layout_centerVertical="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/black"
android:textColor="@color/text_contrast"
android:layout_marginLeft="10dp" />
<ImageView

View file

@ -17,7 +17,7 @@
android:scrollHorizontally="true"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textColor="@android:color/black"
android:textColor="@color/text_contrast"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="left" />

View file

@ -77,7 +77,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/contact_last_name"
android:textColor="@android:color/black"
android:textColor="@color/text_contrast"
android:background="@drawable/chat_fast_address_background"
android:gravity="left"
android:paddingRight="5dp"
@ -89,7 +89,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/contact_first_name"
android:textColor="@android:color/black"
android:textColor="@color/text_contrast"
android:background="@drawable/chat_fast_address_background"
android:gravity="left"
android:paddingRight="5dp"

View file

@ -22,7 +22,7 @@
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/black"
android:textColor="@color/text_contrast"
android:layout_marginLeft="10dp" />
<ImageView

View file

@ -44,7 +44,7 @@
android:singleLine="true"
android:layout_weight="0.2"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/black"
android:textColor="@color/text_contrast"
android:layout_marginLeft="10dp" />
<ImageView

View file

@ -32,14 +32,14 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/black" />
android:textColor="@color/text_contrast" />
<TextView
android:id="@+id/contactAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/black" />
android:textColor="@color/text_contrast" />
</LinearLayout>
@ -57,7 +57,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textColor="@android:color/black" />
android:textColor="@color/text_contrast" />
<TextView
android:id="@+id/date"
@ -65,7 +65,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textColor="@android:color/black" />
android:textColor="@color/text_contrast" />
<TextView
android:id="@+id/time"
@ -76,7 +76,7 @@
android:layout_toRightOf="@id/callDirection"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textColor="@android:color/black" />
android:textColor="@color/text_contrast" />
</RelativeLayout>

View file

@ -21,7 +21,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/black"
android:textColor="@color/text_contrast"
android:layout_marginLeft="30dp"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/delete" />

View file

@ -0,0 +1,16 @@
[net]
download_bw=512
upload_bw=512
firewall_policy=0
[sip]
contact=sip:unknown@unknown-host
use_info=0
use_ipv6=0
keepalive_period=30000
[video]
size=qvga
[app]
sharing_server=https://www.linphone.org:444/upload.php

View file

@ -1,21 +1,11 @@
[net]
download_bw=512
upload_bw=512
firewall_policy=0
mtu=1300
[sip]
sip_port=5060
sip_random_port=1
guess_hostname=1
contact=sip:unknown@unknown-host
inc_timeout=15
use_info=0
use_ipv6=0
register_only_when_network_is_up=1
default_proxy=0
auto_net_state_mon=0
keepalive_period=30000
auto_answer_replacing_calls=1
media_encryption_mandatory=0
@ -34,8 +24,5 @@ remote_ring=/data/data/org.linphone/files/ringback.wav
local_ring=/data/data/org.linphone/files/oldphone_mono.wav
dtmf_player_amp=0.1
[video]
size=vga
[misc]
max_calls=10

View file

@ -0,0 +1,15 @@
[net]
download_bw=380
upload_bw=380
[sip]
contact=sip:unknown@unknown-host
use_info=0
use_ipv6=0
keepalive_period=30000
[video]
size=qvga
[app]
sharing_server=https://www.linphone.org:444/upload.php

View file

@ -1,20 +1,11 @@
[net]
download_bw=380
upload_bw=380
mtu=1300
[sip]
sip_port=5060
sip_random_port=1
guess_hostname=1
contact=sip:unknown@unknown-host
inc_timeout=15
use_info=0
use_ipv6=0
register_only_when_network_is_up=1
default_proxy=0
auto_net_state_mon=0
keepalive_period=30000
auto_answer_replacing_calls=1
media_encryption_mandatory=0
ping_with_options=0
@ -38,8 +29,5 @@ remote_ring=/data/data/org.linphone/files/ringback.wav
local_ring=/data/data/org.linphone/files/oldphone_mono.wav
dtmf_player_amp=0.1
[video]
size=qvga
[misc]
max_calls=10

View file

@ -101,7 +101,6 @@
<string name="pref_preferred_video_size_hd">HD</string>
<string name="pref_preferred_video_size_vga">VGA (640x480)</string>
<string name="pref_preferred_video_size_qvga">QVGA (320x240)</string>
<string name="pref_video_settings_title">Paramètres vidéo</string>
<string name="pref_video_automatically_share_my_video_title">Partager ma vidéo</string>
<string name="pref_video_automatically_accept_video_title">Accepter appels vidéo</string>
@ -372,6 +371,7 @@
<string name="call_state_incoming">Reçu</string>
<string name="pref_background_mode">Actif en arrière plan</string>
<string name="pref_manage">Gestion</string>
<string name="show_image">Afficher</string>
<string name="download_image">Télécharger</string>
@ -379,6 +379,7 @@
<string name="wait">Merci de patienter...</string>
<string name="importing_messages">Mise à jour de la base des messages</string>
<string name="default_account_flag">Compte par défaut</string>
<string name="zrtp_accept">Accepter</string>
<string name="zrtp_deny">Refuser</string>

View file

@ -118,7 +118,10 @@
<string name="pref_video_codec_mpeg4_title">MPEG4</string>
<string name="pref_video_codec_h264_title">H264</string>
<string name="pref_video_codecs_title">Кодеки</string>
<string name="pref_video_codecs_key">pref_video_codecs_key</string>
<string name="pref_preferred_video_size">Preferred video size</string>
<string name="pref_preferred_video_size_hd">HD</string>
<string name="pref_preferred_video_size_vga">VGA (640x480)</string>
<string name="pref_preferred_video_size_qvga">QVGA (320x240)</string>
<string name="menu_videocall_back_to_dialer_title">Показать клавиатуру</string>
<string name="menu_videocall_switch_camera_title">Лицевая/Задняя камера</string>
<string name="menu_videocall_change_resolution_when_low_resolution">Высокое разрешение</string>
@ -418,6 +421,22 @@
<string name="pref_background_mode">Фоновый режим</string>
<string name="show_image">Show</string>
<string name="download_image">Скачать</string>
<string name="download_image_failed">Ошибка скачивания. Проверьте ваше интернет соединение или попробуйте позже.</string>
<string name="pref_auth_userid">Auth userid</string>
<string name="pref_help_auth_userid">Enter authentication userid (optionnal)</string>
<string name="pref_upnp_enable">Enable UPNP</string>
<string name="pref_manage">Manage</string>
<string name="wait">Please wait...</string>
<string name="importing_messages">Updating messages database</string>
<string name="default_account_flag">Default account</string>
<string name="zrtp_accept">Accept</string>
<string name="zrtp_deny">Deny</string>
<string name="zrtp_help">You should only accept if you have the same code (see above) as your correspondent</string>
</resources>

View file

@ -25,4 +25,6 @@
<color name="transparent">#00000000</color>
<color name="landscape_background">#CCCCCC</color>
<color name="text_contrast">#ff000000</color> <!-- If background is white, set to black, else set to white -->
</resources>

View file

@ -8,6 +8,7 @@
<string name="push_sender_id">622464153529</string>
<string name="default_domain">sip.linphone.org</string>
<string name="default_stun">stun.linphone.org</string>
<bool name="override_domain_using_default_one">false</bool> <!-- Replace the domain for outgoing calls by the one above -->
<string name="wizard_url">https://www.linphone.org/wizard.php</string>

View file

@ -1,71 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="pref_tunnel_host_default"></string>
<string name="pref_tunnel_port_default">443</string>
<string name="default_tunnel_mode_entry_value">@string/tunnel_mode_entry_value_disabled</string>
<bool name="pref_echo_canceller_default">true</bool>
<!-- Audio codecs -->
<bool name="pref_codec_opus_default">true</bool>
<bool name="pref_codec_speex16_default">true</bool>
<bool name="pref_codec_speex8_default">true</bool>
<bool name="pref_codec_ilbc_default">true</bool>
<bool name="pref_codec_amr_default">false</bool>
<bool name="pref_codec_g729_default">true</bool>
<bool name="pref_codec_amrwb_default">false</bool>
<bool name="pref_codec_gsm_default">true</bool>
<bool name="pref_codec_g722_default">false</bool>
<bool name="pref_codec_silk24_default">false</bool>
<bool name="pref_codec_silk16_default">true</bool>
<bool name="pref_codec_silk8_default">false</bool>
<bool name="pref_codec_pcmu_default">true</bool>
<bool name="pref_codec_pcma_default">true</bool>
<!-- Video -->
<bool name="pref_video_enable_default">true</bool>
<bool name="pref_video_use_front_camera_default">true</bool>
<bool name="pref_video_initiate_call_with_video_default">true</bool>
<bool name="pref_video_automatically_share_my_video_default">true</bool>
<bool name="pref_video_automatically_accept_video_default">true</bool>
<!-- Preferred video size -->
<string name="pref_preferred_video_size_default">@string/pref_preferred_video_size_vga_key</string>
<!-- Video codecs -->
<bool name="pref_video_codec_vp8_default">true</bool>
<bool name="pref_video_codec_h264_default">false</bool>
<bool name="pref_video_codec_mpeg4_default">false</bool>
<bool name="pref_video_codec_h263_default">false</bool>
<!-- Network -->
<bool name="pref_wifi_only_default">false</bool>
<string name="default_stun">stun.linphone.org</string>
<bool name="pref_ice_enabled_default">false</bool>
<bool name="pref_upnp_enabled_default">false</bool>
<bool name="pref_transport_use_random_ports_default">true</bool>
<string name="pref_sip_port_default">5060</string>
<string name="pref_transport_default">@string/pref_transport_udp_key</string>
<string name="default_audio_port">7078</string>
<string name="default_video_port">9078</string>
<string name="pref_media_encryption_default">@string/pref_media_encryption_key_none</string>
<bool name="pref_push_notification_default">false</bool>
<bool name="pref_ipv6_default">false</bool>
<!-- Advanced -->
<bool name="pref_debug_default">false</bool>
<bool name="pref_animation_enable_default">false</bool>
<bool name="pref_autostart_default">false</bool>
<string name="pref_incoming_call_timeout_default">30</string>
<string name="pref_image_sharing_server_default">https://www.linphone.org:444/upload.php</string>
<string name="pref_remote_provisioning_default"></string>
<string name="pref_audio_use_specific_mode_default">0</string>
<string name="pref_expire_default">3600</string>
<string name="pref_display_name_default">Linphone Android</string>
<string name="pref_user_name_default">linphone.android</string>
<bool name="pref_auto_accept_friends_default">false</bool>
<bool name="pref_sipinfo_dtmf_default">false</bool>
<bool name="pref_rfc2833_dtmf_default">true</bool>
<bool name="pref_background_mode_default">true</bool>
</resources>

View file

@ -34,6 +34,7 @@
<string name="pref_sipaccounts_key">pref_sipaccounts_key</string>
<string name="setup_key">setup_key</string>
<string name="pref_video_key">pref_video_key</string>
<string name="pref_video_codecs_key">pref_video_codecs_key</string>
<string name="pref_linphone_friend_key">pref_linphone_friend_key</string>
<string name="pref_transport_key">pref_transport_key</string>
@ -121,4 +122,8 @@
<string name="pref_upnp_enable_key">pref_upnp_enable_key</string>
<string name="pref_first_time_linphone_chat_storage">pref_first_time_linphone_chat_storage</string>
<string name="pref_sipaccount_key">pref_sipaccount_key</string>
<string name="pref_advanced_key">pref_advanced_key</string>
<string name="pref_manage_key">pref_manage_key</string>
</resources>

View file

@ -118,7 +118,6 @@
<string name="pref_video_codec_mpeg4_title">MPEG4</string>
<string name="pref_video_codec_h264_title">H264</string>
<string name="pref_video_codecs_title">Codecs</string>
<string name="pref_video_codecs_key">pref_video_codecs_key</string>
<string name="pref_preferred_video_size">Preferred video size</string>
<string name="pref_preferred_video_size_hd">HD</string>
<string name="pref_preferred_video_size_vga">VGA (640x480)</string>
@ -426,14 +425,16 @@
<string name="download_image">Download</string>
<string name="download_image_failed">Download failed. Please check your internet access or try again later.</string>
<string name="pref_auth_userid">Auth userid*</string>
<string name="pref_auth_userid">Auth userid</string>
<string name="pref_help_auth_userid">Enter authentication userid (optionnal)</string>
<string name="pref_upnp_enable">Enable UPNP</string>
<string name="pref_manage">Manage</string>
<string name="wait">Please wait...</string>
<string name="importing_messages">Updating messages database</string>
<string name="default_account_flag">Default account</string>
<string name="zrtp_accept">Accept</string>
<string name="zrtp_deny">Deny</string>

View file

@ -2,7 +2,8 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="@string/pref_sipaccount">
android:title="@string/pref_sipaccount"
android:key="@string/pref_sipaccount_key">
<EditTextPreference
android:title="@string/pref_username"
@ -24,7 +25,8 @@
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_advanced">
android:title="@string/pref_advanced"
android:key="@string/pref_advanced_key">
<EditTextPreference
android:title="@string/pref_proxy"
@ -37,6 +39,25 @@
android:summary="@string/pref_help_outbound_proxy"
android:persistent="true"/>
<EditTextPreference
android:title="@string/pref_expire_title"
android:key="@string/pref_expire_key"
android:numeric="integer" />
<EditTextPreference
android:title="@string/pref_prefix"
android:key="@string/pref_prefix_key"/>
<CheckBoxPreference
android:title="@string/pref_escape_plus"
android:key="@string/pref_escape_plus_key"/>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/pref_manage"
android:key="@string/pref_manage_key">
<CheckBoxPreference
android:title="@string/pref_disable_account"
android:persistent="true"/>

View file

@ -14,25 +14,22 @@
android:key="@string/setup_key"/>
<PreferenceCategory
android:key="@string/pref_tunnel_key"
android:title="@string/pref_tunnel">
android:title="@string/pref_tunnel"
android:key="@string/pref_tunnel_key">
<EditTextPreference
android:title="@string/pref_tunnel_host"
android:key="@string/pref_tunnel_host_key"
android:defaultValue="@string/pref_tunnel_host_default"/>
android:key="@string/pref_tunnel_host_key"/>
<EditTextPreference
android:title="@string/pref_tunnel_port"
android:key="@string/pref_tunnel_port_key"
android:defaultValue="@string/pref_tunnel_port_default"/>
android:key="@string/pref_tunnel_port_key"/>
<ListPreference
android:title="@string/pref_tunnel_mode"
android:key="@string/pref_tunnel_mode_key"
android:entries="@array/tunnel_mode_entries"
android:entryValues="@array/tunnel_mode_entry_values"
android:defaultValue="@string/default_tunnel_mode_entry_value"
android:key="@string/pref_tunnel_mode_key" />
android:entryValues="@array/tunnel_mode_entry_values"/>
</PreferenceCategory>
@ -40,7 +37,6 @@
android:title="@string/pref_preferences">
<CheckBoxPreference
android:defaultValue="@bool/pref_video_enable_default"
android:title="@string/pref_video_enable_title"
android:key="@string/pref_video_enable_key"/>
@ -48,178 +44,73 @@
android:title="@string/pref_audio">
<CheckBoxPreference
android:key="@string/pref_echo_cancellation_key"
android:defaultValue="@bool/pref_echo_canceller_default"
android:title="@string/pref_echo_cancellation"
android:key="@string/pref_echo_cancellation_key"
android:summary="@string/pref_echo_cancellation_summary"/>
<Preference
android:key="@string/pref_echo_canceller_calibration_key"
android:title="@string/pref_echo_canceller_calibration" />
android:title="@string/pref_echo_canceller_calibration"
android:key="@string/pref_echo_canceller_calibration_key"/>
<PreferenceCategory
android:title="@string/pref_codecs"
android:key="@string/pref_codecs_key">
<CheckBoxPreference
android:key="@string/pref_codec_opus_key"
android:defaultValue="@bool/pref_codec_opus_default"
android:title="@string/pref_codec_opus"/><CheckBoxPreference
android:key="@string/pref_codec_speex16_key"
android:defaultValue="@bool/pref_codec_speex16_default"
android:title="@string/pref_codec_speex16"/>
<CheckBoxPreference
android:key="@string/pref_codec_speex8_key"
android:defaultValue="@bool/pref_codec_speex8_default"
android:title="@string/pref_codec_speex8"/>
<CheckBoxPreference
android:key="@string/pref_codec_ilbc_key"
android:title="@string/pref_codec_ilbc"
android:defaultValue="@bool/pref_codec_ilbc_default"
android:summary="@string/pref_ilbc_summary"/>
<CheckBoxPreference
android:key="@string/pref_codec_amr_key"
android:title="@string/pref_codec_amr"
android:defaultValue="@bool/pref_codec_amr_default" />
<CheckBoxPreference
android:key="@string/pref_codec_g729_key"
android:title="@string/pref_codec_g729"
android:defaultValue="@bool/pref_codec_g729_default" />
<CheckBoxPreference
android:key="@string/pref_codec_amrwb_key"
android:title="@string/pref_codec_amrwb"
android:defaultValue="@bool/pref_codec_amrwb_default" />
<CheckBoxPreference
android:key="@string/pref_codec_gsm_key"
android:defaultValue="@bool/pref_codec_gsm_default"
android:title="@string/pref_codec_gsm"/>
<CheckBoxPreference
android:key="@string/pref_codec_g722_key"
android:defaultValue="@bool/pref_codec_g722_default"
android:title="@string/pref_codec_g722"/>
<CheckBoxPreference
android:key="@string/pref_codec_silk8_key"
android:defaultValue="@bool/pref_codec_silk8_default"
android:title="@string/pref_codec_silk8"/>
<CheckBoxPreference
android:key="@string/pref_codec_silk16_key"
android:defaultValue="@bool/pref_codec_silk16_default"
android:title="@string/pref_codec_silk16"/>
<CheckBoxPreference
android:key="@string/pref_codec_pcmu_key"
android:defaultValue="@bool/pref_codec_pcmu_default"
android:title="@string/pref_codec_pcmu"/>
<CheckBoxPreference
android:key="@string/pref_codec_pcma_key"
android:defaultValue="@bool/pref_codec_pcma_default"
android:title="@string/pref_codec_pcma"/>
</PreferenceCategory>
android:key="@string/pref_codecs_key"/>
</PreferenceScreen>
<PreferenceScreen
android:title="@string/pref_video"
android:dependency="@string/pref_video_enable_key"
android:key="@string/pref_video_key"
android:dependency="@string/pref_video_enable_key"
android:shouldDisableView="true">
<CheckBoxPreference
android:key="@string/pref_video_use_front_camera_key"
android:defaultValue="@bool/pref_video_use_front_camera_default"
android:title="@string/pref_video_use_front_camera_title"
android:key="@string/pref_video_use_front_camera_key"
android:dependency="@string/pref_video_enable_key"
android:layout="@layout/hidden"/>
<CheckBoxPreference
android:key="@string/pref_video_initiate_call_with_video_key"
android:defaultValue="@bool/pref_video_initiate_call_with_video_default"
android:title="@string/pref_video_initiate_call_with_video_title"
android:key="@string/pref_video_initiate_call_with_video_key"
android:summary="@string/pref_video_initiate_call_with_video"
android:dependency="@string/pref_video_enable_key"/>
<CheckBoxPreference
android:key="@string/pref_video_automatically_share_my_video_key"
android:title="@string/pref_video_automatically_share_my_video_title"
android:defaultValue="@bool/pref_video_automatically_share_my_video_default"
android:key="@string/pref_video_automatically_share_my_video_key"
android:summary="@string/pref_video_automatically_share_my_video"
android:dependency="@string/pref_video_enable_key"
android:layout="@layout/hidden"/>
<CheckBoxPreference
android:key="@string/pref_video_automatically_accept_video_key"
android:title="@string/pref_video_automatically_accept_video_title"
android:defaultValue="@bool/pref_video_automatically_accept_video_default"
android:key="@string/pref_video_automatically_accept_video_key"
android:summary="@string/pref_video_automatically_accept_video"
android:dependency="@string/pref_video_enable_key"/>
<ListPreference
android:title="@string/pref_preferred_video_size"
android:key="@string/pref_preferred_video_size_key"
android:defaultValue="@string/pref_preferred_video_size_default" />
android:key="@string/pref_preferred_video_size_key"/>
<PreferenceCategory
android:dependency="@string/pref_video_enable_key"
android:shouldDisableView="true"
android:title="@string/pref_video_codecs_title"
android:key="@string/pref_video_codecs_key"
android:title="@string/pref_video_codecs_title">
<CheckBoxPreference
android:key="@string/pref_video_codec_vp8_key"
android:title="@string/pref_video_codec_vp8_title"
android:defaultValue="@bool/pref_video_codec_vp8_default"/>
<CheckBoxPreference
android:key="@string/pref_video_codec_h264_key"
android:title="@string/pref_video_codec_h264_title"
android:defaultValue="@bool/pref_video_codec_h264_default"/>
<CheckBoxPreference
android:key="@string/pref_video_codec_mpeg4_key"
android:title="@string/pref_video_codec_mpeg4_title"
android:defaultValue="@bool/pref_video_codec_mpeg4_default"/>
<CheckBoxPreference
android:key="@string/pref_video_codec_h263_key"
android:title="@string/pref_video_codec_h263_title"
android:defaultValue="@bool/pref_video_codec_h263_default"
android:layout="@layout/hidden"/>
</PreferenceCategory>
android:dependency="@string/pref_video_enable_key"
android:shouldDisableView="true"/>
</PreferenceScreen>
<PreferenceScreen
android:title="@string/call">
<EditTextPreference
android:title="@string/pref_prefix"
android:key="@string/pref_prefix_key"/>
<CheckBoxPreference
android:title="@string/pref_sipinfo_dtmf"
android:key="@string/pref_sipinfo_dtmf_key"/>
<CheckBoxPreference
android:key="@string/pref_escape_plus_key"
android:title="@string/pref_escape_plus"/>
<CheckBoxPreference
android:key="@string/pref_sipinfo_dtmf_key"
android:defaultValue="@bool/pref_sipinfo_dtmf_default"
android:title="@string/pref_sipinfo_dtmf"/>
<CheckBoxPreference
android:key="@string/pref_rfc2833_dtmf_key"
android:defaultValue="@bool/pref_rfc2833_dtmf_default"
android:title="@string/pref_rfc2833_dtmf"/>
android:title="@string/pref_rfc2833_dtmf"
android:key="@string/pref_rfc2833_dtmf_key"/>
</PreferenceScreen>
@ -227,69 +118,57 @@
android:title="@string/pref_network_title">
<CheckBoxPreference
android:key="@string/pref_wifi_only_key"
android:title="@string/pref_wifi_only"
android:defaultValue="@bool/pref_wifi_only_default"/>
android:key="@string/pref_wifi_only_key"/>
<EditTextPreference
android:title="@string/pref_stun_server"
android:defaultValue="@string/default_stun"
android:key="@string/pref_stun_server_key"/>
<CheckBoxPreference
android:title="@string/pref_ice_enable"
android:key="@string/pref_ice_enable_key"
android:defaultValue="@bool/pref_ice_enabled_default"/>
android:key="@string/pref_ice_enable_key"/>
<CheckBoxPreference
android:title="@string/pref_upnp_enable"
android:key="@string/pref_upnp_enable_key"
android:defaultValue="@bool/pref_upnp_enabled_default"/>
android:key="@string/pref_upnp_enable_key"/>
<CheckBoxPreference
android:key="@string/pref_transport_use_random_ports_key"
android:title="@string/pref_transport_use_random_ports"
android:defaultValue="@bool/pref_transport_use_random_ports_default"/>
android:key="@string/pref_transport_use_random_ports_key"/>
<EditTextPreference
android:key="@string/pref_sip_port_key"
android:title="@string/pref_sip_port_title"
android:defaultValue="@string/pref_sip_port_default"
android:key="@string/pref_sip_port_key"
android:numeric="integer"/>
<EditTextPreference
android:key="@string/pref_audio_port_key"
android:title="@string/pref_audio_port_title"
android:key="@string/pref_audio_port_key"
android:summary="@string/pref_audio_port_description"
android:defaultValue="@string/default_audio_port"
android:layout="@layout/hidden"/>
<EditTextPreference
android:key="@string/pref_video_port_key"
android:title="@string/pref_video_port_title"
android:defaultValue="@string/default_video_port"
android:key="@string/pref_video_port_key"
android:summary="@string/pref_video_port_description"
android:layout="@layout/hidden"/>
<ListPreference
android:title="@string/pref_transport"
android:key="@string/pref_transport_key"
android:defaultValue="@string/pref_transport_default" />
android:key="@string/pref_transport_key"/>
<ListPreference
android:title="@string/pref_media_encryption"
android:key="@string/pref_media_encryption_key"
android:defaultValue="@string/pref_media_encryption_default" />
android:key="@string/pref_media_encryption_key"/>
<CheckBoxPreference
android:key="@string/pref_push_notification_key"
android:title="@string/pref_push_notification"
android:defaultValue="@bool/pref_push_notification_default"/>
android:key="@string/pref_push_notification_key"/>
<CheckBoxPreference
android:key="@string/pref_ipv6_key"
android:title="@string/pref_ipv6_title"
android:defaultValue="@bool/pref_ipv6_default" />
android:key="@string/pref_ipv6_key"/>
</PreferenceScreen>
@ -297,58 +176,43 @@
android:title="@string/pref_advanced">
<CheckBoxPreference
android:key="@string/pref_debug_key"
android:title="@string/pref_debug"
android:defaultValue="@bool/pref_debug_default"/>
android:key="@string/pref_debug_key"/>
<CheckBoxPreference
android:key="@string/pref_background_mode_key"
android:title="@string/pref_background_mode"
android:defaultValue="@bool/pref_background_mode_default"/>
android:key="@string/pref_background_mode_key"/>
<CheckBoxPreference
android:defaultValue="@bool/pref_animation_enable_default"
android:title="@string/pref_animation_enable_title"
android:key="@string/pref_animation_enable_key"/>
<CheckBoxPreference
android:title="@string/pref_autostart"
android:key="@string/pref_autostart_key"
android:defaultValue="@bool/pref_autostart_default"/>
android:key="@string/pref_autostart_key"/>
<EditTextPreference
android:key="@string/pref_incoming_call_timeout_key"
android:title="@string/pref_incoming_call_timeout_title"
android:defaultValue="@string/pref_incoming_call_timeout_default"
android:key="@string/pref_incoming_call_timeout_key"
android:layout="@layout/hidden"/>
<EditTextPreference
android:key="@string/pref_expire_key"
android:title="@string/pref_expire_title"
android:defaultValue="@string/pref_expire_default"
android:numeric="integer" />
<EditTextPreference
android:key="@string/pref_image_sharing_server_key"
android:title="@string/pref_image_sharing_server_title"
android:defaultValue="@string/pref_image_sharing_server_default" />
android:key="@string/pref_image_sharing_server_key"/>
<EditTextPreference
android:key="@string/pref_remote_provisioning_key"
android:title="@string/pref_remote_provisioning_title"
android:defaultValue="@string/pref_remote_provisioning_default" />
android:key="@string/pref_remote_provisioning_key"/>
<PreferenceCategory
android:title="@string/pref_primary_account_title">
<EditTextPreference
android:title="@string/pref_display_name_title"
android:defaultValue="@string/pref_display_name_default"
android:key="@string/pref_display_name_key"/>
<EditTextPreference
android:title="@string/pref_user_name_title"
android:defaultValue="@string/pref_user_name_default"
android:key="@string/pref_user_name_key"/>
</PreferenceCategory>
@ -358,18 +222,17 @@
android:layout="@layout/hidden">
<CheckBoxPreference
android:key="@string/pref_audio_hacks_use_routing_api_key"
android:title="@string/pref_audio_hacks_use_routing_api_title" />
android:title="@string/pref_audio_hacks_use_routing_api_title"
android:key="@string/pref_audio_hacks_use_routing_api_key"/>
<CheckBoxPreference
android:key="@string/pref_audio_hacks_use_galaxys_hack_key"
android:title="@string/pref_audio_hacks_use_galaxys_hack_title" />
android:title="@string/pref_audio_hacks_use_galaxys_hack_title"
android:key="@string/pref_audio_hacks_use_galaxys_hack_key"/>
<EditTextPreference
android:key="@string/pref_audio_use_specific_mode_key"
android:title="@string/pref_audio_use_specific_mode_title"
android:key="@string/pref_audio_use_specific_mode_key"
android:summary="@string/pref_audio_use_specific_mode_summary"
android:defaultValue="@string/pref_audio_use_specific_mode_default"
android:numeric="integer" />
</PreferenceScreen>
@ -383,10 +246,9 @@
android:key="@string/pref_linphone_friend_key">
<CheckBoxPreference
android:key="@string/pref_auto_accept_friends_key"
android:title="@string/pref_auto_accept_friends_title"
android:summary="@string/pref_auto_accept_friends_desc"
android:defaultValue="@bool/pref_auto_accept_friends_default"/>
android:key="@string/pref_auto_accept_friends_key"
android:summary="@string/pref_auto_accept_friends_desc"/>
</PreferenceCategory>

View file

@ -18,11 +18,10 @@ 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.compatibility.Compatibility;
import org.linphone.ui.PreferencesListFragment;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
@ -36,10 +35,17 @@ import android.text.InputType;
*/
public class AccountPreferencesFragment extends PreferencesListFragment {
private int n;
private String key;
private LinphonePreferences mPrefs;
public AccountPreferencesFragment() {
super(R.xml.account_preferences);
mPrefs = LinphonePreferences.instance();
}
@Override
public void onDestroy() {
LinphoneManager.getLc().refreshRegisters();
super.onDestroy();
}
public void onCreate(Bundle savedInstanceState)
@ -48,154 +54,175 @@ public class AccountPreferencesFragment extends PreferencesListFragment {
PreferenceScreen screen = getPreferenceScreen();
n = getArguments().getInt("Account", 0);
key = getAccountNumber(n);
manageAccountPreferencesFields(screen);
}
OnPreferenceChangeListener preferenceChangedListener = new OnPreferenceChangeListener() {
OnPreferenceChangeListener usernameChangedListener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.setAccountUsername(n, newValue.toString());
preference.setSummary(newValue.toString());
return true;
}
};
OnPreferenceChangeListener useridChangedListener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.setAccountUserId(n, newValue.toString());
preference.setSummary(newValue.toString());
return true;
}
};
OnPreferenceChangeListener passwordChangedListener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.setAccountPassword(n, newValue.toString());
return true;
}
};
OnPreferenceChangeListener domainChangedListener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.setAccountDomain(n, newValue.toString());
preference.setSummary(newValue.toString());
return true;
}
};
OnPreferenceChangeListener proxyChangedListener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.setAccountProxy(n, newValue.toString());
preference.setSummary(newValue.toString());
return true;
}
};
OnPreferenceChangeListener outboundProxyChangedListener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.setAccountOutboundProxyEnabled(n, (Boolean) newValue);
return true;
}
};
OnPreferenceChangeListener expiresChangedListener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.setExpires(n, newValue.toString());
preference.setSummary(newValue.toString());
return true;
}
};
OnPreferenceChangeListener prefixChangedListener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String value = newValue.toString();
preference.setSummary(value);
mPrefs.setPrefix(n, value);
return true;
}
};
OnPreferenceChangeListener escapeChangedListener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean value = (Boolean) newValue;
mPrefs.setReplacePlusByZeroZero(n, value);
return true;
}
};
OnPreferenceChangeListener disableChangedListener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.setAccountEnabled(n, (Boolean) newValue);
return true;
}
};
OnPreferenceChangeListener deleteChangedListener = new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
return true;
}
};
private void manageAccountPreferencesFields(PreferenceScreen parent) {
final SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
boolean isDefaultAccount = mPrefs.getDefaultAccountIndex() == n;
PreferenceCategory account = (PreferenceCategory) getPreferenceScreen().getPreference(0);
PreferenceCategory account = (PreferenceCategory) getPreferenceScreen().findPreference(getString(R.string.pref_sipaccount_key));
EditTextPreference username = (EditTextPreference) account.getPreference(0);
username.setText(prefs.getString(getString(R.string.pref_username_key) + key, ""));
username.setText(mPrefs.getAccountUsername(n));
username.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
username.setKey(getString(R.string.pref_username_key) + key);
username.setOnPreferenceChangeListener(preferenceChangedListener);
username.setOnPreferenceChangeListener(usernameChangedListener);
username.setSummary(username.getText());
EditTextPreference userid = (EditTextPreference) account.getPreference(1);
userid.setText(prefs.getString(getString(R.string.pref_auth_userid_key) + key, ""));
userid.setText(mPrefs.getAccountUserId(n));
userid.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
userid.setKey(getString(R.string.pref_auth_userid_key) + key);
userid.setOnPreferenceChangeListener(preferenceChangedListener);
userid.setOnPreferenceChangeListener(useridChangedListener);
userid.setSummary(userid.getText());
EditTextPreference password = (EditTextPreference) account.getPreference(2);
password.setText(prefs.getString(getString(R.string.pref_passwd_key) + key, ""));
password.setText(mPrefs.getAccountPassword(n));
password.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
password.setKey(getString(R.string.pref_passwd_key) + key);
password.setOnPreferenceChangeListener(passwordChangedListener);
EditTextPreference domain = (EditTextPreference) account.getPreference(3);
domain.setText(prefs.getString(getString(R.string.pref_domain_key) + key, ""));
domain.setText(mPrefs.getAccountDomain(n));
domain.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
domain.setKey(getString(R.string.pref_domain_key) + key);
domain.setOnPreferenceChangeListener(preferenceChangedListener);
domain.setOnPreferenceChangeListener(domainChangedListener);
domain.setSummary(domain.getText());
PreferenceCategory advanced = (PreferenceCategory) getPreferenceScreen().getPreference(1);
PreferenceCategory advanced = (PreferenceCategory) getPreferenceScreen().findPreference(getString(R.string.pref_advanced_key));
EditTextPreference proxy = (EditTextPreference) advanced.getPreference(0);
proxy.setText(prefs.getString(getString(R.string.pref_proxy_key) + key, ""));
proxy.setText(mPrefs.getAccountProxy(n));
proxy.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
proxy.setKey(getString(R.string.pref_proxy_key) + key);
proxy.setOnPreferenceChangeListener(preferenceChangedListener);
proxy.setOnPreferenceChangeListener(proxyChangedListener);
proxy.setSummary("".equals(proxy.getText()) || (proxy.getText() == null) ? getString(R.string.pref_help_proxy) : proxy.getText());
Preference outboundProxy = advanced.getPreference(1);
Compatibility.setPreferenceChecked(outboundProxy, prefs.getBoolean(getString(R.string.pref_enable_outbound_proxy_key) + key, false));
outboundProxy.setKey(getString(R.string.pref_enable_outbound_proxy_key) + key);
CheckBoxPreference outboundProxy = (CheckBoxPreference) advanced.getPreference(1);
outboundProxy.setChecked(mPrefs.isAccountOutboundProxySet(n));
outboundProxy.setOnPreferenceChangeListener(outboundProxyChangedListener);
final Preference disable = advanced.getPreference(2);
EditTextPreference expires = (EditTextPreference) advanced.getPreference(2);
expires.setText(mPrefs.getExpires(n));
expires.setOnPreferenceChangeListener(expiresChangedListener);
expires.setSummary(mPrefs.getExpires(n));
EditTextPreference prefix = (EditTextPreference) advanced.getPreference(3);
String prefixValue = mPrefs.getPrefix(n);
prefix.setSummary(prefixValue);
prefix.setText(prefixValue);
prefix.setOnPreferenceChangeListener(prefixChangedListener);
CheckBoxPreference escape = (CheckBoxPreference) advanced.getPreference(4);
escape.setChecked(mPrefs.getReplacePlusByZeroZero(n));
escape.setOnPreferenceChangeListener(escapeChangedListener);
PreferenceCategory manage = (PreferenceCategory) getPreferenceScreen().findPreference(getString(R.string.pref_manage_key));
final CheckBoxPreference disable = (CheckBoxPreference) manage.getPreference(0);
disable.setEnabled(true);
Compatibility.setPreferenceChecked(disable, prefs.getBoolean(getString(R.string.pref_disable_account_key) + key, false));
disable.setKey(getString(R.string.pref_disable_account_key) + key);
disable.setChecked(!mPrefs.isAccountEnabled(n));
disable.setOnPreferenceChangeListener(disableChangedListener);
final Preference delete = advanced.getPreference(4);
delete.setEnabled(true);
delete.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
int nbAccounts = prefs.getInt(getString(R.string.pref_extra_accounts), 1);
SharedPreferences.Editor editor = prefs.edit();
for (int i = n; i < nbAccounts - 1; i++) {
editor.putString(getString(R.string.pref_username_key) + getAccountNumber(i), prefs.getString(getString(R.string.pref_username_key) + getAccountNumber(i+1), null));
editor.putString(getString(R.string.pref_auth_userid_key) + getAccountNumber(i), prefs.getString(getString(R.string.pref_auth_userid_key) + getAccountNumber(i+1), null));
editor.putString(getString(R.string.pref_passwd_key) + getAccountNumber(i), prefs.getString(getString(R.string.pref_passwd_key) + getAccountNumber(i+1), null));
editor.putString(getString(R.string.pref_domain_key) + getAccountNumber(i), prefs.getString(getString(R.string.pref_domain_key) + getAccountNumber(i+1), null));
editor.putString(getString(R.string.pref_proxy_key) + getAccountNumber(i), prefs.getString(getString(R.string.pref_proxy_key) + getAccountNumber(i+1), null));
editor.putBoolean(getString(R.string.pref_enable_outbound_proxy_key) + getAccountNumber(i), prefs.getBoolean(getString(R.string.pref_enable_outbound_proxy_key) + getAccountNumber(i+1), false));
editor.putBoolean(getString(R.string.pref_disable_account_key) + getAccountNumber(i), prefs.getBoolean(getString(R.string.pref_disable_account_key) + getAccountNumber(i+1), false));
}
if (n != 0) {
int lastAccount = nbAccounts - 1;
editor.putString(getString(R.string.pref_username_key) + getAccountNumber(lastAccount), null);
editor.putString(getString(R.string.pref_passwd_key) + getAccountNumber(lastAccount), null);
editor.putString(getString(R.string.pref_domain_key) + getAccountNumber(lastAccount), null);
editor.putString(getString(R.string.pref_proxy_key) + getAccountNumber(lastAccount), null);
editor.putBoolean(getString(R.string.pref_enable_outbound_proxy_key) + getAccountNumber(lastAccount), false);
editor.putBoolean(getString(R.string.pref_disable_account_key) + getAccountNumber(lastAccount), false);
int defaultAccount = prefs.getInt(getString(R.string.pref_default_account_key), 0);
if (defaultAccount > n) {
editor.putInt(getString(R.string.pref_default_account_key), defaultAccount - 1);
}
editor.putInt(getString(R.string.pref_extra_accounts), nbAccounts - 1);
} else if (n == 0 && nbAccounts <= 1) {
editor.putString(getString(R.string.pref_username_key), "");
editor.putString(getString(R.string.pref_passwd_key), "");
editor.putString(getString(R.string.pref_domain_key), "");
} else {
editor.putInt(getString(R.string.pref_extra_accounts), nbAccounts - 1);
}
editor.commit();
LinphoneActivity.instance().displaySettings();
return true;
}
});
Preference mainAccount = advanced.getPreference(3);
Compatibility.setPreferenceChecked(mainAccount, prefs.getInt(getString(R.string.pref_default_account_key), 0) == n);
mainAccount.setEnabled(!Compatibility.isPreferenceChecked(mainAccount));
CheckBoxPreference mainAccount = (CheckBoxPreference) manage.getPreference(1);
mainAccount.setChecked(isDefaultAccount);
mainAccount.setEnabled(!mainAccount.isChecked());
mainAccount.setOnPreferenceClickListener(new OnPreferenceClickListener()
{
public boolean onPreferenceClick(Preference preference) {
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(getString(R.string.pref_default_account_key), n);
editor.commit();
mPrefs.setDefaultAccount(n);
disable.setEnabled(false);
Compatibility.setPreferenceChecked(disable, false);
disable.setChecked(false);
preference.setEnabled(false);
return true;
}
});
}
private String getAccountNumber(int n) {
if (n > 0)
return Integer.toString(n);
else
return "";
}
@Override
public void onPause() {
super.onPause();
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
int n = prefs.getInt(getString(R.string.pref_extra_accounts), 1);
String keyUsername = getString(R.string.pref_username_key) + getAccountNumber(n-1);
if (prefs.getString(keyUsername, "").equals("")) {
//If not, we suppress it to not display a blank field
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(getString(R.string.pref_extra_accounts), n-1);
editor.commit();
}
if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().applyConfigChangesIfNeeded();
final Preference delete = manage.getPreference(2);
delete.setEnabled(true);
delete.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
mPrefs.deleteAccount(n);
LinphoneActivity.instance().displaySettings();
return true;
}
});
}
}

View file

@ -21,14 +21,13 @@ package org.linphone;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.preference.PreferenceManager;
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(context.getString(R.string.pref_autostart_key), false)) {
if (LinphonePreferences.instance().isAutoStartEnabled()) {
Intent lLinphoneServiceIntent = new Intent(Intent.ACTION_MAIN);
lLinphoneServiceIntent.setClass(context, LinphoneService.class);
context.startService(lLinphoneServiceIntent);;

View file

@ -48,7 +48,6 @@ import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
@ -61,7 +60,6 @@ import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Parcelable;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.support.v4.content.CursorLoader;
@ -194,8 +192,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
}
displayChat(displayName, pictureUri);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(LinphoneActivity.instance());
uploadServerUri = prefs.getString(getString(R.string.pref_image_sharing_server_key), getString(R.string.pref_image_sharing_server_default));
uploadServerUri = LinphonePreferences.instance().getSharingPictureServerUrl();
textWatcher = new TextWatcher() {
public void afterTextChanged(Editable arg0) {

View file

@ -37,7 +37,6 @@ import org.linphone.ui.Numpad;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.net.Uri;
@ -45,7 +44,6 @@ import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
@ -127,8 +125,7 @@ public class InCallActivity extends FragmentActivity implements
isTransferAllowed = getApplicationContext().getResources().getBoolean(R.bool.allow_transfers);
showCallListInVideo = getApplicationContext().getResources().getBoolean(R.bool.show_current_calls_above_video);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
isAnimationDisabled = getApplicationContext().getResources().getBoolean(R.bool.disable_animations) || !prefs.getBoolean(getString(R.string.pref_animation_enable_key), false);
isAnimationDisabled = getApplicationContext().getResources().getBoolean(R.bool.disable_animations) || !LinphonePreferences.instance().areAnimationsEnabled();
cameraNumber = AndroidCameraConfiguration.retrieveCameras().length;
if (findViewById(R.id.fragmentContainer) != null) {
@ -273,7 +270,7 @@ public class InCallActivity extends FragmentActivity implements
mHandler.post(new Runnable() {
@Override
public void run() {
if (!isVideoActivatedInSettings()) {
if (!LinphonePreferences.instance().isVideoEnabled()) {
video.setEnabled(false);
} else {
if (isVideoEnabled) {
@ -356,12 +353,6 @@ public class InCallActivity extends FragmentActivity implements
status = statusFragment;
}
private boolean isVideoActivatedInSettings() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean settingsVideoEnabled = prefs.getBoolean(getString(R.string.pref_video_enable_key), false);
return settingsVideoEnabled;
}
@Override
public void onClick(View v) {
int id = v.getId();
@ -1087,7 +1078,7 @@ public class InCallActivity extends FragmentActivity implements
if (state == State.CallUpdatedByRemote) {
// If the correspondent proposes video while audio call
boolean isVideoEnabled = LinphoneManager.getInstance().isVideoEnabled();
boolean isVideoEnabled = LinphonePreferences.instance().isVideoEnabled();
if (!isVideoEnabled) {
acceptCallUpdate(false);
return;
@ -1095,7 +1086,7 @@ public class InCallActivity extends FragmentActivity implements
boolean remoteVideo = call.getRemoteParams().getVideoEnabled();
boolean localVideo = call.getCurrentParamsCopy().getVideoEnabled();
boolean autoAcceptCameraPolicy = LinphoneManager.getInstance().isAutoAcceptCamera();
boolean autoAcceptCameraPolicy = LinphonePreferences.instance().shouldAutomaticallyAcceptVideoRequests();
if (remoteVideo && !localVideo && !autoAcceptCameraPolicy && !LinphoneManager.getLc().isInConference()) {
mHandler.post(new Runnable() {
public void run() {

View file

@ -156,7 +156,7 @@ public class IncomingCallActivity extends Activity implements LinphoneOnCallStat
private void answer() {
LinphoneCallParams params = LinphoneManager.getLc().createDefaultCallParameters();
if (mCall != null && mCall.getRemoteParams() != null && mCall.getRemoteParams().getVideoEnabled() && LinphoneManager.isInstanciated() && LinphoneManager.getInstance().isAutoAcceptCamera()) {
if (mCall != null && mCall.getRemoteParams() != null && mCall.getRemoteParams().getVideoEnabled() && LinphonePreferences.instance().shouldAutomaticallyAcceptVideoRequests()) {
params.setVideoEnabled(true);
} else {
params.setVideoEnabled(false);
@ -176,7 +176,7 @@ public class IncomingCallActivity extends Activity implements LinphoneOnCallStat
return;
}
final LinphoneCallParams remoteParams = mCall.getRemoteParams();
if (remoteParams != null && remoteParams.getVideoEnabled() && LinphoneManager.getInstance().isAutoAcceptCamera()) {
if (remoteParams != null && remoteParams.getVideoEnabled() && LinphonePreferences.instance().shouldAutomaticallyAcceptVideoRequests()) {
LinphoneActivity.instance().startVideoActivity(mCall);
} else {
LinphoneActivity.instance().startIncallActivity(mCall);

View file

@ -27,7 +27,6 @@ import java.util.Collection;
import java.util.List;
import org.linphone.LinphoneManager.AddressType;
import org.linphone.LinphoneManager.LinphoneConfigException;
import org.linphone.LinphoneSimpleListener.LinphoneOnCallStateChangedListener;
import org.linphone.LinphoneSimpleListener.LinphoneOnMessageReceivedListener;
import org.linphone.LinphoneSimpleListener.LinphoneOnRegistrationStateChangedListener;
@ -53,14 +52,12 @@ import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.Fragment.SavedState;
@ -104,6 +101,7 @@ public class LinphoneActivity extends FragmentActivity implements
private LinearLayout menu, mark;
private RelativeLayout contacts, history, settings, chat, aboutChat, aboutSettings;
private FragmentsAvailable currentFragment, nextFragment;
private List<FragmentsAvailable> fragmentsHistory;
private Fragment dialerFragment, messageListenerFragment, messageListFragment, friendStatusListenerFragment;
private SavedState dialerSavedState;
private boolean preferLinphoneContacts = false, isAnimationDisabled = false, isContactPresenceDisabled = true;
@ -139,10 +137,9 @@ public class LinphoneActivity extends FragmentActivity implements
}
boolean useFirstLoginActivity = getResources().getBoolean(R.bool.display_account_wizard_at_first_start);
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
if (useFirstLoginActivity && !pref.getBoolean(getString(R.string.first_launch_suceeded_once_key), false)) {
if (pref.getInt(getString(R.string.pref_extra_accounts), -1) > -1) {
pref.edit().putBoolean(getString(R.string.first_launch_suceeded_once_key), true);
if (useFirstLoginActivity && LinphonePreferences.instance().isFirstLaunch()) {
if (LinphonePreferences.instance().getAccountCount() > 0) {
LinphonePreferences.instance().firstLaunchSuccessful();
} else {
startActivityForResult(new Intent().setClass(this, SetupActivity.class), FIRST_LOGIN_ACTIVITY);
}
@ -150,9 +147,11 @@ public class LinphoneActivity extends FragmentActivity implements
setContentView(R.layout.main);
instance = this;
fragmentsHistory = new ArrayList<FragmentsAvailable>();
initButtons();
currentFragment = nextFragment = FragmentsAvailable.DIALER;
fragmentsHistory.add(currentFragment);
if (savedInstanceState == null) {
if (findViewById(R.id.fragmentContainer) != null) {
dialerFragment = new DialerFragment();
@ -289,7 +288,7 @@ public class LinphoneActivity extends FragmentActivity implements
dialerFragment = newFragment;
break;
case SETTINGS:
newFragment = new PreferencesFragment();
newFragment = new SettingsFragment();
break;
case ACCOUNT_SETTINGS:
newFragment = new AccountPreferencesFragment();
@ -320,8 +319,7 @@ public class LinphoneActivity extends FragmentActivity implements
}
private void updateAnimationsState() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
isAnimationDisabled = getResources().getBoolean(R.bool.disable_animations) || !prefs.getBoolean(getString(R.string.pref_animation_enable_key), false);
isAnimationDisabled = getResources().getBoolean(R.bool.disable_animations) || !LinphonePreferences.instance().areAnimationsEnabled();
isContactPresenceDisabled = !getResources().getBoolean(R.bool.enable_linphone_friends);
}
@ -427,6 +425,10 @@ public class LinphoneActivity extends FragmentActivity implements
getSupportFragmentManager().executePendingTransactions();
currentFragment = newFragmentType;
if (currentFragment == FragmentsAvailable.DIALER) {
fragmentsHistory.clear();
}
fragmentsHistory.add(currentFragment);
}
public void displayHistoryDetail(String sipUri, LinphoneCallLog log) {
@ -674,32 +676,10 @@ public class LinphoneActivity extends FragmentActivity implements
public void applyConfigChangesIfNeeded() {
if (nextFragment != FragmentsAvailable.SETTINGS && nextFragment != FragmentsAvailable.ACCOUNT_SETTINGS) {
reloadConfig();
updateAnimationsState();
}
}
private void reloadConfig() {
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc != null && (lc.isInComingInvitePending() || lc.isIncall())) {
Log.w("Call in progress => settings not applied");
return;
}
try {
LinphoneManager.getInstance().initFromConf();
lc.setVideoPolicy(LinphoneManager.getInstance().isAutoInitiateVideoCalls(), LinphoneManager.getInstance().isAutoAcceptCamera());
} catch (LinphoneException e) {
if (!(e instanceof LinphoneConfigException)) {
Log.e(e, "Cannot update config");
return;
}
LinphoneActivity.instance().showPreferenceErrorDialog(e.getMessage());
}
}
public void displayAccountSettings(int accountNumber) {
Bundle bundle = new Bundle();
bundle.putInt("Account", accountNumber);
@ -996,8 +976,7 @@ public class LinphoneActivity extends FragmentActivity implements
}
sipUri = sipUri.replace("<", "").replace(">", "");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (prefs.getBoolean(getString(R.string.pref_auto_accept_friends_key), false)) {
if (LinphonePreferences.instance().shouldAutomaticallyAcceptFriendsRequests()) {
Contact contact = findContactWithSipAddress(sipUri);
if (contact != null) {
friend.enableSubscribes(true);
@ -1364,7 +1343,7 @@ public class LinphoneActivity extends FragmentActivity implements
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (currentFragment == FragmentsAvailable.DIALER) {
boolean isBackgroundModeActive = PreferenceManager.getDefaultSharedPreferences(this).getBoolean(getString(R.string.pref_background_mode_key), getResources().getBoolean(R.bool.pref_background_mode_default));
boolean isBackgroundModeActive = LinphonePreferences.instance().isBackgroundModeEnabled();
if (!isBackgroundModeActive) {
stopService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class));
finish();
@ -1380,7 +1359,6 @@ public class LinphoneActivity extends FragmentActivity implements
if (currentFragment == FragmentsAvailable.SETTINGS) {
showStatusBar();
reloadConfig();
updateAnimationsState();
} else if (currentFragment == FragmentsAvailable.CHATLIST) {
//Hack to ensure display the status bar on some devices
@ -1388,9 +1366,28 @@ public class LinphoneActivity extends FragmentActivity implements
}
} else {
if (currentFragment == FragmentsAvailable.SETTINGS) {
reloadConfig();
updateAnimationsState();
}
fragmentsHistory.remove(fragmentsHistory.size() - 1);
if (fragmentsHistory.size() > 0) {
FragmentsAvailable newFragmentType = fragmentsHistory.get(fragmentsHistory.size() - 1);
LinearLayout ll = (LinearLayout) findViewById(R.id.fragmentContainer2);
if (newFragmentType.shouldAddItselfToTheRightOf(currentFragment)) {
ll.setVisibility(View.VISIBLE);
} else {
if (newFragmentType == FragmentsAvailable.DIALER
|| newFragmentType == FragmentsAvailable.ABOUT
|| newFragmentType == FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT
|| newFragmentType == FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS
|| newFragmentType == FragmentsAvailable.SETTINGS
|| newFragmentType == FragmentsAvailable.ACCOUNT_SETTINGS) {
ll.setVisibility(View.GONE);
} else {
ll.setVisibility(View.INVISIBLE);
}
}
}
}
}
} else if (keyCode == KeyEvent.KEYCODE_MENU && statusFragment != null) {

View file

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

View file

@ -21,12 +21,6 @@ package org.linphone;
import static android.media.AudioManager.MODE_RINGTONE;
import static android.media.AudioManager.STREAM_RING;
import static android.media.AudioManager.STREAM_VOICE_CALL;
import static org.linphone.R.string.pref_codec_amr_key;
import static org.linphone.R.string.pref_codec_amrwb_key;
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_video_enable_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;
@ -51,7 +45,6 @@ import org.linphone.LinphoneSimpleListener.LinphoneServiceListener;
import org.linphone.compatibility.Compatibility;
import org.linphone.core.CallDirection;
import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneAuthInfo;
import org.linphone.core.LinphoneCall;
import org.linphone.core.LinphoneCall.State;
import org.linphone.core.LinphoneCallParams;
@ -61,11 +54,8 @@ import org.linphone.core.LinphoneChatRoom;
import org.linphone.core.LinphoneContent;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCore.EcCalibratorStatus;
import org.linphone.core.LinphoneCore.FirewallPolicy;
import org.linphone.core.LinphoneCore.GlobalState;
import org.linphone.core.LinphoneCore.MediaEncryption;
import org.linphone.core.LinphoneCore.RegistrationState;
import org.linphone.core.LinphoneCore.Transports;
import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LinphoneCoreListener;
@ -96,7 +86,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.hardware.Sensor;
@ -142,16 +131,12 @@ public class LinphoneManager implements LinphoneCoreListener {
private Context mServiceContext;
private AudioManager mAudioManager;
private PowerManager mPowerManager;
private ConnectivityManager mConnectivityManager;
private SharedPreferences mPref;
private Resources mR;
private LinphonePreferences mPrefs;
private LinphoneCore mLc;
private static Transports initialTransports;
private static LinphonePreferenceManager sLPref;
private String lastLcStatusMessage;
private String basePath;
private static boolean sExited;
private String contactParams;
private boolean mAudioFocused;
private boolean isNetworkReachable;
@ -181,7 +166,7 @@ public class LinphoneManager implements LinphoneCoreListener {
mListenerDispatcher = new ListenerDispatcher(listener);
basePath = c.getFilesDir().getAbsolutePath();
mLPConfigXsd = basePath + "/lpconfig.xsd";
mLinphoneInitialConfigFile = basePath + "/linphonerc";
mLinphoneFactoryConfigFile = basePath + "/linphonerc";
mLinphoneConfigFile = basePath + "/.linphonerc";
mLinphoneRootCaFile = basePath + "/rootca.pem";
mRingSoundFile = basePath + "/oldphone_mono.wav";
@ -189,12 +174,10 @@ public class LinphoneManager implements LinphoneCoreListener {
mPauseSoundFile = basePath + "/toy_mono.wav";
mChatDatabaseFile = basePath + "/linphone-history.db";
sLPref = LinphonePreferenceManager.getInstance(c);
mPrefs = LinphonePreferences.instance();
mAudioManager = ((AudioManager) c.getSystemService(Context.AUDIO_SERVICE));
mVibrator = (Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE);
mPref = PreferenceManager.getDefaultSharedPreferences(c);
mPowerManager = (PowerManager) c.getSystemService(Context.POWER_SERVICE);
mConnectivityManager = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
mR = c.getResources();
}
@ -202,15 +185,15 @@ public class LinphoneManager implements LinphoneCoreListener {
private static final int dbStep = 4;
/** Called when the activity is first created. */
private final String mLPConfigXsd;
private final String mLinphoneInitialConfigFile;
private final String mLinphoneFactoryConfigFile;
private final String mLinphoneRootCaFile;
private final String mLinphoneConfigFile;
public final String mLinphoneConfigFile;
private final String mRingSoundFile;
private final String mRingbackSoundFile;
private final String mPauseSoundFile;
private final String mChatDatabaseFile;
private Timer mTimer = new Timer("Linphone scheduler");
private Timer mTimer;
private BroadcastReceiver mKeepAliveReceiver = new KeepAliveReceiver();
@ -414,9 +397,8 @@ public class LinphoneManager implements LinphoneCoreListener {
if (mLc.isNetworkReachable()) {
try {
if (Version.isVideoCapable()) {
boolean prefVideoEnable = isVideoEnabled();
int key = R.string.pref_video_initiate_call_with_video_key;
boolean prefInitiateWithVideo = getPrefBoolean(key, false);
boolean prefVideoEnable = mPrefs.isVideoEnabled();
boolean prefInitiateWithVideo = mPrefs.shouldInitiateVideoCall();
CallManager.getInstance().inviteAddress(lAddress, prefVideoEnable && prefInitiateWithVideo, isLowBandwidthConnection);
} else {
CallManager.getInstance().inviteAddress(lAddress, false, isLowBandwidthConnection);
@ -435,7 +417,7 @@ public class LinphoneManager implements LinphoneCoreListener {
}
private void resetCameraFromPreferences() {
boolean useFrontCam = getPrefBoolean(R.string.pref_video_use_front_camera_key, mR.getBoolean(R.bool.pref_video_use_front_camera_default));
boolean useFrontCam = mPrefs.useFrontCam();
int camId = 0;
AndroidCamera[] cameras = AndroidCameraConfiguration.retrieveCameras();
@ -469,6 +451,7 @@ public class LinphoneManager implements LinphoneCoreListener {
}
return false;
}
public void enableCamera(LinphoneCall call, boolean enable) {
if (call != null) {
call.enableCamera(enable);
@ -507,7 +490,7 @@ public class LinphoneManager implements LinphoneCoreListener {
return false;
}
String pref = getPrefString(R.string.pref_tunnel_mode_key, R.string.default_tunnel_mode_entry_value);
String pref = mPrefs.getTunnelMode();
if (getString(R.string.tunnel_mode_entry_value_always).equals(pref)) {
return true;
@ -532,7 +515,7 @@ public class LinphoneManager implements LinphoneCoreListener {
mLc.tunnelEnable(true);
} else {
Log.i("Tunnel should not be used");
String pref = getPrefString(R.string.pref_tunnel_mode_key, R.string.default_tunnel_mode_entry_value);
String pref = mPrefs.getTunnelMode();
mLc.tunnelEnable(false);
if (getString(R.string.tunnel_mode_entry_value_auto).equals(pref)) {
mLc.tunnelAutoDetect();
@ -544,18 +527,47 @@ public class LinphoneManager implements LinphoneCoreListener {
try {
copyAssetsFromPackage();
//traces alway start with traces enable to not missed first initialization
boolean isDebugLogEnabled = !(mR.getBoolean(R.bool.disable_every_log)) && getPrefBoolean(R.string.pref_debug_key, mR.getBoolean(R.bool.pref_debug_default));
boolean isDebugLogEnabled = !(mR.getBoolean(R.bool.disable_every_log));
LinphoneCoreFactory.instance().setDebugMode(isDebugLogEnabled, getString(R.string.app_name));
// Try to get remote provisioning
String remote_provisioning = (getPrefString(R.string.pref_remote_provisioning_key, mR.getString(R.string.pref_remote_provisioning_default)));
// First check if there is a remote provisioning url in the old preferences API
String remote_provisioning = mPrefs.getRemoteProvisioningUrl();
if(remote_provisioning != null && remote_provisioning.length() > 0 && RemoteProvisioning.isAvailable()) {
RemoteProvisioning.download(remote_provisioning, mLinphoneConfigFile);
}
mLc = LinphoneCoreFactory.instance().createLinphoneCore(this, mLinphoneConfigFile, mLinphoneInitialConfigFile, null);
mLc.getConfig().setInt("sip", "store_auth_info", 0);
initLiblinphone(c);
PreferencesMigrator prefMigrator = new PreferencesMigrator(mServiceContext);
if (prefMigrator.isMigrationNeeded()) {
prefMigrator.doMigration();
}
if (mServiceContext.getResources().getBoolean(R.bool.enable_push_id)) {
Compatibility.initPushNotificationService(mServiceContext);
}
IntentFilter lFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
lFilter.addAction(Intent.ACTION_SCREEN_OFF);
mServiceContext.registerReceiver(mKeepAliveReceiver, lFilter);
updateNetworkReachability();
startBluetooth();
resetCameraFromPreferences();
}
catch (Exception e) {
Log.e(e, "Cannot start linphone");
}
}
public synchronized void initLiblinphone(Context c) throws LinphoneCoreException {
boolean isDebugLogEnabled = !(mR.getBoolean(R.bool.disable_every_log)) && mPrefs.isDebugEnabled();
LinphoneCoreFactory.instance().setDebugMode(isDebugLogEnabled, getString(R.string.app_name));
mLc = LinphoneCoreFactory.instance().createLinphoneCore(this, mLinphoneConfigFile, mLinphoneFactoryConfigFile, null);
mLc.setContext(c);
try {
String versionName = c.getPackageManager().getPackageInfo(c.getPackageName(), 0).versionName;
@ -567,10 +579,9 @@ public class LinphoneManager implements LinphoneCoreListener {
Log.e(e, "cannot get version name");
}
mLc.enableIpv6(getPrefBoolean(R.string.pref_ipv6_key, false));
mLc.setZrtpSecretsCache(basePath + "/zrtp_secrets");
mLc.setRing(null);
mLc.setRing(mPrefs.getRingtone(null));
mLc.setRootCA(mLinphoneRootCaFile);
mLc.setPlayFile(mPauseSoundFile);
mLc.setChatDatabasePath(mChatDatabaseFile);
@ -579,11 +590,13 @@ public class LinphoneManager implements LinphoneCoreListener {
Log.w("MediaStreamer : " + availableCores + " cores detected and configured");
mLc.setCpuCount(availableCores);
try {
initFromConf();
} catch (LinphoneException e) {
Log.w("no config ready yet");
int camId = 0;
AndroidCamera[] cameras = AndroidCameraConfiguration.retrieveCameras();
for (AndroidCamera androidCamera : cameras) {
if (androidCamera.frontFacing == mPrefs.useFrontCam())
camId = androidCamera.id;
}
LinphoneManager.getLc().setVideoDevice(camId);
TimerTask lTask = new TimerTask() {
@Override
@ -592,34 +605,27 @@ public class LinphoneManager implements LinphoneCoreListener {
}
};
/*use schedule instead of scheduleAtFixedRate to avoid iterate from being call in burst after cpu wake up*/
mTimer = new Timer("Linphone scheduler");
mTimer.schedule(lTask, 0, 20);
IntentFilter lFilter = new IntentFilter(Intent.ACTION_SCREEN_ON);
lFilter.addAction(Intent.ACTION_SCREEN_OFF);
mServiceContext.registerReceiver(mKeepAliveReceiver, lFilter);
startBluetooth();
resetCameraFromPreferences();
}
catch (Exception e) {
Log.e(e, "Cannot start linphone");
}
}
private void copyAssetsFromPackage() throws IOException {
copyIfNotExist(R.raw.oldphone_mono,mRingSoundFile);
copyIfNotExist(R.raw.ringback,mRingbackSoundFile);
copyIfNotExist(R.raw.toy_mono,mPauseSoundFile);
copyFromPackage(R.raw.linphonerc, new File(mLinphoneInitialConfigFile).getName());
copyIfNotExist(R.raw.lpconfig, new File(mLPConfigXsd).getName());
copyIfNotExist(R.raw.rootca, new File(mLinphoneRootCaFile).getName());
copyIfNotExist(R.raw.linphonerc_default, mLinphoneConfigFile);
copyFromPackage(R.raw.linphonerc_factory, new File(mLinphoneFactoryConfigFile).getName());
copyIfNotExist(R.raw.lpconfig, mLPConfigXsd);
copyIfNotExist(R.raw.rootca, mLinphoneRootCaFile);
}
private void copyIfNotExist(int ressourceId,String target) throws IOException {
File lFileToCopy = new File(target);
if (!lFileToCopy.exists()) {
copyFromPackage(ressourceId,lFileToCopy.getName());
}
}
private void copyFromPackage(int ressourceId,String target) throws IOException{
FileOutputStream lOutputStream = mServiceContext.openFileOutput (target, 0);
InputStream lInputStream = mR.openRawResource(ressourceId);
@ -647,267 +653,6 @@ public class LinphoneManager implements LinphoneCoreListener {
return false;
}
void initMediaEncryption(){
String pref = getPrefString(R.string.pref_media_encryption_key, R.string.pref_media_encryption_key_none);
MediaEncryption me=MediaEncryption.None;
if (pref.equals(getString(R.string.pref_media_encryption_key_srtp)))
me = MediaEncryption.SRTP;
else if (pref.equals(getString(R.string.pref_media_encryption_key_zrtp)))
me = MediaEncryption.ZRTP;
Log.i("Media encryption set to " + pref);
mLc.setMediaEncryption(me);
}
private void initFromConfTunnel(){
if (!mLc.isTunnelAvailable())
return;
NetworkInfo info = mConnectivityManager.getActiveNetworkInfo();
mLc.tunnelCleanServers();
String host = getString(R.string.tunnel_host);
if (host == null || host.length() == 0)
host = mPref.getString(getString(R.string.pref_tunnel_host_key), "");
int port = Integer.parseInt(getPrefString(R.string.pref_tunnel_port_key, "443"));
mLc.tunnelAddServerAndMirror(host, port, 12345,500);
manageTunnelServer(info);
}
public void initAccounts() throws LinphoneCoreException {
mLc.clearAuthInfos();
mLc.clearProxyConfigs();
for (int i = 0; i < getPrefExtraAccountsNumber(); i++) {
String key = i == 0 ? "" : String.valueOf(i);
if (!getPrefBoolean(getString(R.string.pref_disable_account_key) + key, false)) {
initAccount(key, i == getPrefInt(R.string.pref_default_account_key, 0));
}
}
LinphoneProxyConfig lDefaultProxyConfig = mLc.getDefaultProxyConfig();
if (lDefaultProxyConfig != null) {
//prefix
String lPrefix = getPrefString(R.string.pref_prefix_key, null);
if (lPrefix != null) {
lDefaultProxyConfig.setDialPrefix(lPrefix);
}
//escape +
lDefaultProxyConfig.setDialEscapePlus(getPrefBoolean(R.string.pref_escape_plus_key, false));
} else if (LinphoneService.isReady()) {
LinphoneService.instance().onRegistrationStateChanged(RegistrationState.RegistrationNone, null);
}
}
private void initAccount(String key, boolean defaultAccount) throws LinphoneCoreException {
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) {
LinphoneAuthInfo lAuthInfo = LinphoneCoreFactory.instance().createAuthInfo(username
, userid
, password
, null
,null);
mLc.addAuthInfo(lAuthInfo);
if (domain != null && domain.length() > 0) {
String identity = "sip:" + username +"@" + domain;
String proxy = getPrefString(getString(R.string.pref_proxy_key) + key, null);
if (proxy == null || proxy.length() == 0) {
proxy = "sip:" + domain;
}
if (!proxy.startsWith("sip:")) {
proxy = "sip:" + proxy;
}
LinphoneProxyConfig proxycon = LinphoneCoreFactory.instance().createProxyConfig(identity, proxy, null, true);
String defaultExpire = getString(R.string.pref_expire_default);
proxycon.setExpires(tryToParseIntValue(getPrefString(R.string.pref_expire_key, defaultExpire), defaultExpire));
// Add parameters for push notifications
if (mR.getBoolean(R.bool.enable_push_id)) {
String regId = getPrefString(R.string.push_reg_id_key, null);
String appId = getString(R.string.push_sender_id);
if (regId != null && getPrefBoolean(R.string.pref_push_notification_key, mR.getBoolean(R.bool.pref_push_notification_default))) {
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";
proxycon.setContactParameters(contactInfos);
}
} else if (contactParams != null) {
proxycon.setContactParameters(contactParams);
}
mLc.addProxyConfig(proxycon);
//outbound proxy
if (getPrefBoolean(getString(R.string.pref_enable_outbound_proxy_key) + key, false)) {
proxycon.setRoute(proxy);
} else {
proxycon.setRoute(null);
}
proxycon.done();
if (defaultAccount) {
mLc.setDefaultProxyConfig(proxycon);
}
}
}
}
private void readAndSetAudioAndVideoPorts() throws NumberFormatException {
int aPortStart, aPortEnd, vPortStart, vPortEnd;
int defaultAudioPort, defaultVideoPort;
defaultAudioPort = Integer.parseInt(getString(R.string.default_audio_port));
defaultVideoPort = Integer.parseInt(getString(R.string.default_video_port));
aPortStart = aPortEnd = defaultAudioPort;
vPortStart = vPortEnd = defaultVideoPort;
String audioPort = getPrefString(R.string.pref_audio_port_key, String.valueOf(aPortStart));
String videoPort = getPrefString(R.string.pref_video_port_key, String.valueOf(vPortStart));
if (audioPort.contains("-")) {
// Port range
aPortStart = Integer.parseInt(audioPort.split("-")[0]);
aPortEnd = Integer.parseInt(audioPort.split("-")[1]);
} else {
try {
aPortStart = aPortEnd = Integer.parseInt(audioPort);
} catch (NumberFormatException nfe) {
aPortStart = aPortEnd = defaultAudioPort;
}
}
if (videoPort.contains("-")) {
// Port range
vPortStart = Integer.parseInt(videoPort.split("-")[0]);
vPortEnd = Integer.parseInt(videoPort.split("-")[1]);
} else {
try {
vPortStart = vPortEnd = Integer.parseInt(videoPort);
} catch (NumberFormatException nfe) {
vPortStart = vPortEnd = defaultVideoPort;
}
}
if (aPortStart >= aPortEnd) {
mLc.setAudioPort(aPortStart);
} else {
mLc.setAudioPortRange(aPortStart, aPortEnd);
}
if (vPortStart >= vPortEnd) {
mLc.setVideoPort(vPortStart);
} else {
mLc.setVideoPortRange(vPortStart, vPortEnd);
}
}
private int tryToParseIntValue(String valueToParse, String defaultValue) {
return tryToParseIntValue(valueToParse, Integer.parseInt(defaultValue));
}
private int tryToParseIntValue(String valueToParse, int defaultValue) {
try {
int returned = Integer.parseInt(valueToParse);
return returned;
} catch (NumberFormatException nfe) {
}
return defaultValue;
}
public void setContactParams(String params) {
contactParams = params;
}
public void initFromConf() throws LinphoneConfigException {
boolean isDebugLogEnabled = !(mR.getBoolean(R.bool.disable_every_log)) && getPrefBoolean(R.string.pref_debug_key, mR.getBoolean(R.bool.pref_debug_default));
LinphoneCoreFactory.instance().setDebugMode(isDebugLogEnabled, getString(R.string.app_name));
initFromConfTunnel();
if (initialTransports == null)
initialTransports = mLc.getSignalingTransportPorts();
setSignalingTransportsFromConfiguration(initialTransports);
initMediaEncryption();
mLc.setVideoPolicy(isAutoInitiateVideoCalls(), isAutoAcceptCamera());
readAndSetAudioAndVideoPorts();
String defaultIncomingCallTimeout = getString(R.string.pref_incoming_call_timeout_default);
int incomingCallTimeout = tryToParseIntValue(getPrefString(R.string.pref_incoming_call_timeout_key, defaultIncomingCallTimeout), defaultIncomingCallTimeout);
mLc.setIncomingTimeout(incomingCallTimeout);
try {
// Configure audio codecs
// enableDisableAudioCodec("speex", 32000, 1, R.string.pref_codec_speex32_key);
enableDisableAudioCodec("speex", 32000, 1, false);
enableDisableAudioCodec("speex", 16000, 1, R.string.pref_codec_speex16_key);
enableDisableAudioCodec("speex", 8000, 1, R.string.pref_codec_speex8_key);
enableDisableAudioCodec("iLBC", 8000, 1, R.string.pref_codec_ilbc_key);
enableDisableAudioCodec("GSM", 8000, 1, R.string.pref_codec_gsm_key);
enableDisableAudioCodec("G722", 8000, 1, R.string.pref_codec_g722_key);
enableDisableAudioCodec("G729", 8000, 1, R.string.pref_codec_g729_key);
enableDisableAudioCodec("PCMU", 8000, 1, R.string.pref_codec_pcmu_key);
enableDisableAudioCodec("PCMA", 8000, 1, R.string.pref_codec_pcma_key);
enableDisableAudioCodec("AMR", 8000, 1, R.string.pref_codec_amr_key);
enableDisableAudioCodec("AMR-WB", 16000, 1, R.string.pref_codec_amrwb_key);
//enableDisableAudioCodec("SILK", 24000, 1, R.string.pref_codec_silk24_key);
enableDisableAudioCodec("SILK", 24000, 1, false);
enableDisableAudioCodec("SILK", 16000, 1, R.string.pref_codec_silk16_key);
//enableDisableAudioCodec("SILK", 12000, 1, R.string.pref_codec_silk12_key);
enableDisableAudioCodec("SILK", 12000, 1, false);
enableDisableAudioCodec("SILK", 8000, 1, R.string.pref_codec_silk8_key);
enableDisableAudioCodec("OPUS", 48000, 1, R.string.pref_codec_opus_key);
// Configure video codecs
for (PayloadType videoCodec : mLc.getVideoCodecs()) {
enableDisableVideoCodecs(videoCodec);
}
boolean useEC = getPrefBoolean(R.string.pref_echo_cancellation_key, mR.getBoolean(R.bool.pref_echo_canceller_default));
mLc.enableEchoCancellation(useEC);
} catch (LinphoneCoreException e) {
throw new LinphoneConfigException(getString(R.string.wrong_settings),e);
}
boolean isVideoEnabled = isVideoEnabled();
mLc.enableVideo(isVideoEnabled, isVideoEnabled);
setPreferredVideoSizeFromConfiguration();
//stun server
String lStun = getPrefString(R.string.pref_stun_server_key, getString(R.string.default_stun));
boolean useICE = getPrefBoolean(R.string.pref_ice_enable_key, mR.getBoolean(R.bool.pref_ice_enabled_default));
boolean useUpnp = getPrefBoolean(R.string.pref_upnp_enable_key, mR.getBoolean(R.bool.pref_upnp_enabled_default));
mLc.setStunServer(lStun);
if (lStun!=null && lStun.length()>0 && useICE) {
mLc.setFirewallPolicy(FirewallPolicy.UseIce);
if (useUpnp) Log.e("Cannot have both ice and upnp enabled, disabling upnp");
} else if (useUpnp) {
mLc.setFirewallPolicy(FirewallPolicy.UseUpnp);
} else if (lStun!=null && lStun.length()>0){
mLc.setFirewallPolicy(FirewallPolicy.UseStun);
} else {
mLc.setFirewallPolicy(FirewallPolicy.NoFirewall);
}
mLc.setUseRfc2833ForDtmfs(getPrefBoolean(R.string.pref_rfc2833_dtmf_key, mR.getBoolean(R.bool.pref_rfc2833_dtmf_default)));
mLc.setUseSipInfoForDtmfs(getPrefBoolean(R.string.pref_sipinfo_dtmf_key, mR.getBoolean(R.bool.pref_sipinfo_dtmf_default)));
String displayName = getPrefString(R.string.pref_display_name_key, getString(R.string.pref_display_name_default));
String username = getPrefString(R.string.pref_user_name_key, getString(R.string.pref_user_name_default));
mLc.setPrimaryContact(displayName, username);
//accounts
try {
initAccounts();
//init network state
updateNetworkReachability();
} catch (LinphoneCoreException e) {
throw new LinphoneConfigException(getString(R.string.wrong_settings),e);
}
}
public void updateNetworkReachability() {
ConnectivityManager cm = (ConnectivityManager) mServiceContext.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo eventInfo = cm.getActiveNetworkInfo();
@ -920,8 +665,7 @@ public class LinphoneManager implements LinphoneCoreListener {
}
} else if (eventInfo.getState() == NetworkInfo.State.CONNECTED){
manageTunnelServer(eventInfo);
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(mServiceContext);
boolean wifiOnly = pref.getBoolean(getString(R.string.pref_wifi_only_key), mR.getBoolean(R.bool.pref_wifi_only_default));
boolean wifiOnly = LinphonePreferences.instance().isWifiOnlyEnabled();
if ((eventInfo.getTypeName().equals("WIFI")) || (!eventInfo.getTypeName().equals("WIFI") && !wifiOnly)) {
if (!isNetworkReachable) {
isNetworkReachable = true;
@ -938,96 +682,6 @@ public class LinphoneManager implements LinphoneCoreListener {
}
}
private void setSignalingTransportsFromConfiguration(Transports t) {
Transports ports = new Transports(t);
boolean useRandomPort = getPrefBoolean(R.string.pref_transport_use_random_ports_key, mR.getBoolean(R.bool.pref_transport_use_random_ports_default));
int lPreviousPort = tryToParseIntValue(getPrefString(R.string.pref_sip_port_key, getString(R.string.pref_sip_port_default)), 5060);
if (lPreviousPort>0xFFFF || useRandomPort) {
lPreviousPort=(int)(Math.random() * (0xFFFF - 1024)) + 1024;
Log.w("Using random port " + lPreviousPort);
}
String transport = getPrefString(R.string.pref_transport_key, getString(R.string.pref_transport_udp_key));
if (transport.equals(getString(R.string.pref_transport_tcp_key)))
{
ports.udp = 0;
ports.tls = 0;
ports.tcp = lPreviousPort;
} else if (transport.equals(getString(R.string.pref_transport_udp_key)))
{
ports.tcp = 0;
ports.tls = 0;
ports.udp = lPreviousPort;
} else if (transport.equals(getString(R.string.pref_transport_tls_key)))
{
ports.udp = 0;
ports.tcp = 0;
ports.tls = lPreviousPort;
}
mLc.setSignalingTransportPorts(ports);
}
private void enableDisableAudioCodec(String codec, int rate, int channels, int key) throws LinphoneCoreException {
PayloadType pt = mLc.findPayloadType(codec, rate, channels);
if (pt !=null) {
boolean enable= getPrefBoolean(key,false);
mLc.enablePayloadType(pt, enable);
}
}
private void enableDisableAudioCodec(String codec, int rate, int channels, boolean enable) throws LinphoneCoreException {
PayloadType pt = mLc.findPayloadType(codec, rate, channels);
if (pt !=null) {
mLc.enablePayloadType(pt, enable);
}
}
private void enableDisableVideoCodecs(PayloadType videoCodec) throws LinphoneCoreException {
String mime = videoCodec.getMime();
int key;
int defaultValueKey;
if ("MP4V-ES".equals(mime)) {
key = R.string.pref_video_codec_mpeg4_key;
defaultValueKey = R.bool.pref_video_codec_mpeg4_default;
} else if ("H264".equals(mime)) {
key = R.string.pref_video_codec_h264_key;
defaultValueKey = R.bool.pref_video_codec_h264_default;
} else if ("H263-1998".equals(mime)) {
key = R.string.pref_video_codec_h263_key;
defaultValueKey = R.bool.pref_video_codec_h263_default;
} else if ("VP8".equals(mime)) {
key = R.string.pref_video_codec_vp8_key;
defaultValueKey = R.bool.pref_video_codec_vp8_default;
} else {
Log.e("Unhandled video codec ", mime);
mLc.enablePayloadType(videoCodec, false);
return;
}
boolean enable = getPrefBoolean(key, mR.getBoolean(defaultValueKey));
mLc.enablePayloadType(videoCodec, enable);
}
private void setPreferredVideoSizeFromConfiguration() {
String preferredVideoSize = getPrefString(R.string.pref_preferred_video_size_key, getString(R.string.pref_preferred_video_size_vga_key));
int bandwidth = 512 + 60;
if (preferredVideoSize.equals(getString(R.string.pref_preferred_video_size_hd_key))) {
preferredVideoSize = "uxga";
bandwidth = 1024 + 60;
} else if (preferredVideoSize.equals(getString(R.string.pref_preferred_video_size_vga_key))) {
preferredVideoSize = "vga";
bandwidth = 512 + 60;
} else if (preferredVideoSize.equals(getString(R.string.pref_preferred_video_size_qvga_key))) {
preferredVideoSize = "qvga";
bandwidth = 380 + 60;
}
mLc.setPreferredVideoSizeByName(preferredVideoSize);
mLc.setUploadBandwidth(bandwidth);
mLc.setDownloadBandwidth(bandwidth);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void doDestroy() {
ChatStorage.getInstance().close();
@ -1064,28 +718,6 @@ public class LinphoneManager implements LinphoneCoreListener {
private String getString(int key) {
return mR.getString(key);
}
private boolean getPrefBoolean(int key, boolean value) {
return mPref.getBoolean(mR.getString(key), value);
}
private boolean getPrefBoolean(String key, boolean value) {
return mPref.getBoolean(key, value);
}
private String getPrefString(int key, String value) {
return mPref.getString(mR.getString(key), value);
}
private int getPrefInt(int key, int value) {
return mPref.getInt(mR.getString(key), value);
}
private String getPrefString(int key, int value) {
return mPref.getString(mR.getString(key), mR.getString(value));
}
private String getPrefString(String key, String value) {
return mPref.getString(key, value);
}
private int getPrefExtraAccountsNumber() {
return mPref.getInt(getString(R.string.pref_extra_accounts), 1);
}
/* Simple implementation as Android way seems very complicate:
For example: with wifi and mobile actives; when pulling mobile down:
@ -1241,7 +873,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();
@ -1285,7 +919,7 @@ public class LinphoneManager implements LinphoneCoreListener {
Compatibility.setAudioManagerInCallMode(mAudioManager);
}
if (Hacks.needSoftvolume() || sLPref.useSoftvolume()) {
if (Hacks.needSoftvolume() || LinphonePreferences.instance().shouldUseSoftvolume()) {
adjustVolume(0); // Synchronize
}
}
@ -1452,55 +1086,6 @@ public class LinphoneManager implements LinphoneCoreListener {
return CallManager.getInstance().reinviteWithVideo();
}
public boolean isVideoEnabled() {
return getPrefBoolean(R.string.pref_video_enable_key, false);
}
public boolean isAutoAcceptCamera() {
return isVideoEnabled() && getPrefBoolean(R.string.pref_video_automatically_accept_video_key, false);
}
public boolean isAutoInitiateVideoCalls() {
return isVideoEnabled() && getPrefBoolean(R.string.pref_video_initiate_call_with_video_key, false);
}
// Called on first launch only
public void initializePayloads() {
Log.i("Initializing supported payloads");
Editor e = mPref.edit();
boolean fastCpu = Version.hasFastCpu();
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(R.string.pref_codec_g722_key), false);
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, 1)!=null;
e.putBoolean(getString(pref_codec_ilbc_key), ilbc);
boolean amr = LinphoneService.isReady() && LinphoneManager.getLc()
.findPayloadType("AMR", 8000, 1)!=null;
e.putBoolean(getString(pref_codec_amr_key), amr);
boolean amrwb = LinphoneService.isReady() && LinphoneManager.getLc()
.findPayloadType("AMR-WB", 16000, 1)!=null;
e.putBoolean(getString(pref_codec_amrwb_key), amrwb);
boolean g729 = LinphoneService.isReady() && LinphoneManager.getLc()
.findPayloadType("G729", 8000, 1)!=null;
e.putBoolean(getString(R.string.pref_codec_g729_key), g729);
if (Version.sdkStrictlyBelow(5) || !Version.hasNeon() || !Hacks.hasCamera()) {
e.putBoolean(getString(pref_video_enable_key), false);
}
e.commit();
}
/**
*
* @return false if already in video call.

View file

@ -1,66 +0,0 @@
/*
PreferenceManager.java
Copyright (C) 2011 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 android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
public class LinphonePreferenceManager {
private static LinphonePreferenceManager instance;
private Context c;
private SharedPreferences p;
public LinphonePreferenceManager(Context context) {
c = context.getApplicationContext();
p = PreferenceManager.getDefaultSharedPreferences(c);
}
private String getString(int key) {
return c.getString(key);
}
public boolean useSoftvolume() {
return p.getBoolean(
getString(R.string.pref_audio_soft_volume_key), false);
}
public boolean useAudioRoutingAPIHack() {
return p.getBoolean(
getString(R.string.pref_audio_hacks_use_routing_api_key), false);
}
public boolean useGalaxySHack() {
return p.getBoolean(
getString(R.string.pref_audio_hacks_use_galaxys_hack_key), false);
}
public int useSpecificAudioModeHack() {
return Integer.parseInt(p.getString(getString(R.string.pref_audio_use_specific_mode_key), "0"));
}
public static final synchronized LinphonePreferenceManager getInstance(Context c) {
if (instance == null) {
instance = new LinphonePreferenceManager(c.getApplicationContext());
}
return instance;
}
}

View file

@ -0,0 +1,714 @@
package org.linphone;
/*
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
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.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
*/
public class LinphonePreferences {
private static final int LINPHONE_CORE_RANDOM_PORT = -1;
private static LinphonePreferences instance;
private Context mContext;
public static final synchronized LinphonePreferences instance() {
if (instance == null) {
instance = new LinphonePreferences();
}
return instance;
}
private LinphonePreferences() {
}
private String getString(int key) {
if (mContext == null) {
mContext = LinphoneManager.getInstance().getContext();
}
return mContext.getString(key);
}
private LinphoneCore getLc() {
return LinphoneManager.getLcIfManagerNotDestroyedOrNull();
}
private LpConfig getConfig() {
LinphoneCore lc = getLc();
if (lc != null)
return lc.getConfig();
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);
}
public void firstLaunchSuccessful() {
getConfig().setBool("app", "first_launch", false);
}
public String getRingtone(String defaultRingtone) {
String ringtone = getLc().getRing();
if (ringtone == null || ringtone.length() == 0)
ringtone = defaultRingtone;
return ringtone;
}
public void setRingtone(String ringtone) {
getLc().setRing(ringtone);
}
public boolean shouldAutomaticallyAcceptFriendsRequests() {
return false; //TODO
}
public boolean shouldUseSoftvolume() {
return false; //TODO
}
// End of app settings
// Accounts settings
private LinphoneProxyConfig getProxyConfig(int n) {
LinphoneProxyConfig[] prxCfgs = getLc().getProxyConfigList();
if (n < 0 || n >= prxCfgs.length)
return null;
return prxCfgs[n];
}
private LinphoneAuthInfo getAuthInfo(int n) {
LinphoneAuthInfo[] authsInfos = getLc().getAuthInfosList();
// 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];
}
private String tempUsername;
private String tempUserId;
private String tempPassword;
private String tempDomain;
private String tempProxy;
private boolean tempOutboundProxy;
private String tempContactsParams;
private String tempExpire;
/**
* Creates a new account using values previously set using setNew* functions
* @throws LinphoneCoreException
*/
public void saveNewAccount() throws LinphoneCoreException {
String identity = "sip:" + tempUsername + "@" + tempDomain;
String proxy = "sip:";
proxy += tempProxy == null ? tempDomain : tempProxy;
String route = tempOutboundProxy ? tempProxy : null;
LinphoneProxyConfig prxCfg = LinphoneCoreFactory.instance().createProxyConfig(identity, proxy, route, true);
if (tempContactsParams != null)
prxCfg.setContactParameters(tempContactsParams);
if (tempExpire != null) {
try {
prxCfg.setExpires(Integer.parseInt(tempExpire));
} catch (NumberFormatException nfe) { }
}
LinphoneAuthInfo authInfo = LinphoneCoreFactory.instance().createAuthInfo(tempUsername, tempUserId, tempPassword, null, null);
getLc().addProxyConfig(prxCfg);
getLc().addAuthInfo(authInfo);
if (getAccountCount() == 1)
getLc().setDefaultProxyConfig(prxCfg);
tempUsername = null;
tempUserId = null;
tempPassword = null;
tempDomain = null;
tempProxy = null;
tempOutboundProxy = false;
tempContactsParams = null;
tempExpire = null;
}
public void setNewAccountUsername(String username) {
tempUsername = username;
}
public void setAccountUsername(int n, String username) {
getAuthInfo(n).setUsername(username);
}
public String getAccountUsername(int n) {
LinphoneAuthInfo authInfo = getAuthInfo(n);
return authInfo == null ? null : authInfo.getUsername();
}
public void setNewAccountUserId(String userId) {
tempUserId = userId;
}
public void setAccountUserId(int n, String userId) {
getAuthInfo(n).setUserId(userId);
}
public String getAccountUserId(int n) {
LinphoneAuthInfo authInfo = getAuthInfo(n);
return authInfo == null ? null : authInfo.getUserId();
}
public void setNewAccountPassword(String password) {
tempPassword = password;
}
public void setAccountPassword(int n, String password) {
getAuthInfo(n).setPassword(password);
}
public String getAccountPassword(int n) {
LinphoneAuthInfo authInfo = getAuthInfo(n);
return authInfo == null ? null : authInfo.getPassword();
}
public void setNewAccountDomain(String domain) {
tempDomain = domain;
}
public void setAccountDomain(int n, String domain) {
String identity = "sip:" + getAccountUsername(n) + "@" + domain;
String proxy = "sip:" + domain;
try {
LinphoneProxyConfig prxCfg = getProxyConfig(n);
prxCfg.setIdentity(identity);
prxCfg.setProxy(proxy);
} catch (LinphoneCoreException e) {
e.printStackTrace();
}
}
public String getAccountDomain(int n) {
return getProxyConfig(n).getDomain();
}
public void setNewAccountProxy(String proxy) {
tempProxy = proxy;
}
public void setAccountProxy(int n, String proxy) {
try {
LinphoneProxyConfig prxCfg = getProxyConfig(n);
prxCfg.setProxy("sip:" + proxy);
} catch (LinphoneCoreException e) {
e.printStackTrace();
}
}
public String getAccountProxy(int n) {
return getProxyConfig(n).getProxy();
}
public void setNewAccountOutboundProxyEnabled(boolean enabled) {
tempOutboundProxy = enabled;
}
public void setAccountOutboundProxyEnabled(int n, boolean enabled) {
try {
if (enabled) {
getProxyConfig(n).setRoute(getAccountProxy(n));
} else {
getProxyConfig(n).setRoute(null);
}
} catch (LinphoneCoreException e) {
e.printStackTrace();
}
}
public void setNewAccountContactParameters(String contactParams) {
tempContactsParams = contactParams;
}
public boolean isAccountOutboundProxySet(int n) {
return getProxyConfig(n).getRoute() != null;
}
public String getExpires(int n) {
return String.valueOf(getProxyConfig(n).getExpires());
}
public void setNewAccountExpires(String expire) {
tempExpire = expire;
}
public void setExpires(int n, String expire) {
try {
LinphoneProxyConfig prxCfg = getProxyConfig(n);
prxCfg.setExpires(Integer.parseInt(expire));
prxCfg.done();
} catch (NumberFormatException nfe) { }
}
public String getPrefix(int n) {
return getProxyConfig(n).getDialPrefix();
}
public void setPrefix(int n, String prefix) {
LinphoneProxyConfig prxCfg = getProxyConfig(n);
prxCfg.setDialPrefix(prefix);
prxCfg.done();
}
public boolean getReplacePlusByZeroZero(int n) {
return getProxyConfig(n).getDialEscapePlus();
}
public void setReplacePlusByZeroZero(int n, boolean replace) {
LinphoneProxyConfig prxCfg = getProxyConfig(n);
prxCfg.setDialEscapePlus(replace);
prxCfg.done();
}
public void setDefaultAccount(int accountIndex) {
LinphoneProxyConfig[] prxCfgs = getLc().getProxyConfigList();
if (accountIndex >= 0 && accountIndex < prxCfgs.length)
getLc().setDefaultProxyConfig(prxCfgs[accountIndex]);
}
public int getDefaultAccountIndex() {
LinphoneProxyConfig defaultPrxCfg = getLc().getDefaultProxyConfig();
if (defaultPrxCfg == null)
return 0;
LinphoneProxyConfig[] prxCfgs = getLc().getProxyConfigList();
for (int i = 0; i < prxCfgs.length; i++) {
if (defaultPrxCfg.getIdentity().equals(prxCfgs[i].getIdentity())) {
return i;
}
}
return 0;
}
public int getAccountCount() {
return getLc().getProxyConfigList().length;
}
public void setAccountEnabled(int n, boolean disabled) {
LinphoneProxyConfig prxCfg = getProxyConfig(n);
try {
prxCfg.enableRegister(!disabled);
prxCfg.done();
} catch (LinphoneCoreException e) {
e.printStackTrace();
}
}
public boolean isAccountEnabled(int n) {
return getProxyConfig(n).registerEnabled();
}
public void deleteAccount(int n) {
LinphoneProxyConfig proxyCfg = getProxyConfig(n);
if (proxyCfg != null)
getLc().removeProxyConfig(proxyCfg);
LinphoneAuthInfo authInfo = getAuthInfo(n);
if (authInfo != null)
getLc().removeAuthInfo(authInfo);
}
// End of accounts settings
// Audio settings
public void setEchoCancellation(boolean enable) {
getLc().enableEchoCancellation(enable);
}
public boolean isEchoCancellationEnabled() {
return getLc().isEchoCancellationEnabled();
}
// End of audio settings
// Video settings
public boolean useFrontCam() {
return getConfig().getBool("app", "front_camera_default", true);
}
public void setFrontCamAsDefault(boolean frontcam) {
getConfig().setBool("app", "front_camera_default", frontcam);
}
public boolean isVideoEnabled() {
return getLc().isVideoSupported() && getLc().isVideoEnabled();
}
public void enableVideo(boolean enable) {
if (enable) {
getLc().enableVideo(shouldAutomaticallyShareMyVideo(), true);
} else {
getLc().enableVideo(false, false);
}
}
public boolean shouldInitiateVideoCall() {
return getLc().getVideoAutoInitiatePolicy();
}
public void setInitiateVideoCall(boolean initiate) {
getLc().setVideoPolicy(initiate, shouldAutomaticallyAcceptVideoRequests());
}
public boolean shouldAutomaticallyAcceptVideoRequests() {
return getLc().getVideoAutoAcceptPolicy();
}
public void setAutomaticallyAcceptVideoRequests(boolean accept) {
getLc().setVideoPolicy(shouldInitiateVideoCall(), accept);
}
public boolean shouldAutomaticallyShareMyVideo() {
return false; //TODO
}
public void setAutomaticallyShareMyVideo(boolean accept) {
//TODO
}
public String getPreferredVideoSize() {
//LinphoneCore can only return video size (width and height), not the name
return getConfig().getString("video", "size", "qvga");
}
public void setPreferredVideoSize(String preferredVideoSize) {
int bandwidth = 512 + 60;
if (preferredVideoSize.equals(getString(R.string.pref_preferred_video_size_hd_key))) {
preferredVideoSize = "uxga";
bandwidth = 1024 + 60;
} else if (preferredVideoSize.equals(getString(R.string.pref_preferred_video_size_vga_key))) {
preferredVideoSize = "vga";
bandwidth = 512 + 60;
} else if (preferredVideoSize.equals(getString(R.string.pref_preferred_video_size_qvga_key))) {
preferredVideoSize = "qvga";
bandwidth = 380 + 60;
}
getLc().setPreferredVideoSizeByName(preferredVideoSize);
getLc().setUploadBandwidth(bandwidth);
getLc().setDownloadBandwidth(bandwidth);
}
// End of video settings
// Call settings
public boolean useRfc2833Dtmfs() {
return getLc().getUseRfc2833ForDtmfs();
}
public void sendDtmfsAsRfc2833(boolean use) {
getLc().setUseRfc2833ForDtmfs(use);
}
public boolean useSipInfoDtmfs() {
return getLc().getUseSipInfoForDtmfs();
}
public void sendDTMFsAsSipInfo(boolean use) {
getLc().setUseSipInfoForDtmfs(use);
}
// End of call settings
// Network settings
public void setWifiOnlyEnabled(Boolean enable) {
getConfig().setBool("app", "wifi_only", enable);
}
public boolean isWifiOnlyEnabled() {
return getConfig().getBool("app", "wifi_only", false);
}
public String getStunServer() {
return getLc().getStunServer();
}
public void setStunServer(String stun) {
getLc().setStunServer(stun);
}
public void setIceEnabled(boolean enabled) {
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 void setUpnpEnabled(boolean enabled) {
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() {
return getLc().upnpAvailable() && getLc().getFirewallPolicy() == FirewallPolicy.UseUpnp;
}
public boolean isIceEnabled() {
return getLc().getFirewallPolicy() == FirewallPolicy.UseIce;
}
public void useRandomPort(boolean enabled) {
useRandomPort(enabled, true);
}
public void useRandomPort(boolean enabled, boolean apply) {
getConfig().setBool("app", "random_port", enabled);
if (apply) {
if (enabled) {
setSipPort(LINPHONE_CORE_RANDOM_PORT);
} else {
if (getTransport().equals(getString(R.string.pref_transport_tls)))
setSipPort(5061);
else
setSipPort(5060);
}
}
}
public boolean isUsingRandomPort() {
return getConfig().getBool("app", "random_port", true);
}
public String getSipPort() {
Transports transports = getLc().getSignalingTransportPorts();
int port;
if (transports.udp > 0)
port = transports.udp;
else if (transports.tcp > 0)
port = transports.tcp;
else
port = transports.tls;
return String.valueOf(port);
}
public void setSipPort(int port) {
Transports transports = getLc().getSignalingTransportPorts();
if (transports.udp > 0)
transports.udp = port;
else if (transports.tcp > 0)
transports.tcp = port;
else
transports.tls = port;
getLc().setSignalingTransportPorts(transports);
}
public String getTransport() {
Transports transports = getLc().getSignalingTransportPorts();
String transport = getString(R.string.pref_transport_udp);
if (transports.tcp > 0)
transport = getString(R.string.pref_transport_tcp);
else if (transports.tls > 0)
transport = getString(R.string.pref_transport_tls);
return transport;
}
public void setTransport(String transportKey) {
if (transportKey == null)
return;
Transports transports = getLc().getSignalingTransportPorts();
if (transports.udp > 0) {
if (transportKey.equals(getString(R.string.pref_transport_tcp_key))) {
transports.tcp = transports.udp;
transports.udp = transports.tls;
} else if (transportKey.equals(getString(R.string.pref_transport_tls_key))) {
transports.tls = transports.udp;
transports.udp = transports.tcp;
}
} else if (transports.tcp > 0) {
if (transportKey.equals(getString(R.string.pref_transport_udp_key))) {
transports.udp = transports.tcp;
transports.tcp = transports.tls;
} else if (transportKey.equals(getString(R.string.pref_transport_tls_key))) {
transports.tls = transports.tcp;
transports.tcp = transports.udp;
}
} else if (transports.tls > 0) {
if (transportKey.equals(getString(R.string.pref_transport_udp_key))) {
transports.udp = transports.tls;
transports.tls = transports.tcp;
} else if (transportKey.equals(getString(R.string.pref_transport_tcp_key))) {
transports.tcp = transports.tls;
transports.tls = transports.udp;
}
}
getLc().setSignalingTransportPorts(transports);
}
public MediaEncryption getMediaEncryption() {
return getLc().getMediaEncryption();
}
public void setMediaEncryption(MediaEncryption menc) {
if (menc == null)
return;
getLc().setMediaEncryption(menc);
}
public void setPushNotificationEnabled(boolean enable) {
getConfig().setBool("app", "push_notification", enable);
}
public boolean isPushNotificationEnabled() {
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);
}
public void useIpv6(Boolean enable) {
getLc().enableIpv6(enable);
}
public boolean isUsingIpv6() {
return getLc().isIpv6Enabled();
}
// End of network settings
// Advanced settings
public void setDebugEnabled(boolean enabled) {
getConfig().setBool("app", "debug", enabled);
LinphoneCoreFactory.instance().setDebugMode(enabled, getString(R.string.app_name));
}
public boolean isDebugEnabled() {
return getConfig().getBool("app", "debug", false);
}
public void setBackgroundModeEnabled(boolean enabled) {
getConfig().setBool("app", "background_mode", enabled);
}
public boolean isBackgroundModeEnabled() {
return getConfig().getBool("app", "background_mode", true);
}
public void setAnimationsEnabled(boolean enabled) {
getConfig().setBool("app", "animations", enabled);
}
public boolean areAnimationsEnabled() {
return getConfig().getBool("app", "animations", false);
}
public boolean isAutoStartEnabled() {
return getConfig().getBool("app", "auto_start", false);
}
public void setAutoStart(boolean autoStartEnabled) {
getConfig().setBool("app", "auto_start", autoStartEnabled);
}
public String getSharingPictureServerUrl() {
return getConfig().getString("app", "sharing_server", null);
}
public void setSharingPictureServerUrl(String url) {
getConfig().setString("app", "sharing_server", url);
}
public void setRemoteProvisioningUrl(String url) {
getConfig().setString("app", "remote_provisioning", url);
}
public String getRemoteProvisioningUrl() {
return getConfig().getString("app", "remote_provisioning", null);
}
public void setDefaultDisplayName(String displayName) {
getLc().setPrimaryContact(displayName, getDefaultUsername());
}
public String getDefaultDisplayName() {
return getLc().getPrimaryContactDisplayName();
}
public void setDefaultUsername(String username) {
getLc().setPrimaryContact(getDefaultDisplayName(), username);
}
public String getDefaultUsername() {
return getLc().getPrimaryContactUsername();
}
// End of advanced settings
// Tunnel settings
public String getTunnelMode() {
return null; //TODO
}
// End of tunnel settings
}

View file

@ -47,7 +47,6 @@ import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Bitmap;
@ -60,7 +59,6 @@ import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
/**
@ -137,12 +135,6 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
super.onCreate();
// In case restart after a crash. Main in LinphoneActivity
LinphonePreferenceManager.getInstance(this);
// Set default preferences
PreferenceManager.setDefaultValues(this, R.xml.preferences, true);
mNotificationTitle = getString(R.string.app_name);
// Dump some debugging information to the logs
@ -580,7 +572,7 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
// If the correspondent proposes video while audio call
boolean remoteVideo = call.getRemoteParams().getVideoEnabled();
boolean localVideo = call.getCurrentParamsCopy().getVideoEnabled();
boolean autoAcceptCameraPolicy = LinphoneManager.getInstance().isAutoAcceptCamera();
boolean autoAcceptCameraPolicy = LinphonePreferences.instance().shouldAutomaticallyAcceptVideoRequests();
if (remoteVideo && !localVideo && !autoAcceptCameraPolicy && !LinphoneManager.getLc().isInConference()) {
try {
LinphoneManager.getLc().deferCallUpdate(call);
@ -619,15 +611,8 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
void onCallStateChanged(LinphoneCall call, State state, String message);
}
public void changeRingtone(String ringtone) {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
editor.putString(getString(R.string.pref_audio_ringtone), ringtone);
editor.commit();
}
public void onRingerPlayerCreated(MediaPlayer mRingerPlayer) {
String uriString = PreferenceManager.getDefaultSharedPreferences(this).getString(getString(R.string.pref_audio_ringtone),
android.provider.Settings.System.DEFAULT_RINGTONE_URI.toString());
String uriString = LinphonePreferences.instance().getRingtone(android.provider.Settings.System.DEFAULT_RINGTONE_URI.toString());
try {
if (uriString.startsWith("content://")) {
mRingerPlayer.setDataSource(this, Uri.parse(uriString));

View file

@ -1,583 +0,0 @@
package org.linphone;
/*
PreferencesFragment.java
Copyright (C) 2012 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 static org.linphone.R.string.ec_calibrating;
import static org.linphone.R.string.pref_codec_amr_key;
import static org.linphone.R.string.pref_codec_amrwb_key;
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_echo_cancellation_key;
import static org.linphone.R.string.pref_echo_canceller_calibration_key;
import static org.linphone.R.string.pref_media_encryption_key;
import static org.linphone.R.string.pref_preferred_video_size_key;
import static org.linphone.R.string.pref_transport_key;
import static org.linphone.R.string.pref_video_enable_key;
import java.util.ArrayList;
import java.util.List;
import org.linphone.LinphoneManager.EcCalibrationListener;
import org.linphone.compatibility.Compatibility;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCore.EcCalibratorStatus;
import org.linphone.core.LinphoneCore.MediaEncryption;
import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.mediastream.Log;
import org.linphone.mediastream.Version;
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
import org.linphone.mediastream.video.capture.hwconf.Hacks;
import org.linphone.setup.SetupActivity;
import org.linphone.ui.LedPreference;
import org.linphone.ui.PreferencesListFragment;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
public class PreferencesFragment extends PreferencesListFragment implements EcCalibrationListener {
private Handler mHandler = new Handler();
private Context mContext;
private Preference ecCalibratePref;
private CheckBoxPreference ecPref;
private ListPreference mencPref;
private int nbAccounts = 1;
private PreferenceCategory accounts;
private static final int WIZARD_INTENT = 1;
public PreferencesFragment() {
super(R.xml.preferences);
}
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
mContext = getActivity();
if (getResources().getBoolean(R.bool.hide_accounts)) {
// Hide category
PreferenceCategory accounts = (PreferenceCategory) findPreference(getString(R.string.pref_sipaccounts_key));
accounts.removeAll();
accounts.setLayoutResource(R.layout.hidden);
}
if (getResources().getBoolean(R.bool.hide_wizard) || getResources().getBoolean(R.bool.replace_wizard_with_old_interface)) {
Preference wizard = findPreference(getString(R.string.setup_key));
if (getResources().getBoolean(R.bool.replace_wizard_with_old_interface)) {
createAddAccountButton();
} else {
wizard.setLayoutResource(R.layout.hidden);
}
} else {
addWizardPreferenceButton();
}
if (getResources().getBoolean(R.bool.disable_animations)) {
uncheckDisableAndHideCheckbox(R.string.pref_animation_enable_key);
}
if (!getResources().getBoolean(R.bool.enable_linphone_friends)) {
PreferenceCategory friends = (PreferenceCategory) findPreference(getString(R.string.pref_linphone_friend_key));
friends.removeAll();
friends.setLayoutResource(R.layout.hidden);
}
EditTextPreference imageSharingServer = (EditTextPreference) findPreference(getString(R.string.pref_image_sharing_server_key));
if (getResources().getBoolean(R.bool.disable_chat)) {
imageSharingServer.setLayoutResource(R.layout.hidden);
}
if (!getResources().getBoolean(R.bool.enable_push_id)) {
findPreference(getString(R.string.pref_push_notification_key)).setLayoutResource(R.layout.hidden);
}
initializeTransportPreferences();
ecCalibratePref = findPreference(pref_echo_canceller_calibration_key);
ecCalibratePref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
startEcCalibration();
return false;
}
});
ecPref = (CheckBoxPreference) findPreference(pref_echo_cancellation_key);
mencPref = (ListPreference) findPreference(pref_media_encryption_key);
boolean fastCpu = Version.hasFastCpu();
if (fastCpu) {
detectAudioCodec(pref_codec_ilbc_key, "iLBC", 8000, 1, false);
findPreference(pref_codec_speex16_key).setEnabled(true);
//findPreference(pref_codec_speex32_key)).setEnabled(enableIlbc);
}
initializeMediaEncryptionPreferences();
detectAudioCodec(pref_codec_amr_key,"AMR", 8000, 1, false);
detectAudioCodec(pref_codec_amrwb_key,"AMR-WB", 16000, 1, false);
//detectAudioCodec(R.string.pref_codec_silk8_key,"SILK",8000, 1, true);
//detectAudioCodec(R.string.pref_codec_silk12_key,"SILK",12000, 1, true);
detectAudioCodec(R.string.pref_codec_silk16_key,"SILK",16000, 1, true);
//detectAudioCodec(R.string.pref_codec_silk24_key,"SILK",24000, 1, true);
detectAudioCodec(R.string.pref_codec_g729_key,"G729",8000, 1, true);
detectAudioCodec(R.string.pref_codec_opus_key,"OPUS",48000, 1, true);
// No video
if (!Version.isVideoCapable()) {
uncheckAndDisableCheckbox(pref_video_enable_key);
} else {
if (!AndroidCameraConfiguration.hasFrontCamera()) {
uncheckDisableAndHideCheckbox(R.string.pref_video_use_front_camera_key);
}
}
initializePreferredVideoSizePreferences();
if (prefs().getBoolean(LinphoneActivity.PREF_FIRST_LAUNCH,true)) {
doOnFirstLaunch();
}
if (Hacks.hasBuiltInEchoCanceller()) {
uncheckDisableAndHideCheckbox(R.string.pref_echo_cancellation_key);
findPreference(R.string.pref_echo_canceller_calibration_key).setLayoutResource(R.layout.hidden);
}
if (getResources().getBoolean(R.bool.disable_all_patented_codecs_for_markets)) {
Preference prefH264 = findPreference(R.string.pref_video_codec_h264_key);
prefH264.setEnabled(false);
prefH264.setSummary(R.string.pref_video_codec_h264_unavailable);
Preference prefMPEG4 = findPreference(R.string.pref_video_codec_mpeg4_key);
prefMPEG4.setEnabled(false);
prefMPEG4.setSummary(R.string.pref_video_codec_mpeg4_unavailable);
} else {
detectVideoCodec(R.string.pref_video_codec_h264_key, "H264");
if (!Version.hasFastCpuWithAsmOptim())
{
// Android without neon doesn't support H264
Log.w("CPU does not have asm optimisations available, disabling H264");
findPreference(R.string.pref_video_codec_h264_key).setEnabled(false);
findPreference(R.string.pref_video_codec_h264_key).setDefaultValue(false);
}
}
if (Hacks.needSoftvolume()) {
Log.w("Using Audio Hack");
checkAndDisableCheckbox(R.string.pref_audio_hacks_use_galaxys_hack_key);
}
if (!LinphoneManager.getLc().isTunnelAvailable()) {
hidePreferenceCategory(R.string.pref_tunnel_key);
}
if (getResources().getBoolean(R.bool.hide_camera_settings)) {
PreferenceScreen videoSettings = (PreferenceScreen) findPreference(getString(R.string.pref_video_key));
videoSettings.removeAll();
videoSettings.setLayoutResource(R.layout.hidden);
Preference enableVideo = findPreference(R.string.pref_video_enable_key);
enableVideo.setLayoutResource(R.layout.hidden);
}
if (getResources().getBoolean(R.bool.display_about_in_settings)) {
findPreference(getString(R.string.menu_about_key)).setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().displayAbout();
return true;
}
return false;
}
});
} else {
findPreference(getString(R.string.menu_about_key)).setLayoutResource(R.layout.hidden);
}
final CheckBoxPreference useRandomPort = (CheckBoxPreference) findPreference(R.string.pref_transport_use_random_ports_key);
final Preference sipPort = findPreference(R.string.pref_sip_port_key);
sipPort.setEnabled(!useRandomPort.isChecked());
useRandomPort.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean isChecked = (Boolean) newValue;
sipPort.setEnabled(!isChecked);
return true;
}
});
CheckBoxPreference wifiOnly = (CheckBoxPreference) findPreference(R.string.pref_wifi_only_key);
wifiOnly.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
LinphoneManager.getInstance().updateNetworkReachability();
return true;
}
});
final CheckBoxPreference useIce = (CheckBoxPreference) findPreference(R.string.pref_ice_enable_key);
final CheckBoxPreference useUpnp = (CheckBoxPreference) findPreference(R.string.pref_upnp_enable_key);
useIce.setEnabled(!useUpnp.isChecked());
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
useUpnp.setEnabled(lc.upnpAvailable() && !useIce.isChecked());
useIce.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean isChecked = (Boolean) newValue;
useUpnp.setEnabled(!isChecked);
return true;
}
});
useUpnp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean isChecked = (Boolean) newValue;
useIce.setEnabled(!isChecked);
return true;
}
});
if (getResources().getBoolean(R.bool.disable_every_log)) {
uncheckDisableAndHideCheckbox(R.string.pref_debug_key);
}
}
private void createAddAccountButton() {
Preference addAccount = findPreference(getString(R.string.setup_key));
addAccount.setTitle(getString(R.string.pref_add_account));
addAccount.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
nbAccounts = prefs.getInt(getString(R.string.pref_extra_accounts), 0);
prefs.edit().putInt(getString(R.string.pref_extra_accounts), nbAccounts+1).commit();
addExtraAccountPreferencesButton(accounts, nbAccounts, true);
LinphoneActivity.instance().displayAccountSettings(nbAccounts);
nbAccounts++;
return true;
}
});
}
private void hidePreferenceCategory(int key) {
PreferenceCategory p = (PreferenceCategory) findPreference(key);
p.removeAll();
p.setLayoutResource(R.layout.hidden);
}
private void doOnFirstLaunch() {
prefs().edit().putBoolean(LinphoneActivity.PREF_FIRST_LAUNCH, false).commit();
}
private synchronized void startEcCalibration() {
try {
LinphoneManager.getInstance().startEcCalibration(this);
ecCalibratePref.setSummary(ec_calibrating);
ecCalibratePref.getEditor().putBoolean(getString(pref_echo_canceller_calibration_key), false).commit();
} catch (LinphoneCoreException e) {
Log.w(e, "Cannot calibrate EC");
}
}
public void onEcCalibrationStatus(final EcCalibratorStatus status, final int delayMs) {
mHandler.post(new Runnable() {
public void run() {
if (status == EcCalibratorStatus.DoneNoEcho) {
ecCalibratePref.setSummary(R.string.no_echo);
ecPref.setChecked(false);
} else if (status == EcCalibratorStatus.Done) {
ecCalibratePref.setSummary(String.format(getString(R.string.ec_calibrated), delayMs));
ecPref.setChecked(true);
} else if (status == EcCalibratorStatus.Failed) {
ecCalibratePref.setSummary(R.string.failed);
ecPref.setChecked(true);
}
}
});
}
private void uncheckDisableAndHideCheckbox(int key) {
manageCheckbox(key, false, false, true);
}
private void uncheckAndDisableCheckbox(int key) {
manageCheckbox(key, false, false, false);
}
private void checkAndDisableCheckbox(int key) {
manageCheckbox(key, true, false, false);
}
private void manageCheckbox(int key, boolean value, boolean enabled, boolean hidden) {
Preference box = findPreference(key);
box.setEnabled(enabled);
Compatibility.setPreferenceChecked(box, value);
writeBoolean(key, value);
if (hidden) box.setLayoutResource(R.layout.hidden);
}
private void writeBoolean(int key, boolean value) {
prefs().edit().putBoolean(getString(key), value).commit();
}
private SharedPreferences prefs() {
return getPreferenceManager().getSharedPreferences();
}
private void detectAudioCodec(int id, String mime, int rate, int channels, boolean hide) {
Log.w("Payload type for codec " + mime + " = " + LinphoneManager.getLc().findPayloadType(mime, rate, channels));
boolean enable = LinphoneService.isReady() && LinphoneManager.getLc().findPayloadType(mime, rate, channels)!=null;
Preference cb = findPreference(id);
cb.setEnabled(enable);
if (hide && !enable) {
cb.setLayoutResource(R.layout.hidden);
}
}
private void detectVideoCodec(int id, String mime) {
findPreference(id).setEnabled(LinphoneManager.getInstance().detectVideoCodec(mime));
}
private void createDynamicAccountsPreferences() {
accounts = (PreferenceCategory) findPreference(getString(R.string.pref_sipaccounts_key));
accounts.removeAll();
// Get already configured extra accounts
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
nbAccounts = prefs.getInt(getString(R.string.pref_extra_accounts), 0);
for (int i = 0; i < nbAccounts; i++) {
// For each, add menus to configure it
addExtraAccountPreferencesButton(accounts, i, false);
}
}
public int getNbAccountsExtra() {
return nbAccounts;
}
private void addExtraAccountPreferencesButton(PreferenceCategory parent, final int n, boolean isNewAccount) {
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
if (isNewAccount) {
SharedPreferences.Editor editor = prefs.edit();
editor.putInt(getString(R.string.pref_extra_accounts), n+1);
editor.commit();
}
final LedPreference me = new LedPreference(mContext);
String keyUsername = getString(R.string.pref_username_key);
String keyDomain = getString(R.string.pref_domain_key);
if (n > 0) {
keyUsername += n + "";
keyDomain += n + "";
}
String username = prefs.getString(keyUsername, "");
String domain = prefs.getString(keyDomain, "");
if (username == null) {
me.setTitle(getString(R.string.pref_sipaccount));
} else {
me.setTitle(username + "@" + domain);
}
me.setOnPreferenceClickListener(new OnPreferenceClickListener()
{
public boolean onPreferenceClick(Preference preference) {
LinphoneActivity.instance().displayAccountSettings(n);
return false;
}
});
updateAccountLed(me, username, domain);
parent.addPreference(me);
}
private void updateAccountLed(final LedPreference me, final String username, final String domain) {
if (LinphoneManager.getLcIfManagerNotDestroyedOrNull() != null) {
for (LinphoneProxyConfig lpc : LinphoneManager.getLc().getProxyConfigList()) {
if (lpc.getIdentity().contains(username) && lpc.getIdentity().contains(domain)) {
if (lpc.getState() == LinphoneCore.RegistrationState.RegistrationOk) {
me.setLed(R.drawable.led_connected);
} else if (lpc.getState() == LinphoneCore.RegistrationState.RegistrationFailed) {
me.setLed(R.drawable.led_error);
} else if (lpc.getState() == LinphoneCore.RegistrationState.RegistrationProgress) {
me.setLed(R.drawable.led_inprogress);
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
updateAccountLed(me, username, domain);
}
}, 1500);
} else {
me.setLed(R.drawable.led_disconnected);
}
break;
}
}
}
}
private void addWizardPreferenceButton() {
Preference wizard = findPreference(getString(R.string.setup_key));
wizard.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(mContext, SetupActivity.class);
startActivityForResult(intent, WIZARD_INTENT);
return true;
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == WIZARD_INTENT && resultCode == Activity.RESULT_OK) {
if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().goToDialer();
}
}
}
private void initializeMediaEncryptionPreferences() {
LinphoneCore lc = null;
try {
lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
} catch (Exception e) {}
List<CharSequence> mencEntries=new ArrayList<CharSequence>();
List<CharSequence> mencEntryValues=new ArrayList<CharSequence>();
mencEntries.add(getString(R.string.media_encryption_none));
mencEntryValues.add(getString(R.string.pref_media_encryption_key_none));
if (lc == null || getResources().getBoolean(R.bool.disable_all_security_features_for_markets)) {
CharSequence[] contents=new CharSequence[mencEntries.size()];
mencEntries.toArray(contents);
mencPref.setEntries(contents);
contents=new CharSequence[mencEntryValues.size()];
mencEntryValues.toArray(contents);
mencPref.setEntryValues(contents);
mencPref.setDefaultValue(getString(R.string.media_encryption_none));
return;
}
boolean hasZrtp = lc.mediaEncryptionSupported(MediaEncryption.ZRTP);
boolean hasSrtp = lc.mediaEncryptionSupported(MediaEncryption.SRTP);
if (!hasSrtp && !hasZrtp){
mencPref.setEnabled(false);
}else{
if (hasSrtp){
mencEntries.add(getString(R.string.media_encryption_srtp));
mencEntryValues.add(getString(R.string.pref_media_encryption_key_srtp));
}
if (hasZrtp){
mencEntries.add(getString(R.string.media_encryption_zrtp));
mencEntryValues.add(getString(R.string.pref_media_encryption_key_zrtp));
}
CharSequence[] contents=new CharSequence[mencEntries.size()];
mencEntries.toArray(contents);
mencPref.setEntries(contents);
contents=new CharSequence[mencEntryValues.size()];
mencEntryValues.toArray(contents);
mencPref.setEntryValues(contents);
mencPref.setDefaultValue(getString(R.string.media_encryption_none));
//mencPref.setValueIndex(mencPref.findIndexOfValue(getString(R.string.media_encryption_none)));
}
}
private void initializePreferredVideoSizePreferences() {
List<CharSequence> entries = new ArrayList<CharSequence>();
List<CharSequence> values = new ArrayList<CharSequence>();
if (Version.isHDVideoCapable()) {
entries.add(getString(R.string.pref_preferred_video_size_hd));
values.add(getString(R.string.pref_preferred_video_size_hd_key));
}
entries.add(getString(R.string.pref_preferred_video_size_vga));
values.add(getString(R.string.pref_preferred_video_size_vga_key));
entries.add(getString(R.string.pref_preferred_video_size_qvga));
values.add(getString(R.string.pref_preferred_video_size_qvga_key));
ListPreference preferredVideoSize = (ListPreference) findPreference(pref_preferred_video_size_key);
CharSequence[] content = new CharSequence[entries.size()];
entries.toArray(content);
preferredVideoSize.setEntries(content);
content = new CharSequence[values.size()];
values.toArray(content);
preferredVideoSize.setEntryValues(content);
}
private void initializeTransportPreferences() {
List<CharSequence> mencEntries=new ArrayList<CharSequence>();
List<CharSequence> mencEntryValues=new ArrayList<CharSequence>();
mencEntries.add(getString(R.string.pref_transport_udp));
mencEntryValues.add(getString(R.string.pref_transport_udp_key));
mencEntries.add(getString(R.string.pref_transport_tcp));
mencEntryValues.add(getString(R.string.pref_transport_tcp_key));
if (!getResources().getBoolean(R.bool.disable_all_security_features_for_markets)) {
mencEntries.add(getString(R.string.pref_transport_tls));
mencEntryValues.add(getString(R.string.pref_transport_tls_key));
}
ListPreference transport = (ListPreference) findPreference(pref_transport_key);
CharSequence[] contents=new CharSequence[mencEntries.size()];
mencEntries.toArray(contents);
transport.setEntries(contents);
contents=new CharSequence[mencEntryValues.size()];
mencEntryValues.toArray(contents);
transport.setEntryValues(contents);
}
private Preference findPreference(int key) {
return getPreferenceManager().findPreference(getString(key));
}
@Override
public void onPause() {
super.onPause();
if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().applyConfigChangesIfNeeded();
}
}
@Override
public void onResume() {
super.onResume();
if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().selectMenu(FragmentsAvailable.SETTINGS);
}
if (!getResources().getBoolean(R.bool.hide_accounts)) {
createDynamicAccountsPreferences();
}
}
}

View file

@ -0,0 +1,148 @@
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;
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);
}
}

View file

@ -45,8 +45,7 @@ public class RemoteProvisioning {
}
String strFileContents = fileContents.toString();
Log.i("Download Success");
Log.i(strFileContents);
Log.i("Remote provisioning download successful");
// Initialize converter
LpConfig lp = LinphoneCoreFactory.instance().createLpConfig(mLocalLP);

View file

@ -0,0 +1,861 @@
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;
import org.linphone.LinphoneManager.EcCalibrationListener;
import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCore.EcCalibratorStatus;
import org.linphone.core.LinphoneCore.MediaEncryption;
import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.core.PayloadType;
import org.linphone.mediastream.Log;
import org.linphone.mediastream.Version;
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
import org.linphone.mediastream.video.capture.hwconf.Hacks;
import org.linphone.setup.SetupActivity;
import org.linphone.ui.LedPreference;
import org.linphone.ui.PreferencesListFragment;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
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;
private Handler mHandler = new Handler();
public SettingsFragment() {
super(R.xml.preferences);
mPrefs = LinphonePreferences.instance();
}
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
// Init the settings page interface
initSettings();
setListeners();
hideSettings();
}
// Inits the values or the listener on some settings
private void initSettings() {
//Init accounts on Resume instead of on Create to update the account list when coming back from wizard
initAudioSettings();
initVideoSettings();
initCallSettings();
initNetworkSettings();
initAdvancedSettings();
// Add action on About button
findPreference(getString(R.string.menu_about_key)).setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().displayAbout();
return true;
}
return false;
}
});
findPreference(getString(R.string.setup_key)).setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Intent intent = new Intent(LinphoneService.instance(), SetupActivity.class);
startActivityForResult(intent, WIZARD_INTENT);
return true;
}
});
}
// Sets listener for each preference to update the matching value in linphonecore
private void setListeners() {
setAudioPreferencesListener();
setVideoPreferencesListener();
setCallPreferencesListener();
setNetworkPreferencesListener();
setAdvancedPreferencesListener();
}
// Read the values set in resources and hides the settings accordingly
private void hideSettings() {
if (!getResources().getBoolean(R.bool.display_about_in_settings)) {
hidePreference(R.string.menu_about_key);
}
if (getResources().getBoolean(R.bool.hide_accounts)) {
emptyAndHidePreference(R.string.pref_sipaccounts_key);
}
if (getResources().getBoolean(R.bool.hide_wizard)) {
hidePreference(R.string.setup_key);
}
if (getResources().getBoolean(R.bool.disable_animations)) {
uncheckAndHidePreference(R.string.pref_animation_enable_key);
}
if (!getResources().getBoolean(R.bool.enable_linphone_friends)) {
emptyAndHidePreference(R.string.pref_linphone_friend_key);
}
if (getResources().getBoolean(R.bool.disable_chat)) {
findPreference(getString(R.string.pref_image_sharing_server_key)).setLayoutResource(R.layout.hidden);
}
if (!getResources().getBoolean(R.bool.enable_push_id)) {
hidePreference(R.string.pref_push_notification_key);
}
if (!Version.isVideoCapable()) {
uncheckAndHidePreference(R.string.pref_video_enable_key);
} else {
if (!AndroidCameraConfiguration.hasFrontCamera()) {
uncheckAndHidePreference(R.string.pref_video_use_front_camera_key);
}
}
if (Hacks.hasBuiltInEchoCanceller()) {
uncheckAndHidePreference(R.string.pref_echo_cancellation_key);
hidePreference(R.string.pref_echo_canceller_calibration_key);
}
if (!LinphoneManager.getLc().isTunnelAvailable()) {
emptyAndHidePreference(R.string.pref_tunnel_key);
}
if (getResources().getBoolean(R.bool.hide_camera_settings)) {
emptyAndHidePreference(R.string.pref_video_key);
hidePreference(R.string.pref_video_enable_key);
}
if (getResources().getBoolean(R.bool.disable_every_log)) {
uncheckAndHidePreference(R.string.pref_debug_key);
}
if (!LinphoneManager.getLc().upnpAvailable()) {
uncheckAndHidePreference(R.string.pref_upnp_enable_key);
}
}
private void uncheckAndHidePreference(int preferenceKey) {
Preference preference = findPreference(getString(preferenceKey));
if (!(preference instanceof CheckBoxPreference))
return;
CheckBoxPreference checkBoxPreference = (CheckBoxPreference) preference;
checkBoxPreference.setChecked(false);
hidePreference(checkBoxPreference);
}
private void emptyAndHidePreference(int preferenceKey) {
Preference preference = findPreference(getString(preferenceKey));
if (preference instanceof PreferenceCategory)
emptyAndHidePreferenceCategory(preferenceKey);
else if (preference instanceof PreferenceScreen)
emptyAndHidePreferenceScreen(preferenceKey);
}
private void emptyAndHidePreferenceCategory(int preferenceKey) {
Preference preference = findPreference(getString(preferenceKey));
if (!(preference instanceof PreferenceCategory))
return;
PreferenceCategory preferenceCategory = (PreferenceCategory) preference;
preferenceCategory.removeAll();
hidePreference(preferenceCategory);
}
private void emptyAndHidePreferenceScreen(int preferenceKey) {
Preference preference = findPreference(getString(preferenceKey));
if (!(preference instanceof PreferenceScreen))
return;
PreferenceScreen preferenceScreen = (PreferenceScreen) preference;
preferenceScreen.removeAll();
hidePreference(preferenceScreen);
}
private void hidePreference(int preferenceKey) {
hidePreference(findPreference(getString(preferenceKey)));
}
private void hidePreference(Preference preference) {
preference.setLayoutResource(R.layout.hidden);
}
private void setPreferenceDefaultValueAndSummary(int pref, String value) {
findPreference(getString(pref)).setDefaultValue(value);
findPreference(getString(pref)).setSummary(value);
}
private void initAccounts() {
PreferenceCategory accounts = (PreferenceCategory) findPreference(getString(R.string.pref_sipaccounts_key));
accounts.removeAll();
// Get already configured extra accounts
int defaultAccountID = mPrefs.getDefaultAccountIndex();
int nbAccounts = mPrefs.getAccountCount();
for (int i = 0; i < nbAccounts; i++) {
final int accountId = i;
// For each, add menus to configure it
LedPreference account = new LedPreference(LinphoneService.instance());
String username = mPrefs.getAccountUsername(accountId);
String domain = mPrefs.getAccountDomain(accountId);
if (username == null) {
account.setTitle(getString(R.string.pref_sipaccount));
} else {
account.setTitle(username + "@" + domain);
}
if (defaultAccountID == i) {
account.setSummary(R.string.default_account_flag);
}
account.setOnPreferenceClickListener(new OnPreferenceClickListener()
{
public boolean onPreferenceClick(Preference preference) {
LinphoneActivity.instance().displayAccountSettings(accountId);
return false;
}
});
updateAccountLed(account, username, domain, mPrefs.isAccountEnabled(i));
accounts.addPreference(account);
}
}
private void updateAccountLed(final LedPreference me, final String username, final String domain, boolean enabled) {
if (!enabled) {
me.setLed(R.drawable.led_disconnected);
return;
}
if (LinphoneManager.getLcIfManagerNotDestroyedOrNull() != null) {
for (LinphoneProxyConfig lpc : LinphoneManager.getLc().getProxyConfigList()) {
LinphoneAddress addr = null;
try {
addr = LinphoneCoreFactory.instance().createLinphoneAddress(lpc.getIdentity());
} catch (LinphoneCoreException e) {
me.setLed(R.drawable.led_disconnected);
return;
}
if (addr.getUserName().equals(username) && addr.getDomain().equals(domain)) {
if (lpc.getState() == LinphoneCore.RegistrationState.RegistrationOk) {
me.setLed(R.drawable.led_connected);
} else if (lpc.getState() == LinphoneCore.RegistrationState.RegistrationFailed) {
me.setLed(R.drawable.led_error);
} else if (lpc.getState() == LinphoneCore.RegistrationState.RegistrationProgress) {
me.setLed(R.drawable.led_inprogress);
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
updateAccountLed(me, username, domain, true);
}
}, 500);
} else {
me.setLed(R.drawable.led_disconnected);
}
break;
}
}
}
}
private void initMediaEncryptionPreference(ListPreference pref) {
List<CharSequence> entries = new ArrayList<CharSequence>();
List<CharSequence> values = new ArrayList<CharSequence>();
entries.add(getString(R.string.media_encryption_none));
values.add(getString(R.string.pref_media_encryption_key_none));
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc == null || getResources().getBoolean(R.bool.disable_all_security_features_for_markets)) {
setListPreferenceValues(pref, entries, values);
return;
}
boolean hasZrtp = lc.mediaEncryptionSupported(MediaEncryption.ZRTP);
boolean hasSrtp = lc.mediaEncryptionSupported(MediaEncryption.SRTP);
if (!hasSrtp && !hasZrtp) {
pref.setEnabled(false);
} else {
if (hasSrtp){
entries.add(getString(R.string.media_encryption_srtp));
values.add(getString(R.string.pref_media_encryption_key_srtp));
}
if (hasZrtp){
entries.add(getString(R.string.media_encryption_zrtp));
values.add(getString(R.string.pref_media_encryption_key_zrtp));
}
setListPreferenceValues(pref, entries, values);
}
MediaEncryption value = mPrefs.getMediaEncryption();
pref.setSummary(value.toString());
String key = getString(R.string.pref_media_encryption_key_none);
if (value.toString().equals(getString(R.string.media_encryption_srtp)))
key = getString(R.string.pref_media_encryption_key_srtp);
else if (value.toString().equals(getString(R.string.media_encryption_zrtp)))
key = getString(R.string.pref_media_encryption_key_zrtp);
pref.setDefaultValue(key);
}
private void initializeTransportPreferences(ListPreference pref) {
List<CharSequence> entries = new ArrayList<CharSequence>();
List<CharSequence> values = new ArrayList<CharSequence>();
entries.add(getString(R.string.pref_transport_udp));
values.add(getString(R.string.pref_transport_udp_key));
entries.add(getString(R.string.pref_transport_tcp));
values.add(getString(R.string.pref_transport_tcp_key));
if (!getResources().getBoolean(R.bool.disable_all_security_features_for_markets)) {
entries.add(getString(R.string.pref_transport_tls));
values.add(getString(R.string.pref_transport_tls_key));
}
setListPreferenceValues(pref, entries, values);
String value = mPrefs.getTransport();
pref.setSummary(value);
String key = getString(R.string.pref_transport_udp_key);
if (value.equals(getString(R.string.pref_transport_tcp)))
key = getString(R.string.pref_transport_tcp_key);
else if (value.equals(getString(R.string.pref_transport_tls)))
key = getString(R.string.pref_transport_tls_key);
pref.setDefaultValue(key);
}
private void initializePreferredVideoSizePreferences(ListPreference pref) {
List<CharSequence> entries = new ArrayList<CharSequence>();
List<CharSequence> values = new ArrayList<CharSequence>();
if (Version.isHDVideoCapable()) {
entries.add(getString(R.string.pref_preferred_video_size_hd));
values.add(getString(R.string.pref_preferred_video_size_hd_key));
}
entries.add(getString(R.string.pref_preferred_video_size_vga));
values.add(getString(R.string.pref_preferred_video_size_vga_key));
entries.add(getString(R.string.pref_preferred_video_size_qvga));
values.add(getString(R.string.pref_preferred_video_size_qvga_key));
setListPreferenceValues(pref, entries, values);
String value = mPrefs.getPreferredVideoSize();
pref.setSummary(value);
String key = getString(R.string.pref_preferred_video_size_qvga_key);
if (value.equals(getString(R.string.pref_preferred_video_size_vga)))
key = getString(R.string.pref_preferred_video_size_vga_key);
else if (value.equals(getString(R.string.pref_preferred_video_size_hd)))
key = getString(R.string.pref_preferred_video_size_hd_key);
pref.setDefaultValue(key);
}
private static void setListPreferenceValues(ListPreference pref, List<CharSequence> entries, List<CharSequence> values) {
CharSequence[] contents = new CharSequence[entries.size()];
entries.toArray(contents);
pref.setEntries(contents);
contents = new CharSequence[values.size()];
values.toArray(contents);
pref.setEntryValues(contents);
}
private void initAudioSettings() {
PreferenceCategory codecs = (PreferenceCategory) findPreference(getString(R.string.pref_codecs_key));
codecs.removeAll();
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
for(final PayloadType pt : lc.getAudioCodecs()) {
CheckBoxPreference codec = new CheckBoxPreference(LinphoneService.instance());
codec.setTitle(pt.getMime());
codec.setSummary(pt.getRate() + " Hz");
codec.setChecked(lc.isPayloadTypeEnabled(pt));
codec.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enable = (Boolean) newValue;
try {
LinphoneManager.getLcIfManagerNotDestroyedOrNull().enablePayloadType(pt, enable);
} catch (LinphoneCoreException e) {
e.printStackTrace();
}
return true;
}
});
codecs.addPreference(codec);
}
CheckBoxPreference echoCancellation = (CheckBoxPreference) findPreference(getString(R.string.pref_echo_cancellation_key));
echoCancellation.setChecked(mPrefs.isEchoCancellationEnabled());
}
private void setAudioPreferencesListener() {
findPreference(getString(R.string.pref_echo_cancellation_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enabled = (Boolean) newValue;
mPrefs.setEchoCancellation(enabled);
return true;
}
});
findPreference(getString(R.string.pref_echo_canceller_calibration_key)).setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
synchronized (SettingsFragment.this) {
try {
LinphoneManager.getInstance().startEcCalibration(SettingsFragment.this);
preference.setSummary(R.string.ec_calibrating);
} catch (LinphoneCoreException e) {
Log.w(e, "Cannot calibrate EC");
}
}
return true;
}
});
}
private void initVideoSettings() {
initializePreferredVideoSizePreferences((ListPreference) findPreference(getString(R.string.pref_preferred_video_size_key)));
PreferenceCategory codecs = (PreferenceCategory) findPreference(getString(R.string.pref_video_codecs_key));
codecs.removeAll();
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
for(final PayloadType pt : lc.getVideoCodecs()) {
CheckBoxPreference codec = new CheckBoxPreference(LinphoneService.instance());
codec.setTitle(pt.getMime());
if (!pt.getMime().equals("VP8")) {
if (getResources().getBoolean(R.bool.disable_all_patented_codecs_for_markets)) {
continue;
} else {
if (!Version.hasFastCpuWithAsmOptim() && pt.getMime().equals("H264"))
{
// Android without neon doesn't support H264
Log.w("CPU does not have asm optimisations available, disabling H264");
continue;
}
}
}
codec.setChecked(lc.isPayloadTypeEnabled(pt));
codec.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enable = (Boolean) newValue;
try {
LinphoneManager.getLcIfManagerNotDestroyedOrNull().enablePayloadType(pt, enable);
} catch (LinphoneCoreException e) {
e.printStackTrace();
}
return true;
}
});
codecs.addPreference(codec);
}
((CheckBoxPreference) findPreference(getString(R.string.pref_video_enable_key))).setChecked(mPrefs.isVideoEnabled());
((CheckBoxPreference) findPreference(getString(R.string.pref_video_use_front_camera_key))).setChecked(mPrefs.useFrontCam());
((CheckBoxPreference) findPreference(getString(R.string.pref_video_initiate_call_with_video_key))).setChecked(mPrefs.shouldInitiateVideoCall());
((CheckBoxPreference) findPreference(getString(R.string.pref_video_automatically_share_my_video_key))).setChecked(mPrefs.shouldAutomaticallyShareMyVideo());
((CheckBoxPreference) findPreference(getString(R.string.pref_video_automatically_accept_video_key))).setChecked(mPrefs.shouldAutomaticallyAcceptVideoRequests());
}
private void setVideoPreferencesListener() {
findPreference(getString(R.string.pref_video_enable_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enable = (Boolean) newValue;
mPrefs.enableVideo(enable);
return true;
}
});
findPreference(getString(R.string.pref_video_use_front_camera_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enable = (Boolean) newValue;
mPrefs.setFrontCamAsDefault(enable);
return true;
}
});
findPreference(getString(R.string.pref_video_initiate_call_with_video_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enable = (Boolean) newValue;
mPrefs.setInitiateVideoCall(enable);
return true;
}
});
findPreference(getString(R.string.pref_video_automatically_share_my_video_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enable = (Boolean) newValue;
mPrefs.setAutomaticallyShareMyVideo(enable);
return true;
}
});
findPreference(getString(R.string.pref_video_automatically_accept_video_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enable = (Boolean) newValue;
mPrefs.setAutomaticallyAcceptVideoRequests(enable);
return true;
}
});
findPreference(getString(R.string.pref_preferred_video_size_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.setPreferredVideoSize(newValue.toString());
preference.setSummary(mPrefs.getPreferredVideoSize());
return true;
}
});
}
private void initCallSettings() {
CheckBoxPreference rfc2833 = (CheckBoxPreference) findPreference(getString(R.string.pref_rfc2833_dtmf_key));
CheckBoxPreference sipInfo = (CheckBoxPreference) findPreference(getString(R.string.pref_sipinfo_dtmf_key));
if (mPrefs.useRfc2833Dtmfs()) {
rfc2833.setChecked(true);
sipInfo.setChecked(false);
sipInfo.setEnabled(false);
} else if (mPrefs.useSipInfoDtmfs()) {
sipInfo.setChecked(true);
rfc2833.setChecked(false);
rfc2833.setEnabled(false);
}
}
private void setCallPreferencesListener() {
findPreference(getString(R.string.pref_rfc2833_dtmf_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean use = (Boolean) newValue;
CheckBoxPreference sipInfo = (CheckBoxPreference) findPreference(getString(R.string.pref_sipinfo_dtmf_key));
sipInfo.setEnabled(!use);
sipInfo.setChecked(false);
mPrefs.sendDtmfsAsRfc2833(use);
return true;
}
});
findPreference(getString(R.string.pref_sipinfo_dtmf_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean use = (Boolean) newValue;
CheckBoxPreference rfc2833 = (CheckBoxPreference) findPreference(getString(R.string.pref_rfc2833_dtmf_key));
rfc2833.setEnabled(!use);
rfc2833.setChecked(false);
mPrefs.sendDTMFsAsSipInfo(use);
return true;
}
});
}
private void initNetworkSettings() {
initMediaEncryptionPreference((ListPreference) findPreference(getString(R.string.pref_media_encryption_key)));
initializeTransportPreferences((ListPreference) findPreference(getString(R.string.pref_transport_key)));
((CheckBoxPreference) findPreference(getString(R.string.pref_wifi_only_key))).setChecked(mPrefs.isWifiOnlyEnabled());
// 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));
randomPort.setChecked(mPrefs.isUsingRandomPort());
// Disable sip port choice if port is random
Preference sipPort = findPreference(getString(R.string.pref_sip_port_key));
sipPort.setEnabled(!randomPort.isChecked());
sipPort.setSummary(mPrefs.getSipPort());
sipPort.setDefaultValue(mPrefs.getSipPort());
Preference stun = findPreference(getString(R.string.pref_stun_server_key));
stun.setSummary(mPrefs.getStunServer());
stun.setDefaultValue(mPrefs.getStunServer());
((CheckBoxPreference) findPreference(getString(R.string.pref_push_notification_key))).setChecked(mPrefs.isPushNotificationEnabled());
((CheckBoxPreference) findPreference(getString(R.string.pref_ipv6_key))).setChecked(mPrefs.isUsingIpv6());
}
private void setNetworkPreferencesListener() {
findPreference(getString(R.string.pref_wifi_only_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.setWifiOnlyEnabled((Boolean) newValue);
return true;
}
});
findPreference(getString(R.string.pref_stun_server_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.setStunServer(newValue.toString());
preference.setSummary(newValue.toString());
return true;
}
});
findPreference(getString(R.string.pref_ice_enable_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
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);
return true;
}
});
findPreference(getString(R.string.pref_upnp_enable_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object 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;
}
});
findPreference(getString(R.string.pref_transport_use_random_ports_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean randomPort = (Boolean) newValue;
mPrefs.useRandomPort((Boolean) newValue);
findPreference(getString(R.string.pref_sip_port_key)).setEnabled(!randomPort);
return true;
}
});
findPreference(getString(R.string.pref_sip_port_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
int port = -1;
try {
port = Integer.parseInt(newValue.toString());
} catch (NumberFormatException nfe) { }
mPrefs.setSipPort(port);
preference.setSummary(newValue.toString());
return true;
}
});
findPreference(getString(R.string.pref_transport_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.setTransport(newValue.toString());
preference.setSummary(mPrefs.getTransport());
return true;
}
});
findPreference(getString(R.string.pref_media_encryption_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String value = newValue.toString();
MediaEncryption menc = MediaEncryption.None;
if (value.equals(getString(R.string.pref_media_encryption_key_srtp)))
menc = MediaEncryption.SRTP;
else if (value.equals(getString(R.string.pref_media_encryption_key_zrtp)))
menc = MediaEncryption.ZRTP;
mPrefs.setMediaEncryption(menc);
preference.setSummary(mPrefs.getMediaEncryption().toString());
return true;
}
});
findPreference(getString(R.string.pref_push_notification_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.setPushNotificationEnabled((Boolean) newValue);
return true;
}
});
findPreference(getString(R.string.pref_ipv6_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
mPrefs.useIpv6((Boolean) newValue);
return true;
}
});
}
private void initAdvancedSettings() {
((CheckBoxPreference)findPreference(getString(R.string.pref_debug_key))).setChecked(mPrefs.isDebugEnabled());
((CheckBoxPreference)findPreference(getString(R.string.pref_background_mode_key))).setChecked(mPrefs.isBackgroundModeEnabled());
((CheckBoxPreference)findPreference(getString(R.string.pref_animation_enable_key))).setChecked(mPrefs.areAnimationsEnabled());
((CheckBoxPreference)findPreference(getString(R.string.pref_autostart_key))).setChecked(mPrefs.isAutoStartEnabled());
setPreferenceDefaultValueAndSummary(R.string.pref_image_sharing_server_key, mPrefs.getSharingPictureServerUrl());
setPreferenceDefaultValueAndSummary(R.string.pref_remote_provisioning_key, mPrefs.getRemoteProvisioningUrl());
setPreferenceDefaultValueAndSummary(R.string.pref_display_name_key, mPrefs.getDefaultDisplayName());
setPreferenceDefaultValueAndSummary(R.string.pref_user_name_key, mPrefs.getDefaultUsername());
}
private void setAdvancedPreferencesListener() {
findPreference(getString(R.string.pref_debug_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean value = (Boolean) newValue;
mPrefs.setDebugEnabled(value);
return true;
}
});
findPreference(getString(R.string.pref_background_mode_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean value = (Boolean) newValue;
mPrefs.setBackgroundModeEnabled(value);
return true;
}
});
findPreference(getString(R.string.pref_animation_enable_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean value = (Boolean) newValue;
mPrefs.setAnimationsEnabled(value);
return true;
}
});
findPreference(getString(R.string.pref_autostart_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean value = (Boolean) newValue;
mPrefs.setAutoStart(value);
return true;
}
});
findPreference(getString(R.string.pref_image_sharing_server_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String value = (String) newValue;
mPrefs.setSharingPictureServerUrl(value);
preference.setSummary(value);
return true;
}
});
findPreference(getString(R.string.pref_remote_provisioning_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String value = (String) newValue;
mPrefs.setRemoteProvisioningUrl(value);
preference.setSummary(value);
return true;
}
});
findPreference(getString(R.string.pref_display_name_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String value = (String) newValue;
mPrefs.setDefaultDisplayName(value);
preference.setSummary(value);
return true;
}
});
findPreference(getString(R.string.pref_user_name_key)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String value = (String) newValue;
mPrefs.setDefaultUsername(value);
preference.setSummary(value);
return true;
}
});
}
@Override
public void onEcCalibrationStatus(final EcCalibratorStatus status, final int delayMs) {
mHandler.post(new Runnable() {
public void run() {
CheckBoxPreference echoCancellation = (CheckBoxPreference) findPreference(getString(R.string.pref_echo_cancellation_key));
Preference echoCancellerCalibration = findPreference(getString(R.string.pref_echo_canceller_calibration_key));
if (status == EcCalibratorStatus.DoneNoEcho) {
echoCancellerCalibration.setSummary(R.string.no_echo);
echoCancellation.setChecked(false);
} else if (status == EcCalibratorStatus.Done) {
echoCancellerCalibration.setSummary(String.format(getString(R.string.ec_calibrated), delayMs));
echoCancellation.setChecked(true);
} else if (status == EcCalibratorStatus.Failed) {
echoCancellerCalibration.setSummary(R.string.failed);
echoCancellation.setChecked(true);
}
}
});
}
@Override
public void onResume() {
super.onResume();
initAccounts();
if (LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().selectMenu(FragmentsAvailable.SETTINGS);
}
}
}

View file

@ -38,10 +38,8 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@ -485,13 +483,9 @@ public class StatusFragment extends Fragment {
}
class AccountsListAdapter extends BaseAdapter {
private SharedPreferences prefs;
private List<CheckBox> checkboxes;
AccountsListAdapter() {
if (LinphoneActivity.isInstanciated()) {
prefs = PreferenceManager.getDefaultSharedPreferences(LinphoneActivity.instance());
}
checkboxes = new ArrayList<CheckBox>();
}
@ -501,23 +495,16 @@ public class StatusFragment extends Fragment {
public void onClick(View v) {
CheckBox checkBox = (CheckBox) v;
if (checkBox.isChecked()) {
SharedPreferences.Editor editor = prefs.edit();
String tag = (String) checkBox.getTag();
String sipAddress = tag.split(":")[0];
int accountPosition = Integer.parseInt(tag.split(":")[1]);
int nbAccounts = prefs.getInt(getString(R.string.pref_extra_accounts), 0);
int nbAccounts = LinphonePreferences.instance().getAccountCount();
int accountIndex = 0;
for (int i = 0; i < nbAccounts; i++)
{
String keyUsername = getString(R.string.pref_username_key);
String keyDomain = getString(R.string.pref_domain_key);
if (i > 0) {
keyUsername += i + "";
keyDomain += i + "";
}
String username = prefs.getString(keyUsername, "");
String domain = prefs.getString(keyDomain, "");
String username = LinphonePreferences.instance().getAccountUsername(i);
String domain = LinphonePreferences.instance().getAccountDomain(i);
String identity = username + "@" + domain;
if (identity.equals(sipAddress)) {
accountIndex = i;
@ -525,8 +512,7 @@ public class StatusFragment extends Fragment {
}
}
editor.putInt(getString(R.string.pref_default_account_key), accountIndex);
editor.commit();
LinphonePreferences.instance().setDefaultAccount(accountIndex);
for (CheckBox cb : checkboxes) {
cb.setChecked(false);
@ -590,34 +576,30 @@ public class StatusFragment extends Fragment {
isDefault.setChecked(false);
isDefault.setEnabled(true);
if (prefs != null) {
int nbAccounts = prefs.getInt(getString(R.string.pref_extra_accounts), 0);
int nbAccounts = LinphonePreferences.instance().getAccountCount();
int accountIndex = 0;
for (int i = 0; i < nbAccounts; i++)
{
String keyUsername = getString(R.string.pref_username_key);
String keyDomain = getString(R.string.pref_domain_key);
if (i > 0) {
keyUsername += i + "";
keyDomain += i + "";
}
String username = prefs.getString(keyUsername, "");
String domain = prefs.getString(keyDomain, "");
String username = LinphonePreferences.instance().getAccountUsername(i);
String domain = LinphonePreferences.instance().getAccountDomain(i);
String id = username + "@" + domain;
if (id.equals(sipAddress)) {
accountIndex = i;
break;
}
}
if (prefs.getInt(getString(R.string.pref_default_account_key), 0) == accountIndex) {
// Force led if account is disabled
if (!LinphonePreferences.instance().isAccountEnabled(accountIndex)) {
status.setImageResource(getStatusIconResource(RegistrationState.RegistrationNone, false));
} else {
if (LinphonePreferences.instance().getDefaultAccountIndex() == accountIndex) {
isDefault.setChecked(true);
isDefault.setEnabled(false);
status.setImageResource(getStatusIconResource(lpc.getState(), true));
} else {
status.setImageResource(getStatusIconResource(lpc.getState(), false));
}
} else {
status.setImageResource(getStatusIconResource(lpc.getState(), false));
}
isDefault.setOnClickListener(defaultListener);

View file

@ -1,12 +1,11 @@
package org.linphone.compatibility;
import org.linphone.LinphonePreferences;
import org.linphone.R;
import org.linphone.mediastream.Log;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.view.Display;
import com.google.android.gcm.GCMRegistrar;
@ -40,28 +39,21 @@ public class ApiEightPlus {
}
public static void initPushNotificationService(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
try {
// Starting the push notification service
GCMRegistrar.checkDevice(context);
GCMRegistrar.checkManifest(context);
final String regId = GCMRegistrar.getRegistrationId(context);
String newPushSenderID = context.getString(R.string.push_sender_id);
String currentPushSenderID = prefs.getString(context.getString(R.string.push_sender_id_key), null);
String currentPushSenderID = LinphonePreferences.instance().getPushNotificationRegistrationID();
if (regId.equals("") || currentPushSenderID == null || !currentPushSenderID.equals(newPushSenderID)) {
GCMRegistrar.register(context, newPushSenderID);
Log.d("Push Notification : storing current sender id = " + newPushSenderID);
SharedPreferences.Editor editor = prefs.edit();
editor.putString(context.getString(R.string.push_sender_id_key), newPushSenderID);
editor.commit();
LinphonePreferences.instance().setPushNotificationRegistrationID(newPushSenderID);
} else {
Log.d("Push Notification : already registered with id = " + regId);
SharedPreferences.Editor editor = prefs.edit();
editor.putString(context.getString(R.string.push_reg_id_key), regId);
editor.commit();
LinphonePreferences.instance().setPushNotificationRegistrationID(regId);
}
} catch (java.lang.UnsupportedOperationException e) {
Log.i("Push Notification not activated");

View file

@ -19,14 +19,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
import org.linphone.LinphoneManager;
import org.linphone.LinphonePreferences;
import org.linphone.R;
import org.linphone.core.LinphoneCoreException;
import org.linphone.mediastream.Log;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import com.google.android.gcm.GCMBaseIntentService;
@ -57,27 +55,13 @@ public class GCMService extends GCMBaseIntentService {
@Override
protected void onRegistered(Context context, String regId) {
Log.d("Registered push notification : " + regId);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
editor.putString(context.getString(R.string.push_reg_id_key), regId);
editor.commit();
if (LinphoneManager.isInstanciated()) {
try {
LinphoneManager.getInstance().initAccounts();
} catch (LinphoneCoreException e) {
e.printStackTrace();
}
}
LinphonePreferences.instance().setPushNotificationRegistrationID(regId);
}
@Override
protected void onUnregistered(Context context, String regId) {
Log.w("Unregistered push notification : " + regId);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
editor.putString(context.getString(R.string.push_reg_id_key), null);
editor.commit();
LinphonePreferences.instance().setPushNotificationRegistrationID(null);
}
protected String[] getSenderIds(Context context) {

View file

@ -18,18 +18,17 @@ 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.LinphoneManager;
import org.linphone.LinphonePreferences;
import org.linphone.LinphoneSimpleListener.LinphoneOnRegistrationStateChangedListener;
import org.linphone.R;
import org.linphone.core.LinphoneCore.RegistrationState;
import org.linphone.mediastream.Log;
import org.linphone.core.LinphoneCoreException;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
@ -46,9 +45,9 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
private static SetupActivity instance;
private RelativeLayout back, next, cancel;
private SetupFragmentsEnum currentFragment;
private SharedPreferences mPref;
private SetupFragmentsEnum firstFragment;
private Fragment fragment;
private LinphonePreferences mPrefs;
private boolean accountCreated = false;
private Handler mHandler = new Handler();
@ -69,8 +68,7 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
currentFragment = (SetupFragmentsEnum) savedInstanceState.getSerializable("CurrentFragment");
}
}
mPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
mPrefs = LinphonePreferences.instance();
initUI();
instance = this;
@ -109,6 +107,7 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
int id = v.getId();
if (id == R.id.setup_cancel) {
LinphonePreferences.instance().firstLaunchSuccessful();
if (getResources().getBoolean(R.bool.setup_cancel_move_to_back)) {
moveTaskToBack(true);
} else {
@ -139,6 +138,7 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
@Override
public void onBackPressed() {
if (currentFragment == firstFragment) {
LinphonePreferences.instance().firstLaunchSuccessful();
if (getResources().getBoolean(R.bool.setup_cancel_move_to_back)) {
moveTaskToBack(true);
} else {
@ -163,7 +163,7 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
}
private void launchEchoCancellerCalibration(boolean sendEcCalibrationResult) {
if (LinphoneManager.getLc().needsEchoCalibration() && !mPref.getBoolean(getString(R.string.first_launch_suceeded_once_key), false)) {
if (LinphoneManager.getLc().needsEchoCalibration() && mPrefs.isFirstLaunch()) {
EchoCancellerCalibrationFragment fragment = new EchoCancellerCalibrationFragment();
fragment.enableEcCalibrationResultSending(sendEcCalibrationResult);
changeFragment(fragment);
@ -184,14 +184,6 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
}
saveCreatedAccount(username, password, domain);
LinphoneManager.getInstance().initializePayloads();
try {
LinphoneManager.getInstance().initFromConf();
} catch (Throwable e) {
Log.e(e, "Error while initializing from config in first login activity");
Toast.makeText(this, getString(R.string.error), Toast.LENGTH_LONG).show();
}
if (LinphoneManager.getLc().getDefaultProxyConfig() != null) {
launchEchoCancellerCalibration(sendEcCalibrationResult);
@ -213,7 +205,6 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
}
} else if (state == RegistrationState.RegistrationFailed) {
LinphoneManager.removeListener(registrationListener);
deleteCreatedAccount();
mHandler.post(new Runnable () {
public void run() {
Toast.makeText(SetupActivity.this, getString(R.string.first_launch_bad_login_password), Toast.LENGTH_LONG).show();
@ -227,17 +218,6 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
LinphoneManager.addListener(registrationListener);
saveCreatedAccount(username, password, domain);
LinphoneManager.getInstance().initializePayloads();
try {
LinphoneManager.getInstance().initFromConf();
} catch (Throwable e) {
LinphoneManager.removeListener(registrationListener);
deleteCreatedAccount();
Log.e(e, "Error while initializing from config in first login activity");
Toast.makeText(this, getString(R.string.error), Toast.LENGTH_LONG).show();
}
}
public void linphoneLogIn(String username, String password, boolean validate) {
@ -252,22 +232,6 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
logIn(username, password, domain, false);
}
private void writePreference(int key, String value) {
mPref.edit().putString(getString(key), value).commit();
}
private void writePreference(String key, String value) {
mPref.edit().putString(key, value).commit();
}
private void writePreference(int key, int value) {
mPref.edit().putInt(getString(key), value).commit();
}
private void writePreference(int key, boolean value) {
mPref.edit().putBoolean(getString(key), value).commit();
}
private void display(SetupFragmentsEnum fragment) {
switch (fragment) {
case WELCOME:
@ -305,57 +269,54 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
currentFragment = SetupFragmentsEnum.WIZARD;
}
public void deleteCreatedAccount() {
if (!accountCreated)
return;
writePreference(R.string.pref_extra_accounts, 0);
accountCreated = false;
}
public void saveCreatedAccount(String username, String password, String domain) {
if (accountCreated)
return;
int newAccountId = mPref.getInt(getString(R.string.pref_extra_accounts), 0);
if (newAccountId == -1)
newAccountId = 0;
writePreference(R.string.pref_extra_accounts, newAccountId+1);
if (newAccountId == 0) {
writePreference(R.string.pref_username_key, username);
writePreference(R.string.pref_passwd_key, password);
writePreference(R.string.pref_domain_key, domain);
boolean isMainAccountLinphoneDotOrg = domain.equals(getString(R.string.default_domain));
boolean useLinphoneDotOrgCustomPorts = getResources().getBoolean(R.bool.use_linphone_server_ports);
mPrefs.setNewAccountUsername(username);
mPrefs.setNewAccountDomain(domain);
mPrefs.setNewAccountPassword(password);
if (isMainAccountLinphoneDotOrg && useLinphoneDotOrgCustomPorts) {
if (getResources().getBoolean(R.bool.disable_all_security_features_for_markets)) {
writePreference(R.string.pref_proxy_key, domain + ":5228");
writePreference(R.string.pref_transport_key, getString(R.string.pref_transport_tcp_key));
mPrefs.setNewAccountProxy(domain + ":5228");
mPrefs.setTransport(getString(R.string.pref_transport_tcp_key));
}
else {
writePreference(R.string.pref_proxy_key, domain + ":5223");
writePreference(R.string.pref_transport_key, getString(R.string.pref_transport_tls_key));
mPrefs.setNewAccountProxy(domain + ":5223");
mPrefs.setTransport(getString(R.string.pref_transport_tls_key));
}
writePreference(R.string.pref_expire_key, "604800"); // 3600*24*7
writePreference(R.string.pref_enable_outbound_proxy_key, true);
writePreference(R.string.pref_stun_server_key, getString(R.string.default_stun));
writePreference(R.string.pref_ice_enable_key, true);
writePreference(R.string.pref_push_notification_key, true);
}
mPrefs.setNewAccountExpires("604800");
mPrefs.setNewAccountOutboundProxyEnabled(true);
mPrefs.setStunServer(getString(R.string.default_stun));
mPrefs.setIceEnabled(true);
mPrefs.setPushNotificationEnabled(true);
} else {
writePreference(getString(R.string.pref_username_key) + newAccountId, username);
writePreference(getString(R.string.pref_passwd_key) + newAccountId, password);
writePreference(getString(R.string.pref_domain_key) + newAccountId, domain);
}
String forcedProxy = getResources().getString(R.string.setup_forced_proxy);
if (!TextUtils.isEmpty(forcedProxy)) {
writePreference(R.string.pref_enable_outbound_proxy_key, true);
writePreference(R.string.pref_proxy_key, forcedProxy);
mPrefs.setNewAccountProxy(forcedProxy);
mPrefs.setNewAccountOutboundProxyEnabled(true);
}
}
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;
mPrefs.setNewAccountContactParameters(contactInfos);
}
}
try {
mPrefs.saveNewAccount();
accountCreated = true;
} catch (LinphoneCoreException e) {
e.printStackTrace();
}
}
public void displayWizardConfirm(String username) {
@ -375,16 +336,6 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
public void isAccountVerified() {
Toast.makeText(this, getString(R.string.setup_account_validated), Toast.LENGTH_LONG).show();
LinphoneManager.getInstance().initializePayloads();
try {
LinphoneManager.getInstance().initFromConf();
} catch (Throwable e) {
Log.e(e, "Error while initializing from config in first login activity");
Toast.makeText(this, getString(R.string.error), Toast.LENGTH_LONG).show();
}
launchEchoCancellerCalibration(true);
}
@ -393,7 +344,7 @@ public class SetupActivity extends FragmentActivity implements OnClickListener {
}
public void success() {
writePreference(R.string.first_launch_suceeded_once_key, true);
mPrefs.firstLaunchSuccessful();
setResult(Activity.RESULT_OK);
finish();
}

@ -1 +1 @@
Subproject commit 0e9de476d131cf2e2a39bf6bdf686a451e04d876
Subproject commit 107fb22c07a2372cdaf4d02687d828ec8f044170