Search in sources :

Example 6 with ImsMmTelManager

use of android.telephony.ims.ImsMmTelManager in project android_packages_apps_Settings by omnirom.

the class WifiCallingSliceHelper method createWifiCallingPreferenceSlice.

/**
 * Returns Slice object for wifi calling preference.
 *
 * If wifi calling is not turned on, this method will return a slice to turn on wifi calling.
 *
 * If wifi calling preference is not user editable, this method will return a slice to display
 * appropriate message.
 *
 * If wifi calling preference can be changed, this method will return a slice with 3 or 4 rows:
 * Header Row: current preference settings
 * Row 1: wifi only option with ACTION_WIFI_CALLING_PREFERENCE_WIFI_ONLY, if wifi only option
 * is editable
 * Row 2: wifi preferred option with ACTION_WIFI_CALLING_PREFERENCE_WIFI_PREFERRED
 * Row 3: cellular preferred option with ACTION_WIFI_CALLING_PREFERENCE_CELLULAR_PREFERRED
 */
public Slice createWifiCallingPreferenceSlice(Uri sliceUri) {
    final int subId = getDefaultVoiceSubId();
    if (!SubscriptionManager.isValidSubscriptionId(subId)) {
        Log.d(TAG, "Invalid Subscription Id");
        return null;
    }
    final boolean isWifiCallingPrefEditable = isCarrierConfigManagerKeyEnabled(CarrierConfigManager.KEY_EDITABLE_WFC_MODE_BOOL, subId, false);
    final boolean isWifiOnlySupported = isCarrierConfigManagerKeyEnabled(CarrierConfigManager.KEY_CARRIER_WFC_SUPPORTS_WIFI_ONLY_BOOL, subId, true);
    if (!isWifiCallingPrefEditable) {
        Log.d(TAG, "Wifi calling preference is not editable");
        return null;
    }
    if (!queryImsState(subId).isWifiCallingProvisioned()) {
        Log.d(TAG, "Wifi calling is either not provisioned or not enabled by platform");
        return null;
    }
    boolean isWifiCallingEnabled = false;
    int wfcMode = -1;
    try {
        final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId);
        isWifiCallingEnabled = isWifiCallingEnabled();
        wfcMode = getWfcMode(imsMmTelManager);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        Log.e(TAG, "Unable to get wifi calling preferred mode", e);
        return null;
    }
    if (!isWifiCallingEnabled) {
        // wifi calling is not enabled. Ask user to enable wifi calling
        final Resources res = getResourcesForSubId(subId);
        return getNonActionableWifiCallingSlice(res.getText(R.string.wifi_calling_mode_title), res.getText(R.string.wifi_calling_turn_on), sliceUri, getActivityIntent(ACTION_WIFI_CALLING_SETTINGS_ACTIVITY));
    }
    // Return the slice to change wifi calling preference
    return getWifiCallingPreferenceSlice(isWifiOnlySupported, wfcMode, sliceUri, subId);
}
Also used : ImsMmTelManager(android.telephony.ims.ImsMmTelManager) Resources(android.content.res.Resources) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 7 with ImsMmTelManager

use of android.telephony.ims.ImsMmTelManager in project android_packages_apps_Settings by omnirom.

the class WifiCallingSliceHelper method handleWifiCallingPreferenceChanged.

/**
 * Handles wifi calling preference Setting change from wifi calling preference Slice and posts
 * notification for the change. Should be called when intent action is one of the below
 * ACTION_WIFI_CALLING_PREFERENCE_WIFI_ONLY
 * ACTION_WIFI_CALLING_PREFERENCE_WIFI_PREFERRED
 * ACTION_WIFI_CALLING_PREFERENCE_CELLULAR_PREFERRED
 *
 * @param intent intent
 */
