Example usage for android.telephony TelephonyManager DATA_SUSPENDED

List of usage examples for android.telephony TelephonyManager DATA_SUSPENDED

Introduction

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

Prototype

int DATA_SUSPENDED

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

Click Source Link

Document

Data connection state: Suspended.

Usage

From source file:com.karpenstein.signalmon.SignalMonitorActivity.java

/** Called when the activity is first created. */
@Override/* w w w. jav  a  2  s.co m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Get the UI
    textOut = (TextView) findViewById(R.id.textOut);

    // Get the telephony manager
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

    // Create a new PhoneStateListener
    listener = new PhoneStateListener() {
        @Override
        public void onDataActivity(int direction) {
            String dirString = "N/A";
            switch (direction) {
            case TelephonyManager.DATA_ACTIVITY_NONE:
                dirString = "DATA_ACTIVITY_NONE";
                break;
            case TelephonyManager.DATA_ACTIVITY_IN:
                dirString = "DATA_ACTIVITY_IN";
                break;
            case TelephonyManager.DATA_ACTIVITY_OUT:
                dirString = "DATA_ACTIVITY_OUT";
                break;
            case TelephonyManager.DATA_ACTIVITY_INOUT:
                dirString = "DATA_ACTIVITY_INOUT";
                break;
            case TelephonyManager.DATA_ACTIVITY_DORMANT:
                dirString = "DATA_ACTIVITY_DORMANT";
                break;
            }
            textOut.append(dirString + "\n");
        }

        @Override
        public void onSignalStrengthsChanged(SignalStrength signalStrength) {
            textOut.append(signalStrength.toString() + "\n");
        }

        @Override
        public void onDataConnectionStateChanged(int state, int networkType) {
            String stateString = "N/A";
            String netTypString = "N/A";
            switch (state) {
            case TelephonyManager.DATA_CONNECTED:
                stateString = "DATA_CONNECTED";
                break;
            case TelephonyManager.DATA_CONNECTING:
                stateString = "DATA_CONNECTING";
                break;
            case TelephonyManager.DATA_DISCONNECTED:
                stateString = "DATA_DISCONNECTED";
                break;
            case TelephonyManager.DATA_SUSPENDED:
                stateString = "DATA_SUSPENDED";
                break;
            }
            switch (networkType) {
            case TelephonyManager.NETWORK_TYPE_1xRTT:
                netTypString = "NETWORK_TYPE_1xRTT";
                break;
            case TelephonyManager.NETWORK_TYPE_CDMA:
                netTypString = "NETWORK_TYPE_CDMA";
                break;
            case TelephonyManager.NETWORK_TYPE_EDGE:
                netTypString = "NETWORK_TYPE_EDGE";
                break;
            case TelephonyManager.NETWORK_TYPE_EVDO_0:
                netTypString = "NETWORK_TYPE_EVDO_0";
                break;
            case TelephonyManager.NETWORK_TYPE_EVDO_A:
                netTypString = "NETWORK_TYPE_EVDO_A";
                break;
            case TelephonyManager.NETWORK_TYPE_GPRS:
                netTypString = "NETWORK_TYPE_GPRS";
                break;
            case TelephonyManager.NETWORK_TYPE_HSDPA:
                netTypString = "NETWORK_TYPE_HSDPA";
                break;
            case TelephonyManager.NETWORK_TYPE_HSPA:
                netTypString = "NETWORK_TYPE_HSPA";
                break;
            case TelephonyManager.NETWORK_TYPE_HSUPA:
                netTypString = "NETWORK_TYPE_HSUPA";
                break;
            case TelephonyManager.NETWORK_TYPE_IDEN:
                netTypString = "NETWORK_TYPE_IDE";
                break;
            case TelephonyManager.NETWORK_TYPE_UMTS:
                netTypString = "NETWORK_TYPE_UMTS";
                break;
            case TelephonyManager.NETWORK_TYPE_UNKNOWN:
                netTypString = "NETWORK_TYPE_UNKNOWN";
                break;
            }
            textOut.append(String.format("onDataConnectionStateChanged: %s; %s\n", stateString, netTypString));
        }
    };

    // Register the listener with the telephony manager
    telephonyManager.listen(listener, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
            | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS | PhoneStateListener.LISTEN_DATA_ACTIVITY);

    // start the NetServerService
    startService(new Intent(this, NetServerService.class));
}

From source file:com.fallahpoor.infocenter.fragments.SimFragment.java

private String getDataConnectionState(TelephonyManager telephonyManager) {

    int dataStateInt = telephonyManager.getDataState();
    String dataStateStr;// www  .jav a2 s . co  m

    switch (dataStateInt) {
    case TelephonyManager.DATA_CONNECTED:
        dataStateStr = getString(R.string.sim_sub_item_data_connected);
        break;
    case TelephonyManager.DATA_CONNECTING:
        dataStateStr = getString(R.string.sim_sub_item_data_connecting);
        break;
    case TelephonyManager.DATA_DISCONNECTED:
        dataStateStr = getString(R.string.sim_sub_item_data_disconnected);
        break;
    case TelephonyManager.DATA_SUSPENDED:
        dataStateStr = getString(R.string.sim_sub_item_data_suspended);
        break;
    default:
        dataStateStr = getString(R.string.unknown);
    }

    return dataStateStr;

}

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

private void bindNotifInd() {
    showMmsView(false);//from   w w  w .jav a 2  s. c o m

    mBodyTextView.setText(formatMessage(mMessageItem, null, mMessageItem.mSubject, mMessageItem.mHighlight,
            mMessageItem.mTextContentType));

    mDateView.setText(buildTimestampLine(mMessageItem.mTimestamp));

    final String msgSizeText = mContext.getString(R.string.message_size_label)
            + String.valueOf((mMessageItem.mMessageSize + 1023) / 1024) + mContext.getString(R.string.kilobyte);

    mMessageSizeView.setText(msgSizeText);
    mMessageSizeView.setVisibility(View.VISIBLE);

    updateSimIndicatorView(mMessageItem.mSubId);

    switch (mMessageItem.getMmsDownloadStatus()) {
    case DownloadManager.STATE_PRE_DOWNLOADING:
    case DownloadManager.STATE_DOWNLOADING:
        showDownloadingAttachment();
        break;
    case DownloadManager.STATE_UNKNOWN:
    case DownloadManager.STATE_UNSTARTED:
        DownloadManager downloadManager = DownloadManager.getInstance();
        boolean autoDownload = downloadManager.isAuto();
        boolean dataSuspended = (MmsApp.getApplication().getTelephonyManager()
                .getDataState() == TelephonyManager.DATA_SUSPENDED);

        // If we're going to automatically start downloading the mms attachment, then
        // don't bother showing the download button for an instant before the actual
        // download begins. Instead, show downloading as taking place.
        if (autoDownload && !dataSuspended) {
            showDownloadingAttachment();
            break;
        }
    case DownloadManager.STATE_TRANSIENT_FAILURE:
    case DownloadManager.STATE_PERMANENT_FAILURE:
    default:
        setLongClickable(true);
        inflateDownloadControls();
        mDownloading.setVisibility(View.GONE);
        mDownloadButton.setVisibility(View.VISIBLE);
        mDownloadButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mDownloading.setVisibility(View.VISIBLE);
                try {
                    NotificationInd nInd = (NotificationInd) PduPersister.getPduPersister(mContext)
                            .load(mMessageItem.mMessageUri);
                    Log.d(TAG, "Download notify Uri = " + mMessageItem.mMessageUri);
                    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
                    builder.setTitle(R.string.download);
                    builder.setCancelable(true);
                    // Judge notification weather is expired
                    if (nInd.getExpiry() < System.currentTimeMillis() / 1000L) {
                        // builder.setIcon(R.drawable.ic_dialog_alert_holo_light);
                        builder.setMessage(mContext.getString(R.string.service_message_not_found));
                        builder.show();
                        SqliteWrapper.delete(mContext, mContext.getContentResolver(), mMessageItem.mMessageUri,
                                null, null);
                        return;
                    }
                    // Judge whether memory is full
                    else if (MessageUtils.isMmsMemoryFull()) {
                        builder.setMessage(mContext.getString(R.string.sms_full_body));
                        builder.show();
                        return;
                    }
                    // Judge whether message size is too large
                    else if ((int) nInd.getMessageSize() > MmsConfig.getMaxMessageSize()) {
                        builder.setMessage(mContext.getString(R.string.mms_too_large));
                        builder.show();
                        return;
                    }
                } catch (MmsException e) {
                    Log.e(TAG, e.getMessage(), e);
                    return;
                }
                mDownloadButton.setVisibility(View.GONE);
                Intent intent = new Intent(mContext, TransactionService.class);
                intent.putExtra(TransactionBundle.URI, mMessageItem.mMessageUri.toString());
                intent.putExtra(TransactionBundle.TRANSACTION_TYPE, Transaction.RETRIEVE_TRANSACTION);
                intent.putExtra(PhoneConstants.SUBSCRIPTION_KEY, mMessageItem.mSubId);

                mContext.startService(intent);

                DownloadManager.getInstance().markState(mMessageItem.mMessageUri,
                        DownloadManager.STATE_PRE_DOWNLOADING);
            }
        });
        break;
    }

    // Hide the indicators.
    mLockedIndicator.setVisibility(View.GONE);
    mDeliveredIndicator.setVisibility(View.GONE);
    mDetailsIndicator.setVisibility(View.GONE);
    updateAvatarView(mMessageItem.mAddress, false);
}

From source file:org.restcomm.app.qoslib.Services.LibPhoneStateListener.java

@Override
public void onDataConnectionStateChanged(int state, int networkType) {
    super.onDataConnectionStateChanged(state, networkType);
    //MMCLogger.logToFile(MMCLogger.Level.DEBUG, TAG, "onDataConnectionStateChanged", String.format("Network type: %d, State: %d", networkType, state));

    //notify MainService of the new network type
    mPhoneState.updateNetworkType(networkType);

    int datastate = telephonyManager.getDataState();
    // disregard network change events if data is disabled or in airplane mode
    if (datastate == TelephonyManager.DATA_SUSPENDED
            || mPhoneState.previousServiceState == mPhoneState.SERVICE_STATE_AIRPLANE)
        return;/*from w w w . java 2s  .  c  o m*/

    if (PhoneState.ActiveConnection(owner) > 1) {// 10=Wifi, 11=Wimax, 12=Ethernet, 0=other
        mPhoneState.previousNetworkTier = -1;
        return;
    }

    // Ignore any data outages that occur just after turning screen off, these are probably not to be blamed on the carrier
    if (mPhoneState.getScreenOnTime(false) + 30000 > System.currentTimeMillis())
        return;

    try {

        String conn = owner.getConnectionHistory().updateConnectionHistory(networkType, state,
                telephonyManager.getDataActivity(), mPhoneState.previousServiceStateObj,
                owner.getConnectivityManager().getActiveNetworkInfo());
        if (conn != null)
            owner.getIntentDispatcher().updateConnection(conn, false);

    } catch (Exception e) {
    }

    int networkGeneration = mPhoneState.getNetworkGeneration(networkType);

    // The 3G outage will be handled by the Service state outage
    if (mPhoneState.previousServiceState == ServiceState.STATE_OUT_OF_SERVICE
            || mPhoneState.previousServiceState == ServiceState.STATE_EMERGENCY_ONLY)
        return;
    //if the network generation hasn't changed, then don't cause an event
    if (mPhoneState.previousNetworkTier == networkGeneration && mPhoneState.previousNetworkState == state) {
        return;
    }

    SignalEx signal = mPhoneState.getLastMMCSignal();
    if (signal != null) {
        signal.setTimestamp(System.currentTimeMillis());
        mPhoneState.clearLastMMCSignal(); // to force a duplicate signal to be added
        processNewMMCSignal(signal);
    }
    //this was falsely reporting outages when screen turned off, and not coupling them to regained
    //if (datastate == TelephonyManager.DATA_DISCONNECTED)
    //   networkGeneration = 0;
    // First network state
    if (mPhoneState.previousNetworkType == -1)
        mPhoneState.previousNetworkType = networkType;
    else {
        switch (networkGeneration) {
        case 3: //3g
        case 4: //3g
            stateChanged_3g(state);
            break;
        case 5: //3g
            stateChanged_4g(state);
            break;

        case 1:
        case 2: //2g
            stateChanged_2g(state);
            break;

        // disconnected data without disconnecting service?
        case 0:
            stateChanged_0g(state);
            break;

        }
    }
    //update the previous network generation and state
    if (state == TelephonyManager.DATA_CONNECTED && networkGeneration != 0)
        mPhoneState.previousNetworkTier = networkGeneration;
    // If there is truly an outage, the service state listener will update the previousNetworkTier to 0
    mPhoneState.previousNetworkState = state;
    mPhoneState.previousNetworkType = networkType;

}

