Search in sources :

Example 26 with TelecomManager

use of android.telecom.TelecomManager in project android_packages_apps_Dialer by LineageOS.

the class CallUtil method getVideoCallingAvailability.

/**
 * Determines if video calling is available, and if so whether presence checking is available as
 * well.
 *
 * <p>Returns a bitmask with {@link #VIDEO_CALLING_ENABLED} to indicate that video calling is
 * available, and {@link #VIDEO_CALLING_PRESENCE} if presence indication is also available.
 *
 * @param context The context
 * @return A bit-mask describing the current video capabilities.
 */
public static int getVideoCallingAvailability(Context context) {
    if (!PermissionsUtil.hasPermission(context, android.Manifest.permission.READ_PHONE_STATE) || !CompatUtils.isVideoCompatible()) {
        return VIDEO_CALLING_DISABLED;
    }
    TelecomManager telecommMgr = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
    if (telecommMgr == null) {
        return VIDEO_CALLING_DISABLED;
    }
    List<PhoneAccountHandle> accountHandles = telecommMgr.getCallCapablePhoneAccounts();
    for (PhoneAccountHandle accountHandle : accountHandles) {
        PhoneAccount account = telecommMgr.getPhoneAccount(accountHandle);
        if (account != null) {
            if (account.hasCapabilities(PhoneAccount.CAPABILITY_VIDEO_CALLING)) {
                // Builds prior to N do not have presence support.
                if (!CompatUtils.isVideoPresenceCompatible()) {
                    return VIDEO_CALLING_ENABLED;
                }
                int videoCapabilities = VIDEO_CALLING_ENABLED;
                if (account.hasCapabilities(PhoneAccount.CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
                    videoCapabilities |= VIDEO_CALLING_PRESENCE;
                }
                return videoCapabilities;
            }
        }
    }
    return VIDEO_CALLING_DISABLED;
}
Also used : PhoneAccount(android.telecom.PhoneAccount) PhoneAccountHandle(android.telecom.PhoneAccountHandle) TelecomManager(android.telecom.TelecomManager)

Example 27 with TelecomManager

use of android.telecom.TelecomManager in project android_packages_apps_Settings by omnirom.

the class SimDialogActivity method subscriptionIdToPhoneAccountHandle.

private PhoneAccountHandle subscriptionIdToPhoneAccountHandle(final int subId) {
    final TelecomManager telecomManager = TelecomManager.from(this);
    final TelephonyManager telephonyManager = TelephonyManager.from(this);
    final Iterator<PhoneAccountHandle> phoneAccounts = telecomManager.getCallCapablePhoneAccounts().listIterator();
    while (phoneAccounts.hasNext()) {
        final PhoneAccountHandle phoneAccountHandle = phoneAccounts.next();
        final PhoneAccount phoneAccount = telecomManager.getPhoneAccount(phoneAccountHandle);
        if (subId == telephonyManager.getSubIdForPhoneAccount(phoneAccount)) {
            return phoneAccountHandle;
        }
    }
    return null;
}
Also used : PhoneAccount(android.telecom.PhoneAccount) PhoneAccountHandle(android.telecom.PhoneAccountHandle) TelephonyManager(android.telephony.TelephonyManager) TelecomManager(android.telecom.TelecomManager)

Example 28 with TelecomManager

use of android.telecom.TelecomManager in project android_packages_apps_Settings by omnirom.

the class SimDialogActivity method createDialog.

public Dialog createDialog(final Context context, final int id) {
    final ArrayList<String> list = new ArrayList<String>();
    final SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
    final List<SubscriptionInfo> subInfoList = subscriptionManager.getActiveSubscriptionInfoList();
    final int selectableSubInfoLength = subInfoList == null ? 0 : subInfoList.size();
    final ArrayList<SubscriptionInfo> callsSubInfoList = new ArrayList<SubscriptionInfo>();
    final DialogInterface.OnClickListener selectionListener = new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int value) {
            final SubscriptionInfo sir;
            switch(id) {
                case DATA_PICK:
                    sir = subInfoList.get(value);
                    setDefaultDataSubId(context, sir.getSubscriptionId());
                    break;
                case CALLS_PICK:
                    final TelecomManager telecomManager = TelecomManager.from(context);
                    final List<PhoneAccountHandle> phoneAccountsList = telecomManager.getCallCapablePhoneAccounts();
                    setUserSelectedOutgoingPhoneAccount(value == (callsSubInfoList.size() - 1) ? null : phoneAccountsList.get(value));
                    break;
                case SMS_PICK:
                    sir = subInfoList.get(value);
                    setDefaultSmsSubId(context, sir.getSubscriptionId());
                    break;
                default:
                    throw new IllegalArgumentException("Invalid dialog type " + id + " in SIM dialog.");
            }
            finish();
        }
    };
    Dialog.OnKeyListener keyListener = new Dialog.OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface arg0, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                finish();
            }
            return true;
        }
    };
    if (id == CALLS_PICK) {
        final TelecomManager telecomManager = TelecomManager.from(context);
        final TelephonyManager telephonyManager = TelephonyManager.from(context);
        final Iterator<PhoneAccountHandle> phoneAccounts = telecomManager.getCallCapablePhoneAccounts().listIterator();
        while (phoneAccounts.hasNext()) {
            final PhoneAccount phoneAccount = telecomManager.getPhoneAccount(phoneAccounts.next());
            list.add((String) phoneAccount.getLabel());
            int subId = telephonyManager.getSubIdForPhoneAccount(phoneAccount);
            if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
                final SubscriptionInfo sir = SubscriptionManager.from(context).getActiveSubscriptionInfo(subId);
                callsSubInfoList.add(sir);
            } else {
                callsSubInfoList.add(null);
            }
        }
        list.add(getResources().getString(R.string.sim_calls_ask_first_prefs_title));
        callsSubInfoList.add(null);
    } else {
        for (int i = 0; i < selectableSubInfoLength; ++i) {
            final SubscriptionInfo sir = subInfoList.get(i);
            CharSequence displayName = sir.getDisplayName();
            if (displayName == null) {
                displayName = "";
            }
            list.add(displayName.toString());
        }
    }
    String[] arr = list.toArray(new String[0]);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    ListAdapter adapter = new SelectAccountListAdapter(id == CALLS_PICK ? callsSubInfoList : subInfoList, builder.getContext(), R.layout.select_account_list_item, arr, id);
    switch(id) {
        case DATA_PICK:
            builder.setTitle(R.string.select_sim_for_data);
            break;
        case CALLS_PICK:
            builder.setTitle(R.string.select_sim_for_calls);
            break;
        case SMS_PICK:
            builder.setTitle(R.string.select_sim_for_sms);
            break;
        default:
            throw new IllegalArgumentException("Invalid dialog type " + id + " in SIM dialog.");
    }
    Dialog dialog = builder.setAdapter(adapter, selectionListener).create();
    dialog.setOnKeyListener(keyListener);
    dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialogInterface) {
            finish();
        }
    });
    return dialog;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) SubscriptionInfo(android.telephony.SubscriptionInfo) SubscriptionManager(android.telephony.SubscriptionManager) KeyEvent(android.view.KeyEvent) TelephonyManager(android.telephony.TelephonyManager) Dialog(android.app.Dialog) AlertDialog(android.app.AlertDialog) ListAdapter(android.widget.ListAdapter) PhoneAccountHandle(android.telecom.PhoneAccountHandle) TelecomManager(android.telecom.TelecomManager) PhoneAccount(android.telecom.PhoneAccount)

