Loading src/java/com/android/internal/telephony/dataconnection/DataConnection.java +7 −7 Original line number Diff line number Diff line Loading @@ -73,7 +73,7 @@ import java.util.HashMap; * NOTE: All DataConnection objects must be running on the same looper, which is the default * as the coordinator has members which are used without synchronization. */ public final class DataConnection extends StateMachine { public class DataConnection extends StateMachine { private static final boolean DBG = true; private static final boolean VDBG = true; Loading @@ -96,7 +96,7 @@ public final class DataConnection extends StateMachine { /** * Used internally for saving connecting parameters. */ static class ConnectionParams { public static class ConnectionParams { int mTag; ApnContext mApnContext; int mProfileId; Loading Loading @@ -164,8 +164,8 @@ public final class DataConnection extends StateMachine { //***** Package visible variables int mTag; int mCid; HashMap<ApnContext, ConnectionParams> mApnContexts = null; public int mCid; public HashMap<ApnContext, ConnectionParams> mApnContexts = null; PendingIntent mReconnectIntent = null; Loading Loading @@ -277,7 +277,7 @@ public final class DataConnection extends StateMachine { mLinkProperties.setHttpProxy(proxy); } static class UpdateLinkPropertyResult { public static class UpdateLinkPropertyResult { public DataCallResponse.SetupResult setupResult = DataCallResponse.SetupResult.SUCCESS; public LinkProperties oldLp; public LinkProperties newLp; Loading Loading @@ -321,7 +321,7 @@ public final class DataConnection extends StateMachine { return ret; } UpdateLinkPropertyResult updateLinkProperty(DataCallResponse newState) { public UpdateLinkPropertyResult updateLinkProperty(DataCallResponse newState) { UpdateLinkPropertyResult result = new UpdateLinkPropertyResult(mLinkProperties); if (newState == null) return result; Loading Loading @@ -715,7 +715,7 @@ public final class DataConnection extends StateMachine { result = DataCallResponse.SetupResult.ERR_RilError; result.mFailCause = DcFailCause.fromInt(response.status); } else { if (DBG) log("onSetupConnectionCompleted received DataCallResponse: " + response); if (DBG) log("onSetupConnectionCompleted received successful DataCallResponse"); mCid = response.cid; mPcscfAddr = response.pcscf; Loading src/java/com/android/internal/telephony/dataconnection/DcController.java +3 −3 Original line number Diff line number Diff line Loading @@ -45,7 +45,7 @@ import java.util.HashMap; * multiple data connections. For instance listening for unsolicited messages * and then demultiplexing them to the appropriate DC. */ class DcController extends StateMachine { public class DcController extends StateMachine { private static final boolean DBG = true; private static final boolean VDBG = false; Loading Loading @@ -111,7 +111,7 @@ class DcController extends StateMachine { } } static DcController makeDcc(Phone phone, DcTracker dct, Handler handler) { public static DcController makeDcc(Phone phone, DcTracker dct, Handler handler) { DcController dcc = new DcController("Dcc", phone, dct, handler); dcc.start(); return dcc; Loading @@ -132,7 +132,7 @@ class DcController extends StateMachine { mDcListAll.remove(dc); } void addActiveDcByCid(DataConnection dc) { public void addActiveDcByCid(DataConnection dc) { if (DBG && dc.mCid < 0) { log("addActiveDcByCid dc.mCid < 0 dc=" + dc); } Loading tests/telephonytests/src/com/android/internal/telephony/DcControllerTest.java 0 → 100644 +131 −0 Original line number Diff line number Diff line /* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.telephony; import android.net.LinkProperties; import android.os.AsyncResult; import android.os.Handler; import android.os.HandlerThread; import android.test.suitebuilder.annotation.SmallTest; import com.android.internal.telephony.dataconnection.ApnContext; import com.android.internal.telephony.dataconnection.DataCallResponse; import com.android.internal.telephony.dataconnection.DataConnection; import com.android.internal.telephony.dataconnection.DataConnection.ConnectionParams; import com.android.internal.telephony.dataconnection.DataConnection.UpdateLinkPropertyResult; import com.android.internal.telephony.dataconnection.DcController; import com.android.internal.util.IState; import com.android.internal.util.StateMachine; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; import static com.android.internal.telephony.TelephonyTestUtils.waitForMs; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import static org.mockito.Mockito.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; public class DcControllerTest extends TelephonyTest { private static final int DATA_CONNECTION_ACTIVE_PH_LINK_DORMANT = 1; private static final int EVENT_DATA_STATE_CHANGED = 0x00040007; @Mock DataConnection mDc; @Mock HashMap<ApnContext, ConnectionParams> mApnContexts; UpdateLinkPropertyResult mResult; private DcController mDcc; private class DcControllerTestHandler extends HandlerThread { private DcControllerTestHandler(String name) { super(name); } private Handler mHandler; @Override public void onLooperPrepared() { mHandler = new Handler(); mDcc = DcController.makeDcc(mPhone, mDcTracker, mHandler); setReady(true); } } private IState getCurrentState() { try { Method method = StateMachine.class.getDeclaredMethod("getCurrentState"); method.setAccessible(true); return (IState) method.invoke(mDcc); } catch (Exception e) { fail(e.toString()); return null; } } @Before public void setUp() throws Exception { super.setUp(getClass().getSimpleName()); doReturn("fake.action_detached").when(mPhone).getActionDetached(); mDc.mApnContexts = mApnContexts; doReturn(1).when(mApnContexts).size(); LinkProperties lp = new LinkProperties(); mResult = new UpdateLinkPropertyResult(lp); doReturn(mResult).when(mDc).updateLinkProperty(any(DataCallResponse.class)); new DcControllerTestHandler(TAG).start(); waitUntilReady(); } @After public void tearDown() throws Exception { super.tearDown(); } @Test @SmallTest public void testDataDormant() { assertEquals("DccDefaultState", getCurrentState().getName()); ArrayList<DataCallResponse> l = new ArrayList<DataCallResponse>(); DataCallResponse dcResponse = DcTrackerTest.createDataCallResponse(); dcResponse.active = DATA_CONNECTION_ACTIVE_PH_LINK_DORMANT; l.add(dcResponse); mDc.mCid = 1; mDcc.addActiveDcByCid(mDc); mDcc.sendMessage(EVENT_DATA_STATE_CHANGED, new AsyncResult(null, l, null)); waitForMs(100); verify(mDcTracker, times(1)).sendStopNetStatPoll(eq(DctConstants.Activity.DORMANT)); } } No newline at end of file tests/telephonytests/src/com/android/internal/telephony/DcTrackerTest.java +9 −9 Original line number Diff line number Diff line Loading @@ -74,14 +74,14 @@ public class DcTrackerTest extends TelephonyTest { private final List<String> sApnTypes = Arrays.asList( "default", "mms", "cbs", "fota", "supl", "ia", "emergency", "dun", "hipri", "ims"); private final String FAKE_APN1 = "FAKE APN 1"; private final String FAKE_APN2 = "FAKE APN 2"; private final String FAKE_APN3 = "FAKE APN 3"; private final String FAKE_IFNAME = "FAKE IFNAME"; private final String FAKE_PCSCF_ADDRESS = "22.33.44.55"; private final String FAKE_GATEWAY = "11.22.33.44"; private final String FAKE_DNS = "55.66.77.88"; private final String FAKE_ADDRESS = "99.88.77.66"; private static final String FAKE_APN1 = "FAKE APN 1"; private static final String FAKE_APN2 = "FAKE APN 2"; private static final String FAKE_APN3 = "FAKE APN 3"; private static final String FAKE_IFNAME = "FAKE IFNAME"; private static final String FAKE_PCSCF_ADDRESS = "22.33.44.55"; private static final String FAKE_GATEWAY = "11.22.33.44"; private static final String FAKE_DNS = "55.66.77.88"; private static final String FAKE_ADDRESS = "99.88.77.66"; @Mock ISub mIsub; Loading Loading @@ -303,7 +303,7 @@ public class DcTrackerTest extends TelephonyTest { } // Create a successful data response private DataCallResponse createDataCallResponse() { public static DataCallResponse createDataCallResponse() { DataCallResponse dcResponse = new DataCallResponse(); Loading Loading
src/java/com/android/internal/telephony/dataconnection/DataConnection.java +7 −7 Original line number Diff line number Diff line Loading @@ -73,7 +73,7 @@ import java.util.HashMap; * NOTE: All DataConnection objects must be running on the same looper, which is the default * as the coordinator has members which are used without synchronization. */ public final class DataConnection extends StateMachine { public class DataConnection extends StateMachine { private static final boolean DBG = true; private static final boolean VDBG = true; Loading @@ -96,7 +96,7 @@ public final class DataConnection extends StateMachine { /** * Used internally for saving connecting parameters. */ static class ConnectionParams { public static class ConnectionParams { int mTag; ApnContext mApnContext; int mProfileId; Loading Loading @@ -164,8 +164,8 @@ public final class DataConnection extends StateMachine { //***** Package visible variables int mTag; int mCid; HashMap<ApnContext, ConnectionParams> mApnContexts = null; public int mCid; public HashMap<ApnContext, ConnectionParams> mApnContexts = null; PendingIntent mReconnectIntent = null; Loading Loading @@ -277,7 +277,7 @@ public final class DataConnection extends StateMachine { mLinkProperties.setHttpProxy(proxy); } static class UpdateLinkPropertyResult { public static class UpdateLinkPropertyResult { public DataCallResponse.SetupResult setupResult = DataCallResponse.SetupResult.SUCCESS; public LinkProperties oldLp; public LinkProperties newLp; Loading Loading @@ -321,7 +321,7 @@ public final class DataConnection extends StateMachine { return ret; } UpdateLinkPropertyResult updateLinkProperty(DataCallResponse newState) { public UpdateLinkPropertyResult updateLinkProperty(DataCallResponse newState) { UpdateLinkPropertyResult result = new UpdateLinkPropertyResult(mLinkProperties); if (newState == null) return result; Loading Loading @@ -715,7 +715,7 @@ public final class DataConnection extends StateMachine { result = DataCallResponse.SetupResult.ERR_RilError; result.mFailCause = DcFailCause.fromInt(response.status); } else { if (DBG) log("onSetupConnectionCompleted received DataCallResponse: " + response); if (DBG) log("onSetupConnectionCompleted received successful DataCallResponse"); mCid = response.cid; mPcscfAddr = response.pcscf; Loading
src/java/com/android/internal/telephony/dataconnection/DcController.java +3 −3 Original line number Diff line number Diff line Loading @@ -45,7 +45,7 @@ import java.util.HashMap; * multiple data connections. For instance listening for unsolicited messages * and then demultiplexing them to the appropriate DC. */ class DcController extends StateMachine { public class DcController extends StateMachine { private static final boolean DBG = true; private static final boolean VDBG = false; Loading Loading @@ -111,7 +111,7 @@ class DcController extends StateMachine { } } static DcController makeDcc(Phone phone, DcTracker dct, Handler handler) { public static DcController makeDcc(Phone phone, DcTracker dct, Handler handler) { DcController dcc = new DcController("Dcc", phone, dct, handler); dcc.start(); return dcc; Loading @@ -132,7 +132,7 @@ class DcController extends StateMachine { mDcListAll.remove(dc); } void addActiveDcByCid(DataConnection dc) { public void addActiveDcByCid(DataConnection dc) { if (DBG && dc.mCid < 0) { log("addActiveDcByCid dc.mCid < 0 dc=" + dc); } Loading
tests/telephonytests/src/com/android/internal/telephony/DcControllerTest.java 0 → 100644 +131 −0 Original line number Diff line number Diff line /* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.telephony; import android.net.LinkProperties; import android.os.AsyncResult; import android.os.Handler; import android.os.HandlerThread; import android.test.suitebuilder.annotation.SmallTest; import com.android.internal.telephony.dataconnection.ApnContext; import com.android.internal.telephony.dataconnection.DataCallResponse; import com.android.internal.telephony.dataconnection.DataConnection; import com.android.internal.telephony.dataconnection.DataConnection.ConnectionParams; import com.android.internal.telephony.dataconnection.DataConnection.UpdateLinkPropertyResult; import com.android.internal.telephony.dataconnection.DcController; import com.android.internal.util.IState; import com.android.internal.util.StateMachine; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; import static com.android.internal.telephony.TelephonyTestUtils.waitForMs; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import static org.mockito.Mockito.any; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; public class DcControllerTest extends TelephonyTest { private static final int DATA_CONNECTION_ACTIVE_PH_LINK_DORMANT = 1; private static final int EVENT_DATA_STATE_CHANGED = 0x00040007; @Mock DataConnection mDc; @Mock HashMap<ApnContext, ConnectionParams> mApnContexts; UpdateLinkPropertyResult mResult; private DcController mDcc; private class DcControllerTestHandler extends HandlerThread { private DcControllerTestHandler(String name) { super(name); } private Handler mHandler; @Override public void onLooperPrepared() { mHandler = new Handler(); mDcc = DcController.makeDcc(mPhone, mDcTracker, mHandler); setReady(true); } } private IState getCurrentState() { try { Method method = StateMachine.class.getDeclaredMethod("getCurrentState"); method.setAccessible(true); return (IState) method.invoke(mDcc); } catch (Exception e) { fail(e.toString()); return null; } } @Before public void setUp() throws Exception { super.setUp(getClass().getSimpleName()); doReturn("fake.action_detached").when(mPhone).getActionDetached(); mDc.mApnContexts = mApnContexts; doReturn(1).when(mApnContexts).size(); LinkProperties lp = new LinkProperties(); mResult = new UpdateLinkPropertyResult(lp); doReturn(mResult).when(mDc).updateLinkProperty(any(DataCallResponse.class)); new DcControllerTestHandler(TAG).start(); waitUntilReady(); } @After public void tearDown() throws Exception { super.tearDown(); } @Test @SmallTest public void testDataDormant() { assertEquals("DccDefaultState", getCurrentState().getName()); ArrayList<DataCallResponse> l = new ArrayList<DataCallResponse>(); DataCallResponse dcResponse = DcTrackerTest.createDataCallResponse(); dcResponse.active = DATA_CONNECTION_ACTIVE_PH_LINK_DORMANT; l.add(dcResponse); mDc.mCid = 1; mDcc.addActiveDcByCid(mDc); mDcc.sendMessage(EVENT_DATA_STATE_CHANGED, new AsyncResult(null, l, null)); waitForMs(100); verify(mDcTracker, times(1)).sendStopNetStatPoll(eq(DctConstants.Activity.DORMANT)); } } No newline at end of file
tests/telephonytests/src/com/android/internal/telephony/DcTrackerTest.java +9 −9 Original line number Diff line number Diff line Loading @@ -74,14 +74,14 @@ public class DcTrackerTest extends TelephonyTest { private final List<String> sApnTypes = Arrays.asList( "default", "mms", "cbs", "fota", "supl", "ia", "emergency", "dun", "hipri", "ims"); private final String FAKE_APN1 = "FAKE APN 1"; private final String FAKE_APN2 = "FAKE APN 2"; private final String FAKE_APN3 = "FAKE APN 3"; private final String FAKE_IFNAME = "FAKE IFNAME"; private final String FAKE_PCSCF_ADDRESS = "22.33.44.55"; private final String FAKE_GATEWAY = "11.22.33.44"; private final String FAKE_DNS = "55.66.77.88"; private final String FAKE_ADDRESS = "99.88.77.66"; private static final String FAKE_APN1 = "FAKE APN 1"; private static final String FAKE_APN2 = "FAKE APN 2"; private static final String FAKE_APN3 = "FAKE APN 3"; private static final String FAKE_IFNAME = "FAKE IFNAME"; private static final String FAKE_PCSCF_ADDRESS = "22.33.44.55"; private static final String FAKE_GATEWAY = "11.22.33.44"; private static final String FAKE_DNS = "55.66.77.88"; private static final String FAKE_ADDRESS = "99.88.77.66"; @Mock ISub mIsub; Loading Loading @@ -303,7 +303,7 @@ public class DcTrackerTest extends TelephonyTest { } // Create a successful data response private DataCallResponse createDataCallResponse() { public static DataCallResponse createDataCallResponse() { DataCallResponse dcResponse = new DataCallResponse(); Loading