diff options
author | Roshan Pius <rpius@google.com> | 2018-04-05 10:07:56 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2018-04-12 09:24:10 -0700 |
commit | 102b0edddadbd08d9e252ae87f873ce1bd84d138 (patch) | |
tree | eaa2ac756f0edacdcc99cb48020b5f404d38b9ab /tests | |
parent | 03b2a94a34ab39bc7d8a26824808d7b2e99ee650 (diff) |
WifiServiceImpl: Fix package removal broadcast handling
This has been broken since ag/616463.
Changes in the CL:
a) Move handling of USER_REMOVED to the existing global broadcast
listener in the class.
b) Listen for ACTION_PACKAGE_FULLY_REMOVED (which indicates complete app
removal from the device) using "package" as the data scheme.
Bug: 77588735
Test: Unit tests
Test: Manually verified with logs that both user removed & package
removed broadcasts are being received correctly in WifiServiceImpl.
Change-Id: I5480a145a9255a226dbaa614c906121d274b919c
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index 996363916..5e7b706d1 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -59,10 +59,12 @@ import android.app.AppOpsManager; import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.Context; +import android.content.Intent; import android.content.IntentFilter; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.Resources; +import android.net.Uri; import android.net.wifi.ISoftApCallback; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; @@ -133,6 +135,7 @@ public class WifiServiceImplTest { private static final int TEST_PID2 = 9876; private static final int TEST_UID = 1200000; private static final int OTHER_TEST_UID = 1300000; + private static final int TEST_USER_HANDLE = 13; private static final String WIFI_IFACE_NAME = "wlan0"; private static final String TEST_COUNTRY_CODE = "US"; @@ -2534,6 +2537,88 @@ public class WifiServiceImplTest { verify(mScanRequestProxy).startScan(Process.myUid(), SCAN_PACKAGE_NAME); } + @Test + public void testPackageRemovedBroadcastHandling() { + mWifiServiceImpl.checkAndStartWifi(); + verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(), + (IntentFilter) argThat((IntentFilter filter) -> + filter.hasAction(Intent.ACTION_PACKAGE_FULLY_REMOVED))); + + int uid = TEST_UID; + String packageName = TEST_PACKAGE_NAME; + // Send the broadcast + Intent intent = new Intent(Intent.ACTION_PACKAGE_FULLY_REMOVED); + intent.putExtra(Intent.EXTRA_UID, uid); + intent.setData(Uri.fromParts("package", packageName, "")); + mBroadcastReceiverCaptor.getValue().onReceive(mContext, intent); + + verify(mWifiStateMachine).removeAppConfigs(packageName, uid); + } + + @Test + public void testPackageRemovedBroadcastHandlingWithNoUid() { + mWifiServiceImpl.checkAndStartWifi(); + verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(), + (IntentFilter) argThat((IntentFilter filter) -> + filter.hasAction(Intent.ACTION_PACKAGE_FULLY_REMOVED))); + + String packageName = TEST_PACKAGE_NAME; + // Send the broadcast + Intent intent = new Intent(Intent.ACTION_PACKAGE_FULLY_REMOVED); + intent.setData(Uri.fromParts("package", packageName, "")); + mBroadcastReceiverCaptor.getValue().onReceive(mContext, intent); + + verify(mWifiStateMachine, never()).removeAppConfigs(anyString(), anyInt()); + } + + @Test + public void testPackageRemovedBroadcastHandlingWithNoPackageName() { + mWifiServiceImpl.checkAndStartWifi(); + verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(), + (IntentFilter) argThat((IntentFilter filter) -> + filter.hasAction(Intent.ACTION_PACKAGE_FULLY_REMOVED))); + + int uid = TEST_UID; + // Send the broadcast + Intent intent = new Intent(Intent.ACTION_PACKAGE_FULLY_REMOVED); + intent.putExtra(Intent.EXTRA_UID, uid); + mBroadcastReceiverCaptor.getValue().onReceive(mContext, intent); + + verify(mWifiStateMachine, never()).removeAppConfigs(anyString(), anyInt()); + } + + @Test + public void testUserRemovedBroadcastHandling() { + mWifiServiceImpl.checkAndStartWifi(); + verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(), + (IntentFilter) argThat((IntentFilter filter) -> + filter.hasAction(Intent.ACTION_USER_REMOVED))); + + int userHandle = TEST_USER_HANDLE; + // Send the broadcast + Intent intent = new Intent(Intent.ACTION_USER_REMOVED); + intent.putExtra(Intent.EXTRA_USER_HANDLE, userHandle); + mBroadcastReceiverCaptor.getValue().onReceive(mContext, intent); + + verify(mWifiStateMachine).removeUserConfigs(userHandle); + } + + @Test + public void testUserRemovedBroadcastHandlingWithWrongIntentAction() { + mWifiServiceImpl.checkAndStartWifi(); + verify(mContext).registerReceiver(mBroadcastReceiverCaptor.capture(), + (IntentFilter) argThat((IntentFilter filter) -> + filter.hasAction(Intent.ACTION_USER_REMOVED))); + + int userHandle = TEST_USER_HANDLE; + // Send the broadcast with wrong action + Intent intent = new Intent(Intent.ACTION_USER_FOREGROUND); + intent.putExtra(Intent.EXTRA_USER_HANDLE, userHandle); + mBroadcastReceiverCaptor.getValue().onReceive(mContext, intent); + + verify(mWifiStateMachine, never()).removeUserConfigs(userHandle); + } + private class IdleModeIntentMatcher implements ArgumentMatcher<IntentFilter> { @Override public boolean matches(IntentFilter filter) { |