Skip to content

Commit 5d3dfba

Browse files
author
android-build-team Robot
committed
Merge cherrypicks of [14651914, 14651880, 14651759, 14652210, 14651594, 14651881, 14651915, 14651882, 14651883, 14651799, 14652154, 14651595, 14651760, 14652271, 14652272, 14652273, 14652056, 14651800, 14651801, 14651802, 14651884, 14651885, 14651886, 14652274, 14652275, 14652276, 14652277, 14652278, 14651894, 14651723, 14652211, 14651895, 14651916, 14651887, 14651888, 14651596, 14651889, 14652212, 14651761, 14652310, 14652311, 14651973, 14651974, 14652312, 14652313, 14651896, 14651803] into rvc-qpr3-release
Change-Id: I28774b63565cb22778502a0eb9810751575e2862
2 parents ba595d5 + ee8cc6f commit 5d3dfba

8 files changed

Lines changed: 134 additions & 51 deletions

File tree

core/res/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@
396396
<protected-broadcast android:name="android.net.wifi.p2p.action.WIFI_P2P_PERSISTENT_GROUPS_CHANGED" />
397397
<protected-broadcast android:name="android.net.conn.TETHER_STATE_CHANGED" />
398398
<protected-broadcast android:name="android.net.conn.INET_CONDITION_ACTION" />
399+
<!-- This broadcast is no longer sent in S but it should stay protected to avoid third party
400+
apps broadcasting this and confusing old system apps that may not have been updated. -->
399401
<protected-broadcast android:name="android.net.conn.NETWORK_CONDITIONS_MEASURED" />
400402
<protected-broadcast
401403
android:name="android.net.ConnectivityService.action.PKT_CNT_SAMPLE_INTERVAL_ELAPSED" />

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/rollback/RollbackManagerServiceImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,10 @@ void onBootCompleted() {
554554
PackageInstaller.SessionInfo session = mContext.getPackageManager()
555555
.getPackageInstaller().getSessionInfo(rollback.getStagedSessionId());
556556
if (session == null || session.isStagedSessionFailed()) {
557-
iter.remove();
558-
rollback.delete(mAppDataRollbackHelper);
557+
if (rollback.isEnabling()) {
558+
iter.remove();
559+
rollback.delete(mAppDataRollbackHelper);
560+
}
559561
continue;
560562
}
561563

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

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

33743374
/**
3375-
* Find all visible task stacks containing {@param userId} and intercept them with an activity
3375+
* Find all task stacks containing {@param userId} and intercept them with an activity
33763376
* to block out the contents and possibly start a credential-confirming intent.
33773377
*
33783378
* @param userId user handle for the locked managed profile.
33793379
*/
33803380
void lockAllProfileTasks(@UserIdInt int userId) {
33813381
mService.deferWindowLayout();
33823382
try {
3383-
final PooledConsumer c = PooledLambda.obtainConsumer(
3384-
RootWindowContainer::taskTopActivityIsUser, this, PooledLambda.__(Task.class),
3385-
userId);
3386-
forAllLeafTasks(c, true /* traverseTopToBottom */);
3387-
c.recycle();
3383+
forAllLeafTasks(task -> {
3384+
if (task.getActivity(activity -> !activity.finishing && activity.mUserId == userId)
3385+
!= null) {
3386+
mService.getTaskChangeNotificationController().notifyTaskProfileLocked(
3387+
task.mTaskId, userId);
3388+
}
3389+
}, true /* traverseTopToBottom */);
33883390
} finally {
33893391
mService.continueWindowLayout();
33903392
}
33913393
}
33923394

3393-
/**
3394-
* Detects whether we should show a lock screen in front of this task for a locked user.
3395-
* <p>
3396-
* We'll do this if either of the following holds:
3397-
* <ul>
3398-
* <li>The top activity explicitly belongs to {@param userId}.</li>
3399-
* <li>The top activity returns a result to an activity belonging to {@param userId}.</li>
3400-
* </ul>
3401-
*
3402-
* @return {@code true} if the top activity looks like it belongs to {@param userId}.
3403-
*/
3404-
private void taskTopActivityIsUser(Task task, @UserIdInt int userId) {
3405-
// To handle the case that work app is in the task but just is not the top one.
3406-
final ActivityRecord activityRecord = task.getTopNonFinishingActivity();
3407-
final ActivityRecord resultTo = (activityRecord != null ? activityRecord.resultTo : null);
3408-
3409-
// Check the task for a top activity belonging to userId, or returning a
3410-
// result to an activity belonging to userId. Example case: a document
3411-
// picker for personal files, opened by a work app, should still get locked.
3412-
if ((activityRecord != null && activityRecord.mUserId == userId)
3413-
|| (resultTo != null && resultTo.mUserId == userId)) {
3414-
mService.getTaskChangeNotificationController().notifyTaskProfileLocked(
3415-
task.mTaskId, userId);
3416-
}
3417-
}
3418-
34193395
void cancelInitializingActivities() {
34203396
for (int displayNdx = getChildCount() - 1; displayNdx >= 0; --displayNdx) {
34213397
final DisplayContent display = getChildAt(displayNdx);

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/RollbackTest/RollbackTest/src/com/android/tests/rollback/StagedRollbackTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,33 @@ public void isCheckpointSupported() {
481481
assertThat(sm.isCheckpointSupported()).isTrue();
482482
}
483483

484+
@Test
485+
public void testExpireSession_Phase1_Install() throws Exception {
486+
assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(-1);
487+
Install.single(TestApp.A1).commit();
488+
assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
489+
Install.single(TestApp.A2).setEnableRollback().setStaged().commit();
490+
}
491+
492+
@Test
493+
public void testExpireSession_Phase2_VerifyInstall() throws Exception {
494+
assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
495+
RollbackManager rm = RollbackUtils.getRollbackManager();
496+
RollbackInfo rollback = getUniqueRollbackInfoForPackage(
497+
rm.getAvailableRollbacks(), TestApp.A);
498+
assertThat(rollback).isNotNull();
499+
assertThat(rollback).packagesContainsExactly(Rollback.from(TestApp.A2).to(TestApp.A1));
500+
assertThat(rollback.isStaged()).isTrue();
501+
}
502+
503+
@Test
504+
public void testExpireSession_Phase3_VerifyRollback() throws Exception {
505+
RollbackManager rm = RollbackUtils.getRollbackManager();
506+
RollbackInfo rollback = getUniqueRollbackInfoForPackage(
507+
rm.getAvailableRollbacks(), TestApp.A);
508+
assertThat(rollback).isNotNull();
509+
}
510+
484511
@Test
485512
public void hasMainlineModule() throws Exception {
486513
String pkgName = getModuleMetadataPackageName();

tests/RollbackTest/StagedRollbackTest/src/com/android/tests/rollback/host/StagedRollbackTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
import org.junit.runner.RunWith;
3939

4040
import java.io.File;
41+
import java.time.Instant;
4142
import java.util.Collections;
43+
import java.util.Date;
4244
import java.util.List;
4345
import java.util.concurrent.TimeUnit;
4446
import java.util.stream.Collectors;
@@ -441,6 +443,27 @@ public void testRollbackApexDataDirectories_Ce() throws Exception {
441443
after.forEach(dir -> assertDirectoryIsEmpty(dir));
442444
}
443445

446+
/**
447+
* Tests an available rollback shouldn't be deleted when its session expires.
448+
*/
449+
@Test
450+
public void testExpireSession() throws Exception {
451+
runPhase("testExpireSession_Phase1_Install");
452+
getDevice().reboot();
453+
runPhase("testExpireSession_Phase2_VerifyInstall");
454+
455+
// Advance system clock by 7 days to expire the staged session
456+
Instant t1 = Instant.ofEpochMilli(getDevice().getDeviceDate());
457+
Instant t2 = t1.plusMillis(TimeUnit.DAYS.toMillis(7));
458+
runAsRoot(() -> getDevice().setDate(Date.from(t2)));
459+
460+
// Somehow we need to wait for a while before reboot. Otherwise the change to the
461+
// system clock will be reset after reboot.
462+
Thread.sleep(3000);
463+
getDevice().reboot();
464+
runPhase("testExpireSession_Phase3_VerifyRollback");
465+
}
466+
444467
private void pushTestApex() throws Exception {
445468
CompatibilityBuildHelper buildHelper = new CompatibilityBuildHelper(getBuild());
446469
final String fileName = APK_IN_APEX_TESTAPEX_NAME + "_v1.apex";
@@ -521,4 +544,18 @@ private boolean hasMainlineModule() throws Exception {
521544
return false;
522545
}
523546
}
547+
548+
@FunctionalInterface
549+
private interface ExceptionalRunnable {
550+
void run() throws Exception;
551+
}
552+
553+
private void runAsRoot(ExceptionalRunnable runnable) throws Exception {
554+
try {
555+
getDevice().enableAdbRoot();
556+
runnable.run();
557+
} finally {
558+
getDevice().disableAdbRoot();
559+
}
560+
}
524561
}

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)