Make PendingIntent immutable and correct Settings package name
ConnectivityService puts up some notifications with pending intents, but these pending intents are mutable that content can be changed by someone. So make these pending intents to be immutable. Some OEMs have their own Settings package. Thus, need to get the current using Settings package name instead of just use default name "com.android.settings". Bug: 154928507 Test: atest FrameworksNetTests Change-Id: I02e3277358623400aa03dc8996af3d7c46a8ce76 Merged-In: I02e3277358623400aa03dc8996af3d7c46a8ce76
This commit is contained in:
@@ -67,6 +67,7 @@ import android.app.BroadcastOptions;
|
|||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -3061,7 +3062,11 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// Only the system server can register notifications with package "android"
|
// Only the system server can register notifications with package "android"
|
||||||
final long token = Binder.clearCallingIdentity();
|
final long token = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
pendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
|
pendingIntent = PendingIntent.getBroadcast(
|
||||||
|
mContext,
|
||||||
|
0 /* requestCode */,
|
||||||
|
intent,
|
||||||
|
PendingIntent.FLAG_IMMUTABLE);
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(token);
|
Binder.restoreCallingIdentity(token);
|
||||||
}
|
}
|
||||||
@@ -3917,6 +3922,15 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
pw.decreaseIndent();
|
pw.decreaseIndent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: This method is copied from TetheringNotificationUpdater. Should have a utility class to
|
||||||
|
// unify the method.
|
||||||
|
private static @NonNull String getSettingsPackageName(@NonNull final PackageManager pm) {
|
||||||
|
final Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS);
|
||||||
|
final ComponentName settingsComponent = settingsIntent.resolveActivity(pm);
|
||||||
|
return settingsComponent != null
|
||||||
|
? settingsComponent.getPackageName() : "com.android.settings";
|
||||||
|
}
|
||||||
|
|
||||||
private void showNetworkNotification(NetworkAgentInfo nai, NotificationType type) {
|
private void showNetworkNotification(NetworkAgentInfo nai, NotificationType type) {
|
||||||
final String action;
|
final String action;
|
||||||
final boolean highPriority;
|
final boolean highPriority;
|
||||||
@@ -3951,12 +3965,20 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
if (type != NotificationType.PRIVATE_DNS_BROKEN) {
|
if (type != NotificationType.PRIVATE_DNS_BROKEN) {
|
||||||
intent.setData(Uri.fromParts("netId", Integer.toString(nai.network.netId), null));
|
intent.setData(Uri.fromParts("netId", Integer.toString(nai.network.netId), null));
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
intent.setClassName("com.android.settings",
|
// Some OEMs have their own Settings package. Thus, need to get the current using
|
||||||
"com.android.settings.wifi.WifiNoInternetDialog");
|
// Settings package name instead of just use default name "com.android.settings".
|
||||||
|
final String settingsPkgName = getSettingsPackageName(mContext.getPackageManager());
|
||||||
|
intent.setClassName(settingsPkgName,
|
||||||
|
settingsPkgName + ".wifi.WifiNoInternetDialog");
|
||||||
}
|
}
|
||||||
|
|
||||||
PendingIntent pendingIntent = PendingIntent.getActivityAsUser(
|
PendingIntent pendingIntent = PendingIntent.getActivityAsUser(
|
||||||
mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT);
|
mContext,
|
||||||
|
0 /* requestCode */,
|
||||||
|
intent,
|
||||||
|
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE,
|
||||||
|
null /* options */,
|
||||||
|
UserHandle.CURRENT);
|
||||||
|
|
||||||
mNotifier.showNotification(nai.network.netId, type, nai, null, pendingIntent, highPriority);
|
mNotifier.showNotification(nai.network.netId, type, nai, null, pendingIntent, highPriority);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user