Example usage for android.telephony TelephonyManager SIM_STATE_READY

List of usage examples for android.telephony TelephonyManager SIM_STATE_READY

Introduction

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

Prototype

int SIM_STATE_READY

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

Click Source Link

Document

SIM card state: Ready

Usage

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 w w.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.example.android.phonecallingsample.MainActivity.java

/**
 * Checks whether Telephony is enabled./* ww  w .  j  av a  2  s. co  m*/
 *
 * @return true if enabled, otherwise false
 */
private boolean isTelephonyEnabled() {
    if (mTelephonyManager != null) {
        if (mTelephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY) {
            return true;
        }
    }
    return false;
}

From source file:org.mitre.svmp.client.IntentHandler.java

private static int isTelephonyEnabled(Context context) {
    int resId = 0;
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (tm != null) {
        if (tm.getPhoneType() != TelephonyManager.PHONE_TYPE_GSM
                && !context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY))
            resId = R.string.intentHandler_toast_noTelephonyCDMA;
        else if (tm.getSimState() != TelephonyManager.SIM_STATE_READY)
            resId = R.string.intentHandler_toast_noTelephonyGSM;
    }/* w  w  w  . j  a v  a2  s. co  m*/
    return resId;
}

From source file:com.android.contacts.database.SimContactDaoImpl.java

@Override
public boolean canReadSimContacts() {
    // Require SIM_STATE_READY because the TelephonyManager methods related to SIM require
    // this state
    return hasTelephony() && hasPermissions()
            && mTelephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY;
}

From source file:dev.dworks.apps.asecure.MainActivity.java

private void setNewData() {
    TelephonyManager localTelephonyManager = (TelephonyManager) getApplicationContext()
            .getSystemService(Activity.TELEPHONY_SERVICE);
    operatorName = localTelephonyManager.getSimOperatorName();
    simSerial = localTelephonyManager.getSimSerialNumber();
    if (TelephonyManager.SIM_STATE_READY == localTelephonyManager.getSimState()) {
        operator.setText(operatorName);/*from w ww.ja  va2 s  .  c o  m*/
        number.setText(simSerial);
        simQueryHandler = new SIMQueryHandler(getContentResolver());
        simQueryHandler.startQuery(0, null, SecureSIM.CONTENT_URI, PROJECTION,
                SecureSIMColumns.SIM_NUMBER + " = ? ", new String[] { simSerial }, null);
    } else {
        operator.setText("Unknown");
        number.setText("-");
        register.setImageResource(0);
        register.setOnClickListener(null);
    }
}

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

/**
 * sim??//from   w  w  w  .j a va2s .  co  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:android_network.hetnet.vpn_service.Util.java

public static String getGeneralInfo(Context context) {
    StringBuilder sb = new StringBuilder();
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    sb.append(String.format("Interactive %B\r\n", isInteractive(context)));
    sb.append(String.format("Connected %B\r\n", isConnected(context)));
    sb.append(String.format("WiFi %B\r\n", isWifiActive(context)));
    sb.append(String.format("Metered %B\r\n", isMeteredNetwork(context)));
    sb.append(String.format("Roaming %B\r\n", isRoaming(context)));

    if (tm.getSimState() == TelephonyManager.SIM_STATE_READY)
        sb.append(String.format("SIM %s/%s/%s\r\n", tm.getSimCountryIso(), tm.getSimOperatorName(),
                tm.getSimOperator()));//from  w ww. j a  v a 2  s  .  c  o m
    if (tm.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN)
        sb.append(String.format("Network %s/%s/%s\r\n", tm.getNetworkCountryIso(), tm.getNetworkOperatorName(),
                tm.getNetworkOperator()));

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        sb.append(String.format("Power saving %B\r\n", pm.isPowerSaveMode()));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        sb.append(String.format("Battery optimizing %B\r\n", batteryOptimizing(context)));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
        sb.append(String.format("Data saving %B\r\n", dataSaving(context)));

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

    return sb.toString();
}

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

public static String getGeneralInfo(Context context) {
    StringBuilder sb = new StringBuilder();
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    sb.append(String.format("Interactive %B\r\n", isInteractive(context)));
    sb.append(String.format("Connected %B\r\n", isConnected(context)));
    sb.append(String.format("WiFi %B\r\n", isWifiActive(context)));
    sb.append(String.format("Metered %B\r\n", isMeteredNetwork(context)));
    sb.append(String.format("Roaming %B\r\n", isRoaming(context)));

    sb.append(String.format("Type %s\r\n", getPhoneTypeName(tm.getPhoneType())));

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1 || !hasPhoneStatePermission(context)) {
        if (tm.getSimState() == TelephonyManager.SIM_STATE_READY)
            sb.append(String.format("SIM %s/%s/%s\r\n", tm.getSimCountryIso(), tm.getSimOperatorName(),
                    tm.getSimOperator()));
        if (tm.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN)
            sb.append(String.format("Network %s/%s/%s\r\n", tm.getNetworkCountryIso(),
                    tm.getNetworkOperatorName(), tm.getNetworkOperator()));
    }/*from   ww w. j av a2s .c o  m*/

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        sb.append(String.format("Power saving %B\r\n", pm.isPowerSaveMode()));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        sb.append(String.format("Battery optimizing %B\r\n",
                !pm.isIgnoringBatteryOptimizations(context.getPackageName())));

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

    return sb.toString();
}