Search in sources :

Example 6 with PreciseDataConnectionState

use of android.telephony.PreciseDataConnectionState in project android_frameworks_base by crdroidandroid.

the class TelephonyRegistry method notifyDataConnectionForSubscriber.

public void notifyDataConnectionForSubscriber(int subId, int state, boolean isDataConnectivityPossible, String reason, String apn, String apnType, LinkProperties linkProperties, NetworkCapabilities networkCapabilities, int networkType, boolean roaming) {
    if (!checkNotifyPermission("notifyDataConnection()")) {
        return;
    }
    if (VDBG) {
        log("notifyDataConnectionForSubscriber: subId=" + subId + " state=" + state + " isDataConnectivityPossible=" + isDataConnectivityPossible + " reason='" + reason + "' apn='" + apn + "' apnType=" + apnType + " networkType=" + networkType + " mRecords.size()=" + mRecords.size());
    }
    synchronized (mRecords) {
        int phoneId = SubscriptionManager.getPhoneId(subId);
        if (validatePhoneId(phoneId)) {
            if (VDBG) {
                log(" mConnectedApns[" + phoneId + "]=" + mConnectedApns[phoneId].toString());
            }
            boolean modified = false;
            if (state == TelephonyManager.DATA_CONNECTED) {
                if (!mConnectedApns[phoneId].contains(apnType) && !apnType.equals(PhoneConstants.APN_TYPE_IMS)) {
                    mConnectedApns[phoneId].add(apnType);
                    if (mDataConnectionState[phoneId] != state) {
                        mDataConnectionState[phoneId] = state;
                        modified = true;
                    }
                }
            } else {
                if (mConnectedApns[phoneId].remove(apnType)) {
                    if (mConnectedApns[phoneId].isEmpty()) {
                        mDataConnectionState[phoneId] = state;
                        modified = true;
                    } else {
                    // leave mDataConnectionState as is and
                    // send out the new status for the APN in question.
                    }
                }
            }
            mDataConnectionPossible[phoneId] = isDataConnectivityPossible;
            mDataConnectionReason[phoneId] = reason;
            mDataConnectionLinkProperties[phoneId] = linkProperties;
            mDataConnectionNetworkCapabilities[phoneId] = networkCapabilities;
            if (mDataConnectionNetworkType[phoneId] != networkType) {
                mDataConnectionNetworkType[phoneId] = networkType;
                // need to tell registered listeners about the new network type
                modified = true;
            }
            if (modified) {
                if (DBG) {
                    log("onDataConnectionStateChanged(" + mDataConnectionState[phoneId] + ", " + mDataConnectionNetworkType[phoneId] + ")");
                }
                for (Record r : mRecords) {
                    if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) && idMatch(r.subId, subId, phoneId)) {
                        try {
                            log("Notify data connection state changed on sub: " + subId);
                            r.callback.onDataConnectionStateChanged(mDataConnectionState[phoneId], mDataConnectionNetworkType[phoneId]);
                        } catch (RemoteException ex) {
                            mRemoveList.add(r.binder);
                        }
                    }
                }
                handleRemoveListLocked();
            }
            mPreciseDataConnectionState = new PreciseDataConnectionState(state, networkType, apnType, apn, reason, linkProperties, "");
            for (Record r : mRecords) {
                if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
                    try {
                        r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
                    } catch (RemoteException ex) {
                        mRemoveList.add(r.binder);
                    }
                }
            }
        }
        handleRemoveListLocked();
    }
    broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn, apnType, linkProperties, networkCapabilities, roaming, subId);
    broadcastPreciseDataConnectionStateChanged(state, networkType, apnType, apn, reason, linkProperties, "");
}
Also used : RemoteException(android.os.RemoteException) PreciseDataConnectionState(android.telephony.PreciseDataConnectionState)

Example 7 with PreciseDataConnectionState

use of android.telephony.PreciseDataConnectionState in project android_frameworks_base by AOSPA.

the class TelephonyRegistry method notifyDataConnectionFailedForSubscriber.

public void notifyDataConnectionFailedForSubscriber(int subId, String reason, String apnType) {
    if (!checkNotifyPermission("notifyDataConnectionFailed()")) {
        return;
    }
    if (VDBG) {
        log("notifyDataConnectionFailedForSubscriber: subId=" + subId + " reason=" + reason + " apnType=" + apnType);
    }
    synchronized (mRecords) {
        mPreciseDataConnectionState = new PreciseDataConnectionState(TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
        for (Record r : mRecords) {
            if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
                try {
                    r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
                } catch (RemoteException ex) {
                    mRemoveList.add(r.binder);
                }
            }
        }
        handleRemoveListLocked();
    }
    broadcastDataConnectionFailed(reason, apnType, subId);
    broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, "", reason, null, "");
}
Also used : RemoteException(android.os.RemoteException) PreciseDataConnectionState(android.telephony.PreciseDataConnectionState)

Example 8 with PreciseDataConnectionState

use of android.telephony.PreciseDataConnectionState in project android_frameworks_base by AOSPA.

the class TelephonyRegistry method notifyPreciseDataConnectionFailed.

