Example usage for android.telephony TelephonyManager NETWORK_TYPE_UNKNOWN

List of usage examples for android.telephony TelephonyManager NETWORK_TYPE_UNKNOWN

Introduction

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

Prototype

int NETWORK_TYPE_UNKNOWN

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

Click Source Link

Document

Network type is unknown

Usage

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  w  w  .ja 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  www .  ja  v  a  2s .  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();
}

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 {/*  ww  w . ja v a 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));

}

From source file:org.restcomm.app.utillib.DataObjects.PhoneState.java

public static int rilRadioTechnologyToNetworkType(int rt) {
    switch (rt) {
    case RIL_RADIO_TECHNOLOGY_GPRS:
        return TelephonyManager.NETWORK_TYPE_GPRS;
    case RIL_RADIO_TECHNOLOGY_EDGE:
        return TelephonyManager.NETWORK_TYPE_EDGE;
    case RIL_RADIO_TECHNOLOGY_UMTS:
        return TelephonyManager.NETWORK_TYPE_UMTS;
    case RIL_RADIO_TECHNOLOGY_HSDPA:
        return TelephonyManager.NETWORK_TYPE_HSDPA;
    case RIL_RADIO_TECHNOLOGY_HSUPA:
        return TelephonyManager.NETWORK_TYPE_HSUPA;
    case RIL_RADIO_TECHNOLOGY_HSPA:
        return TelephonyManager.NETWORK_TYPE_HSPA;
    case RIL_RADIO_TECHNOLOGY_IS95A:
    case RIL_RADIO_TECHNOLOGY_IS95B:
        return TelephonyManager.NETWORK_TYPE_CDMA;
    case RIL_RADIO_TECHNOLOGY_1xRTT:
        return TelephonyManager.NETWORK_TYPE_1xRTT;
    case RIL_RADIO_TECHNOLOGY_EVDO_0:
        return TelephonyManager.NETWORK_TYPE_EVDO_0;
    case RIL_RADIO_TECHNOLOGY_EVDO_A:
        return TelephonyManager.NETWORK_TYPE_EVDO_A;
    case RIL_RADIO_TECHNOLOGY_EVDO_B:
        return TelephonyManager.NETWORK_TYPE_EVDO_B;
    case RIL_RADIO_TECHNOLOGY_EHRPD:
        return TelephonyManager.NETWORK_TYPE_EHRPD;
    case RIL_RADIO_TECHNOLOGY_LTE:
        return TelephonyManager.NETWORK_TYPE_LTE;
    case RIL_RADIO_TECHNOLOGY_HSPAP:
        return TelephonyManager.NETWORK_TYPE_HSPAP;
    case RIL_RADIO_TECHNOLOGY_GSM:
        return NETWORK_NEWTYPE_GSM;
    case RIL_RADIO_TECHNOLOGY_TD_SCDMA:
        return NETWORK_NEWTYPE_TD_SCDMA;
    case RIL_RADIO_TECHNOLOGY_IWLAN:
        return NETWORK_NEWTYPE_IWLAN;
    default://from   w w w. j  av  a  2  s  .c o  m
        return TelephonyManager.NETWORK_TYPE_UNKNOWN;
    }
}

From source file:at.alladin.rmbt.android.main.RMBTMainMenuFragment.java

/**
 * //www. j  ava 2  s  . c o  m
 * @param signal
 * @return
 */
private int getAntennaImageResourceId(int signal) {
    int lastNetworkType = informationCollector.getNetwork();
    String lastNetworkTypeString = Helperfunctions.getNetworkTypeName(lastNetworkType);

    if (lastNetworkType == TelephonyManager.NETWORK_TYPE_UNKNOWN) // || signal == Integer.MIN_VALUE)
        return R.drawable.signal_no_connection;

    boolean wlan = "WLAN".equals(lastNetworkTypeString);

    int signalType = informationCollector.getSignalType();

    double relativeSignal = -1d;
    MinMax<Integer> signalBounds = NetworkUtil.getSignalStrengthBounds(signalType);
    //System.out.println("SIGNAL STRENGTH TYPE: " + signalType + " -> " + signalBounds + " / SIGNAL: " + signal);
    if (!(signalBounds.min == Integer.MIN_VALUE || signalBounds.max == Integer.MAX_VALUE)) {
        relativeSignal = (double) (signal - signalBounds.min) / (double) (signalBounds.max - signalBounds.min);
    }

    //System.out.println("relativeSignal: " + relativeSignal + ", networkType: " + networkType + ", lastNetworkTypeString: " + lastNetworkTypeString);
    if (relativeSignal < 0.25d) {
        return (wlan ? R.drawable.signal_wlan_25 : R.drawable.signal_mobile_25);
    } else if (relativeSignal < 0.5d) {
        return (wlan ? R.drawable.signal_wlan_50 : R.drawable.signal_mobile_50);
    } else if (relativeSignal < 0.75d) {
        return (wlan ? R.drawable.signal_wlan_75 : R.drawable.signal_mobile_75);
    } else {
        return (wlan ? R.drawable.signal_wlan : R.drawable.signal_mobile);
    }
}

From source file:at.alladin.rmbt.android.util.InformationCollector.java

/** Returns the network that the phone is on (e.g. Wifi, Edge, GPRS, etc). */
public int getNetwork() {
    int result = TelephonyManager.NETWORK_TYPE_UNKNOWN;

    if (connManager != null) {
        final NetworkInfo activeNetworkInfo = connManager.getActiveNetworkInfo();
        if (activeNetworkInfo != null) {
            final int type = activeNetworkInfo.getType();
            switch (type) {
            case ConnectivityManager.TYPE_WIFI:
                result = NETWORK_WIFI;//from   w  w  w .  ja  v a 2 s .  c  om
                break;

            case ConnectivityManager.TYPE_BLUETOOTH:
                result = NETWORK_BLUETOOTH;
                break;

            case ConnectivityManager.TYPE_ETHERNET:
                result = NETWORK_ETHERNET;
                break;

            case ConnectivityManager.TYPE_MOBILE:
            case ConnectivityManager.TYPE_MOBILE_DUN:
            case ConnectivityManager.TYPE_MOBILE_HIPRI:
            case ConnectivityManager.TYPE_MOBILE_MMS:
            case ConnectivityManager.TYPE_MOBILE_SUPL:
                result = telManager.getNetworkType();
                break;
            }
        }
    }

    /* detect change from wifi to mobile or reverse */
    final int lastNetworkType = this.lastNetworkType.get();
    if (result != TelephonyManager.NETWORK_TYPE_UNKNOWN
            && lastNetworkType != TelephonyManager.NETWORK_TYPE_UNKNOWN) {
        if ((result == ConnectivityManager.TYPE_WIFI && lastNetworkType != ConnectivityManager.TYPE_WIFI)
                || (result != ConnectivityManager.TYPE_WIFI
                        && lastNetworkType == ConnectivityManager.TYPE_WIFI))
            illegalNetworkTypeChangeDetcted.set(true);
    }
    if (result != lastNetworkType) {
        this.lastNetworkType.set(result);
        if (telListener != null)
            telListener.onSignalStrengthsChanged(null);
    }

    return result;
}

From source file:org.pixmob.freemobile.netstat.MonitorService.java

private void updateEventDatabase() {
    final Event e = new Event();
    e.timestamp = System.currentTimeMillis();
    e.screenOn = pm != null && pm.isScreenOn();
    e.batteryLevel = getBatteryLevel();// ww  w  . j av  a2  s. com
    e.wifiConnected = Boolean.TRUE.equals(lastWifiConnected);
    e.mobileConnected = powerOn && Boolean.TRUE.equals(lastMobileNetworkConnected);
    e.mobileOperator = lastMobileOperatorId;
    e.mobileNetworkType = lastMobileNetworkType != null ? lastMobileNetworkType
            : TelephonyManager.NETWORK_TYPE_UNKNOWN;
    e.powerOn = powerOn;
    e.femtocell = Boolean.TRUE.equals(lastIsFemtocell);
    e.firstInsert = firstInsert;
    firstInsert = false;

    try {
        pendingInsert.put(e);
    } catch (InterruptedException ex) {
        Log.w(TAG, "Failed to schedule event insertion", ex);
    }
}

From source file:org.restcomm.app.qoslib.Utils.QosInfo.java

/**
 * Called Internally to initialize all of the current measurements for every type of connected newtork
 * This is like a snapshot of everything at this moment in time
 * The information comes from various sources and it mainly fetched from the database for this call, or from APIs such as WiFi
 */// w w  w. j  a va 2s.c  om
private void updateFromDB() {
    Cursor sig_cursor = null;
    Cursor cell_cursor = null;

    try {
        Uri signalUri = UriMatch.SIGNAL_STRENGTHS.getContentUri();
        Uri limitSignalUri = signalUri.buildUpon().appendQueryParameter("limit", "1").build();
        // sig_cursor = managedQuery(

        Provider dbProvider = ReportManager.getInstance(context.getApplicationContext()).getDBProvider();
        if (dbProvider == null) {
            return;
        }

        sig_cursor = dbProvider.query(UriMatch.SIGNAL_STRENGTHS.getContentUri(), null, null, null,
                Tables.TIMESTAMP_COLUMN_NAME + " DESC");

        sig_cursor.moveToFirst();

        Uri baseStationTable = (UriMatch.BASE_STATIONS
                .getContentUri()/*telephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA
                                ? UriMatchOld.BASE_STATIONS_CDMA.getContentUri()
                                : UriMatchOld.BASE_STATIONS_GSM.getContentUri()*/
        );
        Uri limitBSUri = baseStationTable.buildUpon().appendQueryParameter("limit", "1").build();

        // Cursor cell_cursor = managedQuery(
        cell_cursor = dbProvider.query(limitBSUri, null, null, null, Tables.TIMESTAMP_COLUMN_NAME + " DESC");

        cell_cursor.moveToFirst();

        int LowIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_LOW);
        int MidIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_MID);
        int HighIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_HIGH);
        int CodeIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_CODE);
        int BandIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_BAND);
        int ChanIndex = cell_cursor.getColumnIndex(Tables.BaseStations.BS_CHAN);
        int netTypeIndex = cell_cursor.getColumnIndex(Tables.BaseStations.NET_TYPE);
        String netType = cell_cursor.getString(netTypeIndex);
        int bsLow = cell_cursor.getInt(LowIndex);
        int bsMid = cell_cursor.getInt(MidIndex);
        int bsHigh = cell_cursor.getInt(HighIndex);
        int bsCode = cell_cursor.getInt(CodeIndex);
        int bsBand = cell_cursor.getInt(BandIndex);
        int bsChan = cell_cursor.getInt(ChanIndex);
        if (netType.equals("cdma")) {
            if (LowIndex != -1)
                BID = bsLow;
            if (MidIndex != -1)
                NID = bsMid;
            if (HighIndex != -1)
                SID = bsHigh;
        } else if (netType.equals("gsm")) {
            if (LowIndex != -1) {
                RNC = bsMid;
                CellID = cell_cursor.getInt(LowIndex);
            }
            // the network Id is kept 0 for gsm phones
            if (HighIndex != -1)
                LAC = bsHigh;
            if (bsCode > 0 && bsCode < 1000)
                PSC = bsCode;
            else
                PSC = 0;
            if (bsBand > 0)
                Band = bsBand;
            else
                Band = 0;
            if (bsChan > 0)
                Channel = bsChan;
            else
                Channel = 0;
        }

        if (sig_cursor.getCount() != 0) {
            int signalIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.SIGNAL);
            int signal2GIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.SIGNAL2G);
            int rsrpIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_RSRP);
            int rsrqIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_RSRQ);
            int lteSnrIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_SNR);
            int lteSignalIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_SIGNAL);
            int lteCqiIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.LTE_CQI);
            int ecioIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.ECI0);
            int ecnoIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.ECN0);
            int snrIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.SNR);
            int berIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.BER);
            int rscpIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.RSCP);
            int tierIndex = sig_cursor.getColumnIndex(Tables.SignalStrengths.COVERAGE);
            Integer tier = sig_cursor.isNull(tierIndex) ? null : sig_cursor.getInt(tierIndex);
            Integer rssi = sig_cursor.isNull(signalIndex) ? null : sig_cursor.getInt(signalIndex);
            Integer rssi2G = sig_cursor.isNull(signal2GIndex) ? null : sig_cursor.getInt(signal2GIndex);
            Integer rsrp = sig_cursor.isNull(rsrpIndex) ? null : sig_cursor.getInt(rsrpIndex);
            Float lteSnr = (sig_cursor.isNull(lteSnrIndex) ? null : (float) sig_cursor.getInt(lteSnrIndex));
            Integer lteSignal = sig_cursor.isNull(lteSignalIndex) ? null : sig_cursor.getInt(lteSignalIndex);
            Integer lteCqi = sig_cursor.isNull(lteCqiIndex) ? null : sig_cursor.getInt(lteCqiIndex);
            Integer rsrq = sig_cursor.isNull(rsrqIndex) ? null : sig_cursor.getInt(rsrqIndex);
            Integer eci0 = sig_cursor.isNull(ecioIndex) ? null : sig_cursor.getInt(ecioIndex);
            Integer ecn0 = sig_cursor.isNull(ecnoIndex) ? null : sig_cursor.getInt(ecnoIndex);
            Integer snr = sig_cursor.isNull(snrIndex) ? null : sig_cursor.getInt(snrIndex);
            Integer ber = sig_cursor.isNull(berIndex) ? null : sig_cursor.getInt(berIndex);
            Integer rscp = sig_cursor.isNull(rscpIndex) ? null : sig_cursor.getInt(rscpIndex);

            if (eci0 != null && (netType.equals("cdma") || netType.equals("lte")) && eci0 <= -30)
                eci0 = (eci0 / 10);
            else if (ecn0 != null && ecn0 > 1 && ecn0 < 60 && netType.equals("gsm"))
                ecn0 = -(ecn0 / 2);
            else if (eci0 != null && eci0 > 1 && eci0 < 60 && netType.equals("gsm"))
                eci0 = -(eci0 / 2);

            // if (lteSnr != null && lteSnr > 1 && lteSnr < 500)
            // lteSnr = (lteSnr+5)/10;
            if (lteSignal != null && lteSignal > -120 && lteSignal < -20) // rssi == lteSignal)
            {
                LTE_RSSI = simpleValidate(lteSignal);
                RSSI = 0;
            } else if (rssi == null || rssi == -255)
                RSSI = 0;
            else if (rssi == -256)
                RSSI = -256;
            else {
                String name = "RSCP: ";
                int spacing = 15;
                if (netType.equals("gsm") && (tier == 3 || tier == 4)) {
                    RSCP = rssi;
                    RSSI = 0;
                } else {
                    RSSI = rssi;
                    RSCP = 0;
                }

                LTE_RSSI = 0;
            }
            if (netType.equals("cdma") && rssi2G != null && rssi2G < -30 && rssi2G >= -120)
                CDMA_RSSI = rssi2G;
            if (tier == 5) {
                if (lteSnr != null && lteSnr > -101)
                    lteSnr = lteSnr / 10;
                if (rsrq != null && rsrq > 0)
                    rsrq = -rsrq;
                LTE_RSRP = simpleValidate(rsrp);
                LTE_RSRQ = simpleValidate(rsrq);
                LTE_SNR = simpleValidate(lteSnr);
                LTE_CQI = simpleValidate(lteCqi);
                ECIO = simpleValidate(eci0);
                ECNO = simpleValidate(ecn0);
            }
            //nerdview.setValue(0, "RSCP", simpleValidate(rscp, "RSCP", "dBm"));
            //BER = simpleValidate(ber);
            SNR = simpleValidate(snr);

            if (rsrp != null && rsrp <= -10 && rsrp >= -140 && tier == 5) {
                LTEIdentity = ReportManager.getInstance(context.getApplicationContext()).getNeighbors();
            } else {
                LTEIdentity = null;
                Neighbors = ReportManager.getInstance(context.getApplicationContext()).getNeighbors();
            }
        }
        location = ReportManager.getInstance(context.getApplicationContext()).getLastKnownLocation();

        try {
            JSONObject serviceMode = PhoneState.getServiceMode();
            if (serviceMode != null && serviceMode.getLong("time") + 5000 > System.currentTimeMillis()) {
                if (serviceMode.has("rrc") && serviceMode.getString("rrc").length() > 1) {
                    RRC = serviceMode.getString("rrc");
                } else
                    RRC = null;
                if (serviceMode.has("band") && serviceMode.getString("band").length() > 0) {
                    Band = Integer.parseInt(serviceMode.getString("band"));
                }
                //else
                if (serviceMode.has("freq") && serviceMode.getString("freq").length() > 0) {
                    Band = Integer.parseInt(serviceMode.getString("freq"));
                } else
                    Band = 0;
                if (serviceMode.has("channel") && serviceMode.getString("channel").length() > 0) {
                    Channel = Integer.parseInt(serviceMode.getString("channel"));
                } else
                    Channel = 0;
            } else {
                RRC = null;
                Band = 0;
                Channel = 0;
            }

            TelephonyManager telephonyManager = (TelephonyManager) context
                    .getSystemService(Service.TELEPHONY_SERVICE);
            String carrier = telephonyManager.getNetworkOperatorName();
            String mcc = "0", mnc = "0";
            if (telephonyManager.getNetworkOperator() != null
                    && telephonyManager.getNetworkOperator().length() >= 4) {
                mcc = telephonyManager.getNetworkOperator().substring(0, 3);
                mnc = telephonyManager.getNetworkOperator().substring(3);
            }
            int networkType = telephonyManager.getNetworkType();
            int networkTier = PhoneState.getNetworkGeneration(networkType);
            String nettype = PhoneState.getNetworkName(telephonyManager.getNetworkType());
            String data = PhoneState.getNetworkName(telephonyManager.getNetworkType()) + " ";
            int dataState = telephonyManager.getDataState();
            if (dataState == TelephonyManager.DATA_CONNECTED) {
                String activity = getActivityName(telephonyManager.getDataActivity());
                data += activity;
            } else if (telephonyManager.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN) {
                String state = getStateName(telephonyManager.getDataState());
                data += state;
            }

            Data = data;
            Carrier = carrier;

            Date date = new Date(System.currentTimeMillis());
            final String dateStr = DateFormat.getDateFormat(context).format(date);
            final String timeStr = dateStr + "  " + DateFormat.getTimeFormat(context).format(date);

            Time = timeStr;

            MCC = Integer.parseInt(mcc);
            MNC = Integer.parseInt(mnc);

            // Tell the service we're watching the signal, so keep it updated
            Intent intent = new Intent(CommonIntentActionsOld.VIEWING_SIGNAL);
            context.sendBroadcast(intent);

            WifiInfo wifiinfo = getWifiInfo();
            WifiConfiguration wifiConfig = getWifiConfig();
            setWifi(wifiinfo, wifiConfig);

            // Instantiate only the relevant Network type
            if (netType.equals("cdma"))
                connectedNetwork = CDMAInfo = new CDMAInfo(this);
            else if (netType.equals("gsm") && networkTier < 3)
                connectedNetwork = GSMInfo = new GSMInfo(this);
            else if (netType.equals("gsm") && networkTier < 5)
                connectedNetwork = WCDMAInfo = new WCDMAInfo(this);
            if (networkTier == 5) // LTE
                connectedNetwork = LTEInfo = new LTEInfo(this);
            if (wifiConfig != null)
                connectedNetwork = WiFiInfo = new WIFIInfo(this); // The most relevant network ends up in NetworkInfo
        } catch (Exception e) {
        }

    } catch (Exception e) {
        LoggerUtil.logToFile(LoggerUtil.Level.ERROR, TAG, "updateNerdViewFromDB",
                "exception querying signal data: " + e.getMessage());
    } finally {
        if (cell_cursor != null)
            cell_cursor.close();
        if (sig_cursor != null)
            sig_cursor.close();
    }
}

