Skip to content

Commit d7c3493

Browse files
committed
Merge tag 'android-11.0.0_r29' of https://android.googlesource.com/platform/frameworks/base into staging/lineage-18.1_merge-android-11.0.0_r29
Android 11.0.0 release 29 * tag 'android-11.0.0_r29' of https://android.googlesource.com/platform/frameworks/base: Delete orphaned staging directories for staged session on reboot Clean up staged session data on validation failure [SettingsProvider] fix font size scale validator Remove updateIntentVerificationStatusAsUser from ResolverActivity Ensure caller identity is restored in CP quick-path. Change-Id: Ibdf04c59ddbfa02b2e8151d2a0acfa98cac047ee
2 parents 1a41725 + f156301 commit d7c3493

7 files changed

Lines changed: 132 additions & 86 deletions

File tree

core/java/com/android/internal/app/ResolverActivity.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,25 +1210,6 @@ protected boolean onTargetSelected(TargetInfo target, boolean alwaysCheck) {
12101210
if (TextUtils.isEmpty(packageName)) {
12111211
pm.setDefaultBrowserPackageNameAsUser(ri.activityInfo.packageName, userId);
12121212
}
1213-
} else {
1214-
// Update Domain Verification status
1215-
ComponentName cn = intent.getComponent();
1216-
String packageName = cn.getPackageName();
1217-
String dataScheme = (data != null) ? data.getScheme() : null;
1218-
1219-
boolean isHttpOrHttps = (dataScheme != null) &&
1220-
(dataScheme.equals(IntentFilter.SCHEME_HTTP) ||
1221-
dataScheme.equals(IntentFilter.SCHEME_HTTPS));
1222-
1223-
boolean isViewAction = (action != null) && action.equals(Intent.ACTION_VIEW);
1224-
boolean hasCategoryBrowsable = (categories != null) &&
1225-
categories.contains(Intent.CATEGORY_BROWSABLE);
1226-
1227-
if (isHttpOrHttps && isViewAction && hasCategoryBrowsable) {
1228-
pm.updateIntentVerificationStatusAsUser(packageName,
1229-
PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_ALWAYS,
1230-
userId);
1231-
}
12321213
}
12331214
} else {
12341215
try {

packages/SettingsProvider/src/android/provider/settings/validators/SystemSettingsValidators.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,7 @@ public boolean validate(String value) {
8989
return value == null || value.length() < MAX_LENGTH;
9090
}
9191
});
92-
VALIDATORS.put(
93-
System.FONT_SCALE,
94-
value -> {
95-
try {
96-
return Float.parseFloat(value) >= 0;
97-
} catch (NumberFormatException | NullPointerException e) {
98-
return false;
99-
}
100-
});
92+
VALIDATORS.put(System.FONT_SCALE, new InclusiveFloatRangeValidator(0.85f, 1.3f));
10193
VALIDATORS.put(System.DIM_SCREEN, BOOLEAN_VALIDATOR);
10294
VALIDATORS.put(
10395
System.DISPLAY_COLOR_MODE,

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

Lines changed: 59 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7142,67 +7142,68 @@ && isValidSingletonCall(r == null ? callingUid : r.uid,
71427142
"getContentProviderImpl: after checkContentProviderPermission");
71437143

71447144
final long origId = Binder.clearCallingIdentity();
7145+
try {
7146+
checkTime(startTime, "getContentProviderImpl: incProviderCountLocked");
7147+
7148+
// Return the provider instance right away since it already exists.
7149+
conn = incProviderCountLocked(r, cpr, token, callingUid, callingPackage,
7150+
callingTag, stable);
7151+
if (conn != null && (conn.stableCount+conn.unstableCount) == 1) {
7152+
if (cpr.proc != null
7153+
&& r != null && r.setAdj <= ProcessList.PERCEPTIBLE_LOW_APP_ADJ) {
7154+
// If this is a perceptible app accessing the provider,
7155+
// make sure to count it as being accessed and thus
7156+
// back up on the LRU list. This is good because
7157+
// content providers are often expensive to start.
7158+
checkTime(startTime, "getContentProviderImpl: before updateLruProcess");
7159+
mProcessList.updateLruProcessLocked(cpr.proc, false, null);
7160+
checkTime(startTime, "getContentProviderImpl: after updateLruProcess");
7161+
}
7162+
}
71457163

7146-
checkTime(startTime, "getContentProviderImpl: incProviderCountLocked");
7147-
7148-
// In this case the provider instance already exists, so we can
7149-
// return it right away.
7150-
conn = incProviderCountLocked(r, cpr, token, callingUid, callingPackage, callingTag,
7151-
stable);
7152-
if (conn != null && (conn.stableCount+conn.unstableCount) == 1) {
7153-
if (cpr.proc != null
7154-
&& r != null && r.setAdj <= ProcessList.PERCEPTIBLE_LOW_APP_ADJ) {
7155-
// If this is a perceptible app accessing the provider,
7156-
// make sure to count it as being accessed and thus
7157-
// back up on the LRU list. This is good because
7158-
// content providers are often expensive to start.
7159-
checkTime(startTime, "getContentProviderImpl: before updateLruProcess");
7160-
mProcessList.updateLruProcessLocked(cpr.proc, false, null);
7161-
checkTime(startTime, "getContentProviderImpl: after updateLruProcess");
7162-
}
7163-
}
7164-
7165-
checkTime(startTime, "getContentProviderImpl: before updateOomAdj");
7166-
final int verifiedAdj = cpr.proc.verifiedAdj;
7167-
boolean success = updateOomAdjLocked(cpr.proc, true,
7168-
OomAdjuster.OOM_ADJ_REASON_GET_PROVIDER);
7169-
// XXX things have changed so updateOomAdjLocked doesn't actually tell us
7170-
// if the process has been successfully adjusted. So to reduce races with
7171-
// it, we will check whether the process still exists. Note that this doesn't
7172-
// completely get rid of races with LMK killing the process, but should make
7173-
// them much smaller.
7174-
if (success && verifiedAdj != cpr.proc.setAdj && !isProcessAliveLocked(cpr.proc)) {
7175-
success = false;
7176-
}
7177-
maybeUpdateProviderUsageStatsLocked(r, cpr.info.packageName, name);
7178-
checkTime(startTime, "getContentProviderImpl: after updateOomAdj");
7179-
if (DEBUG_PROVIDER) Slog.i(TAG_PROVIDER, "Adjust success: " + success);
7180-
// NOTE: there is still a race here where a signal could be
7181-
// pending on the process even though we managed to update its
7182-
// adj level. Not sure what to do about this, but at least
7183-
// the race is now smaller.
7184-
if (!success) {
7185-
// Uh oh... it looks like the provider's process
7186-
// has been killed on us. We need to wait for a new
7187-
// process to be started, and make sure its death
7188-
// doesn't kill our process.
7189-
Slog.wtf(TAG, "Existing provider " + cpr.name.flattenToShortString()
7190-
+ " is crashing; detaching " + r);
7191-
boolean lastRef = decProviderCountLocked(conn, cpr, token, stable);
7192-
if (!lastRef) {
7193-
// This wasn't the last ref our process had on
7194-
// the provider... we will be killed during cleaning up, bail.
7195-
return null;
7164+
checkTime(startTime, "getContentProviderImpl: before updateOomAdj");
7165+
final int verifiedAdj = cpr.proc.verifiedAdj;
7166+
boolean success = updateOomAdjLocked(cpr.proc, true,
7167+
OomAdjuster.OOM_ADJ_REASON_GET_PROVIDER);
7168+
// XXX things have changed so updateOomAdjLocked doesn't actually tell us
7169+
// if the process has been successfully adjusted. So to reduce races with
7170+
// it, we will check whether the process still exists. Note that this doesn't
7171+
// completely get rid of races with LMK killing the process, but should make
7172+
// them much smaller.
7173+
if (success && verifiedAdj != cpr.proc.setAdj
7174+
&& !isProcessAliveLocked(cpr.proc)) {
7175+
success = false;
7176+
}
7177+
maybeUpdateProviderUsageStatsLocked(r, cpr.info.packageName, name);
7178+
checkTime(startTime, "getContentProviderImpl: after updateOomAdj");
7179+
if (DEBUG_PROVIDER) Slog.i(TAG_PROVIDER, "Adjust success: " + success);
7180+
// NOTE: there is still a race here where a signal could be
7181+
// pending on the process even though we managed to update its
7182+
// adj level. Not sure what to do about this, but at least
7183+
// the race is now smaller.
7184+
if (!success) {
7185+
// Uh oh... it looks like the provider's process
7186+
// has been killed on us. We need to wait for a new
7187+
// process to be started, and make sure its death
7188+
// doesn't kill our process.
7189+
Slog.wtf(TAG, "Existing provider " + cpr.name.flattenToShortString()
7190+
+ " is crashing; detaching " + r);
7191+
boolean lastRef = decProviderCountLocked(conn, cpr, token, stable);
7192+
if (!lastRef) {
7193+
// This wasn't the last ref our process had on
7194+
// the provider... we will be killed during cleaning up, bail.
7195+
return null;
7196+
}
7197+
// We'll just start a new process to host the content provider
7198+
providerRunning = false;
7199+
conn = null;
7200+
dyingProc = cpr.proc;
7201+
} else {
7202+
cpr.proc.verifiedAdj = cpr.proc.setAdj;
71967203
}
7197-
// We'll just start a new process to host the content provider
7198-
providerRunning = false;
7199-
conn = null;
7200-
dyingProc = cpr.proc;
7201-
} else {
7202-
cpr.proc.verifiedAdj = cpr.proc.setAdj;
7204+
} finally {
7205+
Binder.restoreCallingIdentity(origId);
72037206
}
7204-
7205-
Binder.restoreCallingIdentity(origId);
72067207
}
72077208

72087209
if (!providerRunning) {

services/core/java/com/android/server/pm/PackageInstallerService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,10 @@ private void reconcileStagesLocked(String volumeUuid) {
299299
final ArraySet<File> unclaimedStages = newArraySet(
300300
stagingDir.listFiles(sStageFilter));
301301

302+
// We also need to clean up orphaned staging directory for staged sessions
303+
final File stagedSessionStagingDir = Environment.getDataStagingDirectory(volumeUuid);
304+
unclaimedStages.addAll(newArraySet(stagedSessionStagingDir.listFiles()));
305+
302306
// Ignore stages claimed by active sessions
303307
for (int i = 0; i < mSessions.size(); i++) {
304308
final PackageInstallerSession session = mSessions.valueAt(i);

services/core/java/com/android/server/pm/PackageInstallerSession.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,10 @@ private void onSessionVerificationFailure(int error, String detailMessage) {
15811581
destroyInternal();
15821582
// Dispatch message to remove session from PackageInstallerService.
15831583
dispatchSessionFinished(error, detailMessage, null);
1584+
// TODO(b/173194203): clean up staged session in destroyInternal() call instead
1585+
if (isStaged() && stageDir != null) {
1586+
cleanStageDir();
1587+
}
15841588
}
15851589

15861590
private void onStorageUnhealthy() {

tests/StagedInstallTest/app/src/com/android/tests/stagedinstallinternal/StagedInstallInternalTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ public void testSystemServerRestartDoesNotAffectStagedSessions_Verify() throws E
9696
assertSessionReady(sessionId);
9797
}
9898

99+
@Test
100+
public void testStagedInstallationShouldCleanUpOnValidationFailure() throws Exception {
101+
InstallUtils.commitExpectingFailure(AssertionError.class, "INSTALL_FAILED_INVALID_APK",
102+
Install.single(TestApp.AIncompleteSplit).setStaged());
103+
}
104+
105+
@Test
106+
public void testStagedInstallationShouldCleanUpOnValidationFailureMultiPackage()
107+
throws Exception {
108+
InstallUtils.commitExpectingFailure(AssertionError.class, "INSTALL_FAILED_INVALID_APK",
109+
Install.multi(TestApp.AIncompleteSplit, TestApp.B1, TestApp.Apex1).setStaged());
110+
}
111+
99112
private static void assertSessionReady(int sessionId) {
100113
assertSessionState(sessionId,
101114
(session) -> assertThat(session.isStagedSessionReady()).isTrue());

tests/StagedInstallTest/src/com/android/tests/stagedinstallinternal/host/StagedInstallInternalTest.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.junit.Assert.assertTrue;
2222

2323
import com.android.ddmlib.Log;
24+
import com.android.tradefed.device.DeviceNotAvailableException;
2425
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
2526
import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
2627
import com.android.tradefed.util.ProcessInfo;
@@ -30,6 +31,10 @@
3031
import org.junit.Test;
3132
import org.junit.runner.RunWith;
3233

34+
import java.util.Collections;
35+
import java.util.List;
36+
import java.util.stream.Collectors;
37+
3338
@RunWith(DeviceJUnit4ClassRunner.class)
3439
public class StagedInstallInternalTest extends BaseHostJUnit4Test {
3540

@@ -87,6 +92,52 @@ public void testSystemServerRestartDoesNotAffectStagedSessions() throws Exceptio
8792
runPhase("testSystemServerRestartDoesNotAffectStagedSessions_Verify");
8893
}
8994

95+
@Test
96+
public void testStagedInstallationShouldCleanUpOnValidationFailure() throws Exception {
97+
List<String> before = getStagingDirectories();
98+
runPhase("testStagedInstallationShouldCleanUpOnValidationFailure");
99+
List<String> after = getStagingDirectories();
100+
assertThat(after).isEqualTo(before);
101+
}
102+
103+
@Test
104+
public void testStagedInstallationShouldCleanUpOnValidationFailureMultiPackage()
105+
throws Exception {
106+
List<String> before = getStagingDirectories();
107+
runPhase("testStagedInstallationShouldCleanUpOnValidationFailureMultiPackage");
108+
List<String> after = getStagingDirectories();
109+
assertThat(after).isEqualTo(before);
110+
}
111+
112+
@Test
113+
public void testOrphanedStagingDirectoryGetsCleanedUpOnReboot() throws Exception {
114+
//create random directories in /data/app-staging folder
115+
getDevice().enableAdbRoot();
116+
getDevice().executeShellCommand("mkdir /data/app-staging/session_123");
117+
getDevice().executeShellCommand("mkdir /data/app-staging/random_name");
118+
getDevice().disableAdbRoot();
119+
120+
assertThat(getStagingDirectories()).isNotEmpty();
121+
getDevice().reboot();
122+
assertThat(getStagingDirectories()).isEmpty();
123+
}
124+
125+
private List<String> getStagingDirectories() throws DeviceNotAvailableException {
126+
String baseDir = "/data/app-staging";
127+
try {
128+
getDevice().enableAdbRoot();
129+
return getDevice().getFileEntry(baseDir).getChildren(false)
130+
.stream().filter(entry -> entry.getName().matches("session_\\d+"))
131+
.map(entry -> entry.getName())
132+
.collect(Collectors.toList());
133+
} catch (Exception e) {
134+
// Return an empty list if any error
135+
return Collections.EMPTY_LIST;
136+
} finally {
137+
getDevice().disableAdbRoot();
138+
}
139+
}
140+
90141
private void restartSystemServer() throws Exception {
91142
// Restart the system server
92143
long oldStartTime = getDevice().getProcessByName("system_server").getStartTime();

0 commit comments

Comments
 (0)