Example 29 with TelecomManager

use of android.telecom.TelecomManager in project android_packages_apps_Settings by omnirom.

the class SimDialogActivity method setUserSelectedOutgoingPhoneAccount.

private void setUserSelectedOutgoingPhoneAccount(PhoneAccountHandle phoneAccount) {
    final TelecomManager telecomManager = TelecomManager.from(this);
    telecomManager.setUserSelectedOutgoingPhoneAccount(phoneAccount);
}
Also used : TelecomManager(android.telecom.TelecomManager)

Example 30 with TelecomManager

use of android.telecom.TelecomManager in project android_packages_apps_Settings by omnirom.

the class SimSettings method updateCallValues.

private void updateCallValues() {
    final Preference simPref = findPreference(KEY_CALLS);
    final SubscriptionInfo sir = mSubscriptionManager.getDefaultVoiceSubscriptionInfo();
    final TelecomManager telecomManager = TelecomManager.from(mContext);
    final PhoneAccountHandle phoneAccount = telecomManager.getUserSelectedOutgoingPhoneAccount();
    final List<PhoneAccountHandle> allPhoneAccounts = telecomManager.getCallCapablePhoneAccounts();
    simPref.setTitle(R.string.calls_title);
    if (sir != null) {
        simPref.setSummary(phoneAccount == null ? mContext.getResources().getString(R.string.sim_calls_ask_first_prefs_title) : getSubscriptionDisplayName(sir));
        // Enable data preference in msim mode and call state idle
        simPref.setEnabled(allPhoneAccounts.size() > 1);
    } else {
        simPref.setSummary(phoneAccount == null ? mContext.getResources().getString(R.string.sim_calls_ask_first_prefs_title) : (String) telecomManager.getPhoneAccount(phoneAccount).getLabel());
        simPref.setEnabled(allPhoneAccounts.size() > 1);
    }
}
Also used : PhoneAccountHandle(android.telecom.PhoneAccountHandle) Preference(android.support.v7.preference.Preference) SubscriptionInfo(android.telephony.SubscriptionInfo) TelecomManager(android.telecom.TelecomManager)

Aggregations

TelecomManager (android.telecom.TelecomManager)86 PhoneAccountHandle (android.telecom.PhoneAccountHandle)45 PhoneAccount (android.telecom.PhoneAccount)30 TelephonyManager (android.telephony.TelephonyManager)17 SubscriptionInfo (android.telephony.SubscriptionInfo)11 KeyEvent (android.view.KeyEvent)9 ArrayList (java.util.ArrayList)9 AlertDialog (android.app.AlertDialog)8 ActivityNotFoundException (android.content.ActivityNotFoundException)8 DialogInterface (android.content.DialogInterface)8 Message (android.os.Message)8 SubscriptionManager (android.telephony.SubscriptionManager)8 Dialog (android.app.Dialog)7 ListAdapter (android.widget.ListAdapter)7 Intent (android.content.Intent)6 Preference (android.support.v7.preference.Preference)6 ComponentName (android.content.ComponentName)4 PackageManagerInternal (android.content.pm.PackageManagerInternal)4 RemoteException (android.os.RemoteException)4 IntArray (android.util.IntArray)4