diff options
author | Isaac Chiou <isaacchiou@google.com> | 2020-06-08 19:14:33 +0800 |
---|---|---|
committer | Isaac Chiou <isaacchiou@google.com> | 2020-08-07 16:00:46 +0800 |
commit | c86dbb70981712b48af042e1f4c4670b83f60f6a (patch) | |
tree | 8cb77465b61a6b69c354257f38475f9d1cea505c /tests | |
parent | c4515619fde723d719aca5ba043756515103236d (diff) |
Wifi: Set package name on the intent
Set package name on the intent for EapFailureNotifier and
SimRequiredNotifier
Bug: 156008365
Test: atest FrameworksWifiTests
Test: Make sure notification can be popped up
Test: Verified that the app can no longer hijack the intent. (Was able
to to repro the log from the app before the fix)
Change-Id: I7e66e50d9fd8e953f4a8c75f654448e940389913
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/EapFailureNotifierTest.java | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/EapFailureNotifierTest.java b/tests/wifitests/src/com/android/server/wifi/EapFailureNotifierTest.java index d2a3ac0dc..26391334c 100644 --- a/tests/wifitests/src/com/android/server/wifi/EapFailureNotifierTest.java +++ b/tests/wifitests/src/com/android/server/wifi/EapFailureNotifierTest.java @@ -21,12 +21,17 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSess import static org.junit.Assert.*; import static org.mockito.Mockito.*; +import android.app.ActivityManager; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent; +import android.content.pm.ActivityInfo; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.net.wifi.WifiConfiguration; +import android.os.UserHandle; import android.provider.Settings; import android.service.notification.StatusBarNotification; import android.telephony.SubscriptionManager; @@ -42,13 +47,18 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.MockitoSession; +import java.util.Arrays; + /** * Unit tests for {@link com.android.server.wifi.EapFailureNotifier}. */ @SmallTest public class EapFailureNotifierTest extends WifiBaseTest { + private static final String TEST_SETTINGS_PACKAGE = "android"; + @Mock WifiContext mContext; @Mock Resources mResources; + @Mock PackageManager mPackageManager; @Mock NotificationManager mNotificationManager; @Mock FrameworkFacade mFrameworkFacade; @Mock Notification mNotification; @@ -65,6 +75,7 @@ public class EapFailureNotifierTest extends WifiBaseTest { private static final String UNDEFINED_ERROR_RESOURCE_NAME = "wifi_eap_error_message_code_12345"; private MockitoSession mStaticMockSession = null; + EapFailureNotifier mEapFailureNotifier; /** @@ -73,15 +84,26 @@ public class EapFailureNotifierTest extends WifiBaseTest { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); + ResolveInfo settingsResolveInfo = new ResolveInfo(); + settingsResolveInfo.activityInfo = new ActivityInfo(); + settingsResolveInfo.activityInfo.packageName = TEST_SETTINGS_PACKAGE; + when(mPackageManager.queryIntentActivitiesAsUser( + argThat(((intent) -> intent.getAction().equals(Settings.ACTION_WIFI_SETTINGS))), + anyInt(), any())) + .thenReturn(Arrays.asList(settingsResolveInfo)); + // static mocking mStaticMockSession = mockitoSession() .mockStatic(SubscriptionManager.class) + .mockStatic(ActivityManager.class, withSettings().lenient()) .startMocking(); + when(ActivityManager.getCurrentUser()).thenReturn(UserHandle.USER_SYSTEM); when(mContext.getSystemService(NotificationManager.class)) .thenReturn(mNotificationManager); when(mWifiCarrierInfoManager.getBestMatchSubscriptionId(mWifiConfiguration)).thenReturn(0); lenient().when(SubscriptionManager.getResourcesForSubId(eq(mContext), anyInt())) .thenReturn(mResources); when(mContext.getResources()).thenReturn(mResources); + when(mContext.getPackageManager()).thenReturn(mPackageManager); when(mResources.getIdentifier(eq(DEFINED_ERROR_RESOURCE_NAME), anyString(), anyString())).thenReturn(1); when(mResources.getIdentifier(eq(UNDEFINED_ERROR_RESOURCE_NAME), anyString(), @@ -97,7 +119,10 @@ public class EapFailureNotifierTest extends WifiBaseTest { @After public void cleanUp() throws Exception { - mStaticMockSession.finishMocking(); + validateMockitoUsage(); + if (mStaticMockSession != null) { + mStaticMockSession.finishMocking(); + } } /** @@ -120,6 +145,7 @@ public class EapFailureNotifierTest extends WifiBaseTest { ArgumentCaptor<Intent> intent = ArgumentCaptor.forClass(Intent.class); verify(mFrameworkFacade).getActivity( eq(mContext), eq(0), intent.capture(), eq(PendingIntent.FLAG_UPDATE_CURRENT)); + assertEquals(TEST_SETTINGS_PACKAGE, intent.getValue().getPackage()); assertEquals(Settings.ACTION_WIFI_SETTINGS, intent.getValue().getAction()); } @@ -146,6 +172,7 @@ public class EapFailureNotifierTest extends WifiBaseTest { ArgumentCaptor<Intent> intent = ArgumentCaptor.forClass(Intent.class); verify(mFrameworkFacade).getActivity( eq(mContext), eq(0), intent.capture(), eq(PendingIntent.FLAG_UPDATE_CURRENT)); + assertEquals(TEST_SETTINGS_PACKAGE, intent.getValue().getPackage()); assertEquals(Settings.ACTION_WIFI_SETTINGS, intent.getValue().getAction()); } |