Example usage for android.telephony SubscriptionInfo getSimSlotIndex

List of usage examples for android.telephony SubscriptionInfo getSimSlotIndex

Introduction

In this page you can find the example usage for android.telephony SubscriptionInfo getSimSlotIndex.

Prototype

public int getSimSlotIndex() 

Source Link

Usage

From source file:com.android.messaging.datamodel.ParticipantRefresh.java

/**
 * Ensure that there is a self participant corresponding to every active SIM. Also, ensure
 * that any other older SIM self participants are marked as inactive.
 */// w w  w . ja  v a 2 s.  c o  m
private static void refreshSelfParticipantList() {
    if (!OsUtil.isAtLeastL_MR1()) {
        return;
    }

    final DatabaseWrapper db = DataModel.get().getDatabase();

    final List<SubscriptionInfo> subInfoRecords = PhoneUtils.getDefault().toLMr1()
            .getActiveSubscriptionInfoList();
    final ArrayMap<Integer, SubscriptionInfo> activeSubscriptionIdToRecordMap = new ArrayMap<Integer, SubscriptionInfo>();
    db.beginTransaction();
    final Set<Integer> existingSubIds = getExistingSubIds();

    try {
        if (subInfoRecords != null) {
            for (final SubscriptionInfo subInfoRecord : subInfoRecords) {
                final int subId = subInfoRecord.getSubscriptionId();
                // If its a new subscription, add it to the database.
                if (!existingSubIds.contains(subId)) {
                    db.execSQL(DatabaseHelper.getCreateSelfParticipantSql(subId));
                    // Add it to the local set to guard against duplicated entries returned
                    // by subscription manager.
                    existingSubIds.add(subId);
                }
                activeSubscriptionIdToRecordMap.put(subId, subInfoRecord);

                if (subId == PhoneUtils.getDefault().getDefaultSmsSubscriptionId()) {
                    // This is the system default subscription, so update the default self.
                    activeSubscriptionIdToRecordMap.put(ParticipantData.DEFAULT_SELF_SUB_ID, subInfoRecord);
                }
            }
        }

        // For subscriptions already in the database, refresh ParticipantColumns.SIM_SLOT_ID.
        for (final Integer subId : activeSubscriptionIdToRecordMap.keySet()) {
            final SubscriptionInfo record = activeSubscriptionIdToRecordMap.get(subId);
            final String displayName = DatabaseUtils.sqlEscapeString(record.getDisplayName().toString());
            db.execSQL(getUpdateSelfParticipantSubscriptionInfoSql(record.getSimSlotIndex(),
                    record.getIconTint(), displayName, ParticipantColumns.SUB_ID + " = " + subId));
        }
        db.execSQL(getUpdateSelfParticipantSubscriptionInfoSql(ParticipantData.INVALID_SLOT_ID,
                Color.TRANSPARENT, "''", ParticipantColumns.SUB_ID + " NOT IN ("
                        + Joiner.on(", ").join(activeSubscriptionIdToRecordMap.keySet()) + ")"));
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
    // Fix up conversation self ids by reverting to default self for conversations whose self
    // ids are no longer active.
    refreshConversationSelfIds();
}

From source file:android_network.hetnet.vpn_service.Util.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
public static String getSubscriptionInfo(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
        return "Not supported";
    if (!hasPhoneStatePermission(context))
        return "No permission";

    StringBuilder sb = new StringBuilder();
    SubscriptionManager sm = SubscriptionManager.from(context);

    sb.append("Slots ").append(sm.getActiveSubscriptionInfoCount()).append('/')
            .append(sm.getActiveSubscriptionInfoCountMax()).append("\r\n");

    int dataid = -1;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        dataid = sm.getDefaultDataSubscriptionId();

    int voiceid = -1;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        voiceid = sm.getDefaultVoiceSubscriptionId();

    List<SubscriptionInfo> subscriptions = sm.getActiveSubscriptionInfoList();
    if (subscriptions != null)
        for (SubscriptionInfo si : subscriptions)
            sb.append("SIM ").append(si.getSimSlotIndex() + 1).append('/').append(si.getSubscriptionId())
                    .append(' ').append(si.getCountryIso()).append('/').append(si.getMcc()).append(si.getMnc())
                    .append(' ').append(si.getCarrierName())
                    .append(si.getSubscriptionId() == dataid ? " D" : "")
                    .append(si.getSubscriptionId() == voiceid ? " V" : "")
                    .append(si.getDataRoaming() == SubscriptionManager.DATA_ROAMING_ENABLE ? " R" : "")
                    .append("\r\n");

    if (sb.length() > 2)
        sb.setLength(sb.length() - 2);/* ww  w.j  ava  2  s.c o  m*/

    return sb.toString();
}

From source file:com.master.metehan.filtereagle.Util.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
public static String getSubscriptionInfo(Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
        return "Not supported";
    if (!hasPhoneStatePermission(context))
        return "No permission";

    StringBuilder sb = new StringBuilder();
    SubscriptionManager sm = SubscriptionManager.from(context);
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    sb.append("Slots ").append(sm.getActiveSubscriptionInfoCount()).append('/')
            .append(sm.getActiveSubscriptionInfoCountMax()).append("\r\n");

    int dataSubId;
    try {/* ww w .j ava  2 s .  c  o m*/
        dataSubId = Settings.Global.getInt(context.getContentResolver(), "multi_sim_data_call", -1);
    } catch (Throwable ignored) {
        dataSubId = -1;
    }

    Method getNetworkCountryIso = null;
    Method getNetworkOperator = null;
    Method getNetworkOperatorName = null;
    Method getDataEnabled = null;
    try {
        getNetworkCountryIso = tm.getClass().getMethod("getNetworkCountryIsoForSubscription", int.class);
        getNetworkOperator = tm.getClass().getMethod("getNetworkOperatorForSubscription", int.class);
        getNetworkOperatorName = tm.getClass().getMethod("getNetworkOperatorName", int.class);
        getDataEnabled = tm.getClass().getMethod("getDataEnabled", int.class);

        getNetworkCountryIso.setAccessible(true);
        getNetworkOperator.setAccessible(true);
        getNetworkOperatorName.setAccessible(true);
        getDataEnabled.setAccessible(true);
    } catch (NoSuchMethodException ex) {
        Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }

    List<SubscriptionInfo> subscriptions = sm.getActiveSubscriptionInfoList();
    if (subscriptions != null)
        for (SubscriptionInfo si : subscriptions) {
            sb.append("SIM ").append(si.getSimSlotIndex() + 1).append('/').append(si.getSubscriptionId())
                    .append(' ').append(si.getCountryIso()).append('/').append(si.getMcc()).append(si.getMnc())
                    .append(' ').append(si.getCarrierName())
                    .append(si.getDataRoaming() == SubscriptionManager.DATA_ROAMING_ENABLE ? " R" : "")
                    .append(si.getSubscriptionId() == dataSubId ? " *" : "").append("\r\n");
            if (getNetworkCountryIso != null && getNetworkOperator != null && getNetworkOperatorName != null
                    && getDataEnabled != null)
                try {
                    sb.append("Network ").append(si.getSimSlotIndex() + 1).append('/')
                            .append(si.getSubscriptionId()).append(' ')
                            .append(getNetworkCountryIso.invoke(tm, si.getSubscriptionId())).append('/')
                            .append(getNetworkOperator.invoke(tm, si.getSubscriptionId())).append(' ')
                            .append(getNetworkOperatorName.invoke(tm, si.getSubscriptionId()))
                            .append(sm.isNetworkRoaming(si.getSubscriptionId()) ? " R" : "").append(' ')
                            .append(String.format("%B", getDataEnabled.invoke(tm, si.getSubscriptionId())))
                            .append("\r\n");
                } catch (IllegalAccessException | InvocationTargetException ex) {
                    Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                }
        }

    if (sb.length() > 2)
        sb.setLength(sb.length() - 2);

    return sb.toString();
}

From source file:com.android.mms.ui.MessageUtils.java

public static void setSubIconAndLabel(int subId, String subName, TextView subView) {
    Log.i(TAG, "setSubIconAndLabel subId=" + subId);
    int textColor = 0;
    if (subView == null) {
        return;// w  ww  . j a v  a  2s.  co  m
    }
    int activeSubCount = SubscriptionManager.from(MmsApp.getApplication()).getActiveSubscriptionInfoCount();

    if (subName == null && activeSubCount > 1) {
        SubscriptionInfo subInfo = SubscriptionManager.from(MmsApp.getApplication())
                .getActiveSubscriptionInfo(subId);
        Log.d(TAG, "subInfo=" + subInfo);
        if (null != subInfo) {
            if ((subInfo.getSimSlotIndex() == SubscriptionManager.SIM_NOT_INSERTED)
                    || (subInfo.getSimSlotIndex() == SubscriptionManager.INVALID_SUBSCRIPTION_ID)) {
                Log.i(TAG, "current not insert sim card");
            } else {
                subName = subInfo.getDisplayName().toString();
                textColor = subInfo.getIconTint();
            }
        } else {
            Log.i(TAG, "subInfo is null ");
        }
    }

    if (subName == null || activeSubCount <= 1) {
        subView.setVisibility(View.GONE);
    } else {
        subView.setVisibility(View.VISIBLE);
        subView.setTextColor(textColor);
        subView.setText(subName);
    }
}