diff options
author | Roshan Pius <rpius@google.com> | 2019-12-10 07:25:38 -0800 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2019-12-10 09:52:47 -0800 |
commit | 68d2f9f53e5eb7146a0fb46239109bce1b6c3cac (patch) | |
tree | 08b82e69c3a8ff319bb7492f2fb154e57ae22299 | |
parent | b55d1a801204295e9b979a2a358bf306190bf4e6 (diff) |
Wifi: Handle SystemService events in wifi service threads
Handling these SystemService calls synchronously blocks the
system_server bootup sequence. So, post the event to the
appropriate wifi thread for further processing.
Also, make ClientModeImpl.syncInitialize() non blocking. This does not
need to be blocking anymore since all of the init sequence events are
posted.
Bug: 145643629
Bug: 145923491
Test: Device boots up and connects to wifi networks.
Test: Verified that SystemServer timing for wifi is negligible now.
Change-Id: I9e703d6e78cdfe5bbc054eb9ac9437a1d9fcd9ad
9 files changed, 178 insertions, 145 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java index 304ad1b87..46d36758f 100644 --- a/service/java/com/android/server/wifi/ClientModeImpl.java +++ b/service/java/com/android/server/wifi/ClientModeImpl.java @@ -3103,8 +3103,7 @@ public class ClientModeImpl extends StateMachine { } break; case CMD_INITIALIZE: - ok = mWifiNative.initialize(); - replyToMessage(message, message.what, ok ? SUCCESS : FAILURE); + mWifiNative.initialize(); break; case CMD_BOOT_COMPLETED: // get other services that we need to manage @@ -5560,14 +5559,9 @@ public class ClientModeImpl extends StateMachine { /** * Sends a message to initialize the ClientModeImpl. - * - * @return true if succeeded, false otherwise. */ - public boolean syncInitialize(AsyncChannel channel) { - Message resultMsg = channel.sendMessageSynchronously(CMD_INITIALIZE); - boolean result = (resultMsg.arg1 != FAILURE); - resultMsg.recycle(); - return result; + public void initialize() { + sendMessage(CMD_INITIALIZE); } /** diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java index 165df13bc..43a200686 100644 --- a/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -310,75 +310,77 @@ public class WifiServiceImpl extends BaseWifiService { * This function is used only at boot time. */ public void checkAndStartWifi() { - // Check if wi-fi needs to be enabled - boolean wifiEnabled = mSettingsStore.isWifiToggleEnabled(); - Log.i(TAG, "WifiService starting up with Wi-Fi " + (wifiEnabled ? "enabled" : "disabled")); - - registerForScanModeChange(); - mContext.registerReceiver( - new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - if (mSettingsStore.handleAirplaneModeToggled()) { - mActiveModeWarden.airplaneModeToggled(); + mWifiThreadRunner.post(() -> { + // Check if wi-fi needs to be enabled + boolean wifiEnabled = mSettingsStore.isWifiToggleEnabled(); + Log.i(TAG, + "WifiService starting up with Wi-Fi " + (wifiEnabled ? "enabled" : "disabled")); + + registerForScanModeChange(); + mContext.registerReceiver( + new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (mSettingsStore.handleAirplaneModeToggled()) { + mActiveModeWarden.airplaneModeToggled(); + } } - } - }, - new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED)); - - mContext.registerReceiver( - new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - String state = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE); - if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(state)) { - Log.d(TAG, "resetting networks because SIM was removed"); - mClientModeImpl.resetSimAuthNetworks(false); - } else if (IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(state)) { - Log.d(TAG, "resetting networks because SIM was loaded"); - mClientModeImpl.resetSimAuthNetworks(true); + }, + new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED)); + + mContext.registerReceiver( + new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String state = intent.getStringExtra( + IccCardConstants.INTENT_KEY_ICC_STATE); + if (IccCardConstants.INTENT_VALUE_ICC_ABSENT.equals(state)) { + Log.d(TAG, "resetting networks because SIM was removed"); + mClientModeImpl.resetSimAuthNetworks(false); + } else if (IccCardConstants.INTENT_VALUE_ICC_LOADED.equals(state)) { + Log.d(TAG, "resetting networks because SIM was loaded"); + mClientModeImpl.resetSimAuthNetworks(true); + } } - } - }, - new IntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED)); + }, + new IntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED)); - // Adding optimizations of only receiving broadcasts when wifi is enabled - // can result in race conditions when apps toggle wifi in the background - // without active user involvement. Always receive broadcasts. - registerForBroadcasts(); - mInIdleMode = mPowerManager.isDeviceIdleMode(); + // Adding optimizations of only receiving broadcasts when wifi is enabled + // can result in race conditions when apps toggle wifi in the background + // without active user involvement. Always receive broadcasts. + registerForBroadcasts(); + mInIdleMode = mPowerManager.isDeviceIdleMode(); - if (!mClientModeImpl.syncInitialize(mClientModeImplChannel)) { - Log.wtf(TAG, "Failed to initialize ClientModeImpl"); - } - mActiveModeWarden.start(); + mClientModeImpl.initialize(); + mActiveModeWarden.start(); + }); } public void handleBootCompleted() { - Log.d(TAG, "Handle boot completed"); - - // Register for system broadcasts. - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction(Intent.ACTION_USER_REMOVED); - intentFilter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED); - intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED); - intentFilter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); - boolean trackEmergencyCallState = mContext.getResources().getBoolean( - R.bool.config_wifi_turn_off_during_emergency_call); - if (trackEmergencyCallState) { - intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALL_STATE_CHANGED); - } - mContext.registerReceiver(mReceiver, intentFilter); - mWifiThreadRunner.post(() -> { + Log.d(TAG, "Handle boot completed"); + + // Register for system broadcasts. + IntentFilter intentFilter = new IntentFilter(); + intentFilter.addAction(Intent.ACTION_USER_REMOVED); + intentFilter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED); + intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED); + intentFilter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); + boolean trackEmergencyCallState = mContext.getResources().getBoolean( + R.bool.config_wifi_turn_off_during_emergency_call); + if (trackEmergencyCallState) { + intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALL_STATE_CHANGED); + } + mContext.registerReceiver(mReceiver, intentFilter); + new MemoryStoreImpl(mContext, mWifiInjector, mWifiInjector.getWifiScoreCard()).start(); if (!mWifiConfigManager.loadFromStore()) { Log.e(TAG, "Failed to load from config store"); } mPasspointManager.initializeProvisioner( mWifiInjector.getPasspointProvisionerHandlerThread().getLooper()); + mClientModeImpl.handleBootCompleted(); }); - mClientModeImpl.handleBootCompleted(); } public void handleUserSwitch(int userId) { diff --git a/service/java/com/android/server/wifi/aware/WifiAwareServiceImpl.java b/service/java/com/android/server/wifi/aware/WifiAwareServiceImpl.java index fbfa50ce0..623846fae 100644 --- a/service/java/com/android/server/wifi/aware/WifiAwareServiceImpl.java +++ b/service/java/com/android/server/wifi/aware/WifiAwareServiceImpl.java @@ -69,6 +69,7 @@ public class WifiAwareServiceImpl extends IWifiAwareManager.Stub { private WifiPermissionsUtil mWifiPermissionsUtil; private WifiAwareStateManager mStateManager; private WifiAwareShellCommand mShellCommand; + private Handler mHandler; private final Object mLock = new Object(); private final SparseArray<IBinder.DeathRecipient> mDeathRecipientsByClientId = @@ -104,23 +105,28 @@ public class WifiAwareServiceImpl extends IWifiAwareManager.Stub { mWifiPermissionsUtil = wifiPermissionsUtil; mStateManager = awareStateManager; mShellCommand = awareShellCommand; - mStateManager.start(mContext, handlerThread.getLooper(), awareMetrics, wifiPermissionsUtil, - permissionsWrapper, new Clock()); - - frameworkFacade.registerContentObserver(mContext, - Settings.Global.getUriFor(Settings.Global.WIFI_VERBOSE_LOGGING_ENABLED), true, - new ContentObserver(new Handler(handlerThread.getLooper())) { - @Override - public void onChange(boolean selfChange) { - enableVerboseLogging(frameworkFacade.getIntegerSetting(mContext, - Settings.Global.WIFI_VERBOSE_LOGGING_ENABLED, 0), awareStateManager, - wifiAwareNativeManager, wifiAwareNativeApi, - wifiAwareNativeCallback); - } - }); - enableVerboseLogging(frameworkFacade.getIntegerSetting(mContext, - Settings.Global.WIFI_VERBOSE_LOGGING_ENABLED, 0), awareStateManager, - wifiAwareNativeManager, wifiAwareNativeApi, wifiAwareNativeCallback); + mHandler = new Handler(handlerThread.getLooper()); + + mHandler.post(() -> { + mStateManager.start(mContext, handlerThread.getLooper(), awareMetrics, + wifiPermissionsUtil, permissionsWrapper, new Clock()); + + frameworkFacade.registerContentObserver(mContext, + Settings.Global.getUriFor(Settings.Global.WIFI_VERBOSE_LOGGING_ENABLED), true, + new ContentObserver(new Handler(handlerThread.getLooper())) { + @Override + public void onChange(boolean selfChange) { + enableVerboseLogging(frameworkFacade.getIntegerSetting(mContext, + Settings.Global.WIFI_VERBOSE_LOGGING_ENABLED, 0), + awareStateManager, + wifiAwareNativeManager, wifiAwareNativeApi, + wifiAwareNativeCallback); + } + }); + enableVerboseLogging(frameworkFacade.getIntegerSetting(mContext, + Settings.Global.WIFI_VERBOSE_LOGGING_ENABLED, 0), awareStateManager, + wifiAwareNativeManager, wifiAwareNativeApi, wifiAwareNativeCallback); + }); } private void enableVerboseLogging(int verbose, WifiAwareStateManager awareStateManager, @@ -154,7 +160,7 @@ public class WifiAwareServiceImpl extends IWifiAwareManager.Stub { public void startLate() { Log.i(TAG, "Late initialization of Wi-Fi Aware service"); - mStateManager.startLate(); + mHandler.post(() -> mStateManager.startLate()); } @Override diff --git a/service/java/com/android/server/wifi/rtt/RttServiceImpl.java b/service/java/com/android/server/wifi/rtt/RttServiceImpl.java index 6e35eb5ad..659553656 100644 --- a/service/java/com/android/server/wifi/rtt/RttServiceImpl.java +++ b/service/java/com/android/server/wifi/rtt/RttServiceImpl.java @@ -250,67 +250,67 @@ public class RttServiceImpl extends IWifiRttManager.Stub { mRttMetrics = rttMetrics; mWifiPermissionsUtil = wifiPermissionsUtil; mRttServiceSynchronized = new RttServiceSynchronized(looper, rttNative); - mActivityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); mPowerManager = mContext.getSystemService(PowerManager.class); - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); - mContext.registerReceiver(new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); - if (mDbg) Log.v(TAG, "BroadcastReceiver: action=" + action); - if (PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED.equals(action)) { - if (mPowerManager.isDeviceIdleMode()) { - disable(); - } else { - enableIfPossible(); + mRttServiceSynchronized.mHandler.post(() -> { + IntentFilter intentFilter = new IntentFilter(); + intentFilter.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); + mContext.registerReceiver(new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (mDbg) Log.v(TAG, "BroadcastReceiver: action=" + action); + + if (PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED.equals(action)) { + if (mPowerManager.isDeviceIdleMode()) { + disable(); + } else { + enableIfPossible(); + } } } - } - }, intentFilter); - - frameworkFacade.registerContentObserver(mContext, - Settings.Global.getUriFor(Settings.Global.WIFI_VERBOSE_LOGGING_ENABLED), true, - new ContentObserver(mRttServiceSynchronized.mHandler) { - @Override - public void onChange(boolean selfChange) { - enableVerboseLogging(frameworkFacade.getIntegerSetting(mContext, - Settings.Global.WIFI_VERBOSE_LOGGING_ENABLED, 0)); - } - }); + }, intentFilter); - enableVerboseLogging(frameworkFacade.getIntegerSetting(mContext, - Settings.Global.WIFI_VERBOSE_LOGGING_ENABLED, 0)); + frameworkFacade.registerContentObserver(mContext, + Settings.Global.getUriFor(Settings.Global.WIFI_VERBOSE_LOGGING_ENABLED), true, + new ContentObserver(mRttServiceSynchronized.mHandler) { + @Override + public void onChange(boolean selfChange) { + enableVerboseLogging(frameworkFacade.getIntegerSetting(mContext, + Settings.Global.WIFI_VERBOSE_LOGGING_ENABLED, 0)); + } + }); - frameworkFacade.registerContentObserver(mContext, - Settings.Global.getUriFor(Settings.Global.WIFI_RTT_BACKGROUND_EXEC_GAP_MS), - true, - new ContentObserver(mRttServiceSynchronized.mHandler) { - @Override - public void onChange(boolean selfChange) { - updateBackgroundThrottlingInterval(frameworkFacade); - } - }); + enableVerboseLogging(frameworkFacade.getIntegerSetting(mContext, + Settings.Global.WIFI_VERBOSE_LOGGING_ENABLED, 0)); - updateBackgroundThrottlingInterval(frameworkFacade); + frameworkFacade.registerContentObserver(mContext, + Settings.Global.getUriFor(Settings.Global.WIFI_RTT_BACKGROUND_EXEC_GAP_MS), + true, + new ContentObserver(mRttServiceSynchronized.mHandler) { + @Override + public void onChange(boolean selfChange) { + updateBackgroundThrottlingInterval(frameworkFacade); + } + }); - intentFilter = new IntentFilter(); - intentFilter.addAction(LocationManager.MODE_CHANGED_ACTION); - mContext.registerReceiver(new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - if (mDbg) Log.v(TAG, "onReceive: MODE_CHANGED_ACTION: intent=" + intent); - if (mWifiPermissionsUtil.isLocationModeEnabled()) { - enableIfPossible(); - } else { - disable(); + updateBackgroundThrottlingInterval(frameworkFacade); + + intentFilter = new IntentFilter(); + intentFilter.addAction(LocationManager.MODE_CHANGED_ACTION); + mContext.registerReceiver(new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + if (mDbg) Log.v(TAG, "onReceive: MODE_CHANGED_ACTION: intent=" + intent); + if (mWifiPermissionsUtil.isLocationModeEnabled()) { + enableIfPossible(); + } else { + disable(); + } } - } - }, intentFilter); + }, intentFilter); - mRttServiceSynchronized.mHandler.post(() -> { rttNative.start(mRttServiceSynchronized.mHandler); }); } diff --git a/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java b/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java index f6345ec12..bc727591e 100644 --- a/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java +++ b/service/java/com/android/server/wifi/scanner/WifiScanningServiceImpl.java @@ -36,6 +36,7 @@ import android.os.BadParcelableException; import android.os.BatteryStatsManager; import android.os.Binder; import android.os.Bundle; +import android.os.Handler; import android.os.Looper; import android.os.Message; import android.os.Messenger; @@ -404,16 +405,18 @@ public class WifiScanningServiceImpl extends IWifiScanner.Stub { } public void startService() { - mBackgroundScanStateMachine = new WifiBackgroundScanStateMachine(mLooper); - mSingleScanStateMachine = new WifiSingleScanStateMachine(mLooper); - mPnoScanStateMachine = new WifiPnoScanStateMachine(mLooper); - - mBackgroundScanStateMachine.start(); - mSingleScanStateMachine.start(); - mPnoScanStateMachine.start(); - - // Create client handler only after StateMachines are ready. - mClientHandler = new ClientHandler(TAG, mLooper); + new Handler(mLooper).post(() -> { + mBackgroundScanStateMachine = new WifiBackgroundScanStateMachine(mLooper); + mSingleScanStateMachine = new WifiSingleScanStateMachine(mLooper); + mPnoScanStateMachine = new WifiPnoScanStateMachine(mLooper); + + mBackgroundScanStateMachine.start(); + mSingleScanStateMachine.start(); + mPnoScanStateMachine.start(); + + // Create client handler only after StateMachines are ready. + mClientHandler = new ClientHandler(TAG, mLooper); + }); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java index c21d4332a..19496a7b7 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java @@ -568,9 +568,8 @@ public class ClientModeImplTest extends WifiBaseTest { mConfigUpdateListenerCaptor.capture()); assertNotNull(mConfigUpdateListenerCaptor.getValue()); - mLooper.startAutoDispatch(); - mCmi.syncInitialize(mCmiAsyncChannel); - mLooper.stopAutoDispatch(); + mCmi.initialize(); + mLooper.dispatchAll(); } @After diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index e08038d88..0273211c7 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -303,7 +303,6 @@ public class WifiServiceImplTest extends WifiBaseTest { when(mWifiInjector.getWifiCountryCode()).thenReturn(mWifiCountryCode); when(mWifiInjector.getWifiMetrics()).thenReturn(mWifiMetrics); when(mWifiInjector.getClientModeImpl()).thenReturn(mClientModeImpl); - when(mClientModeImpl.syncInitialize(any())).thenReturn(true); when(mClientModeImpl.getHandler()).thenReturn(new Handler()); when(mWifiInjector.getActiveModeWarden()).thenReturn(mActiveModeWarden); when(mWifiInjector.getAsyncChannelHandlerThread()).thenReturn(mHandlerThread); @@ -758,6 +757,7 @@ public class WifiServiceImplTest extends WifiBaseTest { public void testSetWifiEnabledFromNetworkSettingsHolderWhenApEnabled() throws Exception { when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); + mLooper.dispatchAll(); verifyApRegistration(); mStateMachineSoftApCallback.onStateChanged(WIFI_AP_STATE_ENABLED, 0); @@ -782,6 +782,7 @@ public class WifiServiceImplTest extends WifiBaseTest { eq(Build.VERSION_CODES.Q), anyInt())).thenReturn(true); when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); + mLooper.dispatchAll(); verifyApRegistration(); mStateMachineSoftApCallback.onStateChanged(WIFI_AP_STATE_ENABLED, 0); @@ -1166,6 +1167,7 @@ public class WifiServiceImplTest extends WifiBaseTest { public void testWifiControllerStartsWhenDeviceBootsWithWifiDisabled() { when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); + mLooper.dispatchAll(); verify(mActiveModeWarden).start(); verify(mActiveModeWarden, never()).wifiToggled(); } @@ -1182,6 +1184,7 @@ public class WifiServiceImplTest extends WifiBaseTest { when(mContext.checkPermission(eq(android.Manifest.permission.NETWORK_SETTINGS), anyInt(), anyInt())).thenReturn(PackageManager.PERMISSION_GRANTED); mWifiServiceImpl.checkAndStartWifi(); + mLooper.dispatchAll(); verify(mActiveModeWarden).start(); } @@ -2376,6 +2379,7 @@ public class WifiServiceImplTest extends WifiBaseTest { public void testRegisteredCallbacksTriggeredOnSoftApFailureGeneric() throws Exception { when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); + mLooper.dispatchAll(); verifyApRegistration(); @@ -2394,6 +2398,7 @@ public class WifiServiceImplTest extends WifiBaseTest { public void testRegisteredCallbacksTriggeredOnSoftApFailureNoChannel() throws Exception { when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); + mLooper.dispatchAll(); verifyApRegistration(); @@ -2412,6 +2417,7 @@ public class WifiServiceImplTest extends WifiBaseTest { private void setupLocalOnlyHotspot() throws Exception { when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); + mLooper.dispatchAll(); verifyApRegistration(); @@ -2460,6 +2466,7 @@ public class WifiServiceImplTest extends WifiBaseTest { public void testRegisteredCallbacksNotTriggeredOnSoftApStart() throws Exception { when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); + mLooper.dispatchAll(); verifyApRegistration(); @@ -2510,6 +2517,7 @@ public class WifiServiceImplTest extends WifiBaseTest { public void testAllRegisteredCallbacksTriggeredWhenSoftApFails() throws Exception { when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); + mLooper.dispatchAll(); verifyApRegistration(); @@ -2535,6 +2543,7 @@ public class WifiServiceImplTest extends WifiBaseTest { public void testAllRegisteredCallbacksTriggeredWhenSoftApStops() throws Exception { when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); + mLooper.dispatchAll(); verifyApRegistration(); @@ -2567,6 +2576,7 @@ public class WifiServiceImplTest extends WifiBaseTest { public void testAllRegisteredCallbacksTriggeredWhenSoftApStopsLOHSNotActive() throws Exception { when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); + mLooper.dispatchAll(); verifyApRegistration(); @@ -2719,6 +2729,7 @@ public class WifiServiceImplTest extends WifiBaseTest { throws Exception { when(mSettingsStore.isWifiToggleEnabled()).thenReturn(false); mWifiServiceImpl.checkAndStartWifi(); + mLooper.dispatchAll(); verifyApRegistration(); // register a request so we don't drop the LOHS interface ip update @@ -3252,7 +3263,9 @@ public class WifiServiceImplTest extends WifiBaseTest { when(mWifiInjector.getPasspointProvisionerHandlerThread()) .thenReturn(mock(HandlerThread.class)); mWifiServiceImpl.checkAndStartWifi(); + mLooper.dispatchAll(); mWifiServiceImpl.handleBootCompleted(); + mLooper.dispatchAll(); verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(), (IntentFilter) argThat(new IdleModeIntentMatcher())); @@ -3336,6 +3349,7 @@ public class WifiServiceImplTest extends WifiBaseTest { @Test public void testPackageRemovedBroadcastHandling() { mWifiServiceImpl.checkAndStartWifi(); + mLooper.dispatchAll(); verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(), argThat((IntentFilter filter) -> filter.hasAction(Intent.ACTION_PACKAGE_FULLY_REMOVED))); @@ -3364,6 +3378,7 @@ public class WifiServiceImplTest extends WifiBaseTest { @Test public void testPackageRemovedBroadcastHandlingWithNoUid() { mWifiServiceImpl.checkAndStartWifi(); + mLooper.dispatchAll(); verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(), argThat((IntentFilter filter) -> filter.hasAction(Intent.ACTION_PACKAGE_FULLY_REMOVED))); @@ -3387,6 +3402,7 @@ public class WifiServiceImplTest extends WifiBaseTest { @Test public void testPackageRemovedBroadcastHandlingWithNoPackageName() { mWifiServiceImpl.checkAndStartWifi(); + mLooper.dispatchAll(); verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(), argThat((IntentFilter filter) -> filter.hasAction(Intent.ACTION_PACKAGE_FULLY_REMOVED))); @@ -3412,7 +3428,9 @@ public class WifiServiceImplTest extends WifiBaseTest { when(mWifiInjector.getPasspointProvisionerHandlerThread()) .thenReturn(mock(HandlerThread.class)); mWifiServiceImpl.checkAndStartWifi(); + mLooper.dispatchAll(); mWifiServiceImpl.handleBootCompleted(); + mLooper.dispatchAll(); verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(), argThat((IntentFilter filter) -> filter.hasAction(Intent.ACTION_USER_REMOVED))); @@ -3432,7 +3450,9 @@ public class WifiServiceImplTest extends WifiBaseTest { when(mWifiInjector.getPasspointProvisionerHandlerThread()) .thenReturn(mock(HandlerThread.class)); mWifiServiceImpl.checkAndStartWifi(); + mLooper.dispatchAll(); mWifiServiceImpl.handleBootCompleted(); + mLooper.dispatchAll(); verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(), argThat((IntentFilter filter) -> filter.hasAction(Intent.ACTION_USER_REMOVED))); @@ -3542,6 +3562,7 @@ public class WifiServiceImplTest extends WifiBaseTest { @Test public void testSimStateChangeDoesNotResetCountryCode() { mWifiServiceImpl.checkAndStartWifi(); + mLooper.dispatchAll(); verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(), (IntentFilter) argThat((IntentFilter filter) -> filter.hasAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED))); @@ -3560,6 +3581,7 @@ public class WifiServiceImplTest extends WifiBaseTest { @Test public void testEnterAirplaneModeNotResetCountryCode() { mWifiServiceImpl.checkAndStartWifi(); + mLooper.dispatchAll(); verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(), (IntentFilter) argThat((IntentFilter filter) -> filter.hasAction(Intent.ACTION_AIRPLANE_MODE_CHANGED))); diff --git a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareServiceImplTest.java index 1dd3ff8a7..90087d9b1 100644 --- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareServiceImplTest.java @@ -153,6 +153,7 @@ public class WifiAwareServiceImplTest extends WifiBaseTest { mAwareMetricsMock, mWifiPermissionsUtil, mPermissionsWrapperMock, mFrameworkFacade, mock(WifiAwareNativeManager.class), mock(WifiAwareNativeApi.class), mock(WifiAwareNativeCallback.class)); + mMockLooper.dispatchAll(); verify(mAwareStateManagerMock).start(eq(mContextMock), any(), eq(mAwareMetricsMock), eq(mWifiPermissionsUtil), eq(mPermissionsWrapperMock), any()); } diff --git a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java index 89b1e8bac..37fe00e03 100644 --- a/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java +++ b/tests/wifitests/src/com/android/server/wifi/scanner/WifiScanningServiceTest.java @@ -439,6 +439,7 @@ public class WifiScanningServiceTest extends WifiBaseTest { private static final int MAX_AP_PER_SCAN = 16; private void startServiceAndLoadDriver() { mWifiScanningServiceImpl.startService(); + mLooper.dispatchAll(); mWifiScanningServiceImpl.setWifiHandlerLogForTest(mLog); setupAndLoadDriver(TEST_MAX_SCAN_BUCKETS_IN_CAPABILITIES); } @@ -498,6 +499,7 @@ public class WifiScanningServiceTest extends WifiBaseTest { @Test public void startService() throws Exception { mWifiScanningServiceImpl.startService(); + mLooper.dispatchAll(); mWifiScanningServiceImpl.setWifiHandlerLogForTest(mLog); verifyNoMoreInteractions(mWifiScannerImplFactory); @@ -512,6 +514,7 @@ public class WifiScanningServiceTest extends WifiBaseTest { @Test public void disconnectClientBeforeWifiEnabled() throws Exception { mWifiScanningServiceImpl.startService(); + mLooper.dispatchAll(); mWifiScanningServiceImpl.setWifiHandlerLogForTest(mLog); BidirectionalAsyncChannel controlChannel = connectChannel(mock(Handler.class)); mLooper.dispatchAll(); @@ -558,6 +561,7 @@ public class WifiScanningServiceTest extends WifiBaseTest { @Test public void disconnectClientAfterStartingWifi() throws Exception { mWifiScanningServiceImpl.startService(); + mLooper.dispatchAll(); mWifiScanningServiceImpl.setWifiHandlerLogForTest(mLog); BidirectionalAsyncChannel controlChannel = connectChannel(mock(Handler.class)); mLooper.dispatchAll(); @@ -596,6 +600,7 @@ public class WifiScanningServiceTest extends WifiBaseTest { @Test public void rejectBackgroundScanRequestWhenHalReturnsInvalidCapabilities() throws Exception { mWifiScanningServiceImpl.startService(); + mLooper.dispatchAll(); mWifiScanningServiceImpl.setWifiHandlerLogForTest(mLog); setupAndLoadDriver(0); @@ -2633,6 +2638,7 @@ public class WifiScanningServiceTest extends WifiBaseTest { @Test public void rejectRestrictedMessagesFromNonPrivilegedApps() throws Exception { mWifiScanningServiceImpl.startService(); + mLooper.dispatchAll(); mWifiScanningServiceImpl.setWifiHandlerLogForTest(mLog); Handler handler = mock(Handler.class); BidirectionalAsyncChannel controlChannel = connectChannel(handler); |