public void handleWifiCallingPreferenceChanged(Intent intent) {
    final int subId = getDefaultVoiceSubId();
    final int errorValue = -1;
    if (SubscriptionManager.isValidSubscriptionId(subId)) {
        final boolean isWifiCallingPrefEditable = isCarrierConfigManagerKeyEnabled(CarrierConfigManager.KEY_EDITABLE_WFC_MODE_BOOL, subId, false);
        final boolean isWifiOnlySupported = isCarrierConfigManagerKeyEnabled(CarrierConfigManager.KEY_CARRIER_WFC_SUPPORTS_WIFI_ONLY_BOOL, subId, true);
        final WifiCallingQueryImsState queryState = queryImsState(subId);
        if (isWifiCallingPrefEditable && queryState.isWifiCallingProvisioned() && queryState.isEnabledByUser() && queryState.isAllowUserControl()) {
            // Change the preference only when wifi calling is enabled
            // And when wifi calling preference is editable for the current carrier
            final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId);
            final int currentValue = imsMmTelManager.getVoWiFiModeSetting();
            int newValue = errorValue;
            switch(intent.getAction()) {
                case ACTION_WIFI_CALLING_PREFERENCE_WIFI_ONLY:
                    if (isWifiOnlySupported) {
                        // change to wifi_only when wifi_only is enabled.
                        newValue = ImsMmTelManager.WIFI_MODE_WIFI_ONLY;
                    }
                    break;
                case ACTION_WIFI_CALLING_PREFERENCE_WIFI_PREFERRED:
                    newValue = ImsMmTelManager.WIFI_MODE_WIFI_PREFERRED;
                    break;
                case ACTION_WIFI_CALLING_PREFERENCE_CELLULAR_PREFERRED:
                    newValue = ImsMmTelManager.WIFI_MODE_CELLULAR_PREFERRED;
                    break;
            }
            if (newValue != errorValue && newValue != currentValue) {
                // Update the setting only when there is a valid update
                imsMmTelManager.setVoWiFiModeSetting(newValue);
            }
        }
    }
    // notify change in slice in any case to get re-queried. This would result in displaying
    // appropriate message.
    mContext.getContentResolver().notifyChange(WIFI_CALLING_PREFERENCE_URI, null);
}
Also used : WifiCallingQueryImsState(com.android.settings.network.ims.WifiCallingQueryImsState) ImsMmTelManager(android.telephony.ims.ImsMmTelManager)

Example 8 with ImsMmTelManager

use of android.telephony.ims.ImsMmTelManager in project android_packages_apps_Settings by omnirom.

the class WifiCallingSliceHelper method handleWifiCallingChanged.

/**
 * Handles wifi calling setting change from wifi calling slice and posts notification. Should be
 * called when intent action is ACTION_WIFI_CALLING_CHANGED. Executed in @WorkerThread
 *
 * @param intent action performed
 */
public void handleWifiCallingChanged(Intent intent) {
    final int subId = getDefaultVoiceSubId();
    if (SubscriptionManager.isValidSubscriptionId(subId)) {
        final WifiCallingQueryImsState queryState = queryImsState(subId);
        if (queryState.isWifiCallingProvisioned()) {
            final boolean currentValue = queryState.isEnabledByUser() && queryState.isAllowUserControl();
            final boolean newValue = intent.getBooleanExtra(EXTRA_TOGGLE_STATE, currentValue);
            final Intent activationAppIntent = getWifiCallingCarrierActivityIntent(subId);
            if (!newValue || activationAppIntent == null) {
                // or there is no activation involved - Update the setting
                if (newValue != currentValue) {
                    final ImsMmTelManager imsMmTelManager = getImsMmTelManager(subId);
                    imsMmTelManager.setVoWiFiSettingEnabled(newValue);
                }
            }
        }
    }
    // notify change in slice in any case to get re-queried. This would result in displaying
    // appropriate message with the updated setting.
    mContext.getContentResolver().notifyChange(WIFI_CALLING_URI, null);
}
Also used : WifiCallingQueryImsState(com.android.settings.network.ims.WifiCallingQueryImsState) ImsMmTelManager(android.telephony.ims.ImsMmTelManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 9 with ImsMmTelManager

use of android.telephony.ims.ImsMmTelManager in project android_packages_apps_Settings by omnirom.

the class ImsQueryController method isServiceStateReady.

@VisibleForTesting
boolean isServiceStateReady(int subId) throws InterruptedException, ImsException, IllegalArgumentException {
    if (!SubscriptionManager.isValidSubscriptionId(subId)) {
        return false;
    }
    final ImsMmTelManager imsMmTelManager = ImsMmTelManager.createForSubscriptionId(subId);
    // TODO: have a shared thread pool instead of create ExecutorService
    // everytime to improve performance.
    final ExecutorService executor = Executors.newSingleThreadExecutor();
    final IntegerConsumer intResult = new IntegerConsumer();
    imsMmTelManager.getFeatureState(executor, intResult);
    return (intResult.get(TIMEOUT_MILLIS) == ImsFeature.STATE_READY);
}
Also used : ImsMmTelManager(android.telephony.ims.ImsMmTelManager) ExecutorService(java.util.concurrent.ExecutorService) VisibleForTesting(androidx.annotation.VisibleForTesting)

Aggregations

ImsMmTelManager (android.telephony.ims.ImsMmTelManager)9 VisibleForTesting (androidx.annotation.VisibleForTesting)2 WifiCallingQueryImsState (com.android.settings.network.ims.WifiCallingQueryImsState)2 ExecutorService (java.util.concurrent.ExecutorService)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Resources (android.content.res.Resources)1 ImsException (android.telephony.ims.ImsException)1 RequiresApi (androidx.annotation.RequiresApi)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Test (org.junit.Test)1 Implementation (org.robolectric.annotation.Implementation)1