From source file:org.restcomm.app.qoslib.Services.Events.EventManager.java

/**
 * At the start of the event, stores like-timestamped entries in the tables for signals, cells and locations
 * This is so that querying the timespan of the event recording will easily return records for the beginning of the event
 * among other things/*from   www. j a v  a2s.c o  m*/
 * @param event
 */
public void signalSnapshot(EventObj event) {
    // In case the signal hasn't changed recently (last 30 sec or so), 
    // the signal won't be retrieved by the cursor unless we timestamp the last known signal now
    try {

        TelephonyManager telephonyManager = (TelephonyManager) context
                .getSystemService(Context.TELEPHONY_SERVICE);
        // Update the database and intents with a snapshot of the last known signal, cell, location
        SignalEx signal = context.getPhoneState().getLastMMCSignal();
        long timestamp = System.currentTimeMillis();
        if (event != null)
            timestamp = event.getEventTimestamp();
        if (signal != null) {
            signal.setTimestamp(timestamp);
            context.getPhoneState().clearLastMMCSignal(); // to force a duplicate signal to be added
            context.getPhoneStateListener().processNewMMCSignal(signal);
        }

        CellLocationEx cell = context.getPhoneStateListener().getLastCellLocation();
        if (cell != null) {
            cell.setCellIdTimestamp(timestamp);
            context.getPhoneStateListener().clearLastCellLocation();
            context.getPhoneStateListener().processNewCellLocation(cell);
        }

        if (event == null)
            return;

        ongoingEvents.add(event);
        Location location = context.getLastLocation();
        int satellites = context.getLastNumSatellites();
        if (location != null) {
            location.setTime(timestamp);
            context.setLastLocation(null); // to force a duplicate location to be added
            context.processNewFilteredLocation(location, satellites);
        }

        // set an initial location on the event if it is recent, but update it if a better location becomes available
        location = context.getLastLocation();
        event.setSignal(context.getPhoneState().getLastMMCSignal());
        event.setCell(context.getPhoneStateListener().getLastCellLocation());
        event.setServiceState(context.getPhoneState().getLastServiceStateObj());

        if (location != null && location.getTime() - 10000 > System.currentTimeMillis())
            event.setLocation(location, context.getLastNumSatellites());

        // Also, set the coverage flags at the time of the event
        int tier = context.getPhoneState().getNetworkGeneration();
        int servicestate = context.getPhoneState().getLastServiceState();
        int datastate = telephonyManager.getDataState();
        int activeConnection = PhoneState.ActiveConnection(context);
        if (activeConnection == 10)
            event.setFlag(EventObj.SERVICE_WIFI, true);
        else if (activeConnection == 11)
            event.setFlag(EventObj.SERVICE_WIMAX, true);
        ReportManager reportManager = ReportManager.getInstance(context);
        if (reportManager.manualPlottingEvent != null || event.getEventType() == EventType.MAN_PLOTTING)
            event.setFlag(EventObj.MANUAL_SAMPLES, true);

        if (datastate == TelephonyManager.DATA_CONNECTED || activeConnection > 1)
            event.setFlag(EventObj.SERVICE_DATA, true);
        else if (datastate == TelephonyManager.DATA_SUSPENDED && servicestate == ServiceState.STATE_IN_SERVICE) // not counted as data outage if data turned off
            event.setFlag(EventObj.SERVICE_DATA, true);
        else
            event.setFlag(EventObj.SERVICE_DATA, false);
        if (servicestate == ServiceState.STATE_OUT_OF_SERVICE
                || servicestate == ServiceState.STATE_EMERGENCY_ONLY)
            event.setFlag(EventObj.SERVICE_VOICE, false);
        else
            event.setFlag(EventObj.SERVICE_VOICE, true);
        if (tier > 2)
            event.setFlag(EventObj.SERVICE_3G, true);
        if (tier > 4)
            event.setFlag(EventObj.SERVICE_4G, true);
        if (context.getPhoneState().isCallConnected() || context.getPhoneState().isCallDialing()
                || event.getEventType().getIntValue() <= 6)
            event.setFlag(EventObj.PHONE_INUSE, true);

        // dropped call detection support using logcat or precise call state?
        if (event.getEventType().getIntValue() <= 7) {
            String pname = context.getPackageName();
            int permissionForReadLogs = context.getPackageManager()
                    .checkPermission(android.Manifest.permission.READ_LOGS, pname); //0 means allowed
            int permissionForPrecise = context.getPackageManager()
                    .checkPermission("android.permission.READ_PRECISE_PHONE_STATE", pname); // 0 means allowed
            if (permissionForPrecise == 0)
                event.setFlag(EventObj.CALL_PRECISE, true);
            else if (permissionForReadLogs == 0)
                event.setFlag(EventObj.CALL_LOGCAT, true);
        }

        event.setBattery(DeviceInfoOld.battery);
        if (event.getEventType() == EventType.COV_VOD_NO || event.getEventType() == EventType.COV_VOD_YES
                || event.getEventType() == EventType.COV_UPDATE
                || event.getEventType() == EventType.TRAVEL_CHECK) {
            long duration = 0;
            if (mLastServiceStateChangeTimeStamp != 0) {
                duration = System.currentTimeMillis() - mLastServiceStateChangeTimeStamp;
                mLastServiceStateChangeTimeStamp = System.currentTimeMillis();
                event.setDuration(duration);
            } else
                duration = mLastScreenOffDuration;

        }
        if (event.getEventType() == EventType.COV_3G_NO || event.getEventType() == EventType.COV_3G_YES
                || event.getEventType() == EventType.COV_UPDATE
                || event.getEventType() == EventType.TRAVEL_CHECK) {
            long duration = 0;
            if (mLast3GStateChangeTimeStamp != 0) {
                duration = System.currentTimeMillis() - mLast3GStateChangeTimeStamp;
                if (event.getEventType() == EventType.COV_UPDATE
                        || event.getEventType() == EventType.TRAVEL_CHECK)
                    event.setEventIndex(duration);
                else
                    event.setDuration(duration);
                mLast3GStateChangeTimeStamp = System.currentTimeMillis();
            }
        }
        //context.getCellHistory ().snapshotHistory();
        String conn = context.getConnectionHistory().updateConnectionHistory(telephonyManager.getNetworkType(),
                telephonyManager.getDataState(), telephonyManager.getDataActivity(),
                context.getPhoneState().getLastServiceStateObj(),
                context.getConnectivityManager().getActiveNetworkInfo());
        context.getIntentDispatcher().updateConnection(conn, true);

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

        localReportEvent(event);
    } catch (Exception e) {
        LoggerUtil.logToFile(LoggerUtil.Level.DEBUG, TAG, "signalSnapshot", "error", e);
    }
}

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

public String getStateName(int state) {
    switch (state) {
    case TelephonyManager.DATA_CONNECTED:
        return "connected";
    case TelephonyManager.DATA_CONNECTING:
        return "connecting";
    case TelephonyManager.DATA_DISCONNECTED:
        return "disconnected";
    case TelephonyManager.DATA_SUSPENDED:
        return "suspended";
    }//from w  w  w . ja v  a  2 s .c  o  m
    return "-";
}

From source file:com.intel.xdk.device.Device.java

private String getConnection() {
    WifiManager wifiMgr = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE);
    if (wifiMgr.isWifiEnabled() == true) {
        return "wifi";
    }//from  w w  w.  ja  v a2s . c o m

    TelephonyManager telMgr = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
    int data = telMgr.getDataState();
    if (data == TelephonyManager.DATA_DISCONNECTED || data == TelephonyManager.DATA_SUSPENDED)
        return "none";
    else
        return "cell";
}