summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/WifiServiceImpl.java44
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java85
2 files changed, 102 insertions, 27 deletions
diff --git a/service/java/com/android/server/wifi/WifiServiceImpl.java b/service/java/com/android/server/wifi/WifiServiceImpl.java
index 7d6c109c1..49f00f88f 100644
--- a/service/java/com/android/server/wifi/WifiServiceImpl.java
+++ b/service/java/com/android/server/wifi/WifiServiceImpl.java
@@ -567,7 +567,6 @@ public class WifiServiceImpl extends IWifiManager.Stub {
// can result in race conditions when apps toggle wifi in the background
// without active user involvement. Always receive broadcasts.
registerForBroadcasts();
- registerForPackageOrUserRemoval();
mInIdleMode = mPowerManager.isDeviceIdleMode();
if (!mWifiStateMachine.syncInitialize(mWifiStateMachineChannel)) {
@@ -2303,6 +2302,9 @@ public class WifiServiceImpl extends IWifiManager.Stub {
String action = intent.getAction();
if (action.equals(Intent.ACTION_USER_PRESENT)) {
mWifiController.sendMessage(CMD_USER_PRESENT);
+ } else if (action.equals(Intent.ACTION_USER_REMOVED)) {
+ int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
+ mWifiStateMachine.removeUserConfigs(userHandle);
} else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE,
BluetoothAdapter.STATE_DISCONNECTED);
@@ -2368,6 +2370,7 @@ public class WifiServiceImpl extends IWifiManager.Stub {
private void registerForBroadcasts() {
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_USER_PRESENT);
+ intentFilter.addAction(Intent.ACTION_USER_REMOVED);
intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
intentFilter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALLBACK_MODE_CHANGED);
@@ -2378,39 +2381,26 @@ public class WifiServiceImpl extends IWifiManager.Stub {
if (trackEmergencyCallState) {
intentFilter.addAction(TelephonyIntents.ACTION_EMERGENCY_CALL_STATE_CHANGED);
}
-
mContext.registerReceiver(mReceiver, intentFilter);
- }
- private void registerForPackageOrUserRemoval() {
- IntentFilter intentFilter = new IntentFilter();
- intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
- intentFilter.addAction(Intent.ACTION_USER_REMOVED);
- mContext.registerReceiverAsUser(new BroadcastReceiver() {
+ intentFilter = new IntentFilter();
+ intentFilter.addAction(Intent.ACTION_PACKAGE_FULLY_REMOVED);
+ intentFilter.addDataScheme("package");
+ mContext.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
- switch (intent.getAction()) {
- case Intent.ACTION_PACKAGE_REMOVED: {
- if (intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
- return;
- }
- int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
- Uri uri = intent.getData();
- if (uid == -1 || uri == null) {
- return;
- }
- String pkgName = uri.getSchemeSpecificPart();
- mWifiStateMachine.removeAppConfigs(pkgName, uid);
- break;
- }
- case Intent.ACTION_USER_REMOVED: {
- int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, 0);
- mWifiStateMachine.removeUserConfigs(userHandle);
- break;
+ String action = intent.getAction();
+ if (action.equals(Intent.ACTION_PACKAGE_FULLY_REMOVED)) {
+ int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
+ Uri uri = intent.getData();
+ if (uid == -1 || uri == null) {
+ return;
}
+ String pkgName = uri.getSchemeSpecificPart();
+ mWifiStateMachine.removeAppConfigs(pkgName, uid);
}
}
- }, UserHandle.ALL, intentFilter, null, null);
+ }, intentFilter);
}
@Override
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) {