diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2017-07-28 02:46:58 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-07-28 02:46:58 +0000 |
commit | 3673d53dea03d18e5b28ce248b9911f81e3f8638 (patch) | |
tree | eac84cc94f5d9f1327cd797476f09ebf88eb9e6a | |
parent | cbd123b9385eb4319676567051d92947fc911d78 (diff) | |
parent | b7f35c58029fe5dce64813271ad4e8b1b6ea8893 (diff) |
Merge "wifi(framework): Modify the SAR power levels interface" into oc-dr1-dev
5 files changed, 144 insertions, 97 deletions
diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index c0ec8b76d..973b659d2 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -1684,24 +1684,21 @@ public class WifiNative { } /** - * Set the TX power limit. - * Primarily used for meeting SAR requirements during voice calls. - * - * @param powerLevelInDbm Power level to set in dBm. - * @return true for success; false for failure or if the HAL version does not support this API. + * Tx power level scenarios that can be selected. */ - public boolean setTxPowerLimit(int powerLevelInDbm) { - return mWifiVendorHal.setTxPowerLimit(powerLevelInDbm); - } + public static final int TX_POWER_SCENARIO_NORMAL = 0; + public static final int TX_POWER_SCENARIO_VOICE_CALL = 1; /** - * Reset the TX power limit. + * Select one of the pre-configured TX power level scenarios or reset it back to normal. * Primarily used for meeting SAR requirements during voice calls. * + * @param scenario Should be one {@link #TX_POWER_SCENARIO_NORMAL} or + * {@link #TX_POWER_SCENARIO_VOICE_CALL}. * @return true for success; false for failure or if the HAL version does not support this API. */ - public boolean resetTxPowerLimit() { - return mWifiVendorHal.resetTxPowerLimit(); + public boolean selectTxPowerScenario(int scenario) { + return mWifiVendorHal.selectTxPowerScenario(scenario); } /******************************************************** diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index 33d8a14e5..e4abc96bb 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -733,10 +733,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss private static final int CMD_DIAGS_CONNECT_TIMEOUT = BASE + 252; /* Used to set the tx power limit for SAR during the start of a phone call. */ - private static final int CMD_SET_SAR_TX_POWER_LIMIT = BASE + 253; - - /* Used to reset the tx power limit for SAR at end of a phone call. */ - private static final int CMD_RESET_SAR_TX_POWER_LIMIT = BASE + 254; + private static final int CMD_SELECT_TX_POWER_SCENARIO = BASE + 253; // For message logging. private static final Class[] sMessageClasses = { @@ -804,7 +801,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss private final boolean mEnableChipWakeUpWhenAssociated; private final boolean mEnableRssiPollWhenAssociated; private final boolean mEnableVoiceCallSarTxPowerLimit; - private final int mVoiceCallSarTxPowerLimitInDbm; int mRunningBeaconCount = 0; @@ -1051,8 +1047,6 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss R.bool.config_wifi_enable_disconnection_debounce); mEnableVoiceCallSarTxPowerLimit = mContext.getResources().getBoolean( R.bool.config_wifi_framework_enable_voice_call_sar_tx_power_limit); - mVoiceCallSarTxPowerLimitInDbm = mContext.getResources().getInteger( - R.integer.config_wifi_framework_voice_call_sar_tx_power_limit_in_dbm); mEnableChipWakeUpWhenAssociated = true; mEnableRssiPollWhenAssociated = true; @@ -3782,9 +3776,11 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss public void onCallStateChanged(int state, String incomingNumber) { if (mEnableVoiceCallSarTxPowerLimit) { if (state == CALL_STATE_OFFHOOK) { - sendMessage(CMD_SET_SAR_TX_POWER_LIMIT, mVoiceCallSarTxPowerLimitInDbm); + sendMessage(CMD_SELECT_TX_POWER_SCENARIO, + WifiNative.TX_POWER_SCENARIO_VOICE_CALL); } else if (state == CALL_STATE_IDLE) { - sendMessage(CMD_RESET_SAR_TX_POWER_LIMIT); + sendMessage(CMD_SELECT_TX_POWER_SCENARIO, + WifiNative.TX_POWER_SCENARIO_NORMAL); } } } @@ -3942,8 +3938,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss case CMD_ROAM_WATCHDOG_TIMER: case CMD_DISABLE_P2P_WATCHDOG_TIMER: case CMD_DISABLE_EPHEMERAL_NETWORK: - case CMD_SET_SAR_TX_POWER_LIMIT: - case CMD_RESET_SAR_TX_POWER_LIMIT: + case CMD_SELECT_TX_POWER_SCENARIO: messageHandlingStatus = MESSAGE_HANDLING_STATUS_DISCARD; break; case CMD_SET_SUSPEND_OPT_ENABLED: @@ -4336,9 +4331,11 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss // appropriately. if (mEnableVoiceCallSarTxPowerLimit) { if (getTelephonyManager().isOffhook()) { - sendMessage(CMD_SET_SAR_TX_POWER_LIMIT, mVoiceCallSarTxPowerLimitInDbm); - } else if (getTelephonyManager().isIdle()) { - sendMessage(CMD_RESET_SAR_TX_POWER_LIMIT); + sendMessage(CMD_SELECT_TX_POWER_SCENARIO, + WifiNative.TX_POWER_SCENARIO_VOICE_CALL); + } else { + sendMessage(CMD_SELECT_TX_POWER_SCENARIO, + WifiNative.TX_POWER_SCENARIO_NORMAL); } } @@ -4523,17 +4520,11 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss mWifiConnectivityManager.forceConnectivityScan(); } break; - case CMD_SET_SAR_TX_POWER_LIMIT: - int txPowerLevelInDbm = message.arg1; - logd("Setting Tx power limit to " + txPowerLevelInDbm); - if (!mWifiNative.setTxPowerLimit(txPowerLevelInDbm)) { - loge("Failed to set TX power limit"); - } - break; - case CMD_RESET_SAR_TX_POWER_LIMIT: - logd("Resetting Tx power limit"); - if (!mWifiNative.resetTxPowerLimit()) { - loge("Failed to reset TX power limit"); + case CMD_SELECT_TX_POWER_SCENARIO: + int txPowerScenario = message.arg1; + logd("Setting Tx power scenario to " + txPowerScenario); + if (!mWifiNative.selectTxPowerScenario(txPowerScenario)) { + loge("Failed to set TX power scenario"); } break; default: diff --git a/service/java/com/android/server/wifi/WifiVendorHal.java b/service/java/com/android/server/wifi/WifiVendorHal.java index b434f519e..12674aa27 100644 --- a/service/java/com/android/server/wifi/WifiVendorHal.java +++ b/service/java/com/android/server/wifi/WifiVendorHal.java @@ -2370,40 +2370,42 @@ public class WifiVendorHal { return android.hardware.wifi.V1_1.IWifiChip.castFrom(mIWifiChip); } - /** - * Set the TX power limit. - * Primarily used for meeting SAR requirements during voice calls. - * - * @param powerLevelInDbm Power level to set in dBm. - * @return true for success; false for failure or if the HAL version does not support this API. - */ - public boolean setTxPowerLimit(int powerLevelInDbm) { - synchronized (sLock) { - try { - android.hardware.wifi.V1_1.IWifiChip iWifiChipV11 = getWifiChipForV1_1Mockable(); - if (iWifiChipV11 == null) return boolResult(false); - WifiStatus status = iWifiChipV11.setTxPowerLimit(powerLevelInDbm); - if (!ok(status)) return false; - } catch (RemoteException e) { - handleRemoteException(e); - return false; - } - return true; + private int frameworkToHalTxPowerScenario(int scenario) { + switch (scenario) { + case WifiNative.TX_POWER_SCENARIO_VOICE_CALL: + return android.hardware.wifi.V1_1.IWifiChip.TxPowerScenario.VOICE_CALL; + default: + throw new IllegalArgumentException("bad scenario: " + scenario); } } /** - * Reset the TX power limit. + * Select one of the pre-configured TX power level scenarios or reset it back to normal. * Primarily used for meeting SAR requirements during voice calls. * + * @param scenario Should be one {@link WifiNative#TX_POWER_SCENARIO_NORMAL} or + * {@link WifiNative#TX_POWER_SCENARIO_VOICE_CALL}. * @return true for success; false for failure or if the HAL version does not support this API. */ - public boolean resetTxPowerLimit() { + public boolean selectTxPowerScenario(int scenario) { synchronized (sLock) { try { android.hardware.wifi.V1_1.IWifiChip iWifiChipV11 = getWifiChipForV1_1Mockable(); if (iWifiChipV11 == null) return boolResult(false); - WifiStatus status = iWifiChipV11.resetTxPowerLimit(); + WifiStatus status; + if (scenario != WifiNative.TX_POWER_SCENARIO_NORMAL) { + int halScenario; + try { + halScenario = frameworkToHalTxPowerScenario(scenario); + } catch (IllegalArgumentException e) { + mLog.err("Illegal argument for select tx power scenario") + .c(e.toString()).flush(); + return false; + } + status = iWifiChipV11.selectTxPowerScenario(halScenario); + } else { + status = iWifiChipV11.resetTxPowerScenario(); + } if (!ok(status)) return false; } catch (RemoteException e) { handleRemoteException(e); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java index 10d6460ab..427d700b1 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -1902,7 +1902,7 @@ public class WifiStateMachineTest { * setting/resetting Tx power limit. */ @Test - public void testVoiceCallSar_disabledTxPowerLimit_WifiOn() throws Exception { + public void testVoiceCallSar_disabledTxPowerScenario_WifiOn() throws Exception { loadComponentsInStaMode(); mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE); assertEquals(WifiStateMachine.CONNECT_MODE, mWsm.getOperationalModeForTest()); @@ -1915,7 +1915,7 @@ public class WifiStateMachineTest { * setting/resetting Tx power limit. */ @Test - public void testVoiceCallSar_enabledTxPowerLimit_WifiOn() throws Exception { + public void testVoiceCallSar_enabledTxPowerScenario_WifiOn() throws Exception { mResources.setBoolean( R.bool.config_wifi_framework_enable_voice_call_sar_tx_power_limit, true); initializeWsm(); @@ -1933,16 +1933,13 @@ public class WifiStateMachineTest { * {@link TelephonyManager#CALL_STATE_OFFHOOK}. */ @Test - public void testVoiceCallSar_enabledTxPowerLimitCallStateOffHook_WhenWifiTurnedOn() + public void testVoiceCallSar_enabledTxPowerScenarioCallStateOffHook_WhenWifiTurnedOn() throws Exception { - int powerLevelInDbm = -45; - mResources.setInteger( - R.integer.config_wifi_framework_voice_call_sar_tx_power_limit_in_dbm, - powerLevelInDbm); mResources.setBoolean( R.bool.config_wifi_framework_enable_voice_call_sar_tx_power_limit, true); initializeWsm(); + when(mWifiNative.selectTxPowerScenario(anyInt())).thenReturn(true); when(mTelephonyManager.isOffhook()).thenReturn(true); loadComponentsInStaMode(); @@ -1950,7 +1947,7 @@ public class WifiStateMachineTest { assertEquals(WifiStateMachine.CONNECT_MODE, mWsm.getOperationalModeForTest()); assertEquals("DisconnectedState", getCurrentState().getName()); assertNotNull(mPhoneStateListener); - verify(mWifiNative).setTxPowerLimit(eq(powerLevelInDbm)); + verify(mWifiNative).selectTxPowerScenario(eq(WifiNative.TX_POWER_SCENARIO_VOICE_CALL)); } /** @@ -1959,12 +1956,13 @@ public class WifiStateMachineTest { * {@link TelephonyManager#CALL_STATE_IDLE}. */ @Test - public void testVoiceCallSar_enabledTxPowerLimitCallStateIdle_WhenWifiTurnedOn() + public void testVoiceCallSar_enabledTxPowerScenarioCallStateIdle_WhenWifiTurnedOn() throws Exception { mResources.setBoolean( R.bool.config_wifi_framework_enable_voice_call_sar_tx_power_limit, true); initializeWsm(); + when(mWifiNative.selectTxPowerScenario(anyInt())).thenReturn(true); when(mTelephonyManager.isIdle()).thenReturn(true); loadComponentsInStaMode(); @@ -1972,7 +1970,30 @@ public class WifiStateMachineTest { assertEquals(WifiStateMachine.CONNECT_MODE, mWsm.getOperationalModeForTest()); assertEquals("DisconnectedState", getCurrentState().getName()); assertNotNull(mPhoneStateListener); - verify(mWifiNative).resetTxPowerLimit(); + } + + /** + * Test that we do register the telephony call state listener on devices which do support + * setting/resetting Tx power limit and set the tx power level if we're in state + * {@link TelephonyManager#CALL_STATE_OFFHOOK}. This test checks if the + * {@link WifiNative#selectTxPowerScenario(int)} failure is handled correctly. + */ + @Test + public void testVoiceCallSar_enabledTxPowerScenarioCallStateOffHook_WhenWifiTurnedOn_Fails() + throws Exception { + mResources.setBoolean( + R.bool.config_wifi_framework_enable_voice_call_sar_tx_power_limit, true); + initializeWsm(); + + when(mWifiNative.selectTxPowerScenario(anyInt())).thenReturn(false); + when(mTelephonyManager.isOffhook()).thenReturn(true); + + loadComponentsInStaMode(); + mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE); + assertEquals(WifiStateMachine.CONNECT_MODE, mWsm.getOperationalModeForTest()); + assertEquals("DisconnectedState", getCurrentState().getName()); + assertNotNull(mPhoneStateListener); + verify(mWifiNative).selectTxPowerScenario(eq(WifiNative.TX_POWER_SCENARIO_VOICE_CALL)); } /** @@ -1981,16 +2002,14 @@ public class WifiStateMachineTest { * {@link TelephonyManager#CALL_STATE_OFFHOOK}. */ @Test - public void testVoiceCallSar_enabledTxPowerLimitCallStateOffHook_WhenWifiOn() throws Exception { - int powerLevelInDbm = -45; - mResources.setInteger( - R.integer.config_wifi_framework_voice_call_sar_tx_power_limit_in_dbm, - powerLevelInDbm); - testVoiceCallSar_enabledTxPowerLimit_WifiOn(); + public void testVoiceCallSar_enabledTxPowerScenarioCallStateOffHook_WhenWifiOn() + throws Exception { + when(mWifiNative.selectTxPowerScenario(anyInt())).thenReturn(true); + testVoiceCallSar_enabledTxPowerScenario_WifiOn(); mPhoneStateListener.onCallStateChanged(TelephonyManager.CALL_STATE_OFFHOOK, ""); mLooper.dispatchAll(); - verify(mWifiNative).setTxPowerLimit(eq(powerLevelInDbm)); + verify(mWifiNative).selectTxPowerScenario(eq(WifiNative.TX_POWER_SCENARIO_VOICE_CALL)); } /** @@ -1999,12 +2018,31 @@ public class WifiStateMachineTest { * {@link TelephonyManager#CALL_STATE_IDLE}. */ @Test - public void testVoiceCallSar_enabledTxPowerLimitCallStateIdle_WhenWifiOn() throws Exception { - testVoiceCallSar_enabledTxPowerLimit_WifiOn(); + public void testVoiceCallSar_enabledTxPowerScenarioCallStateIdle_WhenWifiOn() throws Exception { + when(mWifiNative.selectTxPowerScenario(anyInt())).thenReturn(true); + testVoiceCallSar_enabledTxPowerScenario_WifiOn(); mPhoneStateListener.onCallStateChanged(TelephonyManager.CALL_STATE_IDLE, ""); mLooper.dispatchAll(); - verify(mWifiNative).resetTxPowerLimit(); + verify(mWifiNative, atLeastOnce()) + .selectTxPowerScenario(eq(WifiNative.TX_POWER_SCENARIO_NORMAL)); + } + + /** + * Test that we invoke the corresponding WifiNative method when + * {@link PhoneStateListener#onCallStateChanged(int, String)} is invoked with state + * {@link TelephonyManager#CALL_STATE_OFFHOOK}. This test checks if the + * {@link WifiNative#selectTxPowerScenario(int)} failure is handled correctly. + */ + @Test + public void testVoiceCallSar_enabledTxPowerScenarioCallStateOffHook_WhenWifiOn_Fails() + throws Exception { + when(mWifiNative.selectTxPowerScenario(anyInt())).thenReturn(false); + testVoiceCallSar_enabledTxPowerScenario_WifiOn(); + + mPhoneStateListener.onCallStateChanged(TelephonyManager.CALL_STATE_OFFHOOK, ""); + mLooper.dispatchAll(); + verify(mWifiNative).selectTxPowerScenario(eq(WifiNative.TX_POWER_SCENARIO_VOICE_CALL)); } /** @@ -2014,18 +2052,18 @@ public class WifiStateMachineTest { * wifi is off (state machine is not in SupplicantStarted state). */ @Test - public void testVoiceCallSar_enabledTxPowerLimitCallState_WhenWifiOff() throws Exception { + public void testVoiceCallSar_enabledTxPowerScenarioCallState_WhenWifiOff() throws Exception { mResources.setBoolean( R.bool.config_wifi_framework_enable_voice_call_sar_tx_power_limit, true); initializeWsm(); mPhoneStateListener.onCallStateChanged(TelephonyManager.CALL_STATE_OFFHOOK, ""); mLooper.dispatchAll(); - verify(mWifiNative, never()).setTxPowerLimit(anyInt()); + verify(mWifiNative, never()).selectTxPowerScenario(anyInt()); mPhoneStateListener.onCallStateChanged(TelephonyManager.CALL_STATE_IDLE, ""); mLooper.dispatchAll(); - verify(mWifiNative, never()).resetTxPowerLimit(); + verify(mWifiNative, never()).selectTxPowerScenario(anyInt()); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java index 3f2f389c5..84de9d227 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java @@ -1844,48 +1844,67 @@ public class WifiVendorHalTest { } /** - * Test the new setTxPowerLimit HIDL method invocation. This should return failure if the + * Test the new selectTxPowerScenario HIDL method invocation. This should return failure if the * HAL service is exposing the 1.0 interface. */ @Test - public void testSetTxPowerLimit() throws RemoteException { - int powerLevelInDbm = -45; - + public void testSelectTxPowerScenario() throws RemoteException { assertTrue(mWifiVendorHal.startVendorHal(true)); // Should fail because we exposed the 1.0 IWifiChip. - assertFalse(mWifiVendorHal.setTxPowerLimit(powerLevelInDbm)); - verify(mIWifiChipV11, never()).setTxPowerLimit(eq(powerLevelInDbm)); + assertFalse( + mWifiVendorHal.selectTxPowerScenario(WifiNative.TX_POWER_SCENARIO_VOICE_CALL)); + verify(mIWifiChipV11, never()).selectTxPowerScenario(anyInt()); mWifiVendorHal.stopVendorHal(); // Now expose the 1.1 IWifiChip. mWifiVendorHal = new WifiVendorHalSpyV1_1(mHalDeviceManager, mLooper.getLooper()); - when(mIWifiChipV11.setTxPowerLimit(anyInt())).thenReturn(mWifiStatusSuccess); + when(mIWifiChipV11.selectTxPowerScenario(anyInt())).thenReturn(mWifiStatusSuccess); assertTrue(mWifiVendorHal.startVendorHal(true)); - assertTrue(mWifiVendorHal.setTxPowerLimit(powerLevelInDbm)); - verify(mIWifiChipV11).setTxPowerLimit(eq(powerLevelInDbm)); + assertTrue( + mWifiVendorHal.selectTxPowerScenario(WifiNative.TX_POWER_SCENARIO_VOICE_CALL)); + verify(mIWifiChipV11).selectTxPowerScenario( + eq(android.hardware.wifi.V1_1.IWifiChip.TxPowerScenario.VOICE_CALL)); + verify(mIWifiChipV11, never()).resetTxPowerScenario(); mWifiVendorHal.stopVendorHal(); } /** - * Test the new setTxPowerLimit HIDL method invocation. This should return failure if the + * Test the new resetTxPowerScenario HIDL method invocation. This should return failure if the * HAL service is exposing the 1.0 interface. */ @Test - public void testResetTxPowerLimit() throws RemoteException { + public void testResetTxPowerScenario() throws RemoteException { assertTrue(mWifiVendorHal.startVendorHal(true)); // Should fail because we exposed the 1.0 IWifiChip. - assertFalse(mWifiVendorHal.resetTxPowerLimit()); - verify(mIWifiChipV11, never()).resetTxPowerLimit(); + assertFalse(mWifiVendorHal.selectTxPowerScenario(WifiNative.TX_POWER_SCENARIO_NORMAL)); + verify(mIWifiChipV11, never()).resetTxPowerScenario(); mWifiVendorHal.stopVendorHal(); // Now expose the 1.1 IWifiChip. mWifiVendorHal = new WifiVendorHalSpyV1_1(mHalDeviceManager, mLooper.getLooper()); - when(mIWifiChipV11.resetTxPowerLimit()).thenReturn(mWifiStatusSuccess); + when(mIWifiChipV11.resetTxPowerScenario()).thenReturn(mWifiStatusSuccess); + + assertTrue(mWifiVendorHal.startVendorHal(true)); + assertTrue(mWifiVendorHal.selectTxPowerScenario(WifiNative.TX_POWER_SCENARIO_NORMAL)); + verify(mIWifiChipV11).resetTxPowerScenario(); + verify(mIWifiChipV11, never()).selectTxPowerScenario(anyInt()); + mWifiVendorHal.stopVendorHal(); + } + + /** + * Test the new selectTxPowerScenario HIDL method invocation with a bad scenario index. + */ + @Test + public void testInvalidSelectTxPowerScenario() throws RemoteException { + // Expose the 1.1 IWifiChip. + mWifiVendorHal = new WifiVendorHalSpyV1_1(mHalDeviceManager, mLooper.getLooper()); + when(mIWifiChipV11.selectTxPowerScenario(anyInt())).thenReturn(mWifiStatusSuccess); assertTrue(mWifiVendorHal.startVendorHal(true)); - assertTrue(mWifiVendorHal.resetTxPowerLimit()); - verify(mIWifiChipV11).resetTxPowerLimit(); + assertFalse(mWifiVendorHal.selectTxPowerScenario(-6)); + verify(mIWifiChipV11, never()).selectTxPowerScenario(anyInt()); + verify(mIWifiChipV11, never()).resetTxPowerScenario(); mWifiVendorHal.stopVendorHal(); } |