Mark apexd session as successful before marking staged session applied

Failing to mark session as successful won't block this staged session:
- it's mostly for bookkeeping purposes, in the future apexd might just
  delete information about the session after it is marked as successful;
- in case this call failed, when new session is staged apexd will delete
  all dangling sessions.

Bug: 124215327
Fixes: 124215327
Test: apex_e2e_tests
Change-Id: I7c9a068bc32352792610e7190e08a884bb5d09a5
This commit is contained in:
Nikita Ioffe
2019-02-15 14:22:44 +00:00
parent e4f26ef212
commit a820bd9f3f
2 changed files with 29 additions and 3 deletions

View File

@@ -166,6 +166,27 @@ class ApexManager {
}
}
/**
* Marks a staged session as successful.
*
* <p>Only activated session can be marked as successful.
*
* @param sessionId the identifier of the {@link PackageInstallerSession} being marked as
* successful.
*/
void markStagedSessionSuccessful(int sessionId) {
try {
mApexService.markStagedSessionSuccessful(sessionId);
} catch (RemoteException re) {
Slog.e(TAG, "Unable to contact apexservice", re);
throw new RuntimeException(re);
} catch (Exception e) {
// It is fine to just log an exception in this case. APEXd will be able to recover in
// case markStagedSessionSuccessful fails.
Slog.e(TAG, "Failed to mark session " + sessionId + " as successful", e);
}
}
/**
* Dumps various state information to the provided {@link PrintWriter} object.
*
@@ -196,7 +217,7 @@ class ApexManager {
ipw.increaseIndent();
final ApexSessionInfo[] sessions = mApexService.getSessions();
for (ApexSessionInfo si : sessions) {
ipw.println("Session ID: " + Integer.toString(si.sessionId));
ipw.println("Session ID: " + si.sessionId);
ipw.increaseIndent();
if (si.isUnknown) {
ipw.println("State: UNKNOWN");

View File

@@ -247,7 +247,8 @@ public class StagingManager {
}
private void resumeSession(@NonNull PackageInstallerSession session) {
if (sessionContainsApex(session)) {
boolean hasApex = sessionContainsApex(session);
if (hasApex) {
// Check with apexservice whether the apex packages have been activated.
ApexSessionInfo apexSessionInfo = mApexManager.getStagedSessionInfo(session.sessionId);
if (apexSessionInfo == null) {
@@ -271,7 +272,7 @@ public class StagingManager {
mBgHandler.post(() -> preRebootVerification(session));
return;
}
if (!apexSessionInfo.isActivated) {
if (!apexSessionInfo.isActivated && !apexSessionInfo.isSuccess) {
// In all the remaining cases apexd will try to apply the session again at next
// boot. Nothing to do here for now.
Slog.w(TAG, "Staged session " + session.sessionId + " scheduled to be applied "
@@ -287,7 +288,11 @@ public class StagingManager {
+ "more information.");
return;
}
session.setStagedSessionApplied();
if (hasApex) {
mApexManager.markStagedSessionSuccessful(session.sessionId);
}
}
private String findFirstAPKInDir(File stageDir) {