public void notifyPreciseDataConnectionFailed(String reason, String apnType, String apn, String failCause) {
    if (!checkNotifyPermission("notifyPreciseDataConnectionFailed()")) {
        return;
    }
    synchronized (mRecords) {
        mPreciseDataConnectionState = new PreciseDataConnectionState(TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
        for (Record r : mRecords) {
            if (r.matchPhoneStateListenerEvent(PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE)) {
                try {
                    r.callback.onPreciseDataConnectionStateChanged(mPreciseDataConnectionState);
                } catch (RemoteException ex) {
                    mRemoveList.add(r.binder);
                }
            }
        }
        handleRemoveListLocked();
    }
    broadcastPreciseDataConnectionStateChanged(TelephonyManager.DATA_UNKNOWN, TelephonyManager.NETWORK_TYPE_UNKNOWN, apnType, apn, reason, null, failCause);
}
Also used : RemoteException(android.os.RemoteException) PreciseDataConnectionState(android.telephony.PreciseDataConnectionState)

Example 9 with PreciseDataConnectionState

use of android.telephony.PreciseDataConnectionState in project robolectric by robolectric.

the class PreciseDataConnectionStateBuilderTest method build_preciseDataConnectionState_nullApnSetting.

@Test
public void build_preciseDataConnectionState_nullApnSetting() {
    PreciseDataConnectionState state = PreciseDataConnectionStateBuilder.newBuilder().setDataState(TelephonyManager.DATA_DISCONNECTED).setNetworkType(TelephonyManager.NETWORK_TYPE_LTE).setDataFailCause(DataFailCause.IMEI_NOT_ACCEPTED).build();
    assertThat(state).isNotNull();
    assertThat(state.getState()).isEqualTo(TelephonyManager.DATA_DISCONNECTED);
    assertThat(state.getNetworkType()).isEqualTo(TelephonyManager.NETWORK_TYPE_LTE);
    assertThat(state.getLastCauseCode()).isEqualTo(DataFailCause.IMEI_NOT_ACCEPTED);
    assertThat(state.getApnSetting()).isNull();
}
Also used : PreciseDataConnectionState(android.telephony.PreciseDataConnectionState) Test(org.junit.Test)

Example 10 with PreciseDataConnectionState

use of android.telephony.PreciseDataConnectionState in project android_frameworks_opt_telephony by LineageOS.

the class TelephonyRegistryTest method testPreciseDataConnectionStateChanged.

/**
 * Test multi sim config change.
 */
@Test
public void testPreciseDataConnectionStateChanged() {
    final int subId = 1;
    doReturn(mMockSubInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(anyInt());
    doReturn(0).when(mMockSubInfo).getSimSlotIndex();
    // Initialize the PSL with a PreciseDataConnection
    mTelephonyRegistry.notifyDataConnectionForSubscriber(/*phoneId*/
    0, subId, ApnSetting.TYPE_DEFAULT, new PreciseDataConnectionState(0, 0, 0, "default", new LinkProperties(), 0, null));
    mTelephonyRegistry.listenForSubscriber(subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mPhoneStateListener.callback, PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE, true);
    processAllMessages();
    // Verify that the PDCS is reported for the only APN
    assertEquals(mPhoneStateListener.invocationCount.get(), 1);
    // Add IMS APN and verify that the listener is invoked for the IMS APN
    mTelephonyRegistry.notifyDataConnectionForSubscriber(/*phoneId*/
    0, subId, ApnSetting.TYPE_IMS, new PreciseDataConnectionState(0, 0, 0, "ims", new LinkProperties(), 0, null));
    processAllMessages();
    assertEquals(mPhoneStateListener.invocationCount.get(), 2);
    // Unregister the listener
    mTelephonyRegistry.listenForSubscriber(subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mPhoneStateListener.callback, PhoneStateListener.LISTEN_NONE, true);
    processAllMessages();
    // Re-register the listener and ensure that both APN types are reported
    mTelephonyRegistry.listenForSubscriber(subId, mContext.getOpPackageName(), mContext.getAttributionTag(), mPhoneStateListener.callback, PhoneStateListener.LISTEN_PRECISE_DATA_CONNECTION_STATE, true);
    processAllMessages();
    assertEquals(mPhoneStateListener.invocationCount.get(), 4);
    // Send a duplicate event to the TelephonyRegistry and verify that the listener isn't
    // invoked.
    mTelephonyRegistry.notifyDataConnectionForSubscriber(/*phoneId*/
    0, subId, ApnSetting.TYPE_IMS, new PreciseDataConnectionState(0, 0, 0, "ims", new LinkProperties(), 0, null));
    processAllMessages();
    assertEquals(mPhoneStateListener.invocationCount.get(), 4);
}
Also used : LinkProperties(android.net.LinkProperties) PreciseDataConnectionState(android.telephony.PreciseDataConnectionState) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test)

Aggregations

PreciseDataConnectionState (android.telephony.PreciseDataConnectionState)20 RemoteException (android.os.RemoteException)15 Test (org.junit.Test)3 ApnSetting (android.telephony.data.ApnSetting)2 NonNull (android.annotation.NonNull)1 LinkProperties (android.net.LinkProperties)1 ServiceState (android.telephony.ServiceState)1 SmallTest (android.test.suitebuilder.annotation.SmallTest)1 DcTracker (com.android.internal.telephony.dataconnection.DcTracker)1