Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 1 | package com.android.systemui.statusbar.policy; |
| 2 | |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 3 | import android.os.Looper; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 4 | import android.telephony.TelephonyManager; |
Jason Monk | e427cb8 | 2015-07-28 09:18:08 -0400 | [diff] [blame] | 5 | import android.test.suitebuilder.annotation.SmallTest; |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 6 | |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 7 | import org.mockito.Mockito; |
| 8 | |
Jason Monk | e427cb8 | 2015-07-28 09:18:08 -0400 | [diff] [blame] | 9 | @SmallTest |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 10 | public class NetworkControllerDataTest extends NetworkControllerBaseTest { |
| 11 | |
| 12 | public void test3gDataIcon() { |
| 13 | setupDefaultSignal(); |
| 14 | |
| 15 | verifyDataIndicators(TelephonyIcons.DATA_3G[1][0 /* No direction */], |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 16 | TelephonyIcons.QS_DATA_3G); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | public void testRoamingDataIcon() { |
| 20 | setupDefaultSignal(); |
| 21 | setGsmRoaming(true); |
| 22 | |
| 23 | verifyLastMobileDataIndicators(true, |
| 24 | TelephonyIcons.TELEPHONY_SIGNAL_STRENGTH_ROAMING[1][DEFAULT_LEVEL], |
| 25 | TelephonyIcons.ROAMING_ICON); |
| 26 | verifyLastQsMobileDataIndicators(true, |
| 27 | TelephonyIcons.QS_TELEPHONY_SIGNAL_STRENGTH[1][DEFAULT_LEVEL], |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 28 | TelephonyIcons.QS_DATA_R, false, false); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | public void test2gDataIcon() { |
| 32 | setupDefaultSignal(); |
| 33 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 34 | TelephonyManager.NETWORK_TYPE_GSM); |
| 35 | |
| 36 | verifyDataIndicators(TelephonyIcons.DATA_G[1][0 /* No direction */], |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 37 | TelephonyIcons.QS_DATA_G); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | public void testCdmaDataIcon() { |
| 41 | setupDefaultSignal(); |
| 42 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 43 | TelephonyManager.NETWORK_TYPE_CDMA); |
| 44 | |
| 45 | verifyDataIndicators(TelephonyIcons.DATA_1X[1][0 /* No direction */], |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 46 | TelephonyIcons.QS_DATA_1X); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | public void testEdgeDataIcon() { |
| 50 | setupDefaultSignal(); |
| 51 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 52 | TelephonyManager.NETWORK_TYPE_EDGE); |
| 53 | |
| 54 | verifyDataIndicators(TelephonyIcons.DATA_E[1][0 /* No direction */], |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 55 | TelephonyIcons.QS_DATA_E); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | public void testLteDataIcon() { |
| 59 | setupDefaultSignal(); |
| 60 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 61 | TelephonyManager.NETWORK_TYPE_LTE); |
| 62 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 63 | verifyDataIndicators(TelephonyIcons.DATA_LTE[1][0 /* No direction */], |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 64 | TelephonyIcons.QS_DATA_LTE); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | public void testHspaDataIcon() { |
| 68 | setupDefaultSignal(); |
| 69 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 70 | TelephonyManager.NETWORK_TYPE_HSPA); |
| 71 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 72 | verifyDataIndicators(TelephonyIcons.DATA_H[1][0 /* No direction */], |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 73 | TelephonyIcons.QS_DATA_H); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 74 | } |
| 75 | |
Jason Monk | 7150d7f | 2015-07-09 10:14:12 -0400 | [diff] [blame] | 76 | public void testWfcNoDataIcon() { |
| 77 | setupDefaultSignal(); |
| 78 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 79 | TelephonyManager.NETWORK_TYPE_IWLAN); |
| 80 | |
| 81 | verifyDataIndicators(0, 0); |
| 82 | } |
| 83 | |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 84 | public void test4gDataIcon() { |
| 85 | // Switch to showing 4g icon and re-initialize the NetworkController. |
| 86 | mConfig.show4gForLte = true; |
| 87 | mNetworkController = new NetworkControllerImpl(mContext, mMockCm, mMockTm, mMockWm, mMockSm, |
Jason Monk | 07b75fe | 2015-05-14 16:47:03 -0400 | [diff] [blame] | 88 | mConfig, Looper.getMainLooper(), mCallbackHandler, |
| 89 | Mockito.mock(AccessPointControllerImpl.class), |
Jason Monk | c6cc626 | 2015-06-11 11:10:15 -0400 | [diff] [blame] | 90 | Mockito.mock(MobileDataControllerImpl.class), mMockSubDefaults); |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 91 | setupNetworkController(); |
| 92 | |
| 93 | setupDefaultSignal(); |
| 94 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 95 | TelephonyManager.NETWORK_TYPE_LTE); |
| 96 | |
| 97 | verifyDataIndicators(TelephonyIcons.DATA_4G[1][0 /* No direction */], |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 98 | TelephonyIcons.QS_DATA_4G); |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | public void test4gDataIconConfigChange() { |
| 102 | setupDefaultSignal(); |
| 103 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 104 | TelephonyManager.NETWORK_TYPE_LTE); |
| 105 | |
| 106 | // Switch to showing 4g icon and re-initialize the NetworkController. |
| 107 | mConfig.show4gForLte = true; |
| 108 | // Can't send the broadcast as that would actually read the config from |
| 109 | // the context. Instead we'll just poke at a function that does all of |
| 110 | // the after work. |
| 111 | mNetworkController.handleConfigurationChanged(); |
| 112 | |
| 113 | verifyDataIndicators(TelephonyIcons.DATA_4G[1][0 /* No direction */], |
Jason Monk | 33f8ae7 | 2015-05-08 10:45:15 -0400 | [diff] [blame] | 114 | TelephonyIcons.QS_DATA_4G); |
Jason Monk | 3aaabd7 | 2014-12-12 11:11:44 -0500 | [diff] [blame] | 115 | } |
| 116 | |
Jason Monk | 67b2c16 | 2016-01-12 10:24:09 -0500 | [diff] [blame^] | 117 | public void testDataChangeWithoutConnectionState() { |
| 118 | setupDefaultSignal(); |
| 119 | updateDataConnectionState(TelephonyManager.DATA_CONNECTED, |
| 120 | TelephonyManager.NETWORK_TYPE_LTE); |
| 121 | |
| 122 | verifyDataIndicators(TelephonyIcons.DATA_LTE[1][0 /* No direction */], |
| 123 | TelephonyIcons.QS_DATA_LTE); |
| 124 | |
| 125 | Mockito.when(mServiceState.getDataNetworkType()) |
| 126 | .thenReturn(TelephonyManager.NETWORK_TYPE_HSPA); |
| 127 | updateServiceState(); |
| 128 | verifyDataIndicators(TelephonyIcons.DATA_H[1][0 /* No direction */], |
| 129 | TelephonyIcons.QS_DATA_H); |
| 130 | } |
| 131 | |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 132 | public void testDataActivity() { |
| 133 | setupDefaultSignal(); |
| 134 | |
| 135 | testDataActivity(TelephonyManager.DATA_ACTIVITY_NONE, false, false); |
| 136 | testDataActivity(TelephonyManager.DATA_ACTIVITY_IN, true, false); |
| 137 | testDataActivity(TelephonyManager.DATA_ACTIVITY_OUT, false, true); |
| 138 | testDataActivity(TelephonyManager.DATA_ACTIVITY_INOUT, true, true); |
| 139 | } |
| 140 | |
| 141 | private void testDataActivity(int direction, boolean in, boolean out) { |
| 142 | updateDataActivity(direction); |
| 143 | |
| 144 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, DEFAULT_ICON); |
| 145 | verifyLastQsMobileDataIndicators(true, DEFAULT_QS_SIGNAL_STRENGTH, |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 146 | DEFAULT_QS_ICON, in, out); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 147 | |
| 148 | } |
| 149 | |
| 150 | private void verifyDataIndicators(int dataIcon, int qsDataIcon) { |
| 151 | verifyLastMobileDataIndicators(true, DEFAULT_SIGNAL_STRENGTH, dataIcon); |
| 152 | verifyLastQsMobileDataIndicators(true, DEFAULT_QS_SIGNAL_STRENGTH, qsDataIcon, false, |
Jason Monk | b574627 | 2014-11-12 16:50:31 -0500 | [diff] [blame] | 153 | false); |
Jason Monk | f13b4b3 | 2014-11-07 16:39:34 -0500 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | } |