Merge "Update the session object with the error msg from ApexSessionInfo" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
d8244c55fd
@@ -955,8 +955,7 @@ public class StagingManager {
|
|||||||
continue;
|
continue;
|
||||||
} else if (isApexSessionFailed(apexSession)) {
|
} else if (isApexSessionFailed(apexSession)) {
|
||||||
hasFailedApexSession = true;
|
hasFailedApexSession = true;
|
||||||
String errorMsg = "APEX activation failed. Check logcat messages from apexd "
|
String errorMsg = "APEX activation failed. " + apexSession.errorMessage;
|
||||||
+ "for more information.";
|
|
||||||
if (!TextUtils.isEmpty(apexSession.crashingNativeProcess)) {
|
if (!TextUtils.isEmpty(apexSession.crashingNativeProcess)) {
|
||||||
prepareForLoggingApexdRevert(session, apexSession.crashingNativeProcess);
|
prepareForLoggingApexdRevert(session, apexSession.crashingNativeProcess);
|
||||||
errorMsg = "Session reverted due to crashing native process: "
|
errorMsg = "Session reverted due to crashing native process: "
|
||||||
|
|||||||
@@ -286,6 +286,7 @@ public class StagingManagerTest {
|
|||||||
ApexSessionInfo activationFailed = new ApexSessionInfo();
|
ApexSessionInfo activationFailed = new ApexSessionInfo();
|
||||||
activationFailed.sessionId = 1543;
|
activationFailed.sessionId = 1543;
|
||||||
activationFailed.isActivationFailed = true;
|
activationFailed.isActivationFailed = true;
|
||||||
|
activationFailed.errorMessage = "Failed for test";
|
||||||
|
|
||||||
ApexSessionInfo staged = new ApexSessionInfo();
|
ApexSessionInfo staged = new ApexSessionInfo();
|
||||||
staged.sessionId = 101;
|
staged.sessionId = 101;
|
||||||
@@ -309,8 +310,8 @@ public class StagingManagerTest {
|
|||||||
|
|
||||||
assertThat(apexSession1.getErrorCode())
|
assertThat(apexSession1.getErrorCode())
|
||||||
.isEqualTo(SessionInfo.STAGED_SESSION_ACTIVATION_FAILED);
|
.isEqualTo(SessionInfo.STAGED_SESSION_ACTIVATION_FAILED);
|
||||||
assertThat(apexSession1.getErrorMessage()).isEqualTo("APEX activation failed. Check logcat "
|
assertThat(apexSession1.getErrorMessage()).isEqualTo("APEX activation failed. "
|
||||||
+ "messages from apexd for more information.");
|
+ "Failed for test");
|
||||||
|
|
||||||
assertThat(apexSession2.getErrorCode())
|
assertThat(apexSession2.getErrorCode())
|
||||||
.isEqualTo(SessionInfo.STAGED_SESSION_ACTIVATION_FAILED);
|
.isEqualTo(SessionInfo.STAGED_SESSION_ACTIVATION_FAILED);
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ java_test_host {
|
|||||||
data: [
|
data: [
|
||||||
":com.android.apex.apkrollback.test_v1",
|
":com.android.apex.apkrollback.test_v1",
|
||||||
":com.android.apex.cts.shim.v2_prebuilt",
|
":com.android.apex.cts.shim.v2_prebuilt",
|
||||||
|
":StagedInstallTestApexV2_WrongSha",
|
||||||
":TestAppAv1",
|
":TestAppAv1",
|
||||||
],
|
],
|
||||||
test_suites: ["general-tests"],
|
test_suites: ["general-tests"],
|
||||||
|
|||||||
@@ -179,6 +179,26 @@ public class StagedInstallInternalTest {
|
|||||||
assertThat(info.isStagedSessionFailed()).isTrue();
|
assertThat(info.isStagedSessionFailed()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApexActivationFailureIsCapturedInSession_Commit() throws Exception {
|
||||||
|
int sessionId = Install.single(TestApp.Apex1).setStaged().commit();
|
||||||
|
assertSessionReady(sessionId);
|
||||||
|
storeSessionId(sessionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApexActivationFailureIsCapturedInSession_Verify() throws Exception {
|
||||||
|
int sessionId = retrieveLastSessionId();
|
||||||
|
assertSessionFailedWithMessage(sessionId, "has unexpected SHA512 hash");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void assertSessionFailedWithMessage(int sessionId, String msg) {
|
||||||
|
assertSessionState(sessionId, (session) -> {
|
||||||
|
assertThat(session.isStagedSessionFailed()).isTrue();
|
||||||
|
assertThat(session.getStagedSessionErrorMessage()).contains(msg);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private static void assertSessionReady(int sessionId) {
|
private static void assertSessionReady(int sessionId) {
|
||||||
assertSessionState(sessionId,
|
assertSessionState(sessionId,
|
||||||
(session) -> assertThat(session.isStagedSessionReady()).isTrue());
|
(session) -> assertThat(session.isStagedSessionReady()).isTrue());
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
|
|||||||
@Rule
|
@Rule
|
||||||
public AbandonSessionsRule mHostTestRule = new AbandonSessionsRule(this);
|
public AbandonSessionsRule mHostTestRule = new AbandonSessionsRule(this);
|
||||||
private static final String SHIM_V2 = "com.android.apex.cts.shim.v2.apex";
|
private static final String SHIM_V2 = "com.android.apex.cts.shim.v2.apex";
|
||||||
|
private static final String APEX_WRONG_SHA = "com.android.apex.cts.shim.v2_wrong_sha.apex";
|
||||||
private static final String APK_A = "TestAppAv1.apk";
|
private static final String APK_A = "TestAppAv1.apk";
|
||||||
private static final String APK_IN_APEX_TESTAPEX_NAME = "com.android.apex.apkrollback.test";
|
private static final String APK_IN_APEX_TESTAPEX_NAME = "com.android.apex.apkrollback.test";
|
||||||
|
|
||||||
@@ -322,6 +323,27 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
|
|||||||
runPhase("testFailStagedSessionIfStagingDirectoryDeleted_Verify");
|
runPhase("testFailStagedSessionIfStagingDirectoryDeleted_Verify");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testApexActivationFailureIsCapturedInSession() throws Exception {
|
||||||
|
// We initiate staging a normal apex update which passes pre-reboot verification.
|
||||||
|
// Then we replace the valid apex waiting in /data/app-staging with something
|
||||||
|
// that cannot be activated and reboot. The apex should fail to activate, which
|
||||||
|
// is what we want for this test.
|
||||||
|
runPhase("testApexActivationFailureIsCapturedInSession_Commit");
|
||||||
|
final String sessionId = getDevice().executeShellCommand(
|
||||||
|
"pm get-stagedsessions --only-ready --only-parent --only-sessionid").trim();
|
||||||
|
assertThat(sessionId).isNotEmpty();
|
||||||
|
// Now replace the valid staged apex with something invalid
|
||||||
|
getDevice().enableAdbRoot();
|
||||||
|
getDevice().executeShellCommand("rm /data/app-staging/session_" + sessionId + "/*");
|
||||||
|
final File invalidApexFile = mHostUtils.getTestFile(APEX_WRONG_SHA);
|
||||||
|
getDevice().pushFile(invalidApexFile,
|
||||||
|
"/data/app-staging/session_" + sessionId + "/base.apex");
|
||||||
|
getDevice().reboot();
|
||||||
|
|
||||||
|
runPhase("testApexActivationFailureIsCapturedInSession_Verify");
|
||||||
|
}
|
||||||
|
|
||||||
private List<String> getStagingDirectories() throws DeviceNotAvailableException {
|
private List<String> getStagingDirectories() throws DeviceNotAvailableException {
|
||||||
String baseDir = "/data/app-staging";
|
String baseDir = "/data/app-staging";
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user