diff options
author | Brad Ebinger <breadley@google.com> | 2020-01-07 16:55:15 -0800 |
---|---|---|
committer | Brad Ebinger <breadley@google.com> | 2020-01-13 13:39:14 -0800 |
commit | 489de20610d73daa45db625934148d54ae564a36 (patch) | |
tree | 975d529c77cfa5b43fadff5919f661c5989c60b9 /rcs/rcsservice/src | |
parent | b437fbd4ab51f82781e19768796215262e15f533 (diff) | |
download | ims-489de20610d73daa45db625934148d54ae564a36.tar.gz |
Use @SystemApi methods to interact with telephony
As part of the Telephony mainline effort, remove @hide dependencies
on telephony in RCS:
1) Use ImsMmTelManager/ProvisioningManager for querying configs.
2) Expose UCE APIs that are needed so far.
3) Use @SystemApi versions of SubscriptionManager/TelephonyManager APIs
4) In PresencePolling app, track default subscription as active
SIM for capability polling (since it doesnt support MSIM yet).
Bug: 147319232
Test: atest CtsTelephonyTestCases; manuallay add contacts, check publish
Merged-In: Ia9f1e8a94896a11201dbd66344fc1caf0589ffc7
Change-Id: Ia9f1e8a94896a11201dbd66344fc1caf0589ffc7
Diffstat (limited to 'rcs/rcsservice/src')
5 files changed, 204 insertions, 198 deletions
diff --git a/rcs/rcsservice/src/com/android/service/ims/RcsService.java b/rcs/rcsservice/src/com/android/service/ims/RcsService.java index f80e2e5..4bbc316 100644 --- a/rcs/rcsservice/src/com/android/service/ims/RcsService.java +++ b/rcs/rcsservice/src/com/android/service/ims/RcsService.java @@ -39,8 +39,8 @@ import android.os.Looper; import android.os.RemoteException; import android.os.ServiceManager; import android.provider.Settings; +import android.provider.Telephony; import android.telephony.AccessNetworkConstants; -import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.ims.ImsException; import android.telephony.ims.ImsMmTelManager; @@ -203,8 +203,8 @@ public class RcsService extends Service { false, mObserver); mSiminfoSettingObserver = new SimInfoContentObserver(); - getContentResolver().registerContentObserver( - SubscriptionManager.CONTENT_URI, false, mSiminfoSettingObserver); + getContentResolver().registerContentObserver(Telephony.SimInfo.CONTENT_URI, false, + mSiminfoSettingObserver); mRetryHandler = new Handler(Looper.getMainLooper()); registerSubscriptionChangedListener(); @@ -229,54 +229,39 @@ public class RcsService extends Service { logger.warn("handleSubscriptionsChanged: SubscriptionManager is null!"); return; } - List<SubscriptionInfo> infos = sm.getActiveSubscriptionInfoList(); - if (infos == null || infos.isEmpty()) { - // There are no active subscriptions right now. + int defaultVoiceSub = RcsSettingUtils.getDefaultSubscriptionId(this); + if (defaultVoiceSub == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { handleImsServiceDown(); - } else { - int defaultVoiceSub = SubscriptionManager.getDefaultVoiceSubscriptionId(); - // Get default voice id and then try to register for IMS callbacks - if (defaultVoiceSub == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { - for (SubscriptionInfo info : infos) { - if (!info.isOpportunistic()) { - defaultVoiceSub = info.getSubscriptionId(); - break; - } - } - } - if (defaultVoiceSub == SubscriptionManager.INVALID_SUBSCRIPTION_ID) { - handleImsServiceDown(); + return; + } + + ImsMmTelManager mIms = ImsMmTelManager.createForSubscriptionId(defaultVoiceSub); + try { + if (defaultVoiceSub == mAssociatedSubscription) { + // Don't register duplicate callbacks for the same subscription. return; } - - ImsMmTelManager mIms = ImsMmTelManager.createForSubscriptionId(defaultVoiceSub); - try { - if (defaultVoiceSub == mAssociatedSubscription) { - // Don't register duplicate callbacks for the same subscription. - return; - } - if (mAssociatedSubscription != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { - // Get rid of any existing registrations. - ImsMmTelManager mOldIms = ImsMmTelManager.createForSubscriptionId( - mAssociatedSubscription); - mOldIms.unregisterImsRegistrationCallback(mImsRegistrationCallback); - mOldIms.unregisterMmTelCapabilityCallback(mCapabilityCallback); - logger.print("callbacks unregistered for sub " + mAssociatedSubscription); - } - // move over registrations. - mIms.registerImsRegistrationCallback(getMainExecutor(), mImsRegistrationCallback); - mIms.registerMmTelCapabilityCallback(getMainExecutor(), mCapabilityCallback); - mAssociatedSubscription = defaultVoiceSub; - logger.print("callbacks registered for sub " + mAssociatedSubscription); - handleImsServiceUp(); - } catch (ImsException e) { - logger.info("Couldn't register callbacks for " + defaultVoiceSub + ": " - + e.getMessage()); - if (e.getCode() == ImsException.CODE_ERROR_SERVICE_UNAVAILABLE) { - // IMS temporarily unavailable. Retry after a few seconds. - mRetryHandler.removeCallbacks(mRegisterCallbacks); - mRetryHandler.postDelayed(mRegisterCallbacks, IMS_SERVICE_RETRY_TIMEOUT_MS); - } + if (mAssociatedSubscription != SubscriptionManager.INVALID_SUBSCRIPTION_ID) { + // Get rid of any existing registrations. + ImsMmTelManager mOldIms = ImsMmTelManager.createForSubscriptionId( + mAssociatedSubscription); + mOldIms.unregisterImsRegistrationCallback(mImsRegistrationCallback); + mOldIms.unregisterMmTelCapabilityCallback(mCapabilityCallback); + logger.print("callbacks unregistered for sub " + mAssociatedSubscription); + } + // move over registrations. + mIms.registerImsRegistrationCallback(getMainExecutor(), mImsRegistrationCallback); + mIms.registerMmTelCapabilityCallback(getMainExecutor(), mCapabilityCallback); + mAssociatedSubscription = defaultVoiceSub; + logger.print("callbacks registered for sub " + mAssociatedSubscription); + handleImsServiceUp(); + } catch (ImsException e) { + logger.info("Couldn't register callbacks for " + defaultVoiceSub + ": " + + e.getMessage()); + if (e.getCode() == ImsException.CODE_ERROR_SERVICE_UNAVAILABLE) { + // IMS temporarily unavailable. Retry after a few seconds. + mRetryHandler.removeCallbacks(mRegisterCallbacks); + mRetryHandler.postDelayed(mRegisterCallbacks, IMS_SERVICE_RETRY_TIMEOUT_MS); } } } diff --git a/rcs/rcsservice/src/com/android/service/ims/RcsSettingUtils.java b/rcs/rcsservice/src/com/android/service/ims/RcsSettingUtils.java index f5f893e..9c867d9 100644 --- a/rcs/rcsservice/src/com/android/service/ims/RcsSettingUtils.java +++ b/rcs/rcsservice/src/com/android/service/ims/RcsSettingUtils.java @@ -30,9 +30,12 @@ package com.android.service.ims; import android.content.Context; import android.os.PersistableBundle; +import android.telephony.AccessNetworkConstants; import android.telephony.CarrierConfigManager; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; +import android.telephony.ims.ImsException; +import android.telephony.ims.ImsMmTelManager; import android.telephony.ims.ProvisioningManager; import android.telephony.ims.feature.MmTelFeature; import android.telephony.ims.stub.ImsRegistrationImplBase; @@ -40,50 +43,37 @@ import android.telephony.ims.stub.ImsRegistrationImplBase; import com.android.ims.internal.Logger; import java.util.List; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; public class RcsSettingUtils { static private Logger logger = Logger.getLogger("RcsSettingUtils"); + private static final int TIMEOUT_GET_CONFIGURATION_MS = 5000; - // Values taken from ImsConfig - Should define in @SystemApi as well. - /** - * SIP T1 timer value in milliseconds. See RFC 3261 for definition. - * Value is in Integer format. - */ - private static final int SIP_T1_TIMER = 7; - /** - * Whether or not capability discovery is provisioned. - */ - private static final int CAPABILITY_DISCOVERY_ENABLED = 17; - /** - * period of time the availability information of a contact is cached on device. - * Value is in Integer format. - */ - private static final int AVAILABILITY_CACHE_EXPIRATION = 19; - /** - * Minimum time between two published messages from the device. - * Value is in Integer format. - */ - private static final int SOURCE_THROTTLE_PUBLISH = 21; - /** - * The Maximum number of MDNs contained in one Request Contained List. - * Value is in Integer format. - */ - private static final int MAX_NUMENTRIES_IN_RCL = 22; - /** - * Expiration timer for subscription of a Request Contained List, used in capability - * polling. - * Value is in Integer format. - */ - private static final int CAPAB_POLL_LIST_SUB_EXP = 23; - /** - * Provisioning status for Enhanced Address Book (EAB) - * Value is in Integer format. - */ - private static final int EAB_SETTING_ENABLED = 25; - /** - * Whether or not mobile data is enabled currently. - */ - private static final int MOBILE_DATA_ENABLED = 29; + // Default number of entries for getMaxNumbersInRCL + private static final int DEFAULT_NUM_ENTRIES_IN_RCL = 100; + // Default for getCapabPollListSubExp in seconds. + private static final int DEFAULT_CAPABILITY_POLL_LIST_SUB_EXPIRATION_SEC = 30; + // Default for getAvailabilityCacheExpiration in seconds. + private static final int DEFAULT_AVAILABILITY_CACHE_EXPIRATION_SEC = 30; + // Default for getPublishThrottle in milliseconds + private static final int DEFAULT_PUBLISH_THROTTLE_MS = 60000; + + public static boolean isVoLteProvisioned(Context context) { + try { + boolean isProvisioned; + ProvisioningManager manager = ProvisioningManager.createForSubscriptionId( + getDefaultSubscriptionId(context)); + isProvisioned = manager.getProvisioningStatusForCapability( + MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE, + ImsRegistrationImplBase.REGISTRATION_TECH_LTE); + logger.debug("isVoLteProvisioned=" + isProvisioned); + return isProvisioned; + } catch (Exception e) { + logger.debug("isVoLteProvisioned, exception = " + e.getMessage()); + return false; + } + } public static boolean isVowifiProvisioned(Context context) { try { @@ -136,7 +126,8 @@ public class RcsSettingUtils { } try { ProvisioningManager manager = ProvisioningManager.createForSubscriptionId(subId); - isProvisioned = manager.getProvisioningIntValue(EAB_SETTING_ENABLED) + isProvisioned = manager.getProvisioningIntValue( + ProvisioningManager.KEY_EAB_PROVISIONING_STATUS) == ProvisioningManager.PROVISIONING_VALUE_ENABLED; } catch (Exception e) { logger.debug("isEabProvisioned: exception=" + e.getMessage()); @@ -150,7 +141,7 @@ public class RcsSettingUtils { try { ProvisioningManager manager = ProvisioningManager.createForSubscriptionId( getDefaultSubscriptionId(context)); - sipT1Timer = manager.getProvisioningIntValue(SIP_T1_TIMER); + sipT1Timer = manager.getProvisioningIntValue(ProvisioningManager.KEY_T1_TIMER_VALUE_MS); } catch (Exception e) { // If there is no active subscriptions, this will throw an exception. logger.debug("getSIPT1Timer: exception=" + e.getMessage()); @@ -167,8 +158,9 @@ public class RcsSettingUtils { try { ProvisioningManager manager = ProvisioningManager.createForSubscriptionId( getDefaultSubscriptionId(context)); - capabilityDiscoveryEnabled = manager.getProvisioningIntValue(CAPABILITY_DISCOVERY_ENABLED) - == ProvisioningManager.PROVISIONING_VALUE_ENABLED; + capabilityDiscoveryEnabled = manager.getProvisioningIntValue( + ProvisioningManager.KEY_RCS_CAPABILITY_DISCOVERY_ENABLED) == + ProvisioningManager.PROVISIONING_VALUE_ENABLED; } catch (Exception e) { // If there is no active subscriptions, this will throw an exception. logger.debug("capabilityDiscoveryEnabled: exception=" + e.getMessage()); @@ -181,11 +173,12 @@ public class RcsSettingUtils { * The Maximum number of MDNs contained in one Request Contained List. */ public static int getMaxNumbersInRCL(Context context) { - int maxNumbersInRCL = 100; + int maxNumbersInRCL = DEFAULT_NUM_ENTRIES_IN_RCL; try { ProvisioningManager manager = ProvisioningManager.createForSubscriptionId( getDefaultSubscriptionId(context)); - maxNumbersInRCL = manager.getProvisioningIntValue(MAX_NUMENTRIES_IN_RCL); + maxNumbersInRCL = manager.getProvisioningIntValue( + ProvisioningManager.KEY_RCS_MAX_NUM_ENTRIES_IN_RCL); } catch (Exception e) { // If there is no active subscriptions, this will throw an exception. logger.debug("getMaxNumbersInRCL: exception=" + e.getMessage()); @@ -198,11 +191,12 @@ public class RcsSettingUtils { * Expiration timer for subscription of a Request Contained List, used in capability polling. */ public static int getCapabPollListSubExp(Context context) { - int capabPollListSubExp = 30; + int capabPollListSubExp = DEFAULT_CAPABILITY_POLL_LIST_SUB_EXPIRATION_SEC; try { ProvisioningManager manager = ProvisioningManager.createForSubscriptionId( getDefaultSubscriptionId(context)); - capabPollListSubExp = manager.getProvisioningIntValue(CAPAB_POLL_LIST_SUB_EXP); + capabPollListSubExp = manager.getProvisioningIntValue( + ProvisioningManager.KEY_RCS_CAPABILITY_POLL_LIST_SUB_EXP_SEC); } catch (Exception e) { // If there is no active subscriptions, this will throw an exception. logger.debug("getCapabPollListSubExp: exception=" + e.getMessage()); @@ -215,12 +209,12 @@ public class RcsSettingUtils { * Period of time the availability information of a contact is cached on device. */ public static int getAvailabilityCacheExpiration(Context context) { - int availabilityCacheExpiration = 30; + int availabilityCacheExpiration = DEFAULT_AVAILABILITY_CACHE_EXPIRATION_SEC; try { ProvisioningManager manager = ProvisioningManager.createForSubscriptionId( getDefaultSubscriptionId(context)); availabilityCacheExpiration = manager.getProvisioningIntValue( - AVAILABILITY_CACHE_EXPIRATION); + ProvisioningManager.KEY_RCS_AVAILABILITY_CACHE_EXPIRATION_SEC); } catch (Exception e) { // If there is no active subscriptions, this will throw an exception. logger.debug("getAvailabilityCacheExpiration: exception=" + e.getMessage()); @@ -229,53 +223,119 @@ public class RcsSettingUtils { return availabilityCacheExpiration; } - public static boolean isMobileDataEnabled(Context context) { - boolean mobileDataEnabled = false; + public static int getPublishThrottle(Context context) { + // Default + int publishThrottle = DEFAULT_PUBLISH_THROTTLE_MS; try { ProvisioningManager manager = ProvisioningManager.createForSubscriptionId( getDefaultSubscriptionId(context)); - mobileDataEnabled = manager.getProvisioningIntValue(MOBILE_DATA_ENABLED) - == ProvisioningManager.PROVISIONING_VALUE_ENABLED; + publishThrottle = manager.getProvisioningIntValue( + ProvisioningManager.KEY_RCS_PUBLISH_SOURCE_THROTTLE_MS); } catch (Exception e) { // If there is no active subscriptions, this will throw an exception. - logger.debug("isMobileDataEnabled: exception=" + e.getMessage()); + logger.debug("publishThrottle: exception=" + e.getMessage()); } - logger.debug("mobileDataEnabled=" + mobileDataEnabled); - return mobileDataEnabled; + logger.debug("publishThrottle=" + publishThrottle); + return publishThrottle; } - public static void setMobileDataEnabled(Context context, boolean mobileDataEnabled) { - logger.debug("mobileDataEnabled=" + mobileDataEnabled); + public static boolean isVtEnabledByUser(Context context) { try { - ProvisioningManager manager = ProvisioningManager.createForSubscriptionId( + ImsMmTelManager mmTelManager = ImsMmTelManager.createForSubscriptionId( getDefaultSubscriptionId(context)); - manager.setProvisioningIntValue(MOBILE_DATA_ENABLED, mobileDataEnabled ? - ProvisioningManager.PROVISIONING_VALUE_ENABLED : - ProvisioningManager.PROVISIONING_VALUE_DISABLED); + return mmTelManager.isVtSettingEnabled(); } catch (Exception e) { - // If there is no active subscriptions, this will throw an exception. - logger.debug("mobileDataEnabled: exception=" + e.getMessage()); + logger.warn("isVtEnabledByUser exception = " + e.getMessage()); + return false; } } - public static int getPublishThrottle(Context context) { - // Default - int publishThrottle = 60000; + public static boolean isWfcEnabledByUser(Context context) { try { - ProvisioningManager manager = ProvisioningManager.createForSubscriptionId( + ImsMmTelManager mmTelManager = ImsMmTelManager.createForSubscriptionId( getDefaultSubscriptionId(context)); - publishThrottle = manager.getProvisioningIntValue(SOURCE_THROTTLE_PUBLISH); + return mmTelManager.isVoWiFiSettingEnabled(); } catch (Exception e) { - // If there is no active subscriptions, this will throw an exception. - logger.debug("publishThrottle: exception=" + e.getMessage()); + logger.warn("isWfcEnabledByUser exception = " + e.getMessage()); + return false; + } + } + + public static boolean isAdvancedCallingEnabledByUser(Context context) { + try { + ImsMmTelManager mmTelManager = ImsMmTelManager.createForSubscriptionId( + getDefaultSubscriptionId(context)); + return mmTelManager.isAdvancedCallingSettingEnabled(); + } catch (Exception e) { + logger.warn("isAdvancedCallingEnabledByUser exception = " + e.getMessage()); + return false; + } + } + + public static boolean isVoLteSupported(Context context) { + LinkedBlockingQueue<Boolean> resultQueue = new LinkedBlockingQueue<>(1); + try { + ImsMmTelManager mmTelManager = ImsMmTelManager.createForSubscriptionId( + getDefaultSubscriptionId(context)); + mmTelManager.isSupported(MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE, + AccessNetworkConstants.TRANSPORT_TYPE_WWAN, Runnable::run, resultQueue::offer); + } catch (ImsException e) { + logger.warn("isVoLteSupported: ImsException = " + e.getMessage()); + return false; + } + try { + Boolean result = resultQueue.poll(TIMEOUT_GET_CONFIGURATION_MS, TimeUnit.MILLISECONDS); + return (result != null) ? result : false; + } catch (InterruptedException e) { + logger.warn("isVoLteSupported, InterruptedException=" + e.getMessage()); + return false; + } + } + + public static boolean isVoWiFiSupported(Context context) { + LinkedBlockingQueue<Boolean> resultQueue = new LinkedBlockingQueue<>(1); + try { + ImsMmTelManager mmTelManager = ImsMmTelManager.createForSubscriptionId( + getDefaultSubscriptionId(context)); + mmTelManager.isSupported(MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE, + AccessNetworkConstants.TRANSPORT_TYPE_WLAN, Runnable::run, resultQueue::offer); + } catch (ImsException e) { + logger.warn("isVoWiFiSupported: ImsException = " + e.getMessage()); + return false; + } + try { + Boolean result = resultQueue.poll(TIMEOUT_GET_CONFIGURATION_MS, TimeUnit.MILLISECONDS); + return (result != null) ? result : false; + } catch (InterruptedException e) { + logger.warn("isVoWiFiSupported, InterruptedException=" + e.getMessage()); + return false; + } + } + + public static boolean isVtSupported(Context context) { + LinkedBlockingQueue<Boolean> resultQueue = new LinkedBlockingQueue<>(1); + try { + ImsMmTelManager mmTelManager = ImsMmTelManager.createForSubscriptionId( + getDefaultSubscriptionId(context)); + mmTelManager.isSupported(MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO, + AccessNetworkConstants.TRANSPORT_TYPE_WWAN, Runnable::run, resultQueue::offer); + } catch (ImsException e) { + logger.warn("isVoWiFiSupported: ImsException = " + e.getMessage()); + return false; + } + try { + Boolean result = resultQueue.poll(TIMEOUT_GET_CONFIGURATION_MS, TimeUnit.MILLISECONDS); + return (result != null) ? result : false; + } catch (InterruptedException e) { + logger.warn("isVtSupported, InterruptedException=" + e.getMessage()); + return false; } - logger.debug("publishThrottle=" + publishThrottle); - return publishThrottle; } - private static int getDefaultSubscriptionId(Context context) { + public static int getDefaultSubscriptionId(Context context) { SubscriptionManager sm = context.getSystemService(SubscriptionManager.class); - List<SubscriptionInfo> infos = sm.getActiveSubscriptionInfoList(); + if (sm == null) return SubscriptionManager.INVALID_SUBSCRIPTION_ID; + List<SubscriptionInfo> infos = sm.getActiveSubscriptionInfoList(); if (infos == null || infos.isEmpty()) { // There are no active subscriptions right now. return SubscriptionManager.INVALID_SUBSCRIPTION_ID; diff --git a/rcs/rcsservice/src/com/android/service/ims/presence/PresenceBase.java b/rcs/rcsservice/src/com/android/service/ims/presence/PresenceBase.java index 9ffcba1..6a82d6b 100644 --- a/rcs/rcsservice/src/com/android/service/ims/presence/PresenceBase.java +++ b/rcs/rcsservice/src/com/android/service/ims/presence/PresenceBase.java @@ -31,10 +31,10 @@ package com.android.service.ims.presence; import android.annotation.IntDef; import android.content.Context; import android.content.Intent; +import android.telephony.ims.ImsManager; import com.android.ims.ResultCode; import com.android.ims.internal.Logger; -import com.android.internal.telephony.TelephonyIntents; import com.android.service.ims.Task; import com.android.service.ims.TaskManager; @@ -184,7 +184,7 @@ public class PresenceBase { protected void notifyDm() { logger.debug("notifyDm"); Intent intent = new Intent( - TelephonyIntents.ACTION_FORBIDDEN_NO_SERVICE_AUTHORIZATION); + ImsManager.ACTION_FORBIDDEN_NO_SERVICE_AUTHORIZATION); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); mContext.sendBroadcast(intent); diff --git a/rcs/rcsservice/src/com/android/service/ims/presence/PresencePublication.java b/rcs/rcsservice/src/com/android/service/ims/presence/PresencePublication.java index 62c5091..3d902b5 100644 --- a/rcs/rcsservice/src/com/android/service/ims/presence/PresencePublication.java +++ b/rcs/rcsservice/src/com/android/service/ims/presence/PresencePublication.java @@ -43,17 +43,14 @@ import android.provider.Settings; import android.telecom.PhoneAccount; import android.telecom.TelecomManager; import android.telephony.AccessNetworkConstants; -import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.telephony.ims.RcsContactUceCapability; import android.telephony.ims.feature.MmTelFeature; import com.android.ims.ImsConfig; -import com.android.ims.ImsManager; import com.android.ims.ResultCode; import com.android.ims.internal.Logger; import com.android.internal.telephony.IccCardConstants; -import com.android.internal.telephony.Phone; import com.android.internal.telephony.TelephonyIntents; import com.android.service.ims.RcsSettingUtils; import com.android.service.ims.Task; @@ -95,7 +92,7 @@ public class PresencePublication extends PresenceBase { private boolean mGotTriggerFromStack = false; private boolean mDonotRetryUntilPowerCycle = false; private boolean mSimLoaded = false; - private int mPreferredTtyMode = Phone.TTY_MODE_OFF; + private int mPreferredTtyMode = TelecomManager.TTY_MODE_OFF; private boolean mImsRegistered = false; private boolean mVtEnabled = false; @@ -160,19 +157,14 @@ public class PresencePublication extends PresenceBase { mConfigVolteProvisionErrorOnPublishResponse = configVolteProvisionErrorOnPublishResponse; mConfigRcsProvisionErrorOnPublishResponse = configRcsProvisionErrorOnPublishResponse; - mVtEnabled = getImsManager().isVtEnabledByUser(); + mVtEnabled = RcsSettingUtils.isVtEnabledByUser(mContext); mDataEnabled = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.MOBILE_DATA, 1) == 1; - new Thread(() -> { - RcsSettingUtils.setMobileDataEnabled(mContext, mDataEnabled); - }).start(); logger.debug("The current mobile data is: " + (mDataEnabled ? "enabled" : "disabled")); - mPreferredTtyMode = Settings.Secure.getInt( - mContext.getContentResolver(), - Settings.Secure.PREFERRED_TTY_MODE, - Phone.TTY_MODE_OFF); + TelecomManager tm = mContext.getSystemService(TelecomManager.class); + mPreferredTtyMode = tm.getCurrentTtyMode(); logger.debug("The current TTY mode is: " + mPreferredTtyMode); mReceiver = new BroadcastReceiver() { @@ -242,7 +234,6 @@ public class PresencePublication extends PresenceBase { int newPreferredTtyMode = intent.getIntExtra( TelecomManager.EXTRA_TTY_PREFERRED_MODE, TelecomManager.TTY_MODE_OFF); - newPreferredTtyMode = telecomTtyModeToPhoneMode(newPreferredTtyMode); logger.debug("Tty mode changed from " + mPreferredTtyMode + " to " + newPreferredTtyMode); @@ -277,23 +268,22 @@ public class PresencePublication extends PresenceBase { sPresencePublication = this; } - private boolean isIPVoiceSupported(boolean volteAvailable, boolean vtAvailable, - boolean voWifiAvailable, boolean viWifiAvailable) { - ImsManager imsManager = getImsManager(); + private boolean isIPVoiceSupported(boolean volteAvailable, boolean voWifiAvailable) { // volte and vowifi can be enabled separately - if(!imsManager.isVolteEnabledByPlatform() && !imsManager.isWfcEnabledByPlatform()) { + if(!RcsSettingUtils.isVoLteSupported(mContext) && + !RcsSettingUtils.isVoWiFiSupported(mContext)) { logger.print("Disabled by platform, voiceSupported=false"); return false; } - if(!imsManager.isVolteProvisionedOnDevice() && + if(!RcsSettingUtils.isVoLteProvisioned(mContext) && !RcsSettingUtils.isVowifiProvisioned(mContext)) { logger.print("Wasn't provisioned, voiceSupported=false"); return false; } - if(!imsManager.isEnhanced4gLteModeSettingEnabledByUser() && - !imsManager.isWfcEnabledByUser()){ + if(!RcsSettingUtils.isAdvancedCallingEnabledByUser(mContext) && + !RcsSettingUtils.isWfcEnabledByUser(mContext)){ logger.print("User didn't enable volte or wfc, voiceSupported=false"); return false; } @@ -320,24 +310,21 @@ public class PresencePublication extends PresenceBase { return true; } - private boolean isIPVideoSupported(boolean volteAvailable, boolean vtAvailable, - boolean voWifiAvailable, boolean viWifiAvailable) { - ImsManager imsManager = getImsManager(); + private boolean isIPVideoSupported(boolean vtAvailable, boolean viWifiAvailable) { // if volte or vt was disabled then the viwifi will be disabled as well. - if(!imsManager.isVolteEnabledByPlatform() || - !imsManager.isVtEnabledByPlatform()) { + if(!RcsSettingUtils.isVoLteSupported(mContext) || + !RcsSettingUtils.isVtSupported(mContext)) { logger.print("Disabled by platform, videoSupported=false"); return false; } - if(!imsManager.isVolteProvisionedOnDevice() || + if(!RcsSettingUtils.isVoLteProvisioned(mContext) || !RcsSettingUtils.isLvcProvisioned(mContext)) { logger.print("Not provisioned. videoSupported=false"); return false; } - if(!imsManager.isEnhanced4gLteModeSettingEnabledByUser() || - !mVtEnabled){ + if(!RcsSettingUtils.isAdvancedCallingEnabledByUser(mContext) || !mVtEnabled){ logger.print("User disabled volte or vt, videoSupported=false"); return false; } @@ -434,7 +421,6 @@ public class PresencePublication extends PresenceBase { logger.print("onMobileDataChanged, mDataEnabled=" + mDataEnabled + " value=" + value); if(mDataEnabled != value) { mDataEnabled = value; - RcsSettingUtils.setMobileDataEnabled(mContext, mDataEnabled); requestLocalPublish(PublishType.PRES_PUBLISH_TRIGGER_DATA_CHANGED); } @@ -703,14 +689,8 @@ public class PresencePublication extends PresenceBase { } public void refreshPublishContent() { - mVolteCapable = isIPVoiceSupported(mIsVolteAvailable, - mIsVtAvailable, - mIsVoWifiAvailable, - mIsViWifiAvailable); - mVtCapable = isIPVideoSupported(mIsVolteAvailable, - mIsVtAvailable, - mIsVoWifiAvailable, - mIsViWifiAvailable); + mVolteCapable = isIPVoiceSupported(mIsVolteAvailable, mIsVoWifiAvailable); + mVtCapable = isIPVideoSupported(mIsVtAvailable, mIsViWifiAvailable); } public boolean getForceToNetwork() { @@ -889,7 +869,7 @@ public class PresencePublication extends PresenceBase { // we need send PUBLISH once even the volte is off when power on the phone. // That will tell other phone that it has no volte/vt capability. - if(!getImsManager().isEnhanced4gLteModeSettingEnabledByUser() && + if(!RcsSettingUtils.isAdvancedCallingEnabledByUser(mContext) && getPublishState() != PUBLISH_STATE_NOT_PUBLISHED) { // volte was not enabled. // or it is turnning off volte. lower layer should unpublish @@ -1055,21 +1035,7 @@ public class PresencePublication extends PresenceBase { } private static boolean isTtyEnabled(int mode) { - return Phone.TTY_MODE_OFF != mode; - } - - private static int telecomTtyModeToPhoneMode(int telecomMode) { - switch (telecomMode) { - case TelecomManager.TTY_MODE_FULL: - return Phone.TTY_MODE_FULL; - case TelecomManager.TTY_MODE_VCO: - return Phone.TTY_MODE_VCO; - case TelecomManager.TTY_MODE_HCO: - return Phone.TTY_MODE_HCO; - case TelecomManager.TTY_MODE_OFF: - default: - return Phone.TTY_MODE_OFF; - } + return TelecomManager.TTY_MODE_OFF != mode; } public void finish() { @@ -1165,9 +1131,4 @@ public class PresencePublication extends PresenceBase { // Had reported IWLAN by trigger and still have DATA. return mMovedToIWLAN && (networkType != TelephonyManager.NETWORK_TYPE_UNKNOWN); } - - - private ImsManager getImsManager() { - return ImsManager.getInstance(mContext, SubscriptionManager.getDefaultVoicePhoneId()); - } } diff --git a/rcs/rcsservice/src/com/android/service/ims/presence/PresenceSubscriber.java b/rcs/rcsservice/src/com/android/service/ims/presence/PresenceSubscriber.java index 9a7e6f9..632e0f5 100644 --- a/rcs/rcsservice/src/com/android/service/ims/presence/PresenceSubscriber.java +++ b/rcs/rcsservice/src/com/android/service/ims/presence/PresenceSubscriber.java @@ -65,20 +65,22 @@ public class PresenceSubscriber extends PresenceBase { mConfigRcsProvisionErrorOnSubscribeResponse = configRcsProvisionErrorOnSubscribeResponse; } - private String numberToUriString(String number){ - String formatedContact = number; - if(!formatedContact.startsWith("sip:") && !formatedContact.startsWith("tel:")){ - String domain = TelephonyManager.getDefault().getIsimDomain(); + private String numberToUriString(String number) { + String formattedContact = number; + TelephonyManager tm = mContext.getSystemService(TelephonyManager.class); + if (tm != null && !formattedContact.startsWith("sip:") + && !formattedContact.startsWith("tel:")){ + String domain = tm.getIsimDomain(); logger.debug("domain=" + domain); - if(domain == null || domain.length() ==0){ - formatedContact = "tel:" + formatedContact; - }else{ - formatedContact = "sip:" + formatedContact + "@" + domain; + if (domain == null || domain.length() == 0){ + formattedContact = "tel:" + formattedContact; + } else { + formattedContact = "sip:" + formattedContact + "@" + domain; } } - logger.print("numberToUriString formatedContact=" + formatedContact); - return formatedContact; + logger.print("numberToUriString formattedContact=" + formattedContact); + return formattedContact; } private String numberToTelString(String number){ @@ -183,11 +185,9 @@ public class PresenceSubscriber extends PresenceBase { } } - boolean isFtSupported = false; // hard code to not support FT at present. - boolean isChatSupported = false; // hard code to not support chat at present. // Only poll/fetch capability/availability on LTE - if(((TelephonyManager.getDefault().getNetworkType() != TelephonyManager.NETWORK_TYPE_LTE) - && !isFtSupported && !isChatSupported)){ + TelephonyManager tm = mContext.getSystemService(TelephonyManager.class); + if(tm == null || (tm.getDataNetworkType() != TelephonyManager.NETWORK_TYPE_LTE)) { logger.error("requestAvailability return ERROR_SERVICE_NOT_AVAILABLE" + " for it is not LTE network"); return ResultCode.ERROR_SERVICE_NOT_AVAILABLE; |