Example usage for android.telecom PhoneAccount hasCapabilities

List of usage examples for android.telecom PhoneAccount hasCapabilities

Introduction

In this page you can find the example usage for android.telecom PhoneAccount hasCapabilities.

Prototype

public boolean hasCapabilities(int capability) 

Source Link

Document

Determines if this PhoneAccount has a capabilities specified by the passed in bit mask.

Usage

From source file:Main.java

/**
 * Return a list of phone accounts that are subscription/SIM accounts.
 *///from www. j a  va2s  .c  o  m
public static List<PhoneAccountHandle> getSubscriptionPhoneAccounts(Context context) {
    final TelecomManager telecomManager = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);

    List<PhoneAccountHandle> subscriptionAccountHandles = new ArrayList<PhoneAccountHandle>();
    List<PhoneAccountHandle> accountHandles = telecomManager.getCallCapablePhoneAccounts();
    for (PhoneAccountHandle accountHandle : accountHandles) {
        PhoneAccount account = telecomManager.getPhoneAccount(accountHandle);
        if (account.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) {
            subscriptionAccountHandles.add(accountHandle);
        }
    }
    return subscriptionAccountHandles;
}

From source file:com.mobileglobe.android.customdialer.common.CallUtil.java

/**
 * Determines if one of the call capable phone accounts defined supports calling with a subject
 * specified./*ww w  . java 2  s .c  om*/
 *
 * @param context The context.
 * @return {@code true} if one of the call capable phone accounts supports calling with a
 *      subject specified, {@code false} otherwise.
 */
@RequiresApi(api = Build.VERSION_CODES.M)
public static boolean isCallWithSubjectSupported(Context context) {
    if (!PermissionsUtil.hasPermission(context, android.Manifest.permission.READ_PHONE_STATE)
            || !CompatUtils.isCallSubjectCompatible()) {
        return false;
    }
    TelecomManager telecommMgr = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
    if (telecommMgr == null) {
        return false;
    }

    if (ActivityCompat.checkSelfPermission(context,
            Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return false;
    }
    List<PhoneAccountHandle> accountHandles = telecommMgr.getCallCapablePhoneAccounts();
    for (PhoneAccountHandle accountHandle : accountHandles) {
        PhoneAccount account = telecommMgr.getPhoneAccount(accountHandle);
        if (account != null && account.hasCapabilities(PhoneAccount.CAPABILITY_CALL_SUBJECT)) {
            return true;
        }
    }
    return false;
}

From source file:com.mobileglobe.android.simpledialer.common.CallUtil.java

/**
 * Determines if one of the call capable phone accounts defined supports calling with a subject
 * specified./* www  .  j a  v  a2 s .  c  om*/
 *
 * @param context The context.
 * @return {@code true} if one of the call capable phone accounts supports calling with a
 *      subject specified, {@code false} otherwise.
 */
@RequiresApi(api = Build.VERSION_CODES.M)
public static boolean isCallWithSubjectSupported(Context context) {
    if (!PermissionsUtil.hasPermission(context, Manifest.permission.READ_PHONE_STATE)
            || !CompatUtils.isCallSubjectCompatible()) {
        return false;
    }
    TelecomManager telecommMgr = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE);
    if (telecommMgr == null) {
        return false;
    }

    if (ActivityCompat.checkSelfPermission(context,
            Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return false;
    }
    List<PhoneAccountHandle> accountHandles = telecommMgr.getCallCapablePhoneAccounts();
    for (PhoneAccountHandle accountHandle : accountHandles) {
        PhoneAccount account = telecommMgr.getPhoneAccount(accountHandle);
        if (account != null && account.hasCapabilities(PhoneAccount.CAPABILITY_CALL_SUBJECT)) {
            return true;
        }
    }
    return false;
}

From source file:com.mobileglobe.android.customdialer.common.CallUtil.java

/**
 * Determines if video calling is available, and if so whether presence checking is available
 * as well./*from  www.  j ava2  s  . c o  m*/
 *
 * 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.
 */
@RequiresApi(api = Build.VERSION_CODES.M)
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;
    }

    if (ActivityCompat.checkSelfPermission(context,
            Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return 0;
    }
    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(PhoneAccountSdkCompat.CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
                    videoCapabilities |= VIDEO_CALLING_PRESENCE;
                }
                return videoCapabilities;
            }
        }
    }
    return VIDEO_CALLING_DISABLED;
}

From source file:com.mobileglobe.android.simpledialer.common.CallUtil.java

/**
 * Determines if video calling is available, and if so whether presence checking is available
 * as well./*from w w w  .j  a  v  a2  s  .  com*/
 *
 * 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.
 */
@RequiresApi(api = Build.VERSION_CODES.M)
public static int getVideoCallingAvailability(Context context) {
    if (!PermissionsUtil.hasPermission(context, 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;
    }

    if (ActivityCompat.checkSelfPermission(context,
            Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return 0;
    }
    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(PhoneAccountSdkCompat.CAPABILITY_VIDEO_CALLING_RELIES_ON_PRESENCE)) {
                    videoCapabilities |= VIDEO_CALLING_PRESENCE;
                }
                return videoCapabilities;
            }
        }
    }
    return VIDEO_CALLING_DISABLED;
}