diff options
author | Tyler Gunn <tgunn@google.com> | 2014-09-10 16:01:02 -0700 |
---|---|---|
committer | Tyler Gunn <tgunn@google.com> | 2014-09-11 17:14:32 +0000 |
commit | baee2955f596f7b79971feb12fa21031a069677d (patch) | |
tree | e8c0abf1d4ad6b3e5abb648ffdcffb3b571a0305 /sip/src/com/android/services/telephony/sip/SipUtil.java | |
parent | c02fbddf3930664d5732efc1c953137d938b5eca (diff) | |
download | android_packages_services_Telephony-baee2955f596f7b79971feb12fa21031a069677d.tar.gz android_packages_services_Telephony-baee2955f596f7b79971feb12fa21031a069677d.tar.bz2 android_packages_services_Telephony-baee2955f596f7b79971feb12fa21031a069677d.zip |
Allowing enable/disable of phone accounts. (3/3)
Phone Accounts:
- Added Phone account enable/disable activity, accessible from the
"Make calls via" preference screen.
- Changed Telephony PhoneAccount registration so that it first updates
existing PhoneAccounts (ensuring enable/disable setting retained), and
then removes any that no longer exist.
SIP:
Removed the "primary profile" SIP setting in favour of being able to
enabled and disable the associated PhoneAccounts.
Added migration to automatically enable the previous "primary profile".
Bug: 17306514
Bug: 17408536
Change-Id: I696e3382730ea7bb40d680798bcab965517c438b
Diffstat (limited to 'sip/src/com/android/services/telephony/sip/SipUtil.java')
-rw-r--r-- | sip/src/com/android/services/telephony/sip/SipUtil.java | 76 |
1 files changed, 65 insertions, 11 deletions
diff --git a/sip/src/com/android/services/telephony/sip/SipUtil.java b/sip/src/com/android/services/telephony/sip/SipUtil.java index e926fa10a..340ebdadf 100644 --- a/sip/src/com/android/services/telephony/sip/SipUtil.java +++ b/sip/src/com/android/services/telephony/sip/SipUtil.java @@ -16,14 +16,23 @@ package com.android.services.telephony.sip; +import com.android.phone.R; + import android.app.PendingIntent; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.net.Uri; import android.net.sip.SipManager; +import android.net.sip.SipProfile; +import android.provider.Settings; +import android.telecomm.PhoneAccount; import android.telecomm.PhoneAccountHandle; import android.telecomm.TelecommManager; +import java.util.Arrays; +import java.util.List; + public class SipUtil { static final String LOG_TAG = "SIP"; static final String EXTRA_INCOMING_CALL_INTENT = @@ -33,21 +42,15 @@ public class SipUtil { static final String GATEWAY_PROVIDER_PACKAGE = "com.android.phone.extra.GATEWAY_PROVIDER_PACKAGE"; - private static boolean sIsVoipSupported; - private static boolean sIsVoipSupportedInitialized; - private SipUtil() { } 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; + return 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); } static PendingIntent createIncomingCallPendingIntent( @@ -74,4 +77,55 @@ public class SipUtil { return new PhoneAccountHandle( new ComponentName(context, SipConnectionService.class), sipUri); } + + /** + * Determines if the {@link android.telecomm.PhoneAccount} associated with a {@link SipProfile} + * is enabled. + * + * @param context The {@link Context}. + * @param profile The {@link SipProfile}. + * @return {@code True} if the {@code PhoneAccount} is enabled. + */ + static boolean isPhoneAccountEnabled(Context context, SipProfile profile) { + PhoneAccount phoneAccount = TelecommManager.from(context) + .getPhoneAccount(SipUtil.createAccountHandle(context, profile.getUriString())); + return phoneAccount != null && phoneAccount.isEnabled(); + } + + /** + * Creates a PhoneAccount for a SipProfile. + * + * @param context The context + * @param profile The SipProfile. + * @return The PhoneAccount. + */ + static PhoneAccount createPhoneAccount(Context context, SipProfile profile) { + + PhoneAccountHandle accountHandle = + SipUtil.createAccountHandle(context, profile.getUriString()); + + List supportedUriSchemes = Arrays.asList(PhoneAccount.SCHEME_SIP); + if (useSipForPstnCalls(context)) { + supportedUriSchemes.add(PhoneAccount.SCHEME_TEL); + } + + PhoneAccount.Builder builder = PhoneAccount.builder(accountHandle, profile.getDisplayName()) + .setCapabilities(PhoneAccount.CAPABILITY_CALL_PROVIDER) + .setAddress(Uri.parse(profile.getUriString())) + .setShortDescription(profile.getDisplayName()) + .setIconResId(R.drawable.ic_dialer_sip_black_24dp) + .setSupportedUriSchemes(supportedUriSchemes); + + return builder.build(); + } + + /** + * Determines if the user has chosen to use SIP for PSTN calls as well as SIP calls. + * @param context The context. + * @return {@code True} if SIP should be used for PSTN calls. + */ + private static boolean useSipForPstnCalls(Context context) { + final SipSharedPreferences sipSharedPreferences = new SipSharedPreferences(context); + return sipSharedPreferences.getSipCallOption().equals(Settings.System.SIP_ALWAYS); + } } |