summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSailesh Nepal <sail@google.com>2014-07-08 23:36:40 -0700
committerSailesh Nepal <sail@google.com>2014-07-09 09:58:35 -0700
commit788959e2d798da2d8a34cf89779421966d200f3d (patch)
treefb368613d5220be01b1ae0663e3c01596acb3045
parent9d67f24b3101e21894610c8e4b74a71ecd018898 (diff)
downloadandroid_packages_services_Telephony-788959e2d798da2d8a34cf89779421966d200f3d.tar.gz
android_packages_services_Telephony-788959e2d798da2d8a34cf89779421966d200f3d.tar.bz2
android_packages_services_Telephony-788959e2d798da2d8a34cf89779421966d200f3d.zip
SIP Part 1, move sip code
This CL moves the SIP code to sip/src/com/android/services/telephony/sip Moving the SIP code helps with a couple of things: - remove legacy dependency on old telephony code (PhoneUtils, etc...) - separate SIP from the PSTN connection code which is very different from SIP code - get the code ready for a future move out of Telephony all together Bug: 14999064 Change-Id: Id32de6517d31be4aa177b2764d5bac1e1f9851c2
-rw-r--r--Android.mk9
-rw-r--r--AndroidManifest.xml28
-rw-r--r--res/values/strings.xml198
-rw-r--r--sip/Android.mk31
-rw-r--r--sip/AndroidManifest.xml22
-rw-r--r--sip/proguard.flags3
-rw-r--r--sip/res/layout/sip_settings_ui.xml (renamed from res/layout/sip_settings_ui.xml)0
-rw-r--r--sip/res/values/array.xml (renamed from res/values/array.xml)0
-rw-r--r--sip/res/values/strings.xml210
-rw-r--r--sip/res/xml/sip_advanced_edit.xml (renamed from res/xml/sip_advanced_edit.xml)0
-rw-r--r--sip/res/xml/sip_edit.xml (renamed from res/xml/sip_edit.xml)0
-rw-r--r--sip/res/xml/sip_setting.xml (renamed from res/xml/sip_setting.xml)0
-rw-r--r--sip/res/xml/sip_settings_category.xml (renamed from res/xml/sip_settings_category.xml)2
-rw-r--r--sip/src/com/android/services/telephony/sip/SipBroadcastReceiver.java97
-rw-r--r--sip/src/com/android/services/telephony/sip/SipConnection.java109
-rw-r--r--sip/src/com/android/services/telephony/sip/SipConnectionService.java (renamed from src/com/android/services/telephony/SipConnectionService.java)169
-rw-r--r--sip/src/com/android/services/telephony/sip/SipEditor.java (renamed from src/com/android/phone/sip/SipEditor.java)133
-rw-r--r--sip/src/com/android/services/telephony/sip/SipProfileDb.java (renamed from src/com/android/phone/sip/SipProfileDb.java)22
-rw-r--r--sip/src/com/android/services/telephony/sip/SipSettings.java (renamed from src/com/android/phone/sip/SipSettings.java)60
-rw-r--r--sip/src/com/android/services/telephony/sip/SipSharedPreferences.java (renamed from src/com/android/phone/sip/SipSharedPreferences.java)13
-rw-r--r--sip/src/com/android/services/telephony/sip/SipUtil.java (renamed from src/com/android/phone/SipUtil.java)25
-rw-r--r--src/com/android/phone/CallFeaturesSetting.java8
-rw-r--r--src/com/android/phone/OutgoingCallBroadcaster.java30
-rw-r--r--src/com/android/phone/PhoneUtils.java16
-rw-r--r--src/com/android/phone/SipBroadcastReceiver.java145
-rw-r--r--src/com/android/phone/SipCallOptionHandler.java499
-rw-r--r--src/com/android/services/telephony/SipConnection.java79
-rw-r--r--src/com/android/services/telephony/TelephonyCallServiceProvider.java5
28 files changed, 712 insertions, 1201 deletions
diff --git a/Android.mk b/Android.mk
index 75c81ac58..586709f47 100644
--- a/Android.mk
+++ b/Android.mk
@@ -6,8 +6,8 @@ include $(CLEAR_VARS)
phone_common_dir := ../../apps/PhoneCommon
-src_dirs := src $(phone_common_dir)/src
-res_dirs := res $(phone_common_dir)/res
+src_dirs := src $(phone_common_dir)/src sip/src
+res_dirs := res $(phone_common_dir)/res sip/res
LOCAL_JAVA_LIBRARIES := telephony-common voip-common ims-common
LOCAL_STATIC_JAVA_LIBRARIES := \
@@ -23,14 +23,15 @@ LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, $(res_dirs))
LOCAL_AAPT_FLAGS := \
--auto-add-overlay \
- --extra-packages com.android.phone.common
+ --extra-packages com.android.phone.common \
+ --extra-packages com.android.services.telephony.sip
LOCAL_PACKAGE_NAME := TeleService
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
-LOCAL_PROGUARD_FLAG_FILES := proguard.flags
+LOCAL_PROGUARD_FLAG_FILES := proguard.flags sip/proguard.flags
include $(BUILD_PACKAGE)
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 83f9f2046..427961607 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -466,32 +466,38 @@
</intent-filter>
</activity>
- <receiver android:name="SipBroadcastReceiver">
+ <service android:singleUser="true"
+ android:name="com.android.services.telephony.sip.SipConnectionService"
+ android:label="@string/sip_connection_service_label">
+ <intent-filter>
+ <action android:name="android.telecomm.ConnectionService" />
+ </intent-filter>
+ </service>
+ <receiver android:name="com.android.services.telephony.sip.SipBroadcastReceiver">
<intent-filter>
<action android:name="com.android.phone.SIP_INCOMING_CALL" />
- <action android:name="com.android.phone.SIP_ADD_PHONE" />
- <action android:name="com.android.phone.SIP_REMOVE_PHONE" />
<action android:name="android.net.sip.SIP_SERVICE_UP" />
</intent-filter>
</receiver>
<activity android:label="Sip Settings"
- android:name=".sip.SipSettings"
+ android:name="com.android.services.telephony.sip.SipSettings"
android:theme="@style/SettingsLight"
android:launchMode="singleTop"
android:configChanges="orientation|screenSize|keyboardHidden"
- android:uiOptions="splitActionBarWhenNarrow">
+ android:uiOptions="splitActionBarWhenNarrow"
+ android:parentActivityName="com.android.phone.CallFeaturesSetting" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.net.sip.NOTIFY" />
</intent-filter>
</activity>
- <activity android:name=".sip.SipEditor"
+ <activity android:name="com.android.services.telephony.sip.SipEditor"
android:theme="@style/SettingsLight"
android:configChanges="orientation|screenSize|keyboardHidden"
android:uiOptions="splitActionBarWhenNarrow">
</activity>
- <activity android:name=".SipCallOptionHandler"
+ <activity android:name="com.android.services.telephony.SipCallOptionHandler"
android:theme="@style/SipCallOptionHandlerTheme"
android:screenOrientation="nosensor"
android:configChanges="orientation|screenSize|keyboardHidden"
@@ -558,14 +564,6 @@
<action android:name="android.telecomm.ConnectionService" />
</intent-filter>
</service>
- <service
- android:singleUser="true"
- android:name="com.android.services.telephony.SipConnectionService"
- android:label="@string/sip_connection_service_label">
- <intent-filter>
- <action android:name="android.telecomm.ConnectionService" />
- </intent-filter>
- </service>
<provider
android:name="PhoneSearchIndexablesProvider"
android:authorities="com.android.phone"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f9ff5b8d3..0e0042b0c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -914,9 +914,6 @@
<!-- In-call screen: message displayed in an error dialog -->
<string name="incall_error_supp_service_hangup">Unable to release call(s).</string>
- <!-- In-call screen: "call type" indication for a SIP call [CHAR LIMIT=30] -->
- <string name="incall_call_type_label_sip">Internet call</string>
-
<!-- Dialog title for the "radio enable" UI for emergency calls -->
<string name="emergency_enable_radio_dialog_title">Emergency call</string>
<!-- Status message for the "radio enable" UI for emergency calls -->
@@ -1132,199 +1129,6 @@
<!-- Use this to describe the select contact button in EditPhoneNumberPreference; currently for screen readers through accessibility. -->
<string name="selectContact">select contact</string>
-
- <!-- Start of SIP related strings defined from here. -->
-
- <!-- Title displayed SIP settings coming after other call settings in the call features screen. [CHAR LIMIT=NONE] -->
- <string name="sip_settings">Internet call settings</string>
- <!-- Title displayed SIP account settings in the sip settings category. [CHAR LIMIT=NONE] -->
- <string name="sip_accounts">Internet calling (SIP) accounts</string>
- <!-- Title displayed SIP account settings in the sip settings category. [CHAR LIMIT=NONE] -->
- <string name="sip_accounts_title">Accounts</string>
- <!-- Title displayed for the button of receiving incoming SIP calls flag. Enabled for receiving calls. [CHAR LIMIT=NONE] -->
- <string name="sip_receive_calls">Receive incoming calls</string>
- <!-- Help user to understand that it will require more battery usage if the 'receiving incoming call' is enabled. [CHAR LIMIT=NONE] -->
- <string name="sip_receive_calls_summary">Reduces battery life</string>
- <!-- Title for the dialog of selecting the way we handle an outgoing call. [CHAR LIMIT=NONE] -->
- <string name="sip_call_options_title">Use Internet calling</string>
- <!-- Title for the dialog of selecting the way we handle an outgoing call (Wi-Fi only). [CHAR LIMIT=NONE] -->
- <string name="sip_call_options_wifi_only_title">Use Internet calling (Wi-Fi only)</string>
-
- <!-- Item of the Internet call option dialog: for routing all outgoing calls via SIP. [CHAR LIMIT=NONE] -->
- <string name="sip_call_options_entry_1">For all calls when data network is available</string>
- <!-- Item of the Internet call option dialog: for routing a outgoing call via SIP if the destination is a SIP URI. [CHAR LIMIT=NONE] -->
- <string name="sip_call_options_entry_2">Only for Internet calls</string>
- <!-- Item of the Internet call option dialog: for asking user to select the way for each outgoing call. [CHAR LIMIT=NONE] -->
- <string name="sip_call_options_entry_3">Ask for each call</string>
- <!-- Item of the Internet call (Wi-Fi only) option dialog: for routing all outgoing calls via SIP. [CHAR LIMIT=NONE] -->
- <string name="sip_call_options_wifi_only_entry_1">For all calls</string>
-
- <!-- Title of the dialog to select the phone type for the outgoing call. [CHAR LIMIT=NONE] -->
- <string name ="pick_outgoing_call_phone_type">Place call</string>
-
- <!-- Title of the dialog to select the phone among the list of phones for the outgoing call. [CHAR LIMIT=NONE] -->
- <string name ="pick_outgoing_sip_phone">Use Internet calling account:</string>
-
- <!-- Text of checkbox to remember the sip phone for all outbound calls. [CHAR LIMIT=NONE] -->
- <string name ="remember_my_choice">Always use to place Internet calls</string>
-
- <!-- Help text of checkbox to unset the default sip phone for all outbound calls. [CHAR LIMIT=NONE] -->
- <string name ="reset_my_choice_hint">You can change which Internet calling account to use by default from the Phone &gt; Settings &gt; Internet call settings &gt; Accounts screen.</string>
-
- <!-- Item of the dialog to select the phone type for outgoing call. [CHAR LIMIT=NONE] -->
- <string name ="pstn_phone">Cell phone call</string>
-
- <!-- Item of the dialog to select the phone type for outgoing call. [CHAR LIMIT=NONE] -->
- <string name ="internet_phone">Internet call</string>
-
- <!-- Title of the dialog to redirect the user to SIP settings. [CHAR LIMIT=NONE] -->
- <string name ="no_sip_account_found_title">No Internet calling account</string>
- <!-- Message of the dialog to redirect the user to SIP settings. [CHAR LIMIT=NONE] -->
- <string name ="no_sip_account_found">There are no Internet calling accounts on this phone. Do you want to add one now?</string>
- <!-- Menu item for no sip account found dialog -->
- <string name="sip_menu_add">Add</string>
-
- <!-- Title for the button to add a new sip account. [CHAR LIMIT=NONE] -->
- <string name="add_sip_account">Add account</string>
- <!-- Title for the button to remove a sip account. [CHAR LIMIT=NONE] -->
- <string name="remove_sip_account">Remove account</string>
- <!-- String of the category which lists all sip accounts. [CHAR LIMIT=NONE] -->
- <string name="sip_account_list">SIP accounts</string>
- <!-- Toast message to indicate that the system is saving the account. [CHAR LIMIT=NONE] -->
- <string name="saving_account">Saving the account\u2026</string>
- <!-- Toast message to indicate that the system is removing the account. [CHAR LIMIT=NONE] -->
- <string name="removing_account">Removing the account\u2026</string>
-
- <!-- Menu item when the menu button is pressed in the sip account editor. [CHAR LIMIT=NONE] -->
- <string name="sip_menu_save">Save</string>
- <!-- Menu item when the menu button is pressed in the sip account editor. [CHAR LIMIT=NONE] -->
- <string name="sip_menu_discard">Discard</string>
-
- <!-- Title of the alert dialog. [CHAR LIMIT=NONE] -->
- <string name="alert_dialog_close">Close the profile</string>
- <!-- Title of the button to show in a alert dialog. [CHAR LIMIT=NONE] -->
- <string name="alert_dialog_ok">OK</string>
- <!-- Title of the button to show in a alert dialog. [CHAR LIMIT=NONE] -->
- <string name="close_profile">Close</string>
-
- <!-- Summary of a SIP account in the list of SIP accounts, consists of primary account status and registration status. This string indicates that this SIP account is a primary account and the string placeholder is the registration status, which will be one of the strings with name starting with "registration_status_" below. [CHAR LIMIT=NONE] -->
- <string name="primary_account_summary_with">Primary account. <xliff:g id="registration_status" example="Registering...">%s</xliff:g></string>
- <!-- Text of Internet-call registration status, checking current registration status with SIP service [CHAR LIMIT=NONE] -->
- <string name="registration_status_checking_status">Checking status...</string>
- <!-- Text of Internet-call registration status, registering with SIP server in order to receive calls on this account [CHAR LIMIT=NONE] -->
- <string name="registration_status_registering">Registering\u2026</string>
- <!-- Text of Internet-call registration status, still trying to register with SIP server [CHAR LIMIT=NONE] -->
- <string name="registration_status_still_trying">Still trying\u2026</string>
- <!-- Text of Internet-call registration status, currently not receiving calls on this account [CHAR LIMIT=NONE] -->
- <string name="registration_status_not_receiving">Not receiving calls.</string>
- <!-- Text of Internet-call registration status, no data connection [CHAR LIMIT=NONE] -->
- <string name="registration_status_no_data">Account registration stopped because there is no Internet connection.</string>
- <!-- Text of Internet-call registration status, no Wi-Fi connection [CHAR LIMIT=NONE] -->
- <string name="registration_status_no_wifi_data">Account registration stopped because there is no Wi-Fi connection.</string>
- <!-- Text of Internet-call registration status, registration process is not running due to some error [CHAR LIMIT=NONE] -->
- <string name="registration_status_not_running">Account registration unsuccessful.</string>
- <!-- Text of Internet-call registration status, currently we can receive calls on this account [CHAR LIMIT=NONE] -->
- <string name="registration_status_done">Receiving calls.</string>
- <!-- Text of Internet-call registration status, registration failed with a reason; will try again later [CHAR LIMIT=NONE] -->
- <string name="registration_status_failed_try_later">Account registration unsuccessful: (<xliff:g id="registration_error_message" example="timed out">%s</xliff:g>); will try later</string>
- <!-- Text of Internet-call registration status, registration failed due to invalid credentials [CHAR LIMIT=NONE] -->
- <string name="registration_status_invalid_credentials">Account registration unsuccessful: Incorrect username or password.</string>
- <!-- Text of Internet-call registration status, registration failed due to unknown host exception [CHAR LIMIT=NONE] -->
- <string name="registration_status_server_unreachable">Account registration unsuccessful: Check the server name.</string>
- <!-- Text for describing the account's owner and status. For example, 'Active, in use by Google Talk', it means that the account managed by SIP service was registered by the application 'Google Talk' and the status is active. [CHAR LIMIT=NONE] -->
- <string name="third_party_account_summary">This account is currently in use by the <xliff:g id="account_owner" example="Google Talk">%s</xliff:g> app.</string>
-
-
- <!-- Title of the sip editor screen. [CHAR LIMIT=NONE] -->
- <string name="sip_edit_title">SIP account details</string>
- <!-- Title of the sip editor screen. [CHAR LIMIT=NONE] -->
- <string name="sip_edit_new_title">SIP account details</string>
-
- <!-- Text of the domain address preference. [CHAR LIMIT=NONE] -->
- <string name="domain_address_title">Server</string>
- <!-- Text of the username preference. [CHAR LIMIT=NONE] -->
- <string name="username_title">Username</string>
- <!-- Text of the password preference. [CHAR LIMIT=NONE] -->
- <string name="password_title">Password</string>
- <!-- Text of the display name preference. [CHAR LIMIT=NONE] -->
- <string name="display_name_title">Display name</string>
- <!-- Text of the outbound proxy address preference. [CHAR LIMIT=NONE] -->
- <string name="proxy_address_title">Outbound proxy address</string>
- <!-- Text of the sip server/proxy port number. [CHAR LIMIT=NONE] -->
- <string name="port_title">Port number</string>
- <!-- Text of the transport type preference. [CHAR LIMIT=NONE] -->
- <string name="transport_title">Transport type</string>
- <!-- Text of the keepalive preference. [CHAR LIMIT=NONE] -->
- <string name="send_keepalive_title">Send keep-alive</string>
- <!-- Text of the set-primary preference. Simplified from "Make this my primary account". [CHAR LIMIT=NONE] -->
- <string name="set_primary_title">Set as primary account</string>
- <!-- Text of the set-primary preference summary. [CHAR LIMIT=NONE] -->
- <string name="set_primary_summary">Used for outbound calls</string>
- <!-- Text of the advanced settings section. [CHAR LIMIT=NONE] -->
- <string name="advanced_settings">Optional settings</string>
- <!-- Text of the username used in authentication. [CHAR LIMIT=NONE] -->
- <string name="auth_username_title">Authentication username</string>
- <!-- Help text of the auth_username field. [CHAR LIMIT=NONE] -->
- <string name="auth_username_summary">Username used for authentication</string>
-
- <!-- Initial status of the preferences is '<Not set>'. [CHAR LIMIT=NONE] -->
- <string name="default_preference_summary">&lt;Not set&gt;</string>
- <!-- Default value for the display-name preference summary. [CHAR LIMIT=NONE] -->
- <string name="display_name_summary">&lt;Same as username&gt;</string>
- <!-- Default value for the outbound-proxy-address preference summary. [CHAR LIMIT=NONE] -->
- <string name="optional_summary">&lt;Optional&gt;</string>
-
- <!-- Default sip server/proxy port number. -->
- <string translatable="false" name="default_port">5060</string>
- <!-- Default sip server/proxy transport protocol. -->
- <string translatable="false" name="default_transport">UDP</string>
-
-
- <!-- Hint to show the advanced settings section. [CHAR LIMIT=NONE] -->
- <string name="advanced_settings_show">▷ Touch to show all</string>
- <!-- Hint to hide the advanced settings section. [CHAR LIMIT=NONE] -->
- <string name="advanced_settings_hide">▽ Touch to hide all</string>
-
- <!-- Text in an alert dialog telling the user that some input field (name of which is also part of the strings being translated above) is required and can not be left blank. [CHAR LIMIT=NONE] -->
- <string name="empty_alert"><xliff:g id="input_field_name" example="Username, Password...">%s</xliff:g> is required and can\'t be left blank.</string>
- <!-- Showing that port number is out of range in an alert dialog. [CHAR LIMIT=NONE] -->
- <string name="not_a_valid_port">Port number should be within 1000 and 65534.</string>
-
- <!-- Title of the alert dialog to notify user that there is no Internet connectivity. [CHAR LIMIT=40] -->
- <string name="no_internet_available_title">No Internet connection</string>
- <!-- Title of the alert dialog to notify user that there is no Wi-Fi connectivity. [CHAR LIMIT=40] -->
- <string name="no_wifi_available_title">No Wi-Fi connection</string>
- <!-- Message of the alert dialog to notify user that there is no Internet connectivity. [CHAR LIMIT=NONE] -->
- <string name="no_internet_available">To place an Internet call, check your Internet connection first.</string>
- <!-- Message of the alert dialog to notify user that there is no Wi-Fi connectivity. [CHAR LIMIT=NONE] -->
- <string name="no_wifi_available">You need to be connected to a Wi-Fi network for Internet calls (use the Wireless &amp; Network settings).</string>
- <!-- Title of the alert dialog to notify user that Internet call is not supported. [CHAR LIMIT=40] -->
- <string name="no_voip">Internet calling not supported</string>
-
- <!-- Option for whether the SIP service should send keepalive messages. [CHAR LIMIT=40] -->
- <string translatable="true" name="sip_system_decide">Automatic</string>
- <!-- Option for whether the SIP service should send keepalive messages. [CHAR LIMIT=40] -->
- <string translatable="true" name="sip_always_send_keepalive">Always send</string>
-
- <!-- Do not translate the following strings. Used for the Internet call options. Need to be in-sync with Settings.System.SIP_ strings. -->
- <string translatable="false" name="sip_always">SIP_ALWAYS</string>
- <string translatable="false" name="sip_address_only">SIP_ADDRESS_ONLY</string>
- <string translatable="false" name="sip_ask_me_each_time">SIP_ASK_ME_EACH_TIME</string>
-
- <!-- Do not translate the following strings. Used for the preference keys -->
- <string translatable="false" name="domain_address">SipDomain</string>
- <string translatable="false" name="username">UserName</string>
- <string translatable="false" name="password">Password</string>
- <string translatable="false" name="display_name">DisplayName</string>
- <string translatable="false" name="proxy_address">ProxyAddress</string>
- <string translatable="false" name="port">Port</string>
- <string translatable="false" name="transport">Protocol</string>
- <string translatable="false" name="send_keepalive">SendKeepAlive</string>
- <string translatable="false" name="set_primary">SetPrimary</string>
- <string translatable="false" name="advanced_settings_container">advanced settings container</string>
- <string translatable="false" name="auth_username">AuthUserName</string>
- <!-- End of SIP settings related strings -->
-
<!-- Dialog title to notify user that Voice calling is not supported
on this device. [CHAR LIMIT=40] -->
<string name="not_voice_capable">Voice calling not supported</string>
@@ -1514,6 +1318,4 @@
<!-- Label for PSTN connection service. -->
<string name="pstn_connection_service_label">Built-in SIM cards</string>
- <!-- Label for SIP connection service. -->
- <string name="sip_connection_service_label">Built-in Internet calling</string>
</resources>
diff --git a/sip/Android.mk b/sip/Android.mk
new file mode 100644
index 000000000..cefb86d0b
--- /dev/null
+++ b/sip/Android.mk
@@ -0,0 +1,31 @@
+# Copyright 2014, The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, res)
+
+LOCAL_JAVA_LIBRARIES := telephony-common voip-common
+
+LOCAL_PACKAGE_NAME := com.android.services.telephony.sip
+
+LOCAL_PROGUARD_FLAG_FILES := proguard.flags
+
+include $(BUILD_PACKAGE)
+include $(CLEAR_VARS)
diff --git a/sip/AndroidManifest.xml b/sip/AndroidManifest.xml
new file mode 100644
index 000000000..0249abdf6
--- /dev/null
+++ b/sip/AndroidManifest.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2014 The Android Open Source Project
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License
+ -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.services.telephony.sip">
+
+</manifest>
+
diff --git a/sip/proguard.flags b/sip/proguard.flags
new file mode 100644
index 000000000..23ae8c150
--- /dev/null
+++ b/sip/proguard.flags
@@ -0,0 +1,3 @@
+-verbose
+-keep class com.android.services.telephony.sip.SipConnectionService
+-keep class com.android.services.telephony.sip.SipBroadcastReceiver
diff --git a/res/layout/sip_settings_ui.xml b/sip/res/layout/sip_settings_ui.xml
index 872c4b502..872c4b502 100644
--- a/res/layout/sip_settings_ui.xml
+++ b/sip/res/layout/sip_settings_ui.xml
diff --git a/res/values/array.xml b/sip/res/values/array.xml
index 245c09b26..245c09b26 100644
--- a/res/values/array.xml
+++ b/sip/res/values/array.xml
diff --git a/sip/res/values/strings.xml b/sip/res/values/strings.xml
new file mode 100644
index 000000000..41499b25f
--- /dev/null
+++ b/sip/res/values/strings.xml
@@ -0,0 +1,210 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2014 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+
+ <!-- Title displayed SIP settings coming after other call settings in the call features screen. [CHAR LIMIT=NONE] -->
+ <string name="sip_settings">Internet call settings</string>
+ <!-- Title displayed SIP account settings in the sip settings category. [CHAR LIMIT=NONE] -->
+ <string name="sip_accounts">Internet calling (SIP) accounts</string>
+ <!-- Title displayed SIP account settings in the sip settings category. [CHAR LIMIT=NONE] -->
+ <string name="sip_accounts_title">Accounts</string>
+ <!-- Title displayed for the button of receiving incoming SIP calls flag. Enabled for receiving calls. [CHAR LIMIT=NONE] -->
+ <string name="sip_receive_calls">Receive incoming calls</string>
+ <!-- Help user to understand that it will require more battery usage if the 'receiving incoming call' is enabled. [CHAR LIMIT=NONE] -->
+ <string name="sip_receive_calls_summary">Reduces battery life</string>
+ <!-- Title for the dialog of selecting the way we handle an outgoing call. [CHAR LIMIT=NONE] -->
+ <string name="sip_call_options_title">Use Internet calling</string>
+ <!-- Title for the dialog of selecting the way we handle an outgoing call (Wi-Fi only). [CHAR LIMIT=NONE] -->
+ <string name="sip_call_options_wifi_only_title">Use Internet calling (Wi-Fi only)</string>
+
+ <!-- Item of the Internet call option dialog: for routing all outgoing calls via SIP. [CHAR LIMIT=NONE] -->
+ <string name="sip_call_options_entry_1">For all calls when data network is available</string>
+ <!-- Item of the Internet call option dialog: for routing a outgoing call via SIP if the destination is a SIP URI. [CHAR LIMIT=NONE] -->
+ <string name="sip_call_options_entry_2">Only for Internet calls</string>
+ <!-- Item of the Internet call option dialog: for asking user to select the way for each outgoing call. [CHAR LIMIT=NONE] -->
+ <string name="sip_call_options_entry_3">Ask for each call</string>
+ <!-- Item of the Internet call (Wi-Fi only) option dialog: for routing all outgoing calls via SIP. [CHAR LIMIT=NONE] -->
+ <string name="sip_call_options_wifi_only_entry_1">For all calls</string>
+
+ <!-- Title of the dialog to select the phone type for the outgoing call. [CHAR LIMIT=NONE] -->
+ <string name ="pick_outgoing_call_phone_type">Place call</string>
+
+ <!-- Title of the dialog to select the phone among the list of phones for the outgoing call. [CHAR LIMIT=NONE] -->
+ <string name ="pick_outgoing_sip_phone">Use Internet calling account:</string>
+
+ <!-- Text of checkbox to remember the sip phone for all outbound calls. [CHAR LIMIT=NONE] -->
+ <string name ="remember_my_choice">Always use to place Internet calls</string>
+
+ <!-- Help text of checkbox to unset the default sip phone for all outbound calls. [CHAR LIMIT=NONE] -->
+ <string name ="reset_my_choice_hint">You can change which Internet calling account to use by default from the Phone &gt; Settings &gt; Internet call settings &gt; Accounts screen.</string>
+
+ <!-- Item of the dialog to select the phone type for outgoing call. [CHAR LIMIT=NONE] -->
+ <string name ="pstn_phone">Cell phone call</string>
+
+ <!-- Item of the dialog to select the phone type for outgoing call. [CHAR LIMIT=NONE] -->
+ <string name ="internet_phone">Internet call</string>
+
+ <!-- Title of the dialog to redirect the user to SIP settings. [CHAR LIMIT=NONE] -->
+ <string name ="no_sip_account_found_title">No Internet calling account</string>
+ <!-- Message of the dialog to redirect the user to SIP settings. [CHAR LIMIT=NONE] -->
+ <string name ="no_sip_account_found">There are no Internet calling accounts on this phone. Do you want to add one now?</string>
+ <!-- Menu item for no sip account found dialog -->
+ <string name="sip_menu_add">Add</string>
+
+ <!-- Title for the button to add a new sip account. [CHAR LIMIT=NONE] -->
+ <string name="add_sip_account">Add account</string>
+ <!-- Title for the button to remove a sip account. [CHAR LIMIT=NONE] -->
+ <string name="remove_sip_account">Remove account</string>
+ <!-- String of the category which lists all sip accounts. [CHAR LIMIT=NONE] -->
+ <string name="sip_account_list">SIP accounts</string>
+ <!-- Toast message to indicate that the system is saving the account. [CHAR LIMIT=NONE] -->
+ <string name="saving_account">Saving the account\u2026</string>
+ <!-- Toast message to indicate that the system is removing the account. [CHAR LIMIT=NONE] -->
+ <string name="removing_account">Removing the account\u2026</string>
+
+ <!-- Menu item when the menu button is pressed in the sip account editor. [CHAR LIMIT=NONE] -->
+ <string name="sip_menu_save">Save</string>
+ <!-- Menu item when the menu button is pressed in the sip account editor. [CHAR LIMIT=NONE] -->
+ <string name="sip_menu_discard">Discard</string>
+
+ <!-- Title of the alert dialog. [CHAR LIMIT=NONE] -->
+ <string name="alert_dialog_close">Close the profile</string>
+ <!-- Title of the button to show in a alert dialog. [CHAR LIMIT=NONE] -->
+ <string name="alert_dialog_ok">OK</string>
+ <!-- Title of the button to show in a alert dialog. [CHAR LIMIT=NONE] -->
+ <string name="close_profile">Close</string>
+
+ <!-- Summary of a SIP account in the list of SIP accounts, consists of primary account status and registration status. This string indicates that this SIP account is a primary account and the string placeholder is the registration status, which will be one of the strings with name starting with "registration_status_" below. [CHAR LIMIT=NONE] -->
+ <string name="primary_account_summary_with">Primary account. <xliff:g id="registration_status" example="Registering...">%s</xliff:g></string>
+ <!-- Text of Internet-call registration status, checking current registration status with SIP service [CHAR LIMIT=NONE] -->
+ <string name="registration_status_checking_status">Checking status...</string>
+ <!-- Text of Internet-call registration status, registering with SIP server in order to receive calls on this account [CHAR LIMIT=NONE] -->
+ <string name="registration_status_registering">Registering\u2026</string>
+ <!-- Text of Internet-call registration status, still trying to register with SIP server [CHAR LIMIT=NONE] -->
+ <string name="registration_status_still_trying">Still trying\u2026</string>
+ <!-- Text of Internet-call registration status, currently not receiving calls on this account [CHAR LIMIT=NONE] -->
+ <string name="registration_status_not_receiving">Not receiving calls.</string>
+ <!-- Text of Internet-call registration status, no data connection [CHAR LIMIT=NONE] -->
+ <string name="registration_status_no_data">Account registration stopped because there is no Internet connection.</string>
+ <!-- Text of Internet-call registration status, no Wi-Fi connection [CHAR LIMIT=NONE] -->
+ <string name="registration_status_no_wifi_data">Account registration stopped because there is no Wi-Fi connection.</string>
+ <!-- Text of Internet-call registration status, registration process is not running due to some error [CHAR LIMIT=NONE] -->
+ <string name="registration_status_not_running">Account registration unsuccessful.</string>
+ <!-- Text of Internet-call registration status, currently we can receive calls on this account [CHAR LIMIT=NONE] -->
+ <string name="registration_status_done">Receiving calls.</string>
+ <!-- Text of Internet-call registration status, registration failed with a reason; will try again later [CHAR LIMIT=NONE] -->
+ <string name="registration_status_failed_try_later">Account registration unsuccessful: (<xliff:g id="registration_error_message" example="timed out">%s</xliff:g>); will try later</string>
+ <!-- Text of Internet-call registration status, registration failed due to invalid credentials [CHAR LIMIT=NONE] -->
+ <string name="registration_status_invalid_credentials">Account registration unsuccessful: Incorrect username or password.</string>
+ <!-- Text of Internet-call registration status, registration failed due to unknown host exception [CHAR LIMIT=NONE] -->
+ <string name="registration_status_server_unreachable">Account registration unsuccessful: Check the server name.</string>
+ <!-- Text for describing the account's owner and status. For example, 'Active, in use by Google Talk', it means that the account managed by SIP service was registered by the application 'Google Talk' and the status is active. [CHAR LIMIT=NONE] -->
+ <string name="third_party_account_summary">This account is currently in use by the <xliff:g id="account_owner" example="Google Talk">%s</xliff:g> app.</string>
+
+
+ <!-- Title of the sip editor screen. [CHAR LIMIT=NONE] -->
+ <string name="sip_edit_title">SIP account details</string>
+ <!-- Title of the sip editor screen. [CHAR LIMIT=NONE] -->
+ <string name="sip_edit_new_title">SIP account details</string>
+
+ <!-- Text of the domain address preference. [CHAR LIMIT=NONE] -->
+ <string name="domain_address_title">Server</string>
+ <!-- Text of the username preference. [CHAR LIMIT=NONE] -->
+ <string name="username_title">Username</string>
+ <!-- Text of the password preference. [CHAR LIMIT=NONE] -->
+ <string name="password_title">Password</string>
+ <!-- Text of the display name preference. [CHAR LIMIT=NONE] -->
+ <string name="display_name_title">Display name</string>
+ <!-- Text of the outbound proxy address preference. [CHAR LIMIT=NONE] -->
+ <string name="proxy_address_title">Outbound proxy address</string>
+ <!-- Text of the sip server/proxy port number. [CHAR LIMIT=NONE] -->
+ <string name="port_title">Port number</string>
+ <!-- Text of the transport type preference. [CHAR LIMIT=NONE] -->
+ <string name="transport_title">Transport type</string>
+ <!-- Text of the keepalive preference. [CHAR LIMIT=NONE] -->
+ <string name="send_keepalive_title">Send keep-alive</string>
+ <!-- Text of the set-primary preference. Simplified from "Make this my primary account". [CHAR LIMIT=NONE] -->
+ <string name="set_primary_title">Set as primary account</string>
+ <!-- Text of the set-primary preference summary. [CHAR LIMIT=NONE] -->
+ <string name="set_primary_summary">Used for outbound calls</string>
+ <!-- Text of the advanced settings section. [CHAR LIMIT=NONE] -->
+ <string name="advanced_settings">Optional settings</string>
+ <!-- Text of the username used in authentication. [CHAR LIMIT=NONE] -->
+ <string name="auth_username_title">Authentication username</string>
+ <!-- Help text of the auth_username field. [CHAR LIMIT=NONE] -->
+ <string name="auth_username_summary">Username used for authentication</string>
+
+ <!-- Initial status of the preferences is '<Not set>'. [CHAR LIMIT=NONE] -->
+ <string name="default_preference_summary">&lt;Not set&gt;</string>
+ <!-- Default value for the display-name preference summary. [CHAR LIMIT=NONE] -->
+ <string name="display_name_summary">&lt;Same as username&gt;</string>
+ <!-- Default value for the outbound-proxy-address preference summary. [CHAR LIMIT=NONE] -->
+ <string name="optional_summary">&lt;Optional&gt;</string>
+
+ <!-- Default sip server/proxy port number. -->
+ <string translatable="false" name="default_port">5060</string>
+ <!-- Default sip server/proxy transport protocol. -->
+ <string translatable="false" name="default_transport">UDP</string>
+
+
+ <!-- Hint to show the advanced settings section. [CHAR LIMIT=NONE] -->
+ <string name="advanced_settings_show">▷ Touch to show all</string>
+ <!-- Hint to hide the advanced settings section. [CHAR LIMIT=NONE] -->
+ <string name="advanced_settings_hide">▽ Touch to hide all</string>
+
+ <!-- Text in an alert dialog telling the user that some input field (name of which is also part of the strings being translated above) is required and can not be left blank. [CHAR LIMIT=NONE] -->
+ <string name="empty_alert"><xliff:g id="input_field_name" example="Username, Password...">%s</xliff:g> is required and can\'t be left blank.</string>
+ <!-- Showing that port number is out of range in an alert dialog. [CHAR LIMIT=NONE] -->
+ <string name="not_a_valid_port">Port number should be within 1000 and 65534.</string>
+
+ <!-- Title of the alert dialog to notify user that there is no Internet connectivity. [CHAR LIMIT=40] -->
+ <string name="no_internet_available_title">No Internet connection</string>
+ <!-- Title of the alert dialog to notify user that there is no Wi-Fi connectivity. [CHAR LIMIT=40] -->
+ <string name="no_wifi_available_title">No Wi-Fi connection</string>
+ <!-- Message of the alert dialog to notify user that there is no Internet connectivity. [CHAR LIMIT=NONE] -->
+ <string name="no_internet_available">To place an Internet call, check your Internet connection first.</string>
+ <!-- Message of the alert dialog to notify user that there is no Wi-Fi connectivity. [CHAR LIMIT=NONE] -->
+ <string name="no_wifi_available">You need to be connected to a Wi-Fi network for Internet calls (use the Wireless &amp; Network settings).</string>
+ <!-- Title of the alert dialog to notify user that Internet call is not supported. [CHAR LIMIT=40] -->
+ <string name="no_voip">Internet calling not supported</string>
+
+ <!-- Option for whether the SIP service should send keepalive messages. [CHAR LIMIT=40] -->
+ <string translatable="true" name="sip_system_decide">Automatic</string>
+ <!-- Option for whether the SIP service should send keepalive messages. [CHAR LIMIT=40] -->
+ <string translatable="true" name="sip_always_send_keepalive">Always send</string>
+
+ <!-- Do not translate the following strings. Used for the Internet call options. Need to be in-sync with Settings.System.SIP_ strings. -->
+ <string translatable="false" name="sip_always">SIP_ALWAYS</string>
+ <string translatable="false" name="sip_address_only">SIP_ADDRESS_ONLY</string>
+ <string translatable="false" name="sip_ask_me_each_time">SIP_ASK_ME_EACH_TIME</string>
+
+ <!-- Do not translate the following strings. Used for the preference keys -->
+ <string translatable="false" name="domain_address">SipDomain</string>
+ <string translatable="false" name="username">UserName</string>
+ <string translatable="false" name="password">Password</string>
+ <string translatable="false" name="display_name">DisplayName</string>
+ <string translatable="false" name="proxy_address">ProxyAddress</string>
+ <string translatable="false" name="port">Port</string>
+ <string translatable="false" name="transport">Protocol</string>
+ <string translatable="false" name="send_keepalive">SendKeepAlive</string>
+ <string translatable="false" name="set_primary">SetPrimary</string>
+ <string translatable="false" name="advanced_settings_container">advanced settings container</string>
+ <string translatable="false" name="auth_username">AuthUserName</string>
+
+ <!-- Label for SIP connection service. -->
+ <string name="sip_connection_service_label">Built-in Internet calling</string>
+</resources>
diff --git a/res/xml/sip_advanced_edit.xml b/sip/res/xml/sip_advanced_edit.xml
index b7974bacc..b7974bacc 100644
--- a/res/xml/sip_advanced_edit.xml
+++ b/sip/res/xml/sip_advanced_edit.xml
diff --git a/res/xml/sip_edit.xml b/sip/res/xml/sip_edit.xml
index f091fc179..f091fc179 100644
--- a/res/xml/sip_edit.xml
+++ b/sip/res/xml/sip_edit.xml
diff --git a/res/xml/sip_setting.xml b/sip/res/xml/sip_setting.xml
index c75440485..c75440485 100644
--- a/res/xml/sip_setting.xml
+++ b/sip/res/xml/sip_setting.xml
diff --git a/res/xml/sip_settings_category.xml b/sip/res/xml/sip_settings_category.xml
index e857be686..17ee577b1 100644
--- a/res/xml/sip_settings_category.xml
+++ b/sip/res/xml/sip_settings_category.xml
@@ -27,7 +27,7 @@
<intent android:action="android.intent.action.MAIN"
android:targetPackage="com.android.phone"
- android:targetClass="com.android.phone.sip.SipSettings" />
+ android:targetClass="com.android.services.telephony.sip.SipSettings" />
</PreferenceScreen>
<ListPreference
diff --git a/sip/src/com/android/services/telephony/sip/SipBroadcastReceiver.java b/sip/src/com/android/services/telephony/sip/SipBroadcastReceiver.java
new file mode 100644
index 000000000..b949351e8
--- /dev/null
+++ b/sip/src/com/android/services/telephony/sip/SipBroadcastReceiver.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.services.telephony.sip;
+
+import com.android.internal.telephony.Phone;
+import com.android.internal.telephony.PhoneConstants;
+import com.android.internal.telephony.PhoneFactory;
+import com.android.internal.telephony.sip.SipPhone;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.net.sip.SipAudioCall;
+import android.net.sip.SipException;
+import android.net.sip.SipManager;
+import android.net.sip.SipProfile;
+import android.util.Log;
+
+import java.util.List;
+
+/**
+ * Broadcast receiver that handles SIP-related intents.
+ */
+public class SipBroadcastReceiver extends BroadcastReceiver {
+ private static final String PREFIX = "[SipBroadcastReceiver] ";
+ private static final boolean VERBOSE = true; /* STOP SHIP if true */
+
+ @Override
+ public void onReceive(Context context, final Intent intent) {
+ String action = intent.getAction();
+
+ if (!SipUtil.isVoipSupported(context)) {
+ if (VERBOSE) log("SIP VOIP not supported: " + action);
+ return;
+ }
+
+ if (action.equals(SipManager.ACTION_SIP_INCOMING_CALL)) {
+ takeCall(context, intent);
+ } else if (action.equals(SipManager.ACTION_SIP_SERVICE_UP)) {
+ registerAllProfiles(context);
+ } else {
+ if (VERBOSE) log("onReceive, action not processed: " + action);
+ }
+ }
+
+ private void takeCall(Context context, Intent intent) {
+ if (VERBOSE) log("takeCall, intent: " + intent);
+ // TODO(sail): Add support for incoming SIP calls.
+ }
+
+ private void registerAllProfiles(final Context context) {
+ if (VERBOSE) log("registerAllProfiles, start auto registration");
+ final SipSharedPreferences sipSharedPreferences = new SipSharedPreferences(context);
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ SipManager sipManager = SipManager.newInstance(context);
+ SipProfileDb profileDb = new SipProfileDb(context);
+ String primaryProfile = sipSharedPreferences.getPrimaryAccount();
+
+ List<SipProfile> sipProfileList = profileDb.retrieveSipProfileList();
+
+ for (SipProfile profile : sipProfileList) {
+ boolean isPrimaryProfile = profile.getUriString().equals(primaryProfile);
+ if (profile.getAutoRegistration() || isPrimaryProfile) {
+ if (VERBOSE) log("registerAllProfiles, profile: " + profile);
+ try {
+ sipManager.open(profile,
+ SipUtil.createIncomingCallPendingIntent(context), null);
+ } catch (SipException e) {
+ log("registerAllProfiles, profile: " + profile.getProfileName() +
+ ", exception: " + e);
+ }
+ }
+ }
+ }}
+ ).start();
+ }
+
+ private static void log(String msg) {
+ Log.d(SipUtil.LOG_TAG, PREFIX + msg);
+ }
+}
diff --git a/sip/src/com/android/services/telephony/sip/SipConnection.java b/sip/src/com/android/services/telephony/sip/SipConnection.java
new file mode 100644
index 000000000..40239a4d7
--- /dev/null
+++ b/sip/src/com/android/services/telephony/sip/SipConnection.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.services.telephony.sip;
+
+import android.telecomm.CallAudioState;
+import android.telecomm.Connection;
+import android.util.Log;
+
+import java.util.List;
+
+public class SipConnection extends Connection {
+ private static final String PREFIX = "[SipConnection] ";
+ private static final boolean VERBOSE = true; /* STOP SHIP if true */
+
+ private final com.android.internal.telephony.Connection mConnection;
+
+ public SipConnection(com.android.internal.telephony.Connection connection) {
+ if (VERBOSE) log("new SipConnection, connection: " + connection);
+ mConnection = connection;
+ }
+
+ @Override
+ protected void onSetAudioState(CallAudioState state) {
+ if (VERBOSE) log("onSetAudioState: " + state);
+ }
+
+ @Override
+ protected void onSetState(int state) {
+ if (VERBOSE) log("onSetState, state: " + Connection.stateToString(state));
+ }
+
+ @Override
+ protected void onPlayDtmfTone(char c) {
+ if (VERBOSE) log("onPlayDtmfTone");
+ }
+
+ @Override
+ protected void onStopDtmfTone() {
+ if (VERBOSE) log("onStopDtmfTone");
+ }
+
+ @Override
+ protected void onDisconnect() {
+ if (VERBOSE) log("onDisconnect");
+ }
+
+ @Override
+ protected void onSeparate() {
+ if (VERBOSE) log("onSeparate");
+ }
+
+ @Override
+ protected void onAbort() {
+ if (VERBOSE) log("onAbort");
+ }
+
+ @Override
+ protected void onHold() {
+ if (VERBOSE) log("onHold");
+ }
+
+ @Override
+ protected void onUnhold() {
+ if (VERBOSE) log("onUnhold");
+ }
+
+ @Override
+ protected void onAnswer() {
+ if (VERBOSE) log("onAnswer");
+ }
+
+ @Override
+ protected void onReject() {
+ if (VERBOSE) log("onReject");
+ }
+
+ @Override
+ protected void onPostDialContinue(boolean proceed) {
+ if (VERBOSE) log("onPostDialContinue, proceed: " + proceed);
+ }
+
+ @Override
+ protected void onChildrenChanged(List<Connection> children) {
+ if (VERBOSE) log("onChildrenChanged, children: " + children);
+ }
+
+ @Override
+ protected void onPhoneAccountClicked() {
+ if (VERBOSE) log("onPhoneAccountClicked");
+ }
+
+ private static void log(String msg) {
+ Log.d(SipUtil.LOG_TAG, PREFIX + msg);
+ }
+}
diff --git a/src/com/android/services/telephony/SipConnectionService.java b/sip/src/com/android/services/telephony/sip/SipConnectionService.java
index ea364bd4f..9b7b33fe2 100644
--- a/src/com/android/services/telephony/SipConnectionService.java
+++ b/sip/src/com/android/services/telephony/sip/SipConnectionService.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.services.telephony;
+package com.android.services.telephony.sip;
import android.content.Context;
import android.net.sip.SipException;
@@ -23,95 +23,25 @@ import android.net.sip.SipProfile;
import android.net.Uri;
import android.os.AsyncTask;
import android.provider.Settings;
+import android.telecomm.Connection;
+import android.telecomm.ConnectionRequest;
+import android.telecomm.ConnectionService;
+import android.telecomm.Response;
+import android.telephony.DisconnectCause;
import android.telephony.PhoneNumberUtils;
+import android.util.Log;
+import com.android.internal.telephony.CallStateException;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.sip.SipPhone;
-import com.android.phone.Constants;
-import com.android.phone.PhoneUtils;
-import com.android.phone.sip.SipProfileDb;
-import com.android.phone.sip.SipSharedPreferences;
-import android.telecomm.Connection;
-import android.telecomm.ConnectionRequest;
-import android.telecomm.Response;
import java.util.HashMap;
-/**
- * Connection service that uses the SIP phone.
- */
-public class SipConnectionService extends TelephonyConnectionService {
- private static HashMap<String, SipPhone> sSipPhones = new HashMap<String, SipPhone>();
-
- /** {@inheritDoc} */
- @Override
- public void onCreateConnections(
- ConnectionRequest request,
- OutgoingCallResponse callback) {
- new GetSipProfileTask(this, request, callback).execute();
- super.onCreateConnections(request, callback);
- }
-
- /** {@inheritDoc} */
- @Override
- public void onCreateIncomingConnection(
- ConnectionRequest request,
- Response<ConnectionRequest, Connection> callback) {
- super.onCreateIncomingConnection(request, callback);
- // TODO: fill in
- }
-
- /** {@inheritDoc} */
- @Override
- protected boolean canCall(Uri handle) {
- return shouldUseSipPhone(handle.getScheme(), handle.getSchemeSpecificPart());
- }
-
- /** {@inheritDoc} */
- @Override
- protected TelephonyConnection onCreateTelephonyConnection(
- ConnectionRequest request,
- Phone phone,
- com.android.internal.telephony.Connection connection) {
- return new SipConnection(connection);
- }
-
- private boolean shouldUseSipPhone(String scheme, String number) {
- // Scheme must be "sip" or "tel".
- boolean isKnownCallScheme = Constants.SCHEME_TEL.equals(scheme)
- || Constants.SCHEME_SIP.equals(scheme);
- if (!isKnownCallScheme) {
- return false;
- }
-
- // Is voip supported
- boolean voipSupported = PhoneUtils.isVoipSupported();
- if (!voipSupported) {
- return false;
- }
-
- // Check SIP address only
- SipSharedPreferences sipSharedPreferences = new SipSharedPreferences(this);
- String callOption = sipSharedPreferences.getSipCallOption();
- boolean isRegularNumber = Constants.SCHEME_TEL.equals(scheme)
- && !PhoneNumberUtils.isUriNumber(number);
- if (callOption.equals(Settings.System.SIP_ADDRESS_ONLY) && isRegularNumber) {
- return false;
- }
-
- // Check if no SIP profiles.
- SipProfileDb sipProfileDb = new SipProfileDb(this);
- if (sipProfileDb.getProfilesCount() == 0 && isRegularNumber) {
- return false;
- }
-
- return true;
- }
+public class SipConnectionService extends ConnectionService {
+ private static final String PREFIX = "[SipConnectionService] ";
+ private static final boolean VERBOSE = true; /* STOP SHIP if true */
- /**
- * Asynchronously looks up the SIP profile to use for the given call.
- */
private class GetSipProfileTask extends AsyncTask<Void, Void, SipProfile> {
private final ConnectionRequest mRequest;
private final OutgoingCallResponse mResponse;
@@ -146,24 +76,79 @@ public class SipConnectionService extends TelephonyConnectionService {
}
}
+ @Override
+ protected void onCreateConnections(
+ ConnectionRequest request,
+ OutgoingCallResponse<Connection> callback) {
+ if (VERBOSE) log("onCreateConnections, request: " + request);
+ new GetSipProfileTask(this, request, callback).execute();
+ }
+
+ @Override
+ protected void onCreateConferenceConnection(
+ String token,
+ Connection connection,
+ Response<String, Connection> callback) {
+ if (VERBOSE) log("onCreateConferenceConnection, connection: " + connection);
+ }
+
+ @Override
+ protected void onCreateIncomingConnection(
+ ConnectionRequest request,
+ Response<ConnectionRequest, Connection> callback) {
+ if (VERBOSE) log("onCreateIncomingConnection, request: " + request);
+ }
+
+ @Override
+ protected void onConnectionAdded(Connection connection) {
+ if (VERBOSE) log("onConnectionAdded, connection: " + connection);
+ }
+
+ @Override
+ protected void onConnectionRemoved(Connection connection) {
+ if (VERBOSE) log("onConnectionRemoved, connection: " + connection);
+ }
+
private void onSipProfileChosen(
SipProfile profile,
ConnectionRequest request,
OutgoingCallResponse response) {
- SipPhone phone = null;
if (profile != null) {
String sipUri = profile.getUriString();
- phone = sSipPhones.get(sipUri);
- if (phone == null) {
- try {
- SipManager.newInstance(this).open(profile);
- phone = (SipPhone) PhoneFactory.makeSipPhone(sipUri);
- sSipPhones.put(sipUri, phone);
- } catch (SipException e) {
- Log.e(this, e, "Failed to make a SIP phone");
- }
+ SipPhone phone = null;
+ try {
+ SipManager.newInstance(this).open(profile);
+ phone = (SipPhone) PhoneFactory.makeSipPhone(sipUri);
+ startCallWithPhone(phone, request, response);
+ } catch (SipException e) {
+ log("Failed to make a SIP phone: " + e);
+ response.onFailure(request, DisconnectCause.ERROR_UNSPECIFIED,
+ "Failed to make a SIP phone: " + e);
}
+ } else {
+ response.onFailure(request, DisconnectCause.ERROR_UNSPECIFIED,
+ "Failed to find SIP profile");
}
- startCallWithPhone(phone, request, response);
+ }
+
+ protected void startCallWithPhone(
+ Phone phone,
+ ConnectionRequest request,
+ OutgoingCallResponse<Connection> response) {
+ String number = request.getHandle().getSchemeSpecificPart();
+ try {
+ com.android.internal.telephony.Connection connection =
+ phone.dial(number, request.getVideoState());
+ SipConnection sipConnection = new SipConnection(connection);
+ response.onSuccess(request, sipConnection);
+ } catch (CallStateException e) {
+ log("Call to Phone.dial failed with exception: " + e);
+ response.onFailure(request, DisconnectCause.ERROR_UNSPECIFIED,
+ "Call to Phone.dial failed with exception: " + e);
+ }
+ }
+
+ private static void log(String msg) {
+ Log.d(SipUtil.LOG_TAG, PREFIX + msg);
}
}
diff --git a/src/com/android/phone/sip/SipEditor.java b/sip/src/com/android/services/telephony/sip/SipEditor.java
index 8145c94a3..a76529686 100644
--- a/src/com/android/phone/sip/SipEditor.java
+++ b/sip/src/com/android/services/telephony/sip/SipEditor.java
@@ -14,13 +14,12 @@
* limitations under the License.
*/
-package com.android.phone.sip;
+package com.android.services.telephony.sip;
import com.android.internal.telephony.CallManager;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
-import com.android.phone.R;
-import com.android.phone.SipUtil;
+import com.android.services.telephony.sip.SipUtil;
import android.app.ActionBar;
import android.app.AlertDialog;
@@ -53,11 +52,13 @@ import java.util.Arrays;
*/
public class SipEditor extends PreferenceActivity
implements Preference.OnPreferenceChangeListener {
+ private static final String PREFIX = "[SipEditor] ";
+ private static final boolean VERBOSE = true; /* STOP SHIP if true */
+
private static final int MENU_SAVE = Menu.FIRST;
private static final int MENU_DISCARD = Menu.FIRST + 1;
private static final int MENU_REMOVE = Menu.FIRST + 2;
- private static final String TAG = SipEditor.class.getSimpleName();
private static final String KEY_PROFILE = "profile";
private static final String GET_METHOD_PREFIX = "get";
private static final char SCRAMBLED = '*';
@@ -119,8 +120,10 @@ public class SipEditor extends PreferenceActivity
String oldValue = getValue();
((EditTextPreference) preference).setText(value);
if (this != Password) {
- Log.v(TAG, this + ": setValue() " + value + ": " + oldValue
- + " --> " + getValue());
+ if (VERBOSE) {
+ log(this + ": setValue() " + value + ": " + oldValue + " --> " +
+ getValue());
+ }
}
} else if (preference instanceof ListPreference) {
((ListPreference) preference).setValue(value);
@@ -155,7 +158,7 @@ public class SipEditor extends PreferenceActivity
@Override
public void onCreate(Bundle savedInstanceState) {
- Log.v(TAG, "start profile editor");
+ if (VERBOSE) log("onCreate, start profile editor");
super.onCreate(savedInstanceState);
mSipManager = SipManager.newInstance(this);
@@ -187,7 +190,7 @@ public class SipEditor extends PreferenceActivity
@Override
public void onPause() {
- Log.v(TAG, "SipEditor onPause(): finishing? " + isFinishing());
+ if (VERBOSE) log("onPause, finishing: " + isFinishing());
if (!isFinishing()) {
mHomeButtonClicked = true;
validateAndSetResult();
@@ -247,13 +250,12 @@ public class SipEditor extends PreferenceActivity
private void saveAndRegisterProfile(SipProfile p) throws IOException {
if (p == null) return;
mProfileDb.saveProfile(p);
- if (p.getAutoRegistration()
- || mSharedPreferences.isPrimaryAccount(p.getUriString())) {
+ if (p.getAutoRegistration() || mSharedPreferences.isPrimaryAccount(p.getUriString())) {
try {
- mSipManager.open(p, SipUtil.createIncomingCallPendingIntent(),
- null);
+ mSipManager.open(p, SipUtil.createIncomingCallPendingIntent(this), null);
} catch (Exception e) {
- Log.e(TAG, "register failed: " + p.getUriString(), e);
+ log("saveAndRegisterProfile, register failed for profile: " + p.getUriString() +
+ ", exception: " + e);
}
}
}
@@ -268,7 +270,7 @@ public class SipEditor extends PreferenceActivity
try {
mSipManager.close(uri);
} catch (Exception e) {
- Log.e(TAG, "unregister failed: " + uri, e);
+ log("unregisterProfile, unregister failed for profile: " + uri + ", exception: " + e);
}
}
@@ -289,7 +291,7 @@ public class SipEditor extends PreferenceActivity
private void showAlert(final String message) {
if (mHomeButtonClicked) {
- Log.v(TAG, "Home button clicked, don't show dialog: " + message);
+ if (VERBOSE) log("Home button clicked, don't show dialog: " + message);
return;
}
runOnUiThread(new Runnable() {
@@ -361,29 +363,26 @@ public class SipEditor extends PreferenceActivity
Intent intent = new Intent(this, SipSettings.class);
intent.putExtra(SipSettings.KEY_SIP_PROFILE, (Parcelable) profile);
setResult(RESULT_OK, intent);
- Toast.makeText(this, R.string.saving_account, Toast.LENGTH_SHORT)
- .show();
+ Toast.makeText(this, R.string.saving_account, Toast.LENGTH_SHORT).show();
replaceProfile(mOldProfile, profile);
// do finish() in replaceProfile() in a background thread
} catch (Exception e) {
- Log.w(TAG, "Can not create new SipProfile", e);
+ log("validateAndSetResult, can not create new SipProfile, exception: " + e);
showAlert(e);
}
}
private void unregisterOldPrimaryAccount() {
String primaryAccountUri = mSharedPreferences.getPrimaryAccount();
- Log.v(TAG, "old primary: " + primaryAccountUri);
- if ((primaryAccountUri != null)
- && !mSharedPreferences.isReceivingCallsEnabled()) {
- Log.v(TAG, "unregister old primary: " + primaryAccountUri);
+ if (VERBOSE) log("unregisterOldPrimaryAccount, old primary: " + primaryAccountUri);
+ if ((primaryAccountUri != null) && !mSharedPreferences.isReceivingCallsEnabled()) {
+ if (VERBOSE) log("unregisterOldPrimaryAccount, calling unregister");
unregisterProfile(primaryAccountUri);
}
}
- private void replaceProfile(final SipProfile oldProfile,
- final SipProfile newProfile) {
+ private void replaceProfile(final SipProfile oldProfile, final SipProfile newProfile) {
// Replace profile in a background thread as it takes time to access the
// storage; do finish() once everything goes fine.
// newProfile may be null if the old profile is to be deleted rather
@@ -401,7 +400,7 @@ public class SipEditor extends PreferenceActivity
saveAndRegisterProfile(newProfile);
finish();
} catch (Exception e) {
- Log.e(TAG, "Can not save/register new SipProfile", e);
+ log("replaceProfile, can not save/register new SipProfile, exception: " + e);
showAlert(e);
}
}
@@ -414,20 +413,20 @@ public class SipEditor extends PreferenceActivity
}
private SipProfile createSipProfile() throws Exception {
- return new SipProfile.Builder(
- PreferenceKey.Username.getValue(),
- PreferenceKey.DomainAddress.getValue())
- .setProfileName(getProfileName())
- .setPassword(PreferenceKey.Password.getValue())
- .setOutboundProxy(PreferenceKey.ProxyAddress.getValue())
- .setProtocol(PreferenceKey.Transport.getValue())
- .setDisplayName(PreferenceKey.DisplayName.getValue())
- .setPort(Integer.parseInt(PreferenceKey.Port.getValue()))
- .setSendKeepAlive(isAlwaysSendKeepAlive())
- .setAutoRegistration(
- mSharedPreferences.isReceivingCallsEnabled())
- .setAuthUserName(PreferenceKey.AuthUserName.getValue())
- .build();
+ return new SipProfile.Builder(
+ PreferenceKey.Username.getValue(),
+ PreferenceKey.DomainAddress.getValue())
+ .setProfileName(getProfileName())
+ .setPassword(PreferenceKey.Password.getValue())
+ .setOutboundProxy(PreferenceKey.ProxyAddress.getValue())
+ .setProtocol(PreferenceKey.Transport.getValue())
+ .setDisplayName(PreferenceKey.DisplayName.getValue())
+ .setPort(Integer.parseInt(PreferenceKey.Port.getValue()))
+ .setSendKeepAlive(isAlwaysSendKeepAlive())
+ .setAutoRegistration(
+ mSharedPreferences.isReceivingCallsEnabled())
+ .setAuthUserName(PreferenceKey.AuthUserName.getValue())
+ .build();
}
public boolean onPreferenceChange(Preference pref, Object newValue) {
@@ -469,15 +468,14 @@ public class SipEditor extends PreferenceActivity
private void loadPreferencesFromProfile(SipProfile p) {
if (p != null) {
- Log.v(TAG, "Edit the existing profile : " + p.getProfileName());
+ if (VERBOSE) log("loadPreferencesFromProfile, existing profile: " + p.getProfileName());
try {
Class profileClass = SipProfile.class;
for (PreferenceKey key : PreferenceKey.values()) {
Method meth = profileClass.getMethod(GET_METHOD_PREFIX
+ getString(key.text), (Class[])null);
if (key == PreferenceKey.SendKeepAlive) {
- boolean value = ((Boolean)
- meth.invoke(p, (Object[]) null)).booleanValue();
+ boolean value = ((Boolean) meth.invoke(p, (Object[]) null)).booleanValue();
key.setValue(getString(value
? R.string.sip_always_send_keepalive
: R.string.sip_system_decide));
@@ -488,10 +486,10 @@ public class SipEditor extends PreferenceActivity
}
checkIfDisplayNameSet();
} catch (Exception e) {
- Log.e(TAG, "Can not load pref from profile", e);
+ log("loadPreferencesFromProfile, can not load pref from profile, exception: " + e);
}
} else {
- Log.v(TAG, "Edit a new profile");
+ if (VERBOSE) log("loadPreferencesFromProfile, edit a new profile");
for (PreferenceKey key : PreferenceKey.values()) {
key.preference.setOnPreferenceChangeListener(this);
@@ -509,10 +507,8 @@ public class SipEditor extends PreferenceActivity
}
private boolean isAlwaysSendKeepAlive() {
- ListPreference pref = (ListPreference)
- PreferenceKey.SendKeepAlive.preference;
- return getString(R.string.sip_always_send_keepalive).equals(
- pref.getValue());
+ ListPreference pref = (ListPreference) PreferenceKey.SendKeepAlive.preference;
+ return getString(R.string.sip_always_send_keepalive).equals(pref.getValue());
}
private void setCheckBox(PreferenceKey key, boolean checked) {
@@ -535,7 +531,7 @@ public class SipEditor extends PreferenceActivity
String displayName = PreferenceKey.DisplayName.getValue();
mDisplayNameSet = !TextUtils.isEmpty(displayName)
&& !displayName.equals(getDefaultDisplayName());
- Log.d(TAG, "displayName set? " + mDisplayNameSet);
+ if (VERBOSE) log("checkIfDisplayNameSet, displayName set: " + mDisplayNameSet);
if (mDisplayNameSet) {
PreferenceKey.DisplayName.preference.setSummary(displayName);
} else {
@@ -562,19 +558,18 @@ public class SipEditor extends PreferenceActivity
PrimaryAccountSelector(SipProfile profile) {
mCheckbox = (CheckBoxPreference) getPreferenceScreen()
.findPreference(getString(R.string.set_primary));
- boolean noPrimaryAccountSet =
- !mSharedPreferences.hasPrimaryAccount();
+ boolean noPrimaryAccountSet = !mSharedPreferences.hasPrimaryAccount();
boolean editNewProfile = (profile == null);
- mWasPrimaryAccount = !editNewProfile
- && mSharedPreferences.isPrimaryAccount(
- profile.getUriString());
+ mWasPrimaryAccount = !editNewProfile && mSharedPreferences.isPrimaryAccount(
+ profile.getUriString());
- Log.v(TAG, " noPrimaryAccountSet: " + noPrimaryAccountSet);
- Log.v(TAG, " editNewProfile: " + editNewProfile);
- Log.v(TAG, " mWasPrimaryAccount: " + mWasPrimaryAccount);
+ if (VERBOSE) {
+ log(" noPrimaryAccountSet: " + noPrimaryAccountSet);
+ log(" editNewProfile: " + editNewProfile);
+ log(" mWasPrimaryAccount: " + mWasPrimaryAccount);
+ }
- mCheckbox.setChecked(mWasPrimaryAccount
- || (editNewProfile && noPrimaryAccountSet));
+ mCheckbox.setChecked(mWasPrimaryAccount || (editNewProfile && noPrimaryAccountSet));
}
boolean isSelected() {
@@ -588,13 +583,14 @@ public class SipEditor extends PreferenceActivity
} else if (mWasPrimaryAccount) {
mSharedPreferences.unsetPrimaryAccount();
}
- Log.d(TAG, " primary account changed to : "
- + mSharedPreferences.getPrimaryAccount());
+ if (VERBOSE) {
+ log("PrimaryAccountSelector.commit, new primary account: " +
+ mSharedPreferences.getPrimaryAccount());
+ }
}
}
- private class AdvancedSettings
- implements Preference.OnPreferenceClickListener {
+ private class AdvancedSettings implements Preference.OnPreferenceClickListener {
private Preference mAdvancedSettingsTrigger;
private Preference[] mPreferences;
private boolean mShowing = false;
@@ -631,7 +627,10 @@ public class SipEditor extends PreferenceActivity
PreferenceGroup screen = (PreferenceGroup) getPreferenceScreen();
for (Preference pref : mPreferences) {
screen.addPreference(pref);
- Log.v(TAG, "add pref " + pref.getKey() + ": order=" + pref.getOrder());
+ if (VERBOSE) {
+ log("AdvancedSettings.show, pref: " + pref.getKey() + ", order: " +
+ pref.getOrder());
+ }
}
}
@@ -645,7 +644,7 @@ public class SipEditor extends PreferenceActivity
}
public boolean onPreferenceClick(Preference preference) {
- Log.v(TAG, "optional settings clicked");
+ if (VERBOSE) log("AdvancedSettings.onPreferenceClick");
if (!mShowing) {
show();
} else {
@@ -654,4 +653,8 @@ public class SipEditor extends PreferenceActivity
return true;
}
}
+
+ private static void log(String msg) {
+ Log.d(SipUtil.LOG_TAG, PREFIX + msg);
+ }
}
diff --git a/src/com/android/phone/sip/SipProfileDb.java b/sip/src/com/android/services/telephony/sip/SipProfileDb.java
index a51dfb955..bf4b6bbe0 100644
--- a/src/com/android/phone/sip/SipProfileDb.java
+++ b/sip/src/com/android/services/telephony/sip/SipProfileDb.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.phone.sip;
+package com.android.services.telephony.sip;
import com.android.internal.os.AtomicFile;
@@ -36,7 +36,8 @@ import java.util.List;
* Utility class that helps perform operations on the SipProfile database.
*/
public class SipProfileDb {
- private static final String TAG = SipProfileDb.class.getSimpleName();
+ private static final String PREFIX = "[SipProfileDb] ";
+ private static final boolean VERBOSE = true; /* STOP SHIP if true */
private static final String PROFILES_DIR = "/profiles/";
private static final String PROFILE_OBJ_FILE = ".pobj";
@@ -46,8 +47,7 @@ public class SipProfileDb {
private int mProfilesCount = -1;
public SipProfileDb(Context context) {
- mProfilesDirectory = context.getFilesDir().getAbsolutePath()
- + PROFILES_DIR;
+ mProfilesDirectory = context.getFilesDir().getAbsolutePath() + PROFILES_DIR;
mSipSharedPreferences = new SipSharedPreferences(context);
}
@@ -71,8 +71,7 @@ public class SipProfileDb {
if (mProfilesCount < 0) retrieveSipProfileListInternal();
File f = new File(mProfilesDirectory + p.getProfileName());
if (!f.exists()) f.mkdirs();
- AtomicFile atomicFile =
- new AtomicFile(new File(f, PROFILE_OBJ_FILE));
+ AtomicFile atomicFile = new AtomicFile(new File(f, PROFILE_OBJ_FILE));
FileOutputStream fos = null;
ObjectOutputStream oos = null;
try {
@@ -92,8 +91,7 @@ public class SipProfileDb {
}
public int getProfilesCount() {
- return (mProfilesCount < 0) ?
- mSipSharedPreferences.getProfilesCount() : mProfilesCount;
+ return (mProfilesCount < 0) ? mSipSharedPreferences.getProfilesCount() : mProfilesCount;
}
public List<SipProfile> retrieveSipProfileList() {
@@ -119,7 +117,7 @@ public class SipProfileDb {
sipProfileList.add(p);
} catch (IOException e) {
- Log.e(TAG, "retrieveProfileListFromStorage()", e);
+ log("retrieveSipProfileListInternal, exception: " + e);
}
}
mProfilesCount = sipProfileList.size();
@@ -135,10 +133,14 @@ public class SipProfileDb {
SipProfile p = (SipProfile) ois.readObject();
return p;
} catch (ClassNotFoundException e) {
- Log.w(TAG, "deserialize a profile: " + e);
+ log("deserialize, exception: " + e);
} finally {
if (ois!= null) ois.close();
}
return null;
}
+
+ private static void log(String msg) {
+ Log.d(SipUtil.LOG_TAG, PREFIX + msg);
+ }
}
diff --git a/src/com/android/phone/sip/SipSettings.java b/sip/src/com/android/services/telephony/sip/SipSettings.java
index d58386c11..cf35e31fa 100644
--- a/src/com/android/phone/sip/SipSettings.java
+++ b/sip/src/com/android/services/telephony/sip/SipSettings.java
@@ -14,14 +14,11 @@
* limitations under the License.
*/
-package com.android.phone.sip;
+package com.android.services.telephony.sip;
import com.android.internal.telephony.CallManager;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
-import com.android.phone.CallFeaturesSetting;
-import com.android.phone.R;
-import com.android.phone.SipUtil;
import android.app.ActionBar;
import android.app.AlertDialog;
@@ -59,6 +56,9 @@ import java.util.Map;
* The PreferenceActivity class for managing sip profile preferences.
*/
public class SipSettings extends PreferenceActivity {
+ private static final String PREFIX = "[SipSettings] ";
+ private static final boolean VERBOSE = true; /* STOP SHIP if true */
+
public static final String SIP_SHARED_PREFERENCES = "SIP_PREFERENCES";
private static final int MENU_ADD_ACCOUNT = Menu.FIRST;
@@ -68,7 +68,6 @@ public class SipSettings extends PreferenceActivity {
private static final String BUTTON_SIP_RECEIVE_CALLS =
"sip_receive_calls_key";
private static final String PREF_SIP_LIST = "sip_account_list";
- private static final String TAG = "SipSettings";
private static final int REQUEST_ADD_OR_EDIT_SIP_PROFILE = 1;
@@ -109,10 +108,13 @@ public class SipSettings extends PreferenceActivity {
int profileUid = mProfile.getCallingUid();
boolean isPrimary = mProfile.getUriString().equals(
mSipSharedPreferences.getPrimaryAccount());
- Log.v(TAG, "profile uid is " + profileUid + " isPrimary:"
- + isPrimary + " registration:" + registrationStatus
- + " Primary:" + mSipSharedPreferences.getPrimaryAccount()
- + " status:" + registrationStatus);
+ if (VERBOSE) {
+ log("SipPreference.updateSummary, profile uid: " + profileUid +
+ " isPrimary: " + isPrimary +
+ " registration: " + registrationStatus +
+ " Primary: " + mSipSharedPreferences.getPrimaryAccount() +
+ " status: " + registrationStatus);
+ }
String summary = "";
if ((profileUid > 0) && (profileUid != mUid)) {
// from third party apps
@@ -131,11 +133,10 @@ public class SipSettings extends PreferenceActivity {
private String getPackageNameFromUid(int uid) {
try {
String[] pkgs = mPackageManager.getPackagesForUid(uid);
- ApplicationInfo ai =
- mPackageManager.getApplicationInfo(pkgs[0], 0);
+ ApplicationInfo ai = mPackageManager.getApplicationInfo(pkgs[0], 0);
return ai.loadLabel(mPackageManager).toString();
} catch (PackageManager.NameNotFoundException e) {
- Log.e(TAG, "cannot find name of uid " + uid, e);
+ log("getPackageNameFromUid, cannot find name of uid: " + uid + ", exception: " + e);
}
return "uid:" + uid;
}
@@ -159,7 +160,6 @@ public class SipSettings extends PreferenceActivity {
ActionBar actionBar = getActionBar();
if (actionBar != null) {
- // android.R.id.home will be triggered in onOptionsItemSelected()
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
@@ -190,18 +190,18 @@ public class SipSettings extends PreferenceActivity {
public void run() {
try {
if (mProfile != null) {
- Log.v(TAG, "Removed Profile:" + mProfile.getProfileName());
+ if (VERBOSE) log("onActivityResult, remove: " + mProfile.getProfileName());
deleteProfile(mProfile);
}
SipProfile profile = intent.getParcelableExtra(KEY_SIP_PROFILE);
if (resultCode == RESULT_OK) {
- Log.v(TAG, "New Profile Name:" + profile.getProfileName());
+ if (VERBOSE) log("onActivityResult, new: " + profile.getProfileName());
addProfile(profile);
}
updateProfilesStatus();
} catch (IOException e) {
- Log.v(TAG, "Can not handle the profile : " + e.getMessage());
+ log("onActivityResult, can not handle the profile: " + e);
}
}
}.start();
@@ -215,8 +215,7 @@ public class SipSettings extends PreferenceActivity {
mButtonSipReceiveCalls.setOnPreferenceClickListener(
new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
- final boolean enabled =
- ((CheckBoxPreference) preference).isChecked();
+ final boolean enabled = ((CheckBoxPreference) preference).isChecked();
new Thread(new Runnable() {
public void run() {
handleSipReceiveCallsOption(enabled);
@@ -235,8 +234,7 @@ public class SipSettings extends PreferenceActivity {
p = updateAutoRegistrationFlag(p, enabled);
try {
if (enabled) {
- mSipManager.open(p,
- SipUtil.createIncomingCallPendingIntent(), null);
+ mSipManager.open(p, SipUtil.createIncomingCallPendingIntent(this), null);
} else {
mSipManager.close(sipUri);
if (mSipSharedPreferences.isPrimaryAccount(sipUri)) {
@@ -245,7 +243,7 @@ public class SipSettings extends PreferenceActivity {
}
}
} catch (Exception e) {
- Log.e(TAG, "register failed", e);
+ log("handleSipReceiveCallsOption, register failed: " + e);
}
}
updateProfilesStatus();
@@ -260,7 +258,7 @@ public class SipSettings extends PreferenceActivity {
mProfileDb.deleteProfile(p);
mProfileDb.saveProfile(newProfile);
} catch (Exception e) {
- Log.e(TAG, "updateAutoRegistrationFlag error", e);
+ log("updateAutoRegistrationFlag, exception: " + e);
}
return newProfile;
}
@@ -272,7 +270,7 @@ public class SipSettings extends PreferenceActivity {
try {
retrieveSipLists();
} catch (Exception e) {
- Log.e(TAG, "isRegistered", e);
+ log("updateProfilesStatus, exception: " + e);
}
}
}).start();
@@ -313,7 +311,7 @@ public class SipSettings extends PreferenceActivity {
mSipManager.setRegistrationListener(
p.getUriString(), createRegistrationListener());
} catch (SipException e) {
- Log.e(TAG, "cannot set registration listener", e);
+ log("retrieveSipLists, cannot set registration listener: " + e);
}
}
}
@@ -342,7 +340,7 @@ public class SipSettings extends PreferenceActivity {
private void addPreferenceFor(SipProfile p) {
String status;
- Log.v(TAG, "addPreferenceFor profile uri" + p.getUri());
+ if (VERBOSE) log("addPreferenceFor, profile uri: " + p.getUri());
SipPreference pref = new SipPreference(this, p);
mSipPreferenceMap.put(p.getUriString(), pref);
mSipListContainer.addPreference(pref);
@@ -386,7 +384,7 @@ public class SipSettings extends PreferenceActivity {
try {
mSipManager.close(p.getUriString());
} catch (Exception e) {
- Log.e(TAG, "unregister failed, SipService died?", e);
+ log("unregisterProfile, unregister failed, SipService died? Exception: " + e);
}
}
}, "unregisterProfile").start();
@@ -403,7 +401,7 @@ public class SipSettings extends PreferenceActivity {
mSipManager.setRegistrationListener(p.getUriString(),
createRegistrationListener());
} catch (Exception e) {
- Log.e(TAG, "cannot set registration listener", e);
+ log("addProfile, cannot set registration listener: " + e);
}
mSipProfileList.add(p);
addPreferenceFor(p);
@@ -500,10 +498,6 @@ public class SipSettings extends PreferenceActivity {
public boolean onOptionsItemSelected(MenuItem item) {
final int itemId = item.getItemId();
switch (itemId) {
- case android.R.id.home: {
- CallFeaturesSetting.goUpToTopLevelSetting(this);
- return true;
- }
case MENU_ADD_ACCOUNT: {
startSipEditor(null);
return true;
@@ -511,4 +505,8 @@ public class SipSettings extends PreferenceActivity {
}
return super.onOptionsItemSelected(item);
}
+
+ private static void log(String msg) {
+ Log.d(SipUtil.LOG_TAG, PREFIX + msg);
+ }
}
diff --git a/src/com/android/phone/sip/SipSharedPreferences.java b/sip/src/com/android/services/telephony/sip/SipSharedPreferences.java
index e15db64ed..ffb1513d2 100644
--- a/src/com/android/phone/sip/SipSharedPreferences.java
+++ b/sip/src/com/android/services/telephony/sip/SipSharedPreferences.java
@@ -14,9 +14,7 @@
* limitations under the License.
*/
-package com.android.phone.sip;
-
-import com.android.phone.R;
+package com.android.services.telephony.sip;
import android.content.ContentResolver;
import android.content.Context;
@@ -30,6 +28,9 @@ import android.util.Log;
* Wrapper for SIP's shared preferences.
*/
public class SipSharedPreferences {
+ private static final String PREFIX = "[SipSharedPreferences] ";
+ private static final boolean VERBOSE = true; /* STOP SHIP if true */
+
private static final String SIP_SHARED_PREFERENCES = "SIP_PREFERENCES";
private static final String KEY_PRIMARY_ACCOUNT = "primary";
private static final String KEY_NUMBER_OF_PROFILES = "profiles";
@@ -100,10 +101,14 @@ public class SipSharedPreferences {
return (Settings.System.getInt(mContext.getContentResolver(),
Settings.System.SIP_RECEIVE_CALLS) != 0);
} catch (SettingNotFoundException e) {
- Log.d("SIP", "ReceiveCall option is not set; use default value");
+ log("isReceivingCallsEnabled, option not set; use default value, exception: " + e);
return false;
}
}
// TODO: back up to Android Backup
+
+ private static void log(String msg) {
+ Log.d(SipUtil.LOG_TAG, PREFIX + msg);
+ }
}
diff --git a/src/com/android/phone/SipUtil.java b/sip/src/com/android/services/telephony/sip/SipUtil.java
index a901d5850..39b565523 100644
--- a/src/com/android/phone/SipUtil.java
+++ b/sip/src/com/android/services/telephony/sip/SipUtil.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.phone;
+package com.android.services.telephony.sip;
import android.app.PendingIntent;
import android.content.Context;
@@ -22,14 +22,29 @@ import android.content.Intent;
import android.net.sip.SipManager;
public class SipUtil {
+ public static final String LOG_TAG = "SIP";
+
+ private static boolean sIsVoipSupported;
+ private static boolean sIsVoipSupportedInitialized;
+
private SipUtil() {
}
- public static PendingIntent createIncomingCallPendingIntent() {
- Context phoneContext = PhoneGlobals.getInstance();
- Intent intent = new Intent(phoneContext, SipBroadcastReceiver.class);
+ public static boolean isVoipSupported(Context context) {
+ if (!sIsVoipSupportedInitialized) {
+ sIsVoipSupported = SipManager.isVoipSupported(context) &&
+ context.getResources().getBoolean(
+ com.android.internal.R.bool.config_built_in_sip_phone) &&
+ context.getResources().getBoolean(
+ com.android.internal.R.bool.config_voice_capable);
+ }
+ return sIsVoipSupported;
+ }
+
+ public static PendingIntent createIncomingCallPendingIntent(Context context) {
+ Intent intent = new Intent(context, SipBroadcastReceiver.class);
intent.setAction(SipManager.ACTION_SIP_INCOMING_CALL);
- return PendingIntent.getBroadcast(phoneContext, 0, intent,
+ return PendingIntent.getBroadcast(context, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
}
}
diff --git a/src/com/android/phone/CallFeaturesSetting.java b/src/com/android/phone/CallFeaturesSetting.java
index 289767d3f..377ca95fd 100644
--- a/src/com/android/phone/CallFeaturesSetting.java
+++ b/src/com/android/phone/CallFeaturesSetting.java
@@ -68,7 +68,8 @@ import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.cdma.TtyIntent;
-import com.android.phone.sip.SipSharedPreferences;
+import com.android.services.telephony.sip.SipSharedPreferences;
+import com.android.services.telephony.sip.SipUtil;
import java.util.Collection;
import java.util.HashMap;
@@ -1751,10 +1752,11 @@ public class CallFeaturesSetting extends PreferenceActivity
private void createSipCallSettings() {
// Add Internet call settings.
- if (PhoneUtils.isVoipSupported()) {
+ if (SipUtil.isVoipSupported(this)) {
mSipManager = SipManager.newInstance(this);
mSipSharedPreferences = new SipSharedPreferences(this);
- addPreferencesFromResource(R.xml.sip_settings_category);
+ addPreferencesFromResource(
+ com.android.services.telephony.sip.R.xml.sip_settings_category);
mButtonSipCallOptions = getSipCallOptionPreference();
mButtonSipCallOptions.setOnPreferenceChangeListener(this);
mButtonSipCallOptions.setValueIndex(
diff --git a/src/com/android/phone/OutgoingCallBroadcaster.java b/src/com/android/phone/OutgoingCallBroadcaster.java
index 636a259d0..fc5cdab9c 100644
--- a/src/com/android/phone/OutgoingCallBroadcaster.java
+++ b/src/com/android/phone/OutgoingCallBroadcaster.java
@@ -309,35 +309,7 @@ public class OutgoingCallBroadcaster extends Activity
*/
private void startSipCallOptionHandler(Context context, Intent intent,
Uri uri, String number) {
- if (VDBG) {
- Log.i(TAG, "startSipCallOptionHandler...");
- Log.i(TAG, "- intent: " + intent);
- Log.i(TAG, "- uri: " + uri);
- Log.i(TAG, "- number: " + number);
- }
-
- // Create a copy of the original CALL intent that started the whole
- // outgoing-call sequence. This intent will ultimately be passed to
- // CallController.placeCall() after the SipCallOptionHandler step.
-
- Intent newIntent = new Intent(Intent.ACTION_CALL, uri);
- newIntent.putExtra(EXTRA_ACTUAL_NUMBER_TO_DIAL, number);
- CallGatewayManager.checkAndCopyPhoneProviderExtras(intent, newIntent);
-
- // Finally, launch the SipCallOptionHandler, with the copy of the
- // original CALL intent stashed away in the EXTRA_NEW_CALL_INTENT
- // extra.
-
- Intent selectPhoneIntent = new Intent(ACTION_SIP_SELECT_PHONE, uri);
- selectPhoneIntent.setClass(context, SipCallOptionHandler.class);
- selectPhoneIntent.putExtra(EXTRA_NEW_CALL_INTENT, newIntent);
- selectPhoneIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- if (DBG) {
- Log.v(TAG, "startSipCallOptionHandler(): " +
- "calling startActivity: " + selectPhoneIntent);
- }
- context.startActivity(selectPhoneIntent);
- // ...and see SipCallOptionHandler.onCreate() for the next step of the sequence.
+ // TODO(sail): Remove this code.
}
/**
diff --git a/src/com/android/phone/PhoneUtils.java b/src/com/android/phone/PhoneUtils.java
index 9452fc5f6..60950a5a5 100644
--- a/src/com/android/phone/PhoneUtils.java
+++ b/src/com/android/phone/PhoneUtils.java
@@ -31,7 +31,6 @@ import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.net.Uri;
-import android.net.sip.SipManager;
import android.os.AsyncResult;
import android.os.Handler;
import android.os.Message;
@@ -2647,21 +2646,6 @@ public class PhoneUtils {
return (state == Call.State.INCOMING && !PhoneGlobals.getInstance().mCM.hasActiveFgCall());
}
- private static boolean sVoipSupported = false;
- static {
- PhoneGlobals app = PhoneGlobals.getInstance();
- sVoipSupported = SipManager.isVoipSupported(app)
- && app.getResources().getBoolean(com.android.internal.R.bool.config_built_in_sip_phone)
- && app.getResources().getBoolean(com.android.internal.R.bool.config_voice_capable);
- }
-
- /**
- * @return true if this device supports voice calls using the built-in SIP stack.
- */
- public static boolean isVoipSupported() {
- return sVoipSupported;
- }
-
public static String getPresentationString(Context context, int presentation) {
String name = context.getString(R.string.unknown);
if (presentation == PhoneConstants.PRESENTATION_RESTRICTED) {
diff --git a/src/com/android/phone/SipBroadcastReceiver.java b/src/com/android/phone/SipBroadcastReceiver.java
deleted file mode 100644
index 8fdc7f730..000000000
--- a/src/com/android/phone/SipBroadcastReceiver.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.phone;
-
-import com.android.internal.telephony.CallManager;
-import com.android.internal.telephony.Phone;
-import com.android.internal.telephony.PhoneConstants;
-import com.android.internal.telephony.PhoneFactory;
-import com.android.internal.telephony.sip.SipPhone;
-import com.android.phone.sip.SipProfileDb;
-import com.android.phone.sip.SipSharedPreferences;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.net.sip.SipAudioCall;
-import android.net.sip.SipException;
-import android.net.sip.SipManager;
-import android.net.sip.SipProfile;
-import android.telephony.Rlog;
-import java.util.List;
-
-/**
- * Broadcast receiver that handles SIP-related intents.
- */
-public class SipBroadcastReceiver extends BroadcastReceiver {
- private static final String TAG = SipBroadcastReceiver.class.getSimpleName();
- private static final boolean DBG = true;
- private SipSharedPreferences mSipSharedPreferences;
-
- @Override
- public void onReceive(Context context, final Intent intent) {
- String action = intent.getAction();
-
- if (!PhoneUtils.isVoipSupported()) {
- if (DBG) log("SIP VOIP not supported: " + action);
- return;
- }
- mSipSharedPreferences = new SipSharedPreferences(context);
-
- if (action.equals(SipManager.ACTION_SIP_INCOMING_CALL)) {
- takeCall(intent);
- } else if (action.equals(SipManager.ACTION_SIP_ADD_PHONE)) {
- String localSipUri = intent.getStringExtra(SipManager.EXTRA_LOCAL_URI);
- SipPhone phone = PhoneFactory.makeSipPhone(localSipUri);
- if (phone != null) {
- CallManager.getInstance().registerPhone(phone);
- }
- if (DBG) log("onReceive: add phone" + localSipUri + " #phones="
- + CallManager.getInstance().getAllPhones().size());
- } else if (action.equals(SipManager.ACTION_SIP_REMOVE_PHONE)) {
- String localSipUri = intent.getStringExtra(SipManager.EXTRA_LOCAL_URI);
- removeSipPhone(localSipUri);
- if (DBG) log("onReceive: remove phone: " + localSipUri + " #phones="
- + CallManager.getInstance().getAllPhones().size());
- } else if (action.equals(SipManager.ACTION_SIP_SERVICE_UP)) {
- if (DBG) log("onReceive: start auto registration");
- registerAllProfiles();
- } else {
- if (DBG) log("onReceive: action not processed: " + action);
- return;
- }
- }
-
- private void removeSipPhone(String sipUri) {
- for (Phone phone : CallManager.getInstance().getAllPhones()) {
- if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_SIP) {
- if (((SipPhone) phone).getSipUri().equals(sipUri)) {
- CallManager.getInstance().unregisterPhone(phone);
- return;
- }
- }
- }
- if (DBG) log("RemoveSipPhone: failed:cannot find phone with uri " + sipUri);
- }
-
- private void takeCall(Intent intent) {
- Context phoneContext = PhoneGlobals.getInstance();
- try {
- SipAudioCall sipAudioCall = SipManager.newInstance(phoneContext)
- .takeAudioCall(intent, null);
- for (Phone phone : CallManager.getInstance().getAllPhones()) {
- if (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_SIP) {
- if (((SipPhone) phone).canTake(sipAudioCall)) {
- if (DBG) log("takeCall: SIP call: " + intent);
- return;
- }
- }
- }
- if (DBG) log("takeCall: not taken, drop SIP call: " + intent);
- } catch (SipException e) {
- loge("takeCall: error incoming SIP call", e);
- }
- }
-
- private void registerAllProfiles() {
- final Context context = PhoneGlobals.getInstance();
- new Thread(new Runnable() {
- @Override
- public void run() {
- SipManager sipManager = SipManager.newInstance(context);
- SipProfileDb profileDb = new SipProfileDb(context);
- List<SipProfile> sipProfileList =
- profileDb.retrieveSipProfileList();
- for (SipProfile profile : sipProfileList) {
- try {
- if (!profile.getAutoRegistration() &&
- !profile.getUriString().equals(
- mSipSharedPreferences.getPrimaryAccount())) {
- continue;
- }
- sipManager.open(profile,
- SipUtil.createIncomingCallPendingIntent(),
- null);
- if (DBG) log("registerAllProfiles: profile=" + profile);
- } catch (SipException e) {
- loge("registerAllProfiles: failed" + profile.getProfileName(), e);
- }
- }
- }}
- ).start();
- }
-
- private void log(String s) {
- Rlog.d(TAG, s);
- }
-
- private void loge(String s, Throwable t) {
- Rlog.e(TAG, s, t);
- }
-}
diff --git a/src/com/android/phone/SipCallOptionHandler.java b/src/com/android/phone/SipCallOptionHandler.java
deleted file mode 100644
index 47c5702d3..000000000
--- a/src/com/android/phone/SipCallOptionHandler.java
+++ /dev/null
@@ -1,499 +0,0 @@
-/**
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.phone;
-
-import com.android.internal.telephony.CallManager;
-import com.android.internal.telephony.Phone;
-import com.android.internal.telephony.PhoneFactory;
-import com.android.phone.sip.SipProfileDb;
-import com.android.phone.sip.SipSettings;
-import com.android.phone.sip.SipSharedPreferences;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.net.ConnectivityManager;
-import android.net.NetworkInfo;
-import android.net.Uri;
-import android.net.sip.SipException;
-import android.net.sip.SipManager;
-import android.net.sip.SipProfile;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
-import android.os.SystemProperties;
-import android.provider.Settings;
-import android.telephony.PhoneNumberUtils;
-import android.telephony.TelephonyManager;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.WindowManager;
-import android.widget.CheckBox;
-import android.widget.CompoundButton;
-import android.widget.TextView;
-
-import java.util.List;
-
-/**
- * Activity that selects the proper phone type for an outgoing call.
- *
- * This activity determines which Phone type (SIP or PSTN) should be used
- * for an outgoing phone call, depending on the outgoing "number" (which
- * may be either a PSTN number or a SIP address) as well as the user's SIP
- * preferences. In some cases this activity has no interaction with the
- * user, but in other cases it may (by bringing up a dialog if the user's
- * preference is "Ask for each call".)
- */
-public class SipCallOptionHandler extends Activity implements
- DialogInterface.OnClickListener, DialogInterface.OnCancelListener,
- CompoundButton.OnCheckedChangeListener {
- static final String TAG = "SipCallOptionHandler";
- private static final boolean DBG =
- (PhoneGlobals.DBG_LEVEL >= 1) && (SystemProperties.getInt("ro.debuggable", 0) == 1);
-
- static final int DIALOG_SELECT_PHONE_TYPE = 0;
- static final int DIALOG_SELECT_OUTGOING_SIP_PHONE = 1;
- static final int DIALOG_START_SIP_SETTINGS = 2;
- static final int DIALOG_NO_INTERNET_ERROR = 3;
- static final int DIALOG_NO_VOIP = 4;
- static final int DIALOG_SELECT_WIFI_CALL = 5;
- static final int DIALOG_SIZE = 6;
-
- private Intent mIntent;
- private List<SipProfile> mProfileList;
- private String mCallOption;
- private String mNumber;
- private SipSharedPreferences mSipSharedPreferences;
- private SipProfileDb mSipProfileDb;
- private Dialog[] mDialogs = new Dialog[DIALOG_SIZE];
- private SipProfile mOutgoingSipProfile;
- private TextView mUnsetPriamryHint;
- private boolean mUseSipPhone = false;
- private boolean mMakePrimary = false;
- private ComponentName mThirdPartyCallComponent;
-
- private static final int EVENT_DELAYED_FINISH = 1;
-
- private static final int DELAYED_FINISH_TIME = 2000; // msec
-
- private final Handler mHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- if (msg.what == EVENT_DELAYED_FINISH) {
- finish();
- } else {
- Log.wtf(TAG, "Unknown message id: " + msg.what);
- }
- }
- };
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- Intent intent = getIntent();
- String action = intent.getAction();
-
- // This activity is only ever launched with the
- // ACTION_SIP_SELECT_PHONE action.
- if (!OutgoingCallBroadcaster.ACTION_SIP_SELECT_PHONE.equals(action)) {
- Log.wtf(TAG, "onCreate: got intent action '" + action + "', expected "
- + OutgoingCallBroadcaster.ACTION_SIP_SELECT_PHONE);
- finish();
- return;
- }
-
- // mIntent is a copy of the original CALL intent that started the
- // whole outgoing-call sequence. This intent will ultimately be
- // passed to CallController.placeCall() after displaying the SIP
- // call options dialog (if necessary).
- mIntent = (Intent) intent.getParcelableExtra(OutgoingCallBroadcaster.EXTRA_NEW_CALL_INTENT);
- if (mIntent == null) {
- finish();
- return;
- }
-
- // Allow this activity to be visible in front of the keyguard.
- // (This is only necessary for obscure scenarios like the user
- // initiating a call and then immediately pressing the Power
- // button.)
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
-
- // If we're trying to make a SIP call, return a SipPhone if one is
- // available.
- //
- // - If it's a sip: URI, this is definitely a SIP call, regardless
- // of whether the data is a SIP address or a regular phone
- // number.
- //
- // - If this is a tel: URI but the data contains an "@" character
- // (see PhoneNumberUtils.isUriNumber()) we consider that to be a
- // SIP number too.
- //
- // TODO: Eventually we may want to disallow that latter case
- // (e.g. "tel:foo@example.com").
- //
- // TODO: We should also consider moving this logic into the
- // CallManager, where it could be made more generic.
- // (For example, each "telephony provider" could be allowed
- // to register the URI scheme(s) that it can handle, and the
- // CallManager would then find the best match for every
- // outgoing call.)
-
- boolean voipSupported = PhoneUtils.isVoipSupported();
- if (DBG) Log.v(TAG, "voipSupported: " + voipSupported);
- mSipProfileDb = new SipProfileDb(this);
- mSipSharedPreferences = new SipSharedPreferences(this);
- mCallOption = mSipSharedPreferences.getSipCallOption();
- if (DBG) Log.v(TAG, "Call option: " + mCallOption);
- Uri uri = mIntent.getData();
- String scheme = uri.getScheme();
- mNumber = PhoneNumberUtils.getNumberFromIntent(mIntent, this);
- boolean isInCellNetwork = PhoneGlobals.getInstance().phoneMgr.isRadioOn();
- boolean isKnownCallScheme = Constants.SCHEME_TEL.equals(scheme)
- || Constants.SCHEME_SIP.equals(scheme);
- boolean isRegularCall = Constants.SCHEME_TEL.equals(scheme)
- && !PhoneNumberUtils.isUriNumber(mNumber);
-
- // Bypass the handler if the call scheme is not sip or tel.
- if (!isKnownCallScheme) {
- setResultAndFinish();
- return;
- }
-
- // Check if VoIP feature is supported.
- if (!voipSupported) {
- if (!isRegularCall) {
- showDialog(DIALOG_NO_VOIP);
- }
- return;
- }
-
- // Since we are not sure if anyone has touched the number during
- // the NEW_OUTGOING_CALL broadcast, we just check if the provider
- // put their gateway information in the intent. If so, it means
- // someone has changed the destination number. We then make the
- // call via the default pstn network. However, if one just alters
- // the destination directly, then we still let it go through the
- // Internet call option process.
- if (!CallGatewayManager.hasPhoneProviderExtras(mIntent)) {
- if (!isNetworkConnected()) {
- if (!isRegularCall) {
- showDialog(DIALOG_NO_INTERNET_ERROR);
- return;
- }
- } else {
- if (mCallOption.equals(Settings.System.SIP_ASK_ME_EACH_TIME)
- && isRegularCall && isInCellNetwork) {
- showDialog(DIALOG_SELECT_PHONE_TYPE);
- return;
- }
- if (!mCallOption.equals(Settings.System.SIP_ADDRESS_ONLY)
- || !isRegularCall) {
- mUseSipPhone = true;
- }
- }
- }
-
- if (mUseSipPhone) {
- // If there is no sip profile and it is a regular call, then we
- // should use pstn network instead.
- if ((mSipProfileDb.getProfilesCount() > 0) || !isRegularCall) {
- startGetPrimarySipPhoneThread();
- return;
- } else {
- mUseSipPhone = false;
- }
- setResultAndFinish();
- }
- }
-
- /**
- * Starts a delayed finish() in order to give the UI
- * some time to start up.
- */
- private void startDelayedFinish() {
- mHandler.sendEmptyMessageDelayed(EVENT_DELAYED_FINISH, DELAYED_FINISH_TIME);
- }
-
- @Override
- public void onPause() {
- super.onPause();
- if (isFinishing()) return;
- for (Dialog dialog : mDialogs) {
- if (dialog != null) dialog.dismiss();
- }
- finish();
- }
-
- protected Dialog onCreateDialog(int id) {
- Dialog dialog;
- switch(id) {
- case DIALOG_SELECT_PHONE_TYPE:
- dialog = new AlertDialog.Builder(this)
- .setTitle(R.string.pick_outgoing_call_phone_type)
- .setIconAttribute(android.R.attr.alertDialogIcon)
- .setSingleChoiceItems(R.array.phone_type_values, -1, this)
- .setNegativeButton(android.R.string.cancel, this)
- .setOnCancelListener(this)
- .create();
- break;
- case DIALOG_SELECT_OUTGOING_SIP_PHONE:
- dialog = new AlertDialog.Builder(this)
- .setTitle(R.string.pick_outgoing_sip_phone)
- .setIconAttribute(android.R.attr.alertDialogIcon)
- .setSingleChoiceItems(getProfileNameArray(), -1, this)
- .setNegativeButton(android.R.string.cancel, this)
- .setOnCancelListener(this)
- .create();
- addMakeDefaultCheckBox(dialog);
- break;
- case DIALOG_START_SIP_SETTINGS:
- dialog = new AlertDialog.Builder(this)
- .setTitle(R.string.no_sip_account_found_title)
- .setMessage(R.string.no_sip_account_found)
- .setIconAttribute(android.R.attr.alertDialogIcon)
- .setPositiveButton(R.string.sip_menu_add, this)
- .setNegativeButton(android.R.string.cancel, this)
- .setOnCancelListener(this)
- .create();
- break;
- case DIALOG_NO_INTERNET_ERROR:
- boolean wifiOnly = SipManager.isSipWifiOnly(this);
- dialog = new AlertDialog.Builder(this)
- .setTitle(wifiOnly ? R.string.no_wifi_available_title
- : R.string.no_internet_available_title)
- .setMessage(wifiOnly ? R.string.no_wifi_available
- : R.string.no_internet_available)
- .setIconAttribute(android.R.attr.alertDialogIcon)
- .setPositiveButton(android.R.string.ok, this)
- .setOnCancelListener(this)
- .create();
- break;
- case DIALOG_NO_VOIP:
- dialog = new AlertDialog.Builder(this)
- .setTitle(R.string.no_voip)
- .setIconAttribute(android.R.attr.alertDialogIcon)
- .setPositiveButton(android.R.string.ok, this)
- .setOnCancelListener(this)
- .create();
- break;
- case DIALOG_SELECT_WIFI_CALL:
- dialog = new AlertDialog.Builder(this)
- .setMessage(R.string.choose_wifi_for_call_msg)
- .setPositiveButton(R.string.choose_wifi_for_call_yes, this)
- .setNegativeButton(R.string.choose_wifi_for_call_no, this)
- .setCancelable(false)
- .create();
- break;
- default:
- dialog = null;
- }
- if (dialog != null) {
- mDialogs[id] = dialog;
- }
- return dialog;
- }
-
- private void addMakeDefaultCheckBox(Dialog dialog) {
- LayoutInflater inflater = (LayoutInflater) getSystemService(
- Context.LAYOUT_INFLATER_SERVICE);
- View view = inflater.inflate(
- com.android.internal.R.layout.always_use_checkbox, null);
- CheckBox makePrimaryCheckBox =
- (CheckBox)view.findViewById(com.android.internal.R.id.alwaysUse);
- makePrimaryCheckBox.setText(R.string.remember_my_choice);
- makePrimaryCheckBox.setOnCheckedChangeListener(this);
- mUnsetPriamryHint = (TextView)view.findViewById(
- com.android.internal.R.id.clearDefaultHint);
- mUnsetPriamryHint.setText(R.string.reset_my_choice_hint);
- mUnsetPriamryHint.setVisibility(View.GONE);
- ((AlertDialog)dialog).setView(view);
- }
-
- private CharSequence[] getProfileNameArray() {
- CharSequence[] entries = new CharSequence[mProfileList.size()];
- int i = 0;
- for (SipProfile p : mProfileList) {
- entries[i++] = p.getProfileName();
- }
- return entries;
- }
-
- public void onClick(DialogInterface dialog, int id) {
- if(dialog == mDialogs[DIALOG_SELECT_WIFI_CALL]) {
- if (id == DialogInterface.BUTTON_NEGATIVE) {
- setResultAndFinish();
- }
- return;
- } else if (id == DialogInterface.BUTTON_NEGATIVE) {
- // button negative is cancel
- finish();
- return;
- } else if(dialog == mDialogs[DIALOG_SELECT_PHONE_TYPE]) {
- String selection = getResources().getStringArray(
- R.array.phone_type_values)[id];
- if (DBG) Log.v(TAG, "User pick phone " + selection);
- if (selection.equals(getString(R.string.internet_phone))) {
- mUseSipPhone = true;
- startGetPrimarySipPhoneThread();
- return;
- }
- } else if (dialog == mDialogs[DIALOG_SELECT_OUTGOING_SIP_PHONE]) {
- mOutgoingSipProfile = mProfileList.get(id);
- } else if ((dialog == mDialogs[DIALOG_NO_INTERNET_ERROR])
- || (dialog == mDialogs[DIALOG_NO_VOIP])) {
- finish();
- return;
- } else {
- if (id == DialogInterface.BUTTON_POSITIVE) {
- // Redirect to sip settings and drop the call.
- Intent newIntent = new Intent(this, SipSettings.class);
- newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(newIntent);
- }
- finish();
- return;
- }
- setResultAndFinish();
- }
-
- public void onCancel(DialogInterface dialog) {
- finish();
- }
-
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
- mMakePrimary = isChecked;
- if (isChecked) {
- mUnsetPriamryHint.setVisibility(View.VISIBLE);
- } else {
- mUnsetPriamryHint.setVisibility(View.INVISIBLE);
- }
- }
-
- private void createSipPhoneIfNeeded(SipProfile p) {
- CallManager cm = PhoneGlobals.getInstance().mCM;
- if (PhoneUtils.getSipPhoneFromUri(cm, p.getUriString()) != null) return;
-
- // Create the phone since we can not find it in CallManager
- try {
- SipManager.newInstance(this).open(p);
- Phone phone = PhoneFactory.makeSipPhone(p.getUriString());
- if (phone != null) {
- cm.registerPhone(phone);
- } else {
- Log.e(TAG, "cannot make sipphone profile" + p);
- }
- } catch (SipException e) {
- Log.e(TAG, "cannot open sip profile" + p, e);
- }
- }
-
- private void setResultAndFinish() {
- runOnUiThread(new Runnable() {
- public void run() {
- if (mOutgoingSipProfile != null) {
- if (!isNetworkConnected()) {
- showDialog(DIALOG_NO_INTERNET_ERROR);
- return;
- }
- if (DBG) Log.v(TAG, "primary SIP URI is " +
- mOutgoingSipProfile.getUriString());
- createSipPhoneIfNeeded(mOutgoingSipProfile);
- mIntent.putExtra(OutgoingCallBroadcaster.EXTRA_SIP_PHONE_URI,
- mOutgoingSipProfile.getUriString());
- if (mMakePrimary) {
- mSipSharedPreferences.setPrimaryAccount(
- mOutgoingSipProfile.getUriString());
- }
- }
-
- if (mUseSipPhone && mOutgoingSipProfile == null) {
- showDialog(DIALOG_START_SIP_SETTINGS);
- return;
- } else {
- // Woo hoo -- it's finally OK to initiate the outgoing call!
- PhoneGlobals.getInstance().callController.placeCall(mIntent);
- }
- startDelayedFinish();
- }
- });
- }
-
- private boolean isNetworkConnected() {
- ConnectivityManager cm = (ConnectivityManager) getSystemService(
- Context.CONNECTIVITY_SERVICE);
- if (cm != null) {
- NetworkInfo ni = cm.getActiveNetworkInfo();
- if ((ni == null) || !ni.isConnected()) return false;
-
- return ((ni.getType() == ConnectivityManager.TYPE_WIFI)
- || !SipManager.isSipWifiOnly(this));
- }
- return false;
- }
-
- private void startGetPrimarySipPhoneThread() {
- new Thread(new Runnable() {
- public void run() {
- getPrimarySipPhone();
- }
- }).start();
- }
-
- private void getPrimarySipPhone() {
- String primarySipUri = mSipSharedPreferences.getPrimaryAccount();
-
- mOutgoingSipProfile = getPrimaryFromExistingProfiles(primarySipUri);
- if (mOutgoingSipProfile == null) {
- if ((mProfileList != null) && (mProfileList.size() > 0)) {
- runOnUiThread(new Runnable() {
- public void run() {
- showDialog(DIALOG_SELECT_OUTGOING_SIP_PHONE);
- }
- });
- return;
- }
- }
- setResultAndFinish();
- }
-
- private SipProfile getPrimaryFromExistingProfiles(String primarySipUri) {
- mProfileList = mSipProfileDb.retrieveSipProfileList();
- if (mProfileList == null) return null;
- for (SipProfile p : mProfileList) {
- if (p.getUriString().equals(primarySipUri)) return p;
- }
- return null;
- }
-
- private boolean isConnectedToWifi() {
- ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
- if (cm != null) {
- NetworkInfo ni = cm.getActiveNetworkInfo();
- return ni != null && ni.isConnected() && ni.getType() == ConnectivityManager.TYPE_WIFI;
- }
- return false;
- }
-}
diff --git a/src/com/android/services/telephony/SipConnection.java b/src/com/android/services/telephony/SipConnection.java
deleted file mode 100644
index 133a42d05..000000000
--- a/src/com/android/services/telephony/SipConnection.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.services.telephony;
-
-import android.telecomm.Connection;
-
-/**
- * A {@link Connection} object for SIP calls.
- */
-public class SipConnection extends TelephonyConnection {
-
- public SipConnection(com.android.internal.telephony.Connection connection) {
- super(connection);
- }
-
- // TODO: Fill in the below methods
-
- /** {@inheritDoc} */
- @Override
- protected void onPlayDtmfTone(char c) {
- super.onPlayDtmfTone(c);
- }
-
- /** {@inheritDoc} */
- @Override
- protected void onStopDtmfTone() {
- super.onStopDtmfTone();
- }
-
- /** {@inheritDoc} */
- @Override
- protected void onDisconnect() {
- super.onDisconnect();
- }
-
- /** {@inheritDoc} */
- @Override
- protected void onAbort() {
- super.onAbort();
- }
-
- /** {@inheritDoc} */
- @Override
- public void onHold() {
- super.onHold();
- }
-
- /** {@inheritDoc} */
- @Override
- protected void onUnhold() {
- super.onUnhold();
- }
-
- /** {@inheritDoc} */
- @Override
- protected void onAnswer() {
- super.onAnswer();
- }
-
- /** {@inheritDoc} */
- @Override
- protected void onReject() {
- super.onReject();
- }
-}
diff --git a/src/com/android/services/telephony/TelephonyCallServiceProvider.java b/src/com/android/services/telephony/TelephonyCallServiceProvider.java
index 12bb2afaf..5225759fa 100644
--- a/src/com/android/services/telephony/TelephonyCallServiceProvider.java
+++ b/src/com/android/services/telephony/TelephonyCallServiceProvider.java
@@ -34,11 +34,6 @@ public class TelephonyCallServiceProvider extends CallServiceProvider {
.setConnectionService(PstnConnectionService.class)
.setNetworkType(CallServiceDescriptor.FLAG_PSTN)
.build());
- descriptors.add(CallServiceDescriptor.newBuilder(this)
- .setConnectionService(SipConnectionService.class)
- .setNetworkType(CallServiceDescriptor.FLAG_WIFI |
- CallServiceDescriptor.FLAG_MOBILE)
- .build());
response.setCallServiceDescriptors(descriptors);
}
}