Loading src/com/android/server/telecom/CreateConnectionTimeout.java +20 −48 Original line number Diff line number Diff line Loading @@ -17,14 +17,10 @@ package com.android.server.telecom; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Handler; import android.os.Looper; import android.telecom.PhoneAccountHandle; import android.telephony.TelephonyManager; import android.telephony.PhoneStateListener; import android.telephony.ServiceState; import java.util.Collection; import java.util.Objects; Loading @@ -32,7 +28,7 @@ import java.util.Objects; /** * Registers a timeout for a call and disconnects the call when the timeout expires. */ final class CreateConnectionTimeout extends PhoneStateListener implements Runnable { final class CreateConnectionTimeout implements Runnable { private final Context mContext; private final PhoneAccountRegistrar mPhoneAccountRegistrar; private final ConnectionServiceWrapper mConnectionService; Loading @@ -43,7 +39,6 @@ final class CreateConnectionTimeout extends PhoneStateListener implements Runnab CreateConnectionTimeout(Context context, PhoneAccountRegistrar phoneAccountRegistrar, ConnectionServiceWrapper service, Call call) { super(Looper.getMainLooper()); mContext = context; mPhoneAccountRegistrar = phoneAccountRegistrar; mConnectionService = service; Loading @@ -69,27 +64,27 @@ final class CreateConnectionTimeout extends PhoneStateListener implements Runnab return false; } // To reduce the number of scenarios where a timeout is needed, only use a timeout if // we're connected to Wi-Fi. This ensures that the fallback connection manager has an // alternate route to place the call. TODO: remove this condition or allow connection // managers to specify transports. See http://b/19199181. if (!isConnectedToWifi()) { // Timeout is only supported for SIM call managers that are set by the carrier. if (!Objects.equals(connectionManager.getComponentName(), mPhoneAccountRegistrar.getSystemSimCallManagerComponent())) { Log.d(this, "isTimeoutNeededForCall, not a system sim call manager"); return false; } Log.d(this, "isTimeoutNeededForCall, returning true"); Log.i(this, "isTimeoutNeededForCall, returning true"); return true; } void registerTimeout() { Log.d(this, "registerTimeout"); mIsRegistered = true; // First find out the cellular service state. Based on the state we decide whether a timeout // will actually be enforced and if so how long it should be. TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); telephonyManager.listen(this, PhoneStateListener.LISTEN_SERVICE_STATE); telephonyManager.listen(this, 0); long timeoutLengthMillis = getTimeoutLengthMillis(); if (timeoutLengthMillis <= 0) { Log.d(this, "registerTimeout, timeout set to %d, skipping", timeoutLengthMillis); } else { mHandler.postDelayed(this, timeoutLengthMillis); } } void unregisterTimeout() { Loading @@ -102,25 +97,10 @@ final class CreateConnectionTimeout extends PhoneStateListener implements Runnab return mIsCallTimedOut; } @Override public void onServiceStateChanged(ServiceState serviceState) { long timeoutLengthMillis = getTimeoutLengthMillis(serviceState); if (!mIsRegistered) { Log.d(this, "onServiceStateChanged, timeout no longer registered, skipping"); } else if (timeoutLengthMillis <= 0) { Log.d(this, "onServiceStateChanged, timeout set to %d, skipping", timeoutLengthMillis); } else if (serviceState.getState() == ServiceState.STATE_IN_SERVICE) { // If cellular service is available then don't bother with a timeout. Log.d(this, "onServiceStateChanged, cellular service available, skipping"); } else { mHandler.postDelayed(this, timeoutLengthMillis); } } @Override public void run() { if (mIsRegistered && isCallBeingPlaced(mCall)) { Log.d(this, "run, call timed out, calling disconnect"); Log.i(this, "run, call timed out, calling disconnect"); mIsCallTimedOut = true; mConnectionService.disconnect(mCall); } Loading @@ -133,24 +113,16 @@ final class CreateConnectionTimeout extends PhoneStateListener implements Runnab || state == CallState.DIALING; } private long getTimeoutLengthMillis(ServiceState serviceState) { private long getTimeoutLengthMillis() { // If the radio is off then use a longer timeout. This gives us more time to power on the // radio. if (serviceState.getState() == ServiceState.STATE_POWER_OFF) { TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager.isRadioOn()) { return Timeouts.getEmergencyCallTimeoutMillis(mContext.getContentResolver()); } else { return Timeouts.getEmergencyCallTimeoutRadioOffMillis( mContext.getContentResolver()); } else { return Timeouts.getEmergencyCallTimeoutMillis(mContext.getContentResolver()); } } private boolean isConnectedToWifi() { ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService( Context.CONNECTIVITY_SERVICE); if (cm != null) { NetworkInfo ni = cm.getActiveNetworkInfo(); return ni != null && ni.isConnected() && ni.getType() == ConnectivityManager.TYPE_WIFI; } return false; } } src/com/android/server/telecom/PhoneAccountRegistrar.java +14 −11 Original line number Diff line number Diff line Loading @@ -286,6 +286,19 @@ public final class PhoneAccountRegistrar { return getSimCallManager(user); } public ComponentName getSystemSimCallManagerComponent() { String defaultSimCallManager = null; CarrierConfigManager configManager = (CarrierConfigManager) mContext.getSystemService( Context.CARRIER_CONFIG_SERVICE); PersistableBundle configBundle = configManager.getConfig(); if (configBundle != null) { defaultSimCallManager = configBundle.getString( CarrierConfigManager.KEY_DEFAULT_SIM_CALL_MANAGER_STRING); } return TextUtils.isEmpty(defaultSimCallManager) ? null : ComponentName.unflattenFromString(defaultSimCallManager); } /** * Returns the {@link PhoneAccountHandle} corresponding to the currently active SIM Call * Manager. SIM Call Manager returned corresponds to the following priority order: Loading @@ -300,17 +313,7 @@ public final class PhoneAccountRegistrar { String dialerPackage = DefaultDialerManager.getDefaultDialerApplication(mContext, user); // Check carrier config. String defaultSimCallManager = null; CarrierConfigManager configManager = (CarrierConfigManager) mContext.getSystemService( Context.CARRIER_CONFIG_SERVICE); PersistableBundle configBundle = configManager.getConfig(); if (configBundle != null) { defaultSimCallManager = configBundle.getString( CarrierConfigManager.KEY_DEFAULT_SIM_CALL_MANAGER_STRING); } ComponentName systemSimCallManagerComponent = TextUtils.isEmpty(defaultSimCallManager) ? null : ComponentName.unflattenFromString(defaultSimCallManager); ComponentName systemSimCallManagerComponent = getSystemSimCallManagerComponent(); PhoneAccountHandle dialerSimCallManager = null; PhoneAccountHandle systemSimCallManager = null; Loading Loading
src/com/android/server/telecom/CreateConnectionTimeout.java +20 −48 Original line number Diff line number Diff line Loading @@ -17,14 +17,10 @@ package com.android.server.telecom; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Handler; import android.os.Looper; import android.telecom.PhoneAccountHandle; import android.telephony.TelephonyManager; import android.telephony.PhoneStateListener; import android.telephony.ServiceState; import java.util.Collection; import java.util.Objects; Loading @@ -32,7 +28,7 @@ import java.util.Objects; /** * Registers a timeout for a call and disconnects the call when the timeout expires. */ final class CreateConnectionTimeout extends PhoneStateListener implements Runnable { final class CreateConnectionTimeout implements Runnable { private final Context mContext; private final PhoneAccountRegistrar mPhoneAccountRegistrar; private final ConnectionServiceWrapper mConnectionService; Loading @@ -43,7 +39,6 @@ final class CreateConnectionTimeout extends PhoneStateListener implements Runnab CreateConnectionTimeout(Context context, PhoneAccountRegistrar phoneAccountRegistrar, ConnectionServiceWrapper service, Call call) { super(Looper.getMainLooper()); mContext = context; mPhoneAccountRegistrar = phoneAccountRegistrar; mConnectionService = service; Loading @@ -69,27 +64,27 @@ final class CreateConnectionTimeout extends PhoneStateListener implements Runnab return false; } // To reduce the number of scenarios where a timeout is needed, only use a timeout if // we're connected to Wi-Fi. This ensures that the fallback connection manager has an // alternate route to place the call. TODO: remove this condition or allow connection // managers to specify transports. See http://b/19199181. if (!isConnectedToWifi()) { // Timeout is only supported for SIM call managers that are set by the carrier. if (!Objects.equals(connectionManager.getComponentName(), mPhoneAccountRegistrar.getSystemSimCallManagerComponent())) { Log.d(this, "isTimeoutNeededForCall, not a system sim call manager"); return false; } Log.d(this, "isTimeoutNeededForCall, returning true"); Log.i(this, "isTimeoutNeededForCall, returning true"); return true; } void registerTimeout() { Log.d(this, "registerTimeout"); mIsRegistered = true; // First find out the cellular service state. Based on the state we decide whether a timeout // will actually be enforced and if so how long it should be. TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); telephonyManager.listen(this, PhoneStateListener.LISTEN_SERVICE_STATE); telephonyManager.listen(this, 0); long timeoutLengthMillis = getTimeoutLengthMillis(); if (timeoutLengthMillis <= 0) { Log.d(this, "registerTimeout, timeout set to %d, skipping", timeoutLengthMillis); } else { mHandler.postDelayed(this, timeoutLengthMillis); } } void unregisterTimeout() { Loading @@ -102,25 +97,10 @@ final class CreateConnectionTimeout extends PhoneStateListener implements Runnab return mIsCallTimedOut; } @Override public void onServiceStateChanged(ServiceState serviceState) { long timeoutLengthMillis = getTimeoutLengthMillis(serviceState); if (!mIsRegistered) { Log.d(this, "onServiceStateChanged, timeout no longer registered, skipping"); } else if (timeoutLengthMillis <= 0) { Log.d(this, "onServiceStateChanged, timeout set to %d, skipping", timeoutLengthMillis); } else if (serviceState.getState() == ServiceState.STATE_IN_SERVICE) { // If cellular service is available then don't bother with a timeout. Log.d(this, "onServiceStateChanged, cellular service available, skipping"); } else { mHandler.postDelayed(this, timeoutLengthMillis); } } @Override public void run() { if (mIsRegistered && isCallBeingPlaced(mCall)) { Log.d(this, "run, call timed out, calling disconnect"); Log.i(this, "run, call timed out, calling disconnect"); mIsCallTimedOut = true; mConnectionService.disconnect(mCall); } Loading @@ -133,24 +113,16 @@ final class CreateConnectionTimeout extends PhoneStateListener implements Runnab || state == CallState.DIALING; } private long getTimeoutLengthMillis(ServiceState serviceState) { private long getTimeoutLengthMillis() { // If the radio is off then use a longer timeout. This gives us more time to power on the // radio. if (serviceState.getState() == ServiceState.STATE_POWER_OFF) { TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); if (telephonyManager.isRadioOn()) { return Timeouts.getEmergencyCallTimeoutMillis(mContext.getContentResolver()); } else { return Timeouts.getEmergencyCallTimeoutRadioOffMillis( mContext.getContentResolver()); } else { return Timeouts.getEmergencyCallTimeoutMillis(mContext.getContentResolver()); } } private boolean isConnectedToWifi() { ConnectivityManager cm = (ConnectivityManager) mContext.getSystemService( Context.CONNECTIVITY_SERVICE); if (cm != null) { NetworkInfo ni = cm.getActiveNetworkInfo(); return ni != null && ni.isConnected() && ni.getType() == ConnectivityManager.TYPE_WIFI; } return false; } }
src/com/android/server/telecom/PhoneAccountRegistrar.java +14 −11 Original line number Diff line number Diff line Loading @@ -286,6 +286,19 @@ public final class PhoneAccountRegistrar { return getSimCallManager(user); } public ComponentName getSystemSimCallManagerComponent() { String defaultSimCallManager = null; CarrierConfigManager configManager = (CarrierConfigManager) mContext.getSystemService( Context.CARRIER_CONFIG_SERVICE); PersistableBundle configBundle = configManager.getConfig(); if (configBundle != null) { defaultSimCallManager = configBundle.getString( CarrierConfigManager.KEY_DEFAULT_SIM_CALL_MANAGER_STRING); } return TextUtils.isEmpty(defaultSimCallManager) ? null : ComponentName.unflattenFromString(defaultSimCallManager); } /** * Returns the {@link PhoneAccountHandle} corresponding to the currently active SIM Call * Manager. SIM Call Manager returned corresponds to the following priority order: Loading @@ -300,17 +313,7 @@ public final class PhoneAccountRegistrar { String dialerPackage = DefaultDialerManager.getDefaultDialerApplication(mContext, user); // Check carrier config. String defaultSimCallManager = null; CarrierConfigManager configManager = (CarrierConfigManager) mContext.getSystemService( Context.CARRIER_CONFIG_SERVICE); PersistableBundle configBundle = configManager.getConfig(); if (configBundle != null) { defaultSimCallManager = configBundle.getString( CarrierConfigManager.KEY_DEFAULT_SIM_CALL_MANAGER_STRING); } ComponentName systemSimCallManagerComponent = TextUtils.isEmpty(defaultSimCallManager) ? null : ComponentName.unflattenFromString(defaultSimCallManager); ComponentName systemSimCallManagerComponent = getSystemSimCallManagerComponent(); PhoneAccountHandle dialerSimCallManager = null; PhoneAccountHandle systemSimCallManager = null; Loading