Skip to content

Commit c33fdd0

Browse files
author
android-build-team Robot
committed
Merge cherrypicks of [14129459, 14130267, 14129460, 14130198, 14130202, 14130204, 14130305, 14130306, 14130307, 14129440, 14129442, 14129443, 14129735, 14129736, 14129737, 14129738, 14129739, 14129444, 14130346, 14129741, 14130347, 14130348, 14129742, 14130349, 14130350, 14130351, 14130352, 14130244, 14129743, 14129744, 14130365, 14130037, 14130321, 14130322, 14130323, 14130324, 14130405] into security-aosp-rvc-release
Change-Id: I8786a91b48d55bcb8c3db013f1c0ffa37ad23c49
2 parents 914a284 + 9b67d75 commit c33fdd0

19 files changed

Lines changed: 981 additions & 505 deletions

File tree

core/java/android/app/ActivityManagerInternal.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,21 @@ public abstract void setDebugFlagsForStartingActivity(ActivityInfo aInfo, int st
377377
*/
378378
public abstract boolean hasRunningForegroundService(int uid, int foregroundServiceType);
379379

380+
/**
381+
* Returns {@code true} if the given notification channel currently has a
382+
* notification associated with a foreground service. This is an AMS check
383+
* because that is the source of truth for the FGS state.
384+
*/
385+
public abstract boolean hasForegroundServiceNotification(String pkg, @UserIdInt int userId,
386+
String channelId);
387+
388+
/**
389+
* If the given app has any FGSs whose notifications are in the given channel,
390+
* stop them.
391+
*/
392+
public abstract void stopForegroundServicesForChannel(String pkg, @UserIdInt int userId,
393+
String channelId);
394+
380395
/**
381396
* Registers the specified {@code processObserver} to be notified of future changes to
382397
* process state.

core/java/android/hardware/display/DisplayManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public final class DisplayManager {
6161
* {@link #EXTRA_WIFI_DISPLAY_STATUS} extra.
6262
* </p><p>
6363
* This broadcast is only sent to registered receivers and can only be sent by the system.
64+
* </p><p>
65+
* {@link android.Manifest.permission#ACCESS_FINE_LOCATION} permission is required to
66+
* receive this broadcast.
6467
* </p>
6568
* @hide
6669
*/

core/java/android/os/Process.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ public class Process {
202202
*/
203203
public static final int SE_UID = 1068;
204204

205+
/**
206+
* Defines the UID/GID for the iorapd.
207+
* @hide
208+
*/
209+
public static final int IORAPD_UID = 1071;
210+
205211
/**
206212
* Defines the UID/GID for the NetworkStack app.
207213
* @hide

packages/SystemUI/src/com/android/systemui/screenshot/SaveImageInBackgroundTask.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,10 @@ Notification.Action createShareAction(Context context, Resources r, Uri uri) {
283283
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
284284

285285
// cancel current pending intent (if any) since clipData isn't used for matching
286-
PendingIntent pendingIntent = PendingIntent.getActivityAsUser(context, 0,
287-
sharingChooserIntent, PendingIntent.FLAG_CANCEL_CURRENT, null, UserHandle.CURRENT);
286+
PendingIntent pendingIntent = PendingIntent.getActivityAsUser(
287+
context, 0, sharingChooserIntent,
288+
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE,
289+
null, UserHandle.CURRENT);
288290

289291
// Create a share action for the notification
290292
PendingIntent shareAction = PendingIntent.getBroadcastAsUser(context, requestCode,
@@ -296,7 +298,8 @@ Notification.Action createShareAction(Context context, Resources r, Uri uri) {
296298
mSmartActionsEnabled)
297299
.setAction(Intent.ACTION_SEND)
298300
.addFlags(Intent.FLAG_RECEIVER_FOREGROUND),
299-
PendingIntent.FLAG_CANCEL_CURRENT, UserHandle.SYSTEM);
301+
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE,
302+
UserHandle.SYSTEM);
300303

301304
Notification.Action.Builder shareActionBuilder = new Notification.Action.Builder(
302305
Icon.createWithResource(r, R.drawable.ic_screenshot_share),
@@ -325,7 +328,7 @@ Notification.Action createEditAction(Context context, Resources r, Uri uri) {
325328
editIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
326329

327330
PendingIntent pendingIntent = PendingIntent.getActivityAsUser(context, 0,
328-
editIntent, 0, null, UserHandle.CURRENT);
331+
editIntent, PendingIntent.FLAG_IMMUTABLE, null, UserHandle.CURRENT);
329332

330333
// Make sure pending intents for the system user are still unique across users
331334
// by setting the (otherwise unused) request code to the current user id.
@@ -342,7 +345,8 @@ Notification.Action createEditAction(Context context, Resources r, Uri uri) {
342345
mSmartActionsEnabled)
343346
.setAction(Intent.ACTION_EDIT)
344347
.addFlags(Intent.FLAG_RECEIVER_FOREGROUND),
345-
PendingIntent.FLAG_CANCEL_CURRENT, UserHandle.SYSTEM);
348+
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE,
349+
UserHandle.SYSTEM);
346350
Notification.Action.Builder editActionBuilder = new Notification.Action.Builder(
347351
Icon.createWithResource(r, R.drawable.ic_screenshot_edit),
348352
r.getString(com.android.internal.R.string.screenshot_edit), editAction);
@@ -364,7 +368,9 @@ Notification.Action createDeleteAction(Context context, Resources r, Uri uri) {
364368
.putExtra(GlobalScreenshot.EXTRA_SMART_ACTIONS_ENABLED,
365369
mSmartActionsEnabled)
366370
.addFlags(Intent.FLAG_RECEIVER_FOREGROUND),
367-
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
371+
PendingIntent.FLAG_CANCEL_CURRENT
372+
| PendingIntent.FLAG_ONE_SHOT
373+
| PendingIntent.FLAG_IMMUTABLE);
368374
Notification.Action.Builder deleteActionBuilder = new Notification.Action.Builder(
369375
Icon.createWithResource(r, R.drawable.ic_screenshot_delete),
370376
r.getString(com.android.internal.R.string.delete), deleteAction);
@@ -405,7 +411,7 @@ private List<Notification.Action> buildSmartActions(
405411
PendingIntent broadcastIntent = PendingIntent.getBroadcast(context,
406412
mRandom.nextInt(),
407413
intent,
408-
PendingIntent.FLAG_CANCEL_CURRENT);
414+
PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE);
409415
broadcastActions.add(new Notification.Action.Builder(action.getIcon(), action.title,
410416
broadcastIntent).setContextual(true).addExtras(extras).build());
411417
}

packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import android.graphics.ColorMatrixColorFilter;
3434
import android.graphics.Paint;
3535
import android.graphics.Rect;
36+
import android.graphics.drawable.BitmapDrawable;
3637
import android.graphics.drawable.Drawable;
3738
import android.graphics.drawable.Icon;
3839
import android.os.Parcelable;
@@ -83,6 +84,16 @@ public class StatusBarIconView extends AnimatedImageView implements StatusIconDi
8384
public static final int STATE_DOT = 1;
8485
public static final int STATE_HIDDEN = 2;
8586

87+
/**
88+
* Maximum allowed byte count for an icon bitmap
89+
* @see android.graphics.RecordingCanvas.MAX_BITMAP_SIZE
90+
*/
91+
private static final int MAX_BITMAP_SIZE = 100 * 1024 * 1024; // 100 MB
92+
/**
93+
* Maximum allowed width or height for an icon drawable, if we can't get byte count
94+
*/
95+
private static final int MAX_IMAGE_SIZE = 5000;
96+
8697
private static final String TAG = "StatusBarIconView";
8798
private static final Property<StatusBarIconView, Float> ICON_APPEAR_AMOUNT
8899
= new FloatProperty<StatusBarIconView>("iconAppearAmount") {
@@ -378,6 +389,22 @@ private boolean updateDrawable(boolean withClear) {
378389
Log.w(TAG, "No icon for slot " + mSlot + "; " + mIcon.icon);
379390
return false;
380391
}
392+
393+
if (drawable instanceof BitmapDrawable && ((BitmapDrawable) drawable).getBitmap() != null) {
394+
// If it's a bitmap we can check the size directly
395+
int byteCount = ((BitmapDrawable) drawable).getBitmap().getByteCount();
396+
if (byteCount > MAX_BITMAP_SIZE) {
397+
Log.w(TAG, "Drawable is too large (" + byteCount + " bytes) " + mIcon);
398+
return false;
399+
}
400+
} else if (drawable.getIntrinsicWidth() > MAX_IMAGE_SIZE
401+
|| drawable.getIntrinsicHeight() > MAX_IMAGE_SIZE) {
402+
// Otherwise, check dimensions
403+
Log.w(TAG, "Drawable is too large (" + drawable.getIntrinsicWidth() + "x"
404+
+ drawable.getIntrinsicHeight() + ") " + mIcon);
405+
return false;
406+
}
407+
381408
if (withClear) {
382409
setImageDrawable(null);
383410
}

packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import android.content.pm.ApplicationInfo;
3636
import android.content.pm.PackageManager;
3737
import android.content.res.Resources;
38+
import android.graphics.Bitmap;
3839
import android.graphics.Color;
3940
import android.graphics.drawable.Icon;
4041
import android.os.UserHandle;
@@ -123,4 +124,13 @@ public void testGetContrastedStaticDrawableColor() {
123124
assertEquals("Transparent backgrounds should fallback to drawable color",
124125
color, mIconView.getStaticDrawableColor());
125126
}
127+
128+
@Test
129+
public void testGiantImageNotAllowed() {
130+
Bitmap largeBitmap = Bitmap.createBitmap(6000, 6000, Bitmap.Config.ARGB_8888);
131+
Icon icon = Icon.createWithBitmap(largeBitmap);
132+
StatusBarIcon largeIcon = new StatusBarIcon(UserHandle.ALL, "mockPackage",
133+
icon, 0, 0, "");
134+
assertFalse(mIconView.set(largeIcon));
135+
}
126136
}

services/core/java/com/android/server/ConnectivityService.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6316,6 +6316,25 @@ private NetworkCapabilities mixInCapabilities(NetworkAgentInfo nai, NetworkCapab
63166316
return newNc;
63176317
}
63186318

6319+
private void updateNetworkInfoForRoamingAndSuspended(NetworkAgentInfo nai,
6320+
NetworkCapabilities prevNc, NetworkCapabilities newNc) {
6321+
final boolean prevSuspended = !prevNc.hasCapability(NET_CAPABILITY_NOT_SUSPENDED);
6322+
final boolean suspended = !newNc.hasCapability(NET_CAPABILITY_NOT_SUSPENDED);
6323+
final boolean prevRoaming = !prevNc.hasCapability(NET_CAPABILITY_NOT_ROAMING);
6324+
final boolean roaming = !newNc.hasCapability(NET_CAPABILITY_NOT_ROAMING);
6325+
if (prevSuspended != suspended) {
6326+
// TODO (b/73132094) : remove this call once the few users of onSuspended and
6327+
// onResumed have been removed.
6328+
notifyNetworkCallbacks(nai, suspended ? ConnectivityManager.CALLBACK_SUSPENDED
6329+
: ConnectivityManager.CALLBACK_RESUMED);
6330+
}
6331+
if (prevSuspended != suspended || prevRoaming != roaming) {
6332+
// updateNetworkInfo will mix in the suspended info from the capabilities and
6333+
// take appropriate action for the network having possibly changed state.
6334+
updateNetworkInfo(nai, nai.networkInfo);
6335+
}
6336+
}
6337+
63196338
/**
63206339
* Update the NetworkCapabilities for {@code nai} to {@code nc}. Specifically:
63216340
*
@@ -6347,25 +6366,13 @@ private void updateCapabilities(final int oldScore, @NonNull final NetworkAgentI
63476366
// on this network. We might have been called by rematchNetworkAndRequests when a
63486367
// network changed foreground state.
63496368
processListenRequests(nai);
6350-
final boolean prevSuspended = !prevNc.hasCapability(NET_CAPABILITY_NOT_SUSPENDED);
6351-
final boolean suspended = !newNc.hasCapability(NET_CAPABILITY_NOT_SUSPENDED);
6352-
final boolean prevRoaming = !prevNc.hasCapability(NET_CAPABILITY_NOT_ROAMING);
6353-
final boolean roaming = !newNc.hasCapability(NET_CAPABILITY_NOT_ROAMING);
6354-
if (prevSuspended != suspended || prevRoaming != roaming) {
6355-
// TODO (b/73132094) : remove this call once the few users of onSuspended and
6356-
// onResumed have been removed.
6357-
notifyNetworkCallbacks(nai, suspended ? ConnectivityManager.CALLBACK_SUSPENDED
6358-
: ConnectivityManager.CALLBACK_RESUMED);
6359-
// updateNetworkInfo will mix in the suspended info from the capabilities and
6360-
// take appropriate action for the network having possibly changed state.
6361-
updateNetworkInfo(nai, nai.networkInfo);
6362-
}
63636369
} else {
63646370
// If the requestable capabilities have changed or the score changed, we can't have been
63656371
// called by rematchNetworkAndRequests, so it's safe to start a rematch.
63666372
rematchAllNetworksAndRequests();
63676373
notifyNetworkCallbacks(nai, ConnectivityManager.CALLBACK_CAP_CHANGED);
63686374
}
6375+
updateNetworkInfoForRoamingAndSuspended(nai, prevNc, newNc);
63696376

63706377
// TODO : static analysis indicates that prevNc can't be null here (getAndSetNetworkCaps
63716378
// never returns null), so mark the relevant members and functions in nai as @NonNull and

services/core/java/com/android/server/am/ActiveServices.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
import java.util.ArrayList;
120120
import java.util.Comparator;
121121
import java.util.List;
122+
import java.util.Objects;
122123
import java.util.Set;
123124
import java.util.function.Predicate;
124125

@@ -433,6 +434,45 @@ boolean hasBackgroundServicesLocked(int callingUser) {
433434
return smap != null ? smap.mStartingBackground.size() >= mMaxStartingBackground : false;
434435
}
435436

437+
boolean hasForegroundServiceNotificationLocked(String pkg, int userId, String channelId) {
438+
final ServiceMap smap = mServiceMap.get(userId);
439+
if (smap != null) {
440+
for (int i = 0; i < smap.mServicesByInstanceName.size(); i++) {
441+
final ServiceRecord sr = smap.mServicesByInstanceName.valueAt(i);
442+
if (sr.appInfo.packageName.equals(pkg) && sr.isForeground) {
443+
if (Objects.equals(sr.foregroundNoti.getChannelId(), channelId)) {
444+
if (DEBUG_FOREGROUND_SERVICE) {
445+
Slog.d(TAG_SERVICE, "Channel u" + userId + "/pkg=" + pkg
446+
+ "/channelId=" + channelId
447+
+ " has fg service notification");
448+
}
449+
return true;
450+
}
451+
}
452+
}
453+
}
454+
return false;
455+
}
456+
457+
void stopForegroundServicesForChannelLocked(String pkg, int userId, String channelId) {
458+
final ServiceMap smap = mServiceMap.get(userId);
459+
if (smap != null) {
460+
for (int i = 0; i < smap.mServicesByInstanceName.size(); i++) {
461+
final ServiceRecord sr = smap.mServicesByInstanceName.valueAt(i);
462+
if (sr.appInfo.packageName.equals(pkg) && sr.isForeground) {
463+
if (Objects.equals(sr.foregroundNoti.getChannelId(), channelId)) {
464+
if (DEBUG_FOREGROUND_SERVICE) {
465+
Slog.d(TAG_SERVICE, "Stopping FGS u" + userId + "/pkg=" + pkg
466+
+ "/channelId=" + channelId
467+
+ " for conversation channel clear");
468+
}
469+
stopServiceLocked(sr);
470+
}
471+
}
472+
}
473+
}
474+
}
475+
436476
private ServiceMap getServiceMapLocked(int callingUser) {
437477
ServiceMap smap = mServiceMap.get(callingUser);
438478
if (smap == null) {

services/core/java/com/android/server/am/ActivityManagerService.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19730,6 +19730,22 @@ public boolean hasRunningForegroundService(int uid, int foregroundServicetype) {
1973019730
return false;
1973119731
}
1973219732

19733+
@Override
19734+
public boolean hasForegroundServiceNotification(String pkg, int userId,
19735+
String channelId) {
19736+
synchronized (ActivityManagerService.this) {
19737+
return mServices.hasForegroundServiceNotificationLocked(pkg, userId, channelId);
19738+
}
19739+
}
19740+
19741+
@Override
19742+
public void stopForegroundServicesForChannel(String pkg, int userId,
19743+
String channelId) {
19744+
synchronized (ActivityManagerService.this) {
19745+
mServices.stopForegroundServicesForChannelLocked(pkg, userId, channelId);
19746+
}
19747+
}
19748+
1973319749
@Override
1973419750
public void registerProcessObserver(IProcessObserver processObserver) {
1973519751
ActivityManagerService.this.registerProcessObserver(processObserver);

services/core/java/com/android/server/connectivity/Vpn.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ public class Vpn {
194194
@VisibleForTesting protected String mPackage;
195195
private int mOwnerUID;
196196
private boolean mIsPackageTargetingAtLeastQ;
197-
private String mInterface;
197+
@VisibleForTesting
198+
protected String mInterface;
198199
private Connection mConnection;
199200

200201
/** Tracks the runners for all VPN types managed by the platform (eg. LegacyVpn, PlatformVpn) */

0 commit comments

Comments
 (0)