FileDocCategorySizeDatePackage
DataConnectionStats.javaAPI DocAndroid 5.1 API6215Thu Mar 12 22:22:42 GMT 2015com.android.server.connectivity

DataConnectionStats

public class DataConnectionStats extends android.content.BroadcastReceiver

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private final android.content.Context
mContext
private final com.android.internal.app.IBatteryStats
mBatteryStats
private IccCardConstants.State
mSimState
private android.telephony.SignalStrength
mSignalStrength
private android.telephony.ServiceState
mServiceState
private int
mDataState
private final android.telephony.PhoneStateListener
mPhoneStateListener
Constructors Summary
public DataConnectionStats(android.content.Context context)


       
        mContext = context;
        mBatteryStats = BatteryStatsService.getService();
    
Methods Summary
private booleanhasService()

        return mServiceState != null
                && mServiceState.getState() != ServiceState.STATE_OUT_OF_SERVICE
                && mServiceState.getState() != ServiceState.STATE_POWER_OFF;
    
private booleanisCdma()

        return mSignalStrength != null && !mSignalStrength.isGsm();
    
private voidnotePhoneDataConnectionState()

        if (mServiceState == null) {
            return;
        }
        boolean simReadyOrUnknown = mSimState == IccCardConstants.State.READY
                || mSimState == IccCardConstants.State.UNKNOWN;
        boolean visible = (simReadyOrUnknown || isCdma()) // we only check the sim state for GSM
                && hasService()
                && mDataState == TelephonyManager.DATA_CONNECTED;
        int networkType = mServiceState.getDataNetworkType();
        if (DEBUG) Log.d(TAG, String.format("Noting data connection for network type %s: %svisible",
                networkType, visible ? "" : "not "));
        try {
            mBatteryStats.notePhoneDataConnectionState(networkType, visible);
        } catch (RemoteException e) {
            Log.w(TAG, "Error noting data connection state", e);
        }
    
public voidonReceive(android.content.Context context, android.content.Intent intent)

        final String action = intent.getAction();
        if (action.equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
            updateSimState(intent);
            notePhoneDataConnectionState();
        } else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION) ||
                action.equals(ConnectivityManager.INET_CONDITION_ACTION)) {
            notePhoneDataConnectionState();
       }
    
public voidstartMonitoring()

        TelephonyManager phone =
                (TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE);
        phone.listen(mPhoneStateListener,
                PhoneStateListener.LISTEN_SERVICE_STATE
              | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
              | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE
              | PhoneStateListener.LISTEN_DATA_ACTIVITY);

        IntentFilter filter = new IntentFilter();
        filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        filter.addAction(ConnectivityManager.INET_CONDITION_ACTION);
        mContext.registerReceiver(this, filter);
    
private final voidupdateSimState(android.content.Intent intent)

        String stateExtra = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
        if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(stateExtra)) {
            mSimState = IccCardConstants.State.ABSENT;
        } else if (IccCardConstants.INTENT_VALUE_ICC_READY.equals(stateExtra)) {
            mSimState = IccCardConstants.State.READY;
        } else if (IccCardConstants.INTENT_VALUE_ICC_LOCKED.equals(stateExtra)) {
            final String lockedReason =
                    intent.getStringExtra(IccCardConstants.INTENT_KEY_LOCKED_REASON);
            if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PIN.equals(lockedReason)) {
                mSimState = IccCardConstants.State.PIN_REQUIRED;
            } else if (IccCardConstants.INTENT_VALUE_LOCKED_ON_PUK.equals(lockedReason)) {
                mSimState = IccCardConstants.State.PUK_REQUIRED;
            } else {
                mSimState = IccCardConstants.State.NETWORK_LOCKED;
            }
        } else {
            mSimState = IccCardConstants.State.UNKNOWN;
        }