Skip to content

Commit 6ded506

Browse files
author
android-build-team Robot
committed
Merge cherrypicks of [14551043, 14550658, 14550659, 14550660, 14550661, 14552046, 14554284, 14554486, 14552047, 14554032, 14554033, 14554034, 14554035, 14554036, 14554037, 14554038, 14554039, 14550926, 14554040, 14554341, 14554662, 14554041] into security-aosp-rvc-release
Change-Id: Ic70e575ee6a7442be13054b67649e340a02c708e
2 parents c33fdd0 + afc122e commit 6ded506

7 files changed

Lines changed: 93 additions & 49 deletions

File tree

core/res/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,8 @@
389389
<protected-broadcast android:name="android.net.wifi.p2p.action.WIFI_P2P_PERSISTENT_GROUPS_CHANGED" />
390390
<protected-broadcast android:name="android.net.conn.TETHER_STATE_CHANGED" />
391391
<protected-broadcast android:name="android.net.conn.INET_CONDITION_ACTION" />
392+
<!-- This broadcast is no longer sent in S but it should stay protected to avoid third party
393+
apps broadcasting this and confusing old system apps that may not have been updated. -->
392394
<protected-broadcast android:name="android.net.conn.NETWORK_CONDITIONS_MEASURED" />
393395
<protected-broadcast
394396
android:name="android.net.ConnectivityService.action.PKT_CNT_SAMPLE_INTERVAL_ELAPSED" />

