diff options
4 files changed, 105 insertions, 22 deletions
diff --git a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java index b0b1251d2..d59d2a0a6 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java +++ b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java @@ -485,6 +485,18 @@ public class WifiNetworkSuggestionsManager { mUserApprovalUiActive = false; } + private void handleUserAllowCarrierExemptionAction(String carrierName, int carrierId) { + Log.i(TAG, "User clicked to allow carrier:" + carrierName); + setHasUserApprovedImsiPrivacyExemptionForCarrier(true, carrierId); + mUserApprovalUiActive = false; + } + + private void handleUserDisallowCarrierExemptionAction(String carrierName, int carrierId) { + Log.i(TAG, "User clicked to disallow carrier:" + carrierName); + setHasUserApprovedImsiPrivacyExemptionForCarrier(false, carrierId); + mUserApprovalUiActive = false; + } + private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { @Override @@ -515,17 +527,16 @@ public class WifiNetworkSuggestionsManager { return; } Log.i(TAG, "User clicked to allow carrier"); - setHasUserApprovedImsiPrivacyExemptionForCarrier(true, carrierId); - mUserApprovalUiActive = false; + sendImsiPrivacyConfirmationDialog(carrierName, carrierId); + // Collapse the notification bar + mContext.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); break; case NOTIFICATION_USER_DISALLOWED_CARRIER_INTENT_ACTION: if (carrierName == null || carrierId == -1) { Log.e(TAG, "No carrier name or carrier id found in intent"); return; } - Log.i(TAG, "User clicked to disallow carrier"); - setHasUserApprovedImsiPrivacyExemptionForCarrier(false, carrierId); - mUserApprovalUiActive = false; + handleUserDisallowCarrierExemptionAction(carrierName, carrierId); break; case NOTIFICATION_USER_DISMISSED_INTENT_ACTION: handleUserDismissAction(); @@ -1318,11 +1329,13 @@ public class WifiNetworkSuggestionsManager { mContext, WifiService.NOTIFICATION_NETWORK_STATUS) .setSmallIcon(Icon.createWithResource(WifiContext.WIFI_OVERLAY_APK_PKG_NAME, com.android.wifi.resources.R.drawable.stat_notify_wifi_in_range)) - .setTicker(mResources.getString(R.string.wifi_suggestion_imsi_privacy_title)) - .setContentTitle(mResources.getString(R.string.wifi_suggestion_imsi_privacy_title)) + .setTicker(mResources.getString( + R.string.wifi_suggestion_imsi_privacy_title, carrierName)) + .setContentTitle(mResources.getString( + R.string.wifi_suggestion_imsi_privacy_title, carrierName)) .setStyle(new Notification.BigTextStyle() - .bigText(mResources.getString(R.string.wifi_suggestion_imsi_privacy_content, - carrierName))) + .bigText(mResources.getString( + R.string.wifi_suggestion_imsi_privacy_content))) .setDeleteIntent(getPrivateBroadcast(NOTIFICATION_USER_DISMISSED_INTENT_ACTION, Pair.create(EXTRA_CARRIER_NAME, carrierName), Pair.create(EXTRA_CARRIER_ID, carrierId))) @@ -1330,8 +1343,8 @@ public class WifiNetworkSuggestionsManager { .setLocalOnly(true) .setColor(mResources.getColor(android.R.color.system_notification_accent_color, mContext.getTheme())) - .addAction(userAllowAppNotificationAction) .addAction(userDisallowAppNotificationAction) + .addAction(userAllowAppNotificationAction) .build(); // Post the notification. @@ -1340,6 +1353,37 @@ public class WifiNetworkSuggestionsManager { mUserApprovalUiActive = true; } + private void sendImsiPrivacyConfirmationDialog(@NonNull String carrierName, int carrierId) { + AlertDialog dialog = mFrameworkFacade.makeAlertDialogBuilder(mContext) + .setTitle(mResources.getString( + R.string.wifi_suggestion_imsi_privacy_exemption_confirmation_title)) + .setMessage(mResources.getString( + R.string.wifi_suggestion_imsi_privacy_exemption_confirmation_content, + carrierName)) + .setPositiveButton(mResources.getText( + R.string.wifi_suggestion_action_allow_imsi_privacy_exemption_confirmation), + (d, which) -> mHandler.post( + () -> handleUserAllowCarrierExemptionAction( + carrierName, carrierId))) + .setNegativeButton(mResources.getText( + R.string.wifi_suggestion_action_disallow_imsi_privacy_exemption_confirmation), + (d, which) -> mHandler.post( + () -> handleUserDisallowCarrierExemptionAction( + carrierName, carrierId))) + .setOnDismissListener( + (d) -> mHandler.post(this::handleUserDismissAction)) + .setOnCancelListener( + (d) -> mHandler.post(this::handleUserDismissAction)) + .create(); + dialog.setCanceledOnTouchOutside(false); + dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); + dialog.getWindow().addSystemFlags( + WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS); + dialog.show(); + mUserApprovalUiActive = true; + } + + /** * Send user approval notification if the app is not approved * @param packageName app package name diff --git a/service/res/values/overlayable.xml b/service/res/values/overlayable.xml index d4aae1277..f88defc43 100644 --- a/service/res/values/overlayable.xml +++ b/service/res/values/overlayable.xml @@ -144,6 +144,10 @@ <item type="string" name="wifi_suggestion_imsi_privacy_content" /> <item type="string" name="wifi_suggestion_action_allow_imsi_privacy_exemption_carrier" /> <item type="string" name="wifi_suggestion_action_disallow_imsi_privacy_exemption_carrier" /> + <item type="string" name="wifi_suggestion_imsi_privacy_exemption_confirmation_title" /> + <item type="string" name="wifi_suggestion_imsi_privacy_exemption_confirmation_content" /> + <item type="string" name="wifi_suggestion_action_allow_imsi_privacy_exemption_confirmation" /> + <item type="string" name="wifi_suggestion_action_disallow_imsi_privacy_exemption_confirmation" /> <item type="string" name="wifi_wakeup_onboarding_title" /> <item type="string" name="wifi_wakeup_onboarding_subtext" /> <item type="string" name="wifi_wakeup_onboarding_action_disable" /> diff --git a/service/res/values/strings.xml b/service/res/values/strings.xml index d6fb5a750..441ecca15 100644 --- a/service/res/values/strings.xml +++ b/service/res/values/strings.xml @@ -49,13 +49,23 @@ <string name="wifi_suggestion_action_disallow_app">No thanks</string> <!-- Notification title for a connection to a SIM-based carrier network without IMSI privacy protection. --> - <string name="wifi_suggestion_imsi_privacy_title">Privacy warning for IMSI protection</string> + <string name="wifi_suggestion_imsi_privacy_title"><xliff:g id="carrierName" example="xxxMobile">%s</xliff:g> wants to auto\u2011connect</string> <!-- Notification content for a connection to a SIM-based carrier network without IMSI privacy protection.--> - <string name="wifi_suggestion_imsi_privacy_content"><xliff:g id="carrierName" example="xxxMobile">%s</xliff:g> suggested networks using your SIM card info without without privacy protection, allow network to be connected automatically? </string> + <string name="wifi_suggestion_imsi_privacy_content">These networks receive a unique ID that can be used to track device location</string> <!-- Notification action for allowing carrier specified in the notification body.--> - <string name="wifi_suggestion_action_allow_imsi_privacy_exemption_carrier">Allow</string> + <string name="wifi_suggestion_action_allow_imsi_privacy_exemption_carrier">Connect anyway</string> <!-- Notification action for disallowing carrier specified in the notification body.--> - <string name="wifi_suggestion_action_disallow_imsi_privacy_exemption_carrier">Disallow</string> + <string name="wifi_suggestion_action_disallow_imsi_privacy_exemption_carrier">Don\u0027t connect</string> + <!-- Confirmation dialog title for a connection to a SIM-based carrier network without IMSI privacy protection. --> + <string name="wifi_suggestion_imsi_privacy_exemption_confirmation_title">Confirm connection?</string> + <!-- Confirmation dialog content for a connection to a SIM-based carrier network without IMSI privacy protection. --> + <string name="wifi_suggestion_imsi_privacy_exemption_confirmation_content">If you connect, <xliff:g id="carrierName" example="xxxMobile">%s</xliff:g> Wi\u2011Fi networks may access or share a unique ID associated with your SIM. This may allow your device\u0027s location to be tracked.</string> + <!-- Confirmation dialog action for allowing carrier specified in the dialog body --> + <string name="wifi_suggestion_action_allow_imsi_privacy_exemption_confirmation">Connect</string> + <!-- Confirmation dialog action for disallowing carrier specified in the dialog body --> + <string name="wifi_suggestion_action_disallow_imsi_privacy_exemption_confirmation">Don\u0027t connect</string> + + <!--Notification title for Wi-Fi Wake onboarding. This is displayed the first time a user disables Wi-Fi with the feature enabled. --> <string name="wifi_wakeup_onboarding_title">Wi\u2011Fi will turn on automatically</string> diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java index 58a47841f..0ec2eb92c 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java @@ -222,16 +222,29 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { .thenReturn("blah"); // setup resource strings for IMSI protection notification. - when(mResources.getString(eq(R.string.wifi_suggestion_imsi_privacy_title))) - .thenReturn("blah"); - when(mResources.getString(eq(R.string.wifi_suggestion_imsi_privacy_content), anyString())) + when(mResources.getString(eq(R.string.wifi_suggestion_imsi_privacy_title), anyString())) .thenAnswer(s -> "blah" + s.getArguments()[1]); + when(mResources.getString(eq(R.string.wifi_suggestion_imsi_privacy_content))) + .thenReturn("blah"); when(mResources.getText( eq(R.string.wifi_suggestion_action_allow_imsi_privacy_exemption_carrier))) .thenReturn("blah"); when(mResources.getText( eq(R.string.wifi_suggestion_action_disallow_imsi_privacy_exemption_carrier))) .thenReturn("blah"); + when(mResources.getString( + eq(R.string.wifi_suggestion_imsi_privacy_exemption_confirmation_title))) + .thenReturn("blah"); + when(mResources.getString( + eq(R.string.wifi_suggestion_imsi_privacy_exemption_confirmation_content), + anyString())).thenAnswer(s -> "blah" + s.getArguments()[1]); + when(mResources.getText( + eq(R.string.wifi_suggestion_action_allow_imsi_privacy_exemption_confirmation))) + .thenReturn("blah"); + when(mResources.getText( + eq(R.string.wifi_suggestion_action_disallow_imsi_privacy_exemption_confirmation))) + .thenReturn("blah"); + // Our app Info. Needed for notification builder. ApplicationInfo ourAppInfo = new ApplicationInfo(); @@ -2719,12 +2732,12 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { verify(mNotificationManger, atLeastOnce()).notify( eq(SystemMessage.NOTE_NETWORK_SUGGESTION_AVAILABLE), eq(mNotification)); - ArgumentCaptor<Notification.BigTextStyle> contentCaptor = - ArgumentCaptor.forClass(Notification.BigTextStyle.class); - verify(mNotificationBuilder, atLeastOnce()).setStyle(contentCaptor.capture()); - Notification.BigTextStyle content = contentCaptor.getValue(); + ArgumentCaptor<CharSequence> contentCaptor = + ArgumentCaptor.forClass(CharSequence.class); + verify(mNotificationBuilder, atLeastOnce()).setContentTitle(contentCaptor.capture()); + CharSequence content = contentCaptor.getValue(); assertNotNull(content); - assertTrue(content.getBigText().toString().contains(carrierName)); + assertTrue(content.toString().contains(carrierName)); } private void validateUserApprovalDialog(String... anyOfExpectedAppNames) { @@ -3398,7 +3411,19 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest { sendBroadcastForUserActionOnImsi(NOTIFICATION_USER_ALLOWED_CARRIER_INTENT_ACTION, TEST_CARRIER_NAME, TEST_CARRIER_ID); verify(mNotificationManger).cancel(SystemMessage.NOTE_NETWORK_SUGGESTION_AVAILABLE); + validateUserApprovalDialog(TEST_CARRIER_NAME); + // Simulate user clicking on allow in the dialog. + ArgumentCaptor<DialogInterface.OnClickListener> clickListenerCaptor = + ArgumentCaptor.forClass(DialogInterface.OnClickListener.class); + verify(mAlertDialogBuilder, atLeastOnce()).setPositiveButton( + any(), clickListenerCaptor.capture()); + assertNotNull(clickListenerCaptor.getValue()); + clickListenerCaptor.getValue().onClick(mAlertDialog, 0); + mLooper.dispatchAll(); + ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); + verify(mContext).sendBroadcast(intentCaptor.capture()); + assertEquals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS, intentCaptor.getValue().getAction()); verify(mWifiConfigManager, times(2)).saveToStore(true); assertTrue(mImsiDataSource.hasNewDataToSerialize()); matchedSuggestion = mWifiNetworkSuggestionsManager |