Example usage for android.telephony TelephonyManager SIM_STATE_UNKNOWN

List of usage examples for android.telephony TelephonyManager SIM_STATE_UNKNOWN

Introduction

In this page you can find the example usage for android.telephony TelephonyManager SIM_STATE_UNKNOWN.

Prototype

int SIM_STATE_UNKNOWN

To view the source code for android.telephony TelephonyManager SIM_STATE_UNKNOWN.

Click Source Link

Document

SIM card state: Unknown.

Usage

From source file:Main.java

/**
 * Returns a constant indicating the state of the default SIM card.
 * @param sim_state "getSimState()"//from   ww w.  jav a2s.  c om
 */
public static String getSimStateStr(int sim_state) {
    switch (sim_state) {
    case TelephonyManager.SIM_STATE_UNKNOWN://0
        return "SIM_STATE_UNKNOWN";
    case TelephonyManager.SIM_STATE_ABSENT://1
        return "SIM_STATE_ABSENT";
    case TelephonyManager.SIM_STATE_PIN_REQUIRED://2
        return "SIM_STATE_PIN_REQUIRED";
    case TelephonyManager.SIM_STATE_PUK_REQUIRED://3
        return "SIM_STATE_PUK_REQUIRED";
    case TelephonyManager.SIM_STATE_NETWORK_LOCKED://4
        return "SIM_STATE_NETWORK_LOCKED";
    case TelephonyManager.SIM_STATE_READY://5
        return "SIM_STATE_READY";
    default:
        return UNKNOWN;
    }
}

From source file:com.android.settings.sim.SimSelectNotification.java

@Override
public void onReceive(Context context, Intent intent) {
    final TelephonyManager telephonyManager = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);
    final SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
    final int numSlots = telephonyManager.getSimCount();

    // Do not create notifications on single SIM devices or when provisioning i.e. Setup Wizard.
    // or User selection of fallback user preference is disabled.
    if (numSlots < 2 || !Utils.isDeviceProvisioned(context)
            || !SystemProperties.getBoolean("persist.radio.aosp_usr_pref_sel", false)) {
        Log.d(TAG, " no of slots " + numSlots + " provision = " + Utils.isDeviceProvisioned(context));
        return;/*w  ww.j a v a  2 s  .  c  o m*/
    }

    // Cancel any previous notifications
    cancelNotification(context);

    // If sim state is not ABSENT or LOADED then ignore
    String simStatus = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
    if (!(IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(simStatus)
            || IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(simStatus))) {
        Log.d(TAG, "sim state is not Absent or Loaded");
        return;
    } else {
        Log.d(TAG, "simstatus = " + simStatus);
    }

    int state;
    for (int i = 0; i < numSlots; i++) {
        state = telephonyManager.getSimState(i);
        if (!(state == TelephonyManager.SIM_STATE_ABSENT || state == TelephonyManager.SIM_STATE_READY
                || state == TelephonyManager.SIM_STATE_UNKNOWN)) {
            Log.d(TAG, "All sims not in valid state yet");
            return;
        }
    }

    List<SubscriptionInfo> sil = subscriptionManager.getActiveSubscriptionInfoList();
    if (sil == null || sil.size() < 1) {
        Log.d(TAG, "Subscription list is empty");
        return;
    }

    // Clear defaults for any subscriptions which no longer exist
    subscriptionManager.clearDefaultsForInactiveSubIds();

    boolean dataSelected = SubscriptionManager
            .isUsableSubIdValue(SubscriptionManager.getDefaultDataSubscriptionId());
    boolean smsSelected = SubscriptionManager
            .isUsableSubIdValue(SubscriptionManager.getDefaultSmsSubscriptionId());

    // If data and sms defaults are selected, dont show notification (Calls default is optional)
    if (dataSelected && smsSelected) {
        Log.d(TAG, "Data & SMS default sims are selected. No notification");
        return;
    }

    // Create a notification to tell the user that some defaults are missing
    createNotification(context);

    if (sil.size() == 1) {
        // If there is only one subscription, ask if user wants to use if for everything
        Intent newIntent = new Intent(context, SimDialogActivity.class);
        newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        newIntent.putExtra(SimDialogActivity.DIALOG_TYPE_KEY, SimDialogActivity.PREFERRED_PICK);
        newIntent.putExtra(SimDialogActivity.PREFERRED_SIM, sil.get(0).getSimSlotIndex());
        context.startActivity(newIntent);
    } else if (!dataSelected) {
        // If there are mulitple, ensure they pick default data
        Intent newIntent = new Intent(context, SimDialogActivity.class);
        newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        newIntent.putExtra(SimDialogActivity.DIALOG_TYPE_KEY, SimDialogActivity.DATA_PICK);
        context.startActivity(newIntent);
    }
}

From source file:com.cyanogenmod.account.util.CMAccountUtils.java

public static boolean isSimMissing(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    int simState = telephonyManager.getSimState();
    return simState == TelephonyManager.SIM_STATE_ABSENT || simState == TelephonyManager.SIM_STATE_UNKNOWN;
}

From source file:com.polyvi.xface.extension.telephony.XTelephonyExt.java

/**
 * sim??/*  w  ww  . j a  va  2 s  .  c  o  m*/
 *
 * @param tm
 * @return
 */
private boolean checkSimCardState(TelephonyManager tm) {
    int simState = tm.getSimState();
    switch (simState) {
    case TelephonyManager.SIM_STATE_ABSENT:
        return false;
    case TelephonyManager.SIM_STATE_NETWORK_LOCKED:
        return true;
    case TelephonyManager.SIM_STATE_PIN_REQUIRED:
        return true;
    case TelephonyManager.SIM_STATE_PUK_REQUIRED:
        return true;
    case TelephonyManager.SIM_STATE_READY:
        return true;
    case TelephonyManager.SIM_STATE_UNKNOWN:
        return false;
    default:
        return false;
    }
}

From source file:com.compal.telephonytest.TelephonyTest.java

public void InformatonAndStatusCheck() {

    StringBuilder sb = new StringBuilder("");
    boolean hasFailInfo = false;

    if (mTelephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE) {
        sb.append("getPhoneType:" + Integer.toString(mTelephonyManager.getPhoneType()) + "\n");
    } else {/*from   w w  w.  ja  va 2 s  .co  m*/
        sb.append("getPhoneType:" + "fail");
        hasFailInfo = true;
    }

    if (mTelephonyManager.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN) {
        sb.append("getNetworkType:" + Integer.toString(mTelephonyManager.getNetworkType()) + "\n");
    } else {
        sb.append("getNetworkType:" + "fail");
        hasFailInfo = true;
    }

    String operatorName = mTelephonyManager.getNetworkOperatorName();
    if (operatorName != null && !operatorName.equals("")) { // OperatorName
        sb.append("getNetworkOperatorName:" + mTelephonyManager.getNetworkOperatorName() + "\n");
    } else {
        sb.append("getNetworkOperatorName:" + "fail");
        hasFailInfo = true;
    }

    String serial = Build.SERIAL;
    if (serial != null && !serial.equals("")) { // SerialNumber
        sb.append("get Serial Number:" + serial + "\n");
    } else {
        sb.append("get Serial Number:" + "fail");
        hasFailInfo = true;
    }

    if (mTelephonyManager.getSimState() != TelephonyManager.SIM_STATE_UNKNOWN) {
        sb.append("getSimState:" + Integer.toString(mTelephonyManager.getSimState()) + "\n");
    } else {
        sb.append("getSimState:" + "fail");
        hasFailInfo = true;
    }

    //It's all ok
    sb.append("isNetworkRoaming:" + Boolean.toString(mTelephonyManager.isNetworkRoaming()) + "\n");

    if (mTelephonyManager.getDataState() != TelephonyManager.DATA_DISCONNECTED) {
        sb.append("getDataState:" + Integer.toString(mTelephonyManager.getDataState()) + "\n");
    } else {
        sb.append("getDataState:" + "fail");
        hasFailInfo = true;
    }

    String formatIP = formatIpAddresses(mLinkProperties);
    if (formatIP != null && !formatIP.equals("")) { //IP Address
        sb.append("IP Address:" + formatIpAddresses(mLinkProperties) + "\n");
    } else {
        sb.append("IP Address:" + "fail");
        hasFailInfo = true;
    }

    if (mTelephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
        if (checkGsmDeviceId(mTelephonyManager.getDeviceId())) {
            sb.append("IMEI:" + mTelephonyManager.getDeviceId() + "\n");
        } else {
            sb.append("IMEI:" + "fail");
            hasFailInfo = true;
        }
    } else {
        sb.append("IMEI:" + "fail");
        hasFailInfo = true;
    }

    Log.i(tag, sb.toString());

    mLog = sb.toString();
    if (!hasFailInfo) {
        Log.i(tag, "test_5th_InformatonAndStatus true");
        outputResult(true, tTelephonyBasicFunc, dBasicInformation, testCaseId);
    } else {
        Log.i(tag, "test_5th_InformatonAndStatus false");
        outputResult(false, tTelephonyBasicFunc, dBasicInformation, testCaseId);
    }

    //Log.i(tag, "getPhoneType:" + Integer.toString(mTelephonyManager.getPhoneType()));
    //Log.i(tag, "getNetworkType:" + Integer.toString(mTelephonyManager.getNetworkType()));
    //Log.i(tag, "getNetworkOperatorName:" + mTelephonyManager.getNetworkOperatorName());
    //Log.i(tag, "getSimSerialNumber:" + mTelephonyManager.getSimSerialNumber());
    //Log.i(tag, "getSimState:" + Integer.toString(mTelephonyManager.getSimState()));
    //Log.i(tag, "isNetworkRoaming:" + Boolean.toString(mTelephonyManager.isNetworkRoaming()));
    //Log.i(tag, "getDataState:" + Integer.toString(mTelephonyManager.getDataState()));   
    //Log.i(tag,"formatIpAddresses(mLinkProperties): " + formatIpAddresses(mLinkProperties));

}