services/core/java/com/android/server/notification/NotificationManagerService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6864,6 +6864,7 @@ void scheduleTimeoutLocked(NotificationRecord record) {
68646864
final PendingIntent pi = PendingIntent.getBroadcast(getContext(),
68656865
REQUEST_CODE_TIMEOUT,
68666866
new Intent(ACTION_NOTIFICATION_TIMEOUT)
6867+
.setPackage(PackageManagerService.PLATFORM_PACKAGE_NAME)
68676868
.setData(new Uri.Builder().scheme(SCHEME_TIMEOUT)
68686869
.appendPath(record.getKey()).build())
68696870
.addFlags(Intent.FLAG_RECEIVER_FOREGROUND)

services/core/java/com/android/server/pm/permission/PermissionManagerService.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,23 +2293,30 @@ private void revokeStoragePermissionsIfScopeExpanded(
22932293
}
22942294

22952295
final int callingUid = Binder.getCallingUid();
2296-
final int userId = UserHandle.getUserId(newPackage.getUid());
2297-
int numRequestedPermissions = newPackage.getRequestedPermissions().size();
2298-
for (int i = 0; i < numRequestedPermissions; i++) {
2299-
PermissionInfo permInfo = getPermissionInfo(newPackage.getRequestedPermissions().get(i),
2300-
newPackage.getPackageName(), 0);
2301-
if (permInfo == null || !STORAGE_PERMISSIONS.contains(permInfo.name)) {
2302-
continue;
2303-
}
2296+
for (int userId: mUserManagerInt.getUserIds()) {
2297+
int numRequestedPermissions = newPackage.getRequestedPermissions().size();
2298+
for (int i = 0; i < numRequestedPermissions; i++) {
2299+
PermissionInfo permInfo = getPermissionInfo(
2300+
newPackage.getRequestedPermissions().get(i),
2301+
newPackage.getPackageName(), 0);
2302+
if (permInfo == null || !STORAGE_PERMISSIONS.contains(permInfo.name)) {
2303+
continue;
2304+
}
23042305

2305-
EventLog.writeEvent(0x534e4554, "171430330", newPackage.getUid(),
2306-
"Revoking permission " + permInfo.name + " from package "
2307-
+ newPackage.getPackageName() + " as either the sdk downgraded "
2308-
+ downgradedSdk + " or newly requested legacy full storage "
2309-
+ newlyRequestsLegacy);
2306+
EventLog.writeEvent(0x534e4554, "171430330", newPackage.getUid(),
2307+
"Revoking permission " + permInfo.name + " from package "
2308+
+ newPackage.getPackageName() + " as either the sdk downgraded "
2309+
+ downgradedSdk + " or newly requested legacy full storage "
2310+
+ newlyRequestsLegacy);
23102311

2311-
revokeRuntimePermissionInternal(permInfo.name, newPackage.getPackageName(),
2312-
false, callingUid, userId, null, permissionCallback);
2312+
try {
2313+
revokeRuntimePermissionInternal(permInfo.name, newPackage.getPackageName(),
2314+
false, callingUid, userId, null, permissionCallback);
2315+
} catch (IllegalStateException | SecurityException e) {
2316+
Log.e(TAG, "unable to revoke " + permInfo.name + " for "
2317+
+ newPackage.getPackageName() + " user " + userId, e);
2318+
}
2319+
}
23132320
}
23142321

23152322
}

services/core/java/com/android/server/wm/RootWindowContainer.java

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3356,50 +3356,26 @@ boolean allPausedActivitiesComplete() {
33563356
}
33573357

33583358
/**
3359-
* Find all visible task stacks containing {@param userId} and intercept them with an activity
3359+
* Find all task stacks containing {@param userId} and intercept them with an activity
33603360
* to block out the contents and possibly start a credential-confirming intent.
33613361
*
33623362
* @param userId user handle for the locked managed profile.
33633363
*/
33643364
void lockAllProfileTasks(@UserIdInt int userId) {
33653365
mService.deferWindowLayout();
33663366
try {
3367-
final PooledConsumer c = PooledLambda.obtainConsumer(
3368-
RootWindowContainer::taskTopActivityIsUser, this, PooledLambda.__(Task.class),
3369-
userId);
3370-
forAllLeafTasks(c, true /* traverseTopToBottom */);
3371-
c.recycle();
3367+
forAllLeafTasks(task -> {
3368+
if (task.getActivity(activity -> !activity.finishing && activity.mUserId == userId)
3369+
!= null) {
3370+
mService.getTaskChangeNotificationController().notifyTaskProfileLocked(
3371+
task.mTaskId, userId);
3372+
}
3373+
}, true /* traverseTopToBottom */);
33723374
} finally {
33733375
mService.continueWindowLayout();
33743376
}
33753377
}
33763378

3377-
/**
3378-
* Detects whether we should show a lock screen in front of this task for a locked user.
3379-
* <p>
3380-
* We'll do this if either of the following holds:
3381-
* <ul>
3382-
* <li>The top activity explicitly belongs to {@param userId}.</li>
3383-
* <li>The top activity returns a result to an activity belonging to {@param userId}.</li>
3384-
* </ul>
3385-
*
3386-
* @return {@code true} if the top activity looks like it belongs to {@param userId}.
3387-
*/
3388-
private void taskTopActivityIsUser(Task task, @UserIdInt int userId) {
3389-
// To handle the case that work app is in the task but just is not the top one.
3390-
final ActivityRecord activityRecord = task.getTopNonFinishingActivity();
3391-
final ActivityRecord resultTo = (activityRecord != null ? activityRecord.resultTo : null);
3392-
3393-
// Check the task for a top activity belonging to userId, or returning a
3394-
// result to an activity belonging to userId. Example case: a document
3395-
// picker for personal files, opened by a work app, should still get locked.
3396-
if ((activityRecord != null && activityRecord.mUserId == userId)
3397-
|| (resultTo != null && resultTo.mUserId == userId)) {
3398-
mService.getTaskChangeNotificationController().notifyTaskProfileLocked(
3399-
task.mTaskId, userId);
3400-
}
3401-
}
3402-
34033379
void cancelInitializingActivities() {
34043380
for (int displayNdx = getChildCount() - 1; displayNdx >= 0; --displayNdx) {
34053381
final DisplayContent display = getChildAt(displayNdx);

services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484

8585
import android.app.ActivityManager;
8686
import android.app.ActivityManagerInternal;
87+
import android.app.AlarmManager;
8788
import android.app.AppOpsManager;
8889
import android.app.AutomaticZenRule;
8990
import android.app.IActivityManager;
@@ -171,6 +172,7 @@
171172
import com.android.server.lights.LogicalLight;
172173
import com.android.server.notification.NotificationManagerService.NotificationAssistants;
173174
import com.android.server.notification.NotificationManagerService.NotificationListeners;
175+
import com.android.server.pm.PackageManagerService;
174176
import com.android.server.statusbar.StatusBarManagerInternal;
175177
import com.android.server.uri.UriGrantsManagerInternal;
176178
import com.android.server.wm.ActivityTaskManagerInternal;
@@ -282,6 +284,8 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
282284
NotificationHistoryManager mHistoryManager;
283285
@Mock
284286
StatsManager mStatsManager;
287+
@Mock
288+
AlarmManager mAlarmManager;
285289
NotificationRecordLoggerFake mNotificationRecordLogger = new NotificationRecordLoggerFake();
286290
private InstanceIdSequence mNotificationInstanceIdSequence = new InstanceIdSequenceFake(
287291
1 << 30);
@@ -423,6 +427,8 @@ public void setUp() throws Exception {
423427
LocalServices.addService(DeviceIdleInternal.class, deviceIdleInternal);
424428
LocalServices.removeServiceForTest(ActivityManagerInternal.class);
425429
LocalServices.addService(ActivityManagerInternal.class, activityManagerInternal);
430+
mContext.addMockSystemService(Context.ALARM_SERVICE, mAlarmManager);
431+
426432

427433
doNothing().when(mContext).sendBroadcastAsUser(any(), any(), any());
428434

@@ -831,6 +837,26 @@ private NotificationRecord addGroupWithBubblesAndValidateAdded(boolean summaryAu
831837
return nrSummary;
832838
}
833839

840+
@Test
841+
public void testLimitTimeOutBroadcast() {
842+
NotificationChannel channel = new NotificationChannel("id", "name",
843+
NotificationManager.IMPORTANCE_HIGH);
844+
Notification.Builder nb = new Notification.Builder(mContext, channel.getId())
845+
.setContentTitle("foo")
846+
.setSmallIcon(android.R.drawable.sym_def_app_icon)
847+
.setTimeoutAfter(1);
848+
849+
StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0,
850+
nb.build(), UserHandle.getUserHandleForUid(mUid), null, 0);
851+
NotificationRecord r = new NotificationRecord(mContext, sbn, channel);
852+
853+
mService.scheduleTimeoutLocked(r);
854+
ArgumentCaptor<PendingIntent> captor = ArgumentCaptor.forClass(PendingIntent.class);
855+
verify(mAlarmManager).setExactAndAllowWhileIdle(anyInt(), anyLong(), captor.capture());
856+
assertEquals(PackageManagerService.PLATFORM_PACKAGE_NAME,
857+
captor.getValue().getIntent().getPackage());
858+
}
859+
834860
@Test
835861
public void testDefaultAssistant_overrideDefault() {
836862
final int userId = 0;

services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
2626
import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
2727

28+
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
2829
import static com.android.server.wm.ActivityStack.ActivityState.FINISHING;
2930
import static com.android.server.wm.ActivityStack.ActivityState.PAUSED;
3031
import static com.android.server.wm.ActivityStack.ActivityState.PAUSING;
@@ -36,10 +37,13 @@
3637
import static org.junit.Assert.assertEquals;
3738
import static org.junit.Assert.assertFalse;
3839
import static org.junit.Assert.assertTrue;
40+
import static org.mockito.ArgumentMatchers.eq;
41+
import static org.mockito.Mockito.verify;
3942

4043
import android.app.WindowConfiguration;
4144
import android.content.ComponentName;
4245
import android.content.pm.ActivityInfo;
46+
import android.os.UserHandle;
4347
import android.platform.test.annotations.Presubmit;
4448

4549
import androidx.test.filters.SmallTest;
@@ -169,5 +173,34 @@ public void testAllPausedActivitiesComplete() {
169173
activity.setState(FINISHING, "test FINISHING");
170174
assertThat(mWm.mRoot.allPausedActivitiesComplete()).isTrue();
171175
}
176+
177+
@Test
178+
public void testLockAllProfileTasks() {
179+
// Make an activity visible with the user id set to 0
180+
DisplayContent displayContent = mWm.mRoot.getDisplayContent(DEFAULT_DISPLAY);
181+
TaskDisplayArea taskDisplayArea = displayContent.getTaskDisplayAreaAt(0);
182+
final ActivityStack stack = createTaskStackOnDisplay(WINDOWING_MODE_FULLSCREEN,
183+
ACTIVITY_TYPE_STANDARD, displayContent);
184+
final ActivityRecord activity = new ActivityTestsBase.ActivityBuilder(stack.mAtmService)
185+
.setStack(stack)
186+
.setUid(0)
187+
.setCreateTask(true)
188+
.build();
189+
190+
// Create another activity on top and the user id is 1
191+
Task task = activity.getTask();
192+
final ActivityRecord topActivity = new ActivityTestsBase.ActivityBuilder(mWm.mAtmService)
193+
.setStack(stack)
194+
.setUid(UserHandle.PER_USER_RANGE + 1)
195+
.setTask(task)
196+
.build();
197+
198+
// Make sure the listeners will be notified for putting the task to locked state
199+
TaskChangeNotificationController controller =
200+
mWm.mAtmService.getTaskChangeNotificationController();
201+
spyOn(controller);
202+
mWm.mRoot.lockAllProfileTasks(0);
203+
verify(controller).notifyTaskProfileLocked(eq(task.mTaskId), eq(0));
204+
}
172205
}
173206

tests/net/integration/src/com/android/server/net/integrationtests/TestNetworkStackService.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ class TestNetworkStackService : Service() {
5959
private class NetworkMonitorDeps(private val privateDnsBypassNetwork: Network) :
6060
NetworkMonitor.Dependencies() {
6161
override fun getPrivateDnsBypassNetwork(network: Network?) = privateDnsBypassNetwork
62-
override fun sendNetworkConditionsBroadcast(context: Context, broadcast: Intent) = Unit
6362
}
6463

6564
private inner class TestNetworkStackConnector(context: Context) : NetworkStackConnector(
@@ -94,4 +93,4 @@ class TestNetworkStackService : Service() {
9493
cb.onNetworkMonitorCreated(NetworkMonitorConnector(nm, TestPermissionChecker()))
9594
}
9695
}
97-
}
96+
}

0 commit comments

Comments
 (0)