summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2020-04-12 19:35:07 -0700
committerRoshan Pius <rpius@google.com>2020-04-13 10:08:32 -0700
commitfba7f4d4f17e44ac6e62d011588f3e426e6f1364 (patch)
tree74edc8cbf753884d079464a2f83a7997a359d38a /service
parentb69b89ff86db7b3e9f4263e7bb7fb48dba69832a (diff)
WrongPasswordNotifier: Set package name on the intent
Bug: 153356468 Test: atest com.android.server.wifi.test Test: Verified that the app can no longer hijack the intent. (Was able to to repro the log from the app before the fix) Test: Verified that the wrong password opens the wifi settings window as before. Change-Id: I70ad71a3d7e2e1b6a6d3b4ba60a99e51b9803129
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/WrongPasswordNotifier.java28
1 files changed, 26 insertions, 2 deletions
diff --git a/service/java/com/android/server/wifi/WrongPasswordNotifier.java b/service/java/com/android/server/wifi/WrongPasswordNotifier.java
index 9975f973a..c645ccf6f 100644
--- a/service/java/com/android/server/wifi/WrongPasswordNotifier.java
+++ b/service/java/com/android/server/wifi/WrongPasswordNotifier.java
@@ -16,22 +16,30 @@
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.graphics.drawable.Icon;
+import android.os.UserHandle;
import android.provider.Settings;
+import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.server.wifi.util.NativeUtil;
+import java.util.List;
+
/**
* Responsible for notifying user for wrong password errors.
*/
public class WrongPasswordNotifier {
+ private static final String TAG = "WrongPasswordNotifier";
// Number of milliseconds to wait before automatically dismiss the notification.
private static final long CANCEL_TIMEOUT_MILLISECONDS = 5 * 60 * 1000;
@@ -73,14 +81,30 @@ public class WrongPasswordNotifier {
}
}
+ 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 wrong password notification for a given Wi-Fi network (specified by its SSID).
*
* @param ssid SSID of the Wi-FI network
*/
private void showNotification(String ssid) {
- Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS);
- intent.putExtra("wifi_start_connect_ssid", NativeUtil.removeEnclosingQuotes(ssid));
+ String settingsPackage = getSettingsPackageName();
+ if (settingsPackage == null) return;
+ Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS)
+ .setPackage(settingsPackage)
+ .putExtra("wifi_start_connect_ssid", NativeUtil.removeEnclosingQuotes(ssid));
Notification.Builder builder = mFrameworkFacade.makeNotificationBuilder(mContext,
WifiService.NOTIFICATION_NETWORK_ALERTS)
.setAutoCancel(true)