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 /service | |
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 'service')
-rw-r--r-- | service/java/com/android/server/wifi/EapFailureNotifier.java | 24 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/SimRequiredNotifier.java | 49 |
2 files changed, 58 insertions, 15 deletions
diff --git a/service/java/com/android/server/wifi/EapFailureNotifier.java b/service/java/com/android/server/wifi/EapFailureNotifier.java index cdb120321..1d82082a0 100644 --- a/service/java/com/android/server/wifi/EapFailureNotifier.java +++ b/service/java/com/android/server/wifi/EapFailureNotifier.java @@ -16,23 +16,29 @@ package com.android.server.wifi; +import android.app.ActivityManager; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.graphics.drawable.Icon; import android.net.wifi.WifiConfiguration; +import android.os.UserHandle; import android.provider.Settings; import android.service.notification.StatusBarNotification; import android.telephony.SubscriptionManager; import android.text.TextUtils; +import android.util.Log; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; +import java.util.List; + /** * This class may be used to launch notifications when EAP failure occurs. */ @@ -92,13 +98,29 @@ public class EapFailureNotifier { showNotification(errorMessage, config.SSID); } + private String getSettingsPackageName() { + Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS); + List<ResolveInfo> resolveInfos = mContext.getPackageManager().queryIntentActivitiesAsUser( + intent, PackageManager.MATCH_SYSTEM_ONLY | PackageManager.MATCH_DEFAULT_ONLY, + UserHandle.of(ActivityManager.getCurrentUser())); + if (resolveInfos == null || resolveInfos.isEmpty()) { + Log.e(TAG, "Failed to resolve wifi settings activity"); + return null; + } + // Pick the first one if there are more than 1 since the list is ordered from best to worst. + return resolveInfos.get(0).activityInfo.packageName; + } + /** * Display eap error notification which defined by carrier. * * @param ssid Error Message which defined by carrier */ private void showNotification(String errorMessage, String ssid) { - Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS); + String settingsPackage = getSettingsPackageName(); + if (settingsPackage == null) return; + Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS) + .setPackage(settingsPackage); Notification.Builder builder = mFrameworkFacade.makeNotificationBuilder(mContext, WifiService.NOTIFICATION_NETWORK_ALERTS) .setAutoCancel(true) diff --git a/service/java/com/android/server/wifi/SimRequiredNotifier.java b/service/java/com/android/server/wifi/SimRequiredNotifier.java index 8e3d22d6a..fed7bd8e2 100644 --- a/service/java/com/android/server/wifi/SimRequiredNotifier.java +++ b/service/java/com/android/server/wifi/SimRequiredNotifier.java @@ -16,22 +16,31 @@ package com.android.server.wifi; +import android.app.ActivityManager; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; import android.graphics.drawable.Icon; import android.net.wifi.WifiConfiguration; +import android.os.UserHandle; import android.provider.Settings; +import android.util.Log; import com.android.internal.messages.nano.SystemMessageProto.SystemMessage; import com.android.wifi.resources.R; + +import java.util.List; + /** * Helper class to generate SIM required notification * */ public class SimRequiredNotifier { + private static final String TAG = "SimRequiredNotifier"; private final WifiContext mContext; private final FrameworkFacade mFrameworkFacade; private final NotificationManager mNotificationManager; @@ -53,8 +62,7 @@ public class SimRequiredNotifier { } else { name = config.SSID; } - mNotificationManager.notify(SystemMessage.NOTE_ID_WIFI_SIM_REQUIRED, - buildSimRequiredNotification(name, carrier)); + showNotification(name, carrier); } /** @@ -64,15 +72,33 @@ public class SimRequiredNotifier { mNotificationManager.cancel(null, SystemMessage.NOTE_ID_WIFI_SIM_REQUIRED); } - private Notification buildSimRequiredNotification(String ssid, String carrier) { + private String getSettingsPackageName() { + Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS); + List<ResolveInfo> resolveInfos = mContext.getPackageManager().queryIntentActivitiesAsUser( + intent, PackageManager.MATCH_SYSTEM_ONLY | PackageManager.MATCH_DEFAULT_ONLY, + UserHandle.of(ActivityManager.getCurrentUser())); + if (resolveInfos == null || resolveInfos.isEmpty()) { + Log.e(TAG, "Failed to resolve wifi settings activity"); + return null; + } + // Pick the first one if there are more than 1 since the list is ordered from best to worst. + return resolveInfos.get(0).activityInfo.packageName; + } + + private void showNotification(String ssid, String carrier) { + String settingsPackage = getSettingsPackageName(); + if (settingsPackage == null) return; + Intent intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) + .setPackage(settingsPackage); + String title = mContext.getResources().getString( R.string.wifi_sim_required_title); String message = mContext.getResources().getString( R.string.wifi_sim_required_message, (ssid == null ? "" : ssid), (carrier == null ? "" : carrier)); - - return mFrameworkFacade.makeNotificationBuilder(mContext, + Notification.Builder builder = mFrameworkFacade.makeNotificationBuilder(mContext, WifiService.NOTIFICATION_NETWORK_ALERTS) .setAutoCancel(true) .setShowWhen(false) @@ -85,14 +111,9 @@ public class SimRequiredNotifier { .setStyle(new Notification.BigTextStyle().bigText(message)) .setSmallIcon(Icon.createWithResource(mContext.getWifiOverlayApkPkgName(), R.drawable.stat_notify_wifi_in_range)) - .setContentIntent(launchWirelessSettings()) - .build(); - } - - private PendingIntent launchWirelessSettings() { - Intent intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS) - .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - return mFrameworkFacade.getActivity(mContext, 0, intent, - PendingIntent.FLAG_UPDATE_CURRENT); + .setContentIntent(mFrameworkFacade.getActivity( + mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)); + mNotificationManager.notify(SystemMessage.NOTE_ID_WIFI_SIM_REQUIRED, + builder.build()); } } |