From source file:com.sonetel.ui.dialpad.DialerFragment.java

protected boolean isInternetAvail(Context context) {
    connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = connectivityManager.getActiveNetworkInfo();

    if (ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI) {
        Log.d(THIS_FILE, "Wifi state is now " + ni.getState().name());
        if (ni.getState() == NetworkInfo.State.CONNECTED) {
            return true;
        }/*from w  w  w .j  a v  a  2  s  . com*/
    }
    if (ni != null && ni.getType() == ConnectivityManager.TYPE_MOBILE) {
        // Any mobile network connected
        if (ni.getState() == NetworkInfo.State.CONNECTED) {
            int subType = ni.getSubtype();

            // 3G (or better)
            if (subType >= TelephonyManager.NETWORK_TYPE_UMTS) {
                return true;
            }

            // GPRS (or unknown)
            if (subType == TelephonyManager.NETWORK_TYPE_GPRS
                    || subType == TelephonyManager.NETWORK_TYPE_UNKNOWN) {
                return true;
            }

            // EDGE
            if (subType == TelephonyManager.NETWORK_TYPE_EDGE) {
                return true;
            }
        }
    }
    if (ni != null && ni.getType() != ConnectivityManager.TYPE_MOBILE
            && ni.getType() != ConnectivityManager.TYPE_WIFI) {
        if (ni.getState() == NetworkInfo.State.CONNECTED) {
            return true;
        }
    }
    return false;

}

From source file:com.codename1.impl.android.AndroidImplementation.java

/**
 * @inheritDoc//ww w . j  ava 2  s . co  m
 */
public int getAPType(String id) {
    if (apIds == null) {
        getAPIds();
    }
    NetworkInfo info = (NetworkInfo) apIds.get(id);
    if (info == null) {
        return NetworkManager.ACCESS_POINT_TYPE_UNKNOWN;
    }
    int type = info.getType();
    int subType = info.getSubtype();
    if (type == ConnectivityManager.TYPE_WIFI) {
        return NetworkManager.ACCESS_POINT_TYPE_WLAN;
    } else if (type == ConnectivityManager.TYPE_MOBILE) {
        switch (subType) {
        case TelephonyManager.NETWORK_TYPE_1xRTT:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK2G; // ~ 50-100 kbps
        case TelephonyManager.NETWORK_TYPE_CDMA:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK2G; // ~ 14-64 kbps
        case TelephonyManager.NETWORK_TYPE_EDGE:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK2G; // ~ 50-100 kbps
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK3G; // ~ 400-1000 kbps
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK3G; // ~ 600-1400 kbps
        case TelephonyManager.NETWORK_TYPE_GPRS:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK2G; // ~ 100 kbps
        case TelephonyManager.NETWORK_TYPE_HSDPA:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK3G; // ~ 2-14 Mbps
        case TelephonyManager.NETWORK_TYPE_HSPA:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK3G; // ~ 700-1700 kbps
        case TelephonyManager.NETWORK_TYPE_HSUPA:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK3G; // ~ 1-23 Mbps
        case TelephonyManager.NETWORK_TYPE_UMTS:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK3G; // ~ 400-7000 kbps
        /*
         * Above API level 7, make sure to set android:targetSdkVersion
         * to appropriate level to use these
         */
        case TelephonyManager.NETWORK_TYPE_EHRPD: // API level 11
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK3G; // ~ 1-2 Mbps
        case TelephonyManager.NETWORK_TYPE_EVDO_B: // API level 9
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK3G; // ~ 5 Mbps
        case TelephonyManager.NETWORK_TYPE_HSPAP: // API level 13
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK3G; // ~ 10-20 Mbps
        case TelephonyManager.NETWORK_TYPE_IDEN: // API level 8
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK2G; // ~25 kbps
        case TelephonyManager.NETWORK_TYPE_LTE: // API level 11
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK3G; // ~ 10+ Mbps
        // Unknown
        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        default:
            return NetworkManager.ACCESS_POINT_TYPE_NETWORK2G;
        }
    } else {
        return NetworkManager.ACCESS_POINT_TYPE_UNKNOWN;
    }
}