Merge "Use PackageManager.INSTALL_XXX error codes (15/n)" into tm-dev

This commit is contained in:
Chun-Wei Wang
2022-03-09 01:15:06 +00:00
committed by Android (Google) Code Review
9 changed files with 68 additions and 76 deletions

View File

@@ -2433,15 +2433,6 @@ public class PackageInstaller {
/** {@hide} */
private static final int[] NO_SESSIONS = {};
/** @hide */
@IntDef(prefix = { "SESSION_" }, value = {
SESSION_NO_ERROR,
SESSION_VERIFICATION_FAILED,
SESSION_ACTIVATION_FAILED,
SESSION_UNKNOWN_ERROR,
SESSION_CONFLICT})
@Retention(RetentionPolicy.SOURCE)
public @interface SessionErrorCode {}
/**
* @deprecated use {@link #SESSION_NO_ERROR}.
*/
@@ -3125,7 +3116,7 @@ public class PackageInstaller {
* If something went wrong with a staged session, clients can check this error code to
* understand which kind of failure happened. Only meaningful if {@code isStaged} is true.
*/
public @SessionErrorCode int getStagedSessionErrorCode() {
public int getStagedSessionErrorCode() {
checkSessionIsStaged();
return mSessionErrorCode;
}
@@ -3140,7 +3131,7 @@ public class PackageInstaller {
}
/** {@hide} */
public void setSessionErrorCode(@SessionErrorCode int errorCode, String errorMessage) {
public void setSessionErrorCode(int errorCode, String errorMessage) {
mSessionErrorCode = errorCode;
mSessionErrorMessage = errorMessage;
}

View File

@@ -2205,6 +2205,14 @@ public abstract class PackageManager {
*/
public static final int INSTALL_FAILED_BAD_PERMISSION_GROUP = -127;
/**
* Installation failed return code: an error occurred during the activation phase of this
* session.
*
* @hide
*/
public static final int INSTALL_ACTIVATION_FAILED = -128;
/** @hide */
@IntDef(flag = true, prefix = { "DELETE_" }, value = {
DELETE_KEEP_DATA,

View File

@@ -29,7 +29,6 @@ import android.apex.CompressedApexInfoList;
import android.apex.IApexService;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageManager;
import android.content.pm.SigningDetails;
import android.content.pm.parsing.result.ParseResult;
@@ -834,7 +833,7 @@ public abstract class ApexManager {
throw new RuntimeException(re);
} catch (Exception e) {
throw new PackageManagerException(
PackageInstaller.SessionInfo.SESSION_VERIFICATION_FAILED,
PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE,
"apexd verification failed : " + e.getMessage());
}
}
@@ -861,7 +860,7 @@ public abstract class ApexManager {
throw new RuntimeException(re);
} catch (Exception e) {
throw new PackageManagerException(
PackageInstaller.SessionInfo.SESSION_VERIFICATION_FAILED,
PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE,
"Failed to mark apexd session as ready : " + e.getMessage());
}
}

View File

@@ -334,7 +334,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
StagingManager.StagedSession stagedSession = session.mStagedSession;
if (!stagedSession.isInTerminalState() && stagedSession.hasParentSessionId()
&& getSession(stagedSession.getParentSessionId()) == null) {
stagedSession.setSessionFailed(SessionInfo.SESSION_ACTIVATION_FAILED,
stagedSession.setSessionFailed(PackageManager.INSTALL_ACTIVATION_FAILED,
"An orphan staged session " + stagedSession.sessionId() + " is found, "
+ "parent " + stagedSession.getParentSessionId() + " is missing");
continue;
@@ -853,7 +853,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
mSilentUpdatePolicy, mInstallThread.getLooper(), mStagingManager, sessionId,
userId, callingUid, installSource, params, createdMillis, 0L, stageDir, stageCid,
null, null, false, false, false, false, null, SessionInfo.INVALID_ID,
false, false, false, SessionInfo.SESSION_NO_ERROR, "");
false, false, false, PackageManager.INSTALL_UNKNOWN, "");
synchronized (mSessions) {
mSessions.put(sessionId, session);

View File

@@ -82,7 +82,6 @@ import android.content.pm.InstallationFileParcel;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageInstaller.SessionInfo;
import android.content.pm.PackageInstaller.SessionInfo.SessionErrorCode;
import android.content.pm.PackageInstaller.SessionParams;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
@@ -462,7 +461,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
@GuardedBy("mLock")
private boolean mSessionFailed;
@GuardedBy("mLock")
private int mSessionErrorCode = SessionInfo.SESSION_NO_ERROR;
private int mSessionErrorCode = PackageManager.INSTALL_UNKNOWN;
@GuardedBy("mLock")
private String mSessionErrorMessage;
@@ -2331,7 +2330,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
}
} else {
PackageManagerException e = (PackageManagerException) t.getCause();
setSessionFailed(SessionInfo.SESSION_ACTIVATION_FAILED,
setSessionFailed(e.error,
PackageManager.installStatusToString(e.error, e.getMessage()));
dispatchSessionFinished(e.error, e.getMessage(), null);
maybeFinishChildSessions(e.error, e.getMessage());
@@ -4045,7 +4044,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
mSessionReady = true;
mSessionApplied = false;
mSessionFailed = false;
mSessionErrorCode = SessionInfo.SESSION_NO_ERROR;
mSessionErrorCode = PackageManager.INSTALL_UNKNOWN;
mSessionErrorMessage = "";
}
mCallback.onSessionChanged(this);
@@ -4073,7 +4072,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
mSessionReady = false;
mSessionApplied = true;
mSessionFailed = false;
mSessionErrorCode = SessionInfo.SESSION_NO_ERROR;
mSessionErrorCode = INSTALL_SUCCEEDED;
mSessionErrorMessage = "";
Slog.d(TAG, "Marking session " + sessionId + " as applied");
}
@@ -4103,7 +4102,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
}
/** {@hide} */
@SessionErrorCode
int getSessionErrorCode() {
synchronized (mLock) {
return mSessionErrorCode;
@@ -4592,7 +4590,7 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
final boolean isFailed = in.getAttributeBoolean(null, ATTR_IS_FAILED, false);
final boolean isApplied = in.getAttributeBoolean(null, ATTR_IS_APPLIED, false);
final int sessionErrorCode = in.getAttributeInt(null, ATTR_SESSION_ERROR_CODE,
SessionInfo.SESSION_NO_ERROR);
PackageManager.INSTALL_UNKNOWN);
final String sessionErrorMessage = readStringAttribute(in, ATTR_SESSION_ERROR_MESSAGE);
if (!isStagedSessionStateValid(isReady, isApplied, isFailed)) {

View File

@@ -24,7 +24,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.IPackageInstallObserver2;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller.SessionInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.SigningDetails;
@@ -110,7 +109,7 @@ final class PackageSessionVerifier {
verifyAPK(session, callback);
} catch (PackageManagerException e) {
String errorMessage = PackageManager.installStatusToString(e.error, e.getMessage());
session.setSessionFailed(SessionInfo.SESSION_VERIFICATION_FAILED, errorMessage);
session.setSessionFailed(e.error, errorMessage);
callback.onResult(e.error, e.getMessage());
}
});
@@ -137,7 +136,7 @@ final class PackageSessionVerifier {
}
if (returnCode != PackageManager.INSTALL_SUCCEEDED) {
String errorMessage = PackageManager.installStatusToString(returnCode, msg);
session.setSessionFailed(SessionInfo.SESSION_VERIFICATION_FAILED, errorMessage);
session.setSessionFailed(returnCode, errorMessage);
callback.onResult(returnCode, msg);
} else {
session.setSessionReady();
@@ -220,7 +219,7 @@ final class PackageSessionVerifier {
}
private void onVerificationFailure(StagingManager.StagedSession session, Callback callback,
@SessionInfo.SessionErrorCode int errorCode, String errorMessage) {
int errorCode, String errorMessage) {
if (!ensureActiveApexSessionIsAborted(session)) {
Slog.e(TAG, "Failed to abort apex session " + session.sessionId());
// Safe to ignore active apex session abortion failure since session will be marked
@@ -312,7 +311,7 @@ final class PackageSessionVerifier {
// Failed to get hold of StorageManager
Slog.e(TAG, "Failed to get hold of StorageManager", e);
throw new PackageManagerException(
SessionInfo.SESSION_UNKNOWN_ERROR,
PackageManager.INSTALL_FAILED_INTERNAL_ERROR,
"Failed to get hold of StorageManager");
}
// Proactively mark session as ready before calling apexd. Although this call order
@@ -350,7 +349,7 @@ final class PackageSessionVerifier {
final ParseResult<SigningDetails> newResult = ApkSignatureVerifier.verify(
input.reset(), apexPath, minSignatureScheme);
if (newResult.isError()) {
throw new PackageManagerException(SessionInfo.SESSION_VERIFICATION_FAILED,
throw new PackageManagerException(PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE,
"Failed to parse APEX package " + apexPath + " : "
+ newResult.getException(), newResult.getException());
}
@@ -369,7 +368,7 @@ final class PackageSessionVerifier {
input.reset(), existingApexPkg.applicationInfo.sourceDir,
SigningDetails.SignatureSchemeVersion.JAR);
if (existingResult.isError()) {
throw new PackageManagerException(SessionInfo.SESSION_VERIFICATION_FAILED,
throw new PackageManagerException(PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE,
"Failed to parse APEX package " + existingApexPkg.applicationInfo.sourceDir
+ " : " + existingResult.getException(), existingResult.getException());
}
@@ -383,7 +382,7 @@ final class PackageSessionVerifier {
return;
}
throw new PackageManagerException(SessionInfo.SESSION_VERIFICATION_FAILED,
throw new PackageManagerException(PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE,
"APK-container signature of APEX package " + packageName + " with version "
+ newApexPkg.versionCodeMajor + " and path " + apexPath + " is not"
+ " compatible with the one currently installed on device");
@@ -426,11 +425,12 @@ final class PackageSessionVerifier {
packageInfo = PackageInfoWithoutStateUtils.generate(parsedPackage, apexInfo, flags);
if (packageInfo == null) {
throw new PackageManagerException(
SessionInfo.SESSION_VERIFICATION_FAILED,
PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE,
"Unable to generate package info: " + apexInfo.modulePath);
}
} catch (PackageManagerException e) {
throw new PackageManagerException(SessionInfo.SESSION_VERIFICATION_FAILED,
throw new PackageManagerException(
PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE,
"Failed to parse APEX package " + apexInfo.modulePath + " : " + e, e);
}
result.add(packageInfo);
@@ -452,7 +452,7 @@ final class PackageSessionVerifier {
}
}
throw new PackageManagerException(
SessionInfo.SESSION_VERIFICATION_FAILED,
PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE,
"Could not find rollback id for commit session: " + sessionId);
}
@@ -560,7 +560,7 @@ final class PackageSessionVerifier {
try {
checkActiveSessions(InstallLocationUtils.getStorageManager().supportsCheckpoint());
} catch (RemoteException e) {
throw new PackageManagerException(SessionInfo.SESSION_VERIFICATION_FAILED,
throw new PackageManagerException(PackageManager.INSTALL_FAILED_INTERNAL_ERROR,
"Can't query fs-checkpoint status : " + e);
}
}
@@ -576,7 +576,7 @@ final class PackageSessionVerifier {
}
if (!supportsCheckpoint && activeSessions > 1) {
throw new PackageManagerException(
SessionInfo.SESSION_VERIFICATION_FAILED,
PackageManager.INSTALL_FAILED_OTHER_STAGED_SESSION_IN_PROGRESS,
"Cannot stage multiple sessions without checkpoint support");
}
}
@@ -607,13 +607,13 @@ final class PackageSessionVerifier {
// will be deleted.
}
stagedSession.setSessionFailed(
SessionInfo.SESSION_CONFLICT,
PackageManager.INSTALL_FAILED_OTHER_STAGED_SESSION_IN_PROGRESS,
"Session was failed by rollback session: " + session.sessionId());
Slog.i(TAG, "Session " + stagedSession.sessionId() + " is marked failed due to "
+ "rollback session: " + session.sessionId());
} else if (!isRollback(session) && isRollback(stagedSession)) {
throw new PackageManagerException(
SessionInfo.SESSION_CONFLICT,
PackageManager.INSTALL_FAILED_OTHER_STAGED_SESSION_IN_PROGRESS,
"Session was failed by rollback session: " + stagedSession.sessionId());
}
@@ -636,7 +636,7 @@ final class PackageSessionVerifier {
final String packageName = child.getPackageName();
if (packageName == null) {
throw new PackageManagerException(
SessionInfo.SESSION_VERIFICATION_FAILED,
PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE,
"Cannot stage session " + child.sessionId() + " with package name null");
}
for (StagingManager.StagedSession stagedSession : mStagedSessions) {
@@ -648,14 +648,14 @@ final class PackageSessionVerifier {
if (stagedSession.getCommittedMillis() < parent.getCommittedMillis()) {
// Fail the session committed later when there are overlapping packages
throw new PackageManagerException(
SessionInfo.SESSION_VERIFICATION_FAILED,
PackageManager.INSTALL_FAILED_OTHER_STAGED_SESSION_IN_PROGRESS,
"Package: " + packageName + " in session: "
+ child.sessionId()
+ " has been staged already by session: "
+ stagedSession.sessionId());
} else {
stagedSession.setSessionFailed(
SessionInfo.SESSION_VERIFICATION_FAILED,
PackageManager.INSTALL_FAILED_OTHER_STAGED_SESSION_IN_PROGRESS,
"Package: " + packageName + " in session: "
+ stagedSession.sessionId()
+ " has been staged already by session: "

View File

@@ -28,8 +28,6 @@ import android.content.IntentFilter;
import android.content.pm.ApexStagedEvent;
import android.content.pm.IStagedApexObserver;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageInstaller.SessionInfo;
import android.content.pm.PackageInstaller.SessionInfo.SessionErrorCode;
import android.content.pm.PackageManager;
import android.content.pm.PackageManagerInternal;
import android.content.pm.StagedApexInfo;
@@ -124,7 +122,7 @@ public class StagingManager {
boolean containsApkSession();
boolean containsApexSession();
void setSessionReady();
void setSessionFailed(@SessionErrorCode int errorCode, String errorMessage);
void setSessionFailed(int errorCode, String errorMessage);
void setSessionApplied();
CompletableFuture<Void> installSession();
boolean hasParentSessionId();
@@ -279,7 +277,7 @@ public class StagingManager {
String packageName = apexSession.getPackageName();
String errorMsg = mApexManager.getApkInApexInstallError(packageName);
if (errorMsg != null) {
throw new PackageManagerException(SessionInfo.SESSION_ACTIVATION_FAILED,
throw new PackageManagerException(PackageManager.INSTALL_ACTIVATION_FAILED,
"Failed to install apk-in-apex of " + packageName + " : " + errorMsg);
}
}
@@ -392,7 +390,7 @@ public class StagingManager {
revertMsg += " Reason for revert: " + reasonForRevert;
}
Slog.d(TAG, revertMsg);
session.setSessionFailed(SessionInfo.SESSION_UNKNOWN_ERROR, revertMsg);
session.setSessionFailed(PackageManager.INSTALL_FAILED_INTERNAL_ERROR, revertMsg);
return;
}
@@ -477,7 +475,7 @@ public class StagingManager {
for (String apkInApex : mApexManager.getApksInApex(packageName)) {
if (!apkNames.add(apkInApex)) {
throw new PackageManagerException(
SessionInfo.SESSION_ACTIVATION_FAILED,
PackageManager.INSTALL_ACTIVATION_FAILED,
"Package: " + packageName + " in session: "
+ apexSession.sessionId() + " has duplicate apk-in-apex: "
+ apkInApex, null);
@@ -495,9 +493,7 @@ public class StagingManager {
// Should be impossible
throw new RuntimeException(e);
} catch (ExecutionException ee) {
PackageManagerException e = (PackageManagerException) ee.getCause();
final String errorMsg = PackageManager.installStatusToString(e.error, e.getMessage());
throw new PackageManagerException(SessionInfo.SESSION_ACTIVATION_FAILED, errorMsg);
throw (PackageManagerException) ee.getCause();
}
}
@@ -651,7 +647,7 @@ public class StagingManager {
// is upgrading. Fail all the sessions and exit early.
for (int i = 0; i < sessions.size(); i++) {
StagedSession session = sessions.get(i);
session.setSessionFailed(SessionInfo.SESSION_ACTIVATION_FAILED,
session.setSessionFailed(PackageManager.INSTALL_ACTIVATION_FAILED,
"Build fingerprint has changed");
}
return;
@@ -691,7 +687,7 @@ public class StagingManager {
final ApexSessionInfo apexSession = apexSessions.get(session.sessionId());
if (apexSession == null || apexSession.isUnknown) {
hasFailedApexSession = true;
session.setSessionFailed(SessionInfo.SESSION_ACTIVATION_FAILED, "apexd did "
session.setSessionFailed(PackageManager.INSTALL_ACTIVATION_FAILED, "apexd did "
+ "not know anything about a staged session supposed to be activated");
continue;
} else if (isApexSessionFailed(apexSession)) {
@@ -707,7 +703,7 @@ public class StagingManager {
errorMsg += " Error: " + apexSession.errorMessage;
}
Slog.d(TAG, errorMsg);
session.setSessionFailed(SessionInfo.SESSION_ACTIVATION_FAILED, errorMsg);
session.setSessionFailed(PackageManager.INSTALL_ACTIVATION_FAILED, errorMsg);
continue;
} else if (apexSession.isActivated || apexSession.isSuccess) {
hasAppliedApexSession = true;
@@ -716,13 +712,13 @@ public class StagingManager {
// Apexd did not apply the session for some unknown reason. There is no guarantee
// that apexd will install it next time. Safer to proactively mark it as failed.
hasFailedApexSession = true;
session.setSessionFailed(SessionInfo.SESSION_ACTIVATION_FAILED,
session.setSessionFailed(PackageManager.INSTALL_ACTIVATION_FAILED,
"Staged session " + session.sessionId() + " at boot didn't activate nor "
+ "fail. Marking it as failed anyway.");
} else {
Slog.w(TAG, "Apex session " + session.sessionId() + " is in impossible state");
hasFailedApexSession = true;
session.setSessionFailed(SessionInfo.SESSION_ACTIVATION_FAILED,
session.setSessionFailed(PackageManager.INSTALL_ACTIVATION_FAILED,
"Impossible state");
}
}
@@ -742,7 +738,7 @@ public class StagingManager {
// Session has been already failed in the loop above.
continue;
}
session.setSessionFailed(SessionInfo.SESSION_ACTIVATION_FAILED,
session.setSessionFailed(PackageManager.INSTALL_ACTIVATION_FAILED,
"Another apex session failed");
}
return;
@@ -758,7 +754,7 @@ public class StagingManager {
} catch (Exception e) {
Slog.e(TAG, "Staged install failed due to unhandled exception", e);
onInstallationFailure(session, new PackageManagerException(
SessionInfo.SESSION_ACTIVATION_FAILED,
PackageManager.INSTALL_FAILED_INTERNAL_ERROR,
"Staged install failed due to unhandled exception: " + e),
supportsCheckpoint, needsCheckpoint);
}

View File

@@ -39,8 +39,7 @@ import android.content.Context;
import android.content.pm.ApexStagedEvent;
import android.content.pm.IStagedApexObserver;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageInstaller.SessionInfo;
import android.content.pm.PackageInstaller.SessionInfo.SessionErrorCode;
import android.content.pm.PackageManager;
import android.content.pm.StagedApexInfo;
import android.os.SystemProperties;
import android.os.storage.IStorageManager;
@@ -158,10 +157,10 @@ public class StagingManagerTest {
mStagingManager.restoreSessions(Arrays.asList(session1, session2), true);
assertThat(session1.getErrorCode()).isEqualTo(SessionInfo.SESSION_ACTIVATION_FAILED);
assertThat(session1.getErrorCode()).isEqualTo(PackageManager.INSTALL_ACTIVATION_FAILED);
assertThat(session1.getErrorMessage()).isEqualTo("Build fingerprint has changed");
assertThat(session2.getErrorCode()).isEqualTo(SessionInfo.SESSION_ACTIVATION_FAILED);
assertThat(session2.getErrorCode()).isEqualTo(PackageManager.INSTALL_ACTIVATION_FAILED);
assertThat(session2.getErrorMessage()).isEqualTo("Build fingerprint has changed");
}
@@ -247,12 +246,12 @@ public class StagingManagerTest {
verify(mStorageManager, never()).abortChanges(eq("abort-staged-install"), eq(false));
assertThat(apexSession.getErrorCode())
.isEqualTo(SessionInfo.SESSION_ACTIVATION_FAILED);
.isEqualTo(PackageManager.INSTALL_ACTIVATION_FAILED);
assertThat(apexSession.getErrorMessage()).isEqualTo("apexd did not know anything about a "
+ "staged session supposed to be activated");
assertThat(apkSession.getErrorCode())
.isEqualTo(SessionInfo.SESSION_ACTIVATION_FAILED);
.isEqualTo(PackageManager.INSTALL_ACTIVATION_FAILED);
assertThat(apkSession.getErrorMessage()).isEqualTo("Another apex session failed");
}
@@ -303,22 +302,22 @@ public class StagingManagerTest {
verify(mStorageManager, never()).abortChanges(eq("abort-staged-install"), eq(false));
assertThat(apexSession1.getErrorCode())
.isEqualTo(SessionInfo.SESSION_ACTIVATION_FAILED);
.isEqualTo(PackageManager.INSTALL_ACTIVATION_FAILED);
assertThat(apexSession1.getErrorMessage()).isEqualTo("APEX activation failed. "
+ "Error: Failed for test");
assertThat(apexSession2.getErrorCode())
.isEqualTo(SessionInfo.SESSION_ACTIVATION_FAILED);
.isEqualTo(PackageManager.INSTALL_ACTIVATION_FAILED);
assertThat(apexSession2.getErrorMessage()).isEqualTo("Staged session 101 at boot didn't "
+ "activate nor fail. Marking it as failed anyway.");
assertThat(apexSession3.getErrorCode())
.isEqualTo(SessionInfo.SESSION_ACTIVATION_FAILED);
.isEqualTo(PackageManager.INSTALL_ACTIVATION_FAILED);
assertThat(apexSession3.getErrorMessage()).isEqualTo("apexd did not know anything about a "
+ "staged session supposed to be activated");
assertThat(apkSession.getErrorCode())
.isEqualTo(SessionInfo.SESSION_ACTIVATION_FAILED);
.isEqualTo(PackageManager.INSTALL_ACTIVATION_FAILED);
assertThat(apkSession.getErrorMessage()).isEqualTo("Another apex session failed");
}
@@ -351,12 +350,12 @@ public class StagingManagerTest {
verify(mStorageManager, never()).abortChanges(eq("abort-staged-install"), eq(false));
assertThat(apexSession.getErrorCode())
.isEqualTo(SessionInfo.SESSION_ACTIVATION_FAILED);
.isEqualTo(PackageManager.INSTALL_ACTIVATION_FAILED);
assertThat(apexSession.getErrorMessage()).isEqualTo("Staged session 1543 at boot didn't "
+ "activate nor fail. Marking it as failed anyway.");
assertThat(apkSession.getErrorCode())
.isEqualTo(SessionInfo.SESSION_ACTIVATION_FAILED);
.isEqualTo(PackageManager.INSTALL_ACTIVATION_FAILED);
assertThat(apkSession.getErrorMessage()).isEqualTo("Another apex session failed");
}
@@ -445,11 +444,11 @@ public class StagingManagerTest {
verify(mStorageManager, never()).abortChanges(eq("abort-staged-install"), eq(false));
assertThat(apexSession.getErrorCode())
.isEqualTo(SessionInfo.SESSION_ACTIVATION_FAILED);
.isEqualTo(PackageManager.INSTALL_ACTIVATION_FAILED);
assertThat(apexSession.getErrorMessage()).isEqualTo("Impossible state");
assertThat(apkSession.getErrorCode())
.isEqualTo(SessionInfo.SESSION_ACTIVATION_FAILED);
.isEqualTo(PackageManager.INSTALL_ACTIVATION_FAILED);
assertThat(apkSession.getErrorMessage()).isEqualTo("Another apex session failed");
}
@@ -755,7 +754,7 @@ public class StagingManagerTest {
/* isReady */ false,
/* isFailed */ false,
/* isApplied */false,
/* stagedSessionErrorCode */ PackageInstaller.SessionInfo.SESSION_NO_ERROR,
/* stagedSessionErrorCode */ PackageManager.INSTALL_UNKNOWN,
/* stagedSessionErrorMessage */ "no error");
StagingManager.StagedSession stagedSession = spy(session.mStagedSession);
@@ -775,7 +774,7 @@ public class StagingManagerTest {
private boolean mIsReady = false;
private boolean mIsApplied = false;
private boolean mIsFailed = false;
private @SessionErrorCode int mErrorCode = -1;
private int mErrorCode = -1;
private String mErrorMessage;
private boolean mIsDestroyed = false;
private int mParentSessionId = -1;
@@ -828,7 +827,7 @@ public class StagingManagerTest {
return this;
}
private @SessionErrorCode int getErrorCode() {
private int getErrorCode() {
return mErrorCode;
}
@@ -940,7 +939,7 @@ public class StagingManagerTest {
}
@Override
public void setSessionFailed(@SessionErrorCode int errorCode, String errorMessage) {
public void setSessionFailed(int errorCode, String errorMessage) {
Preconditions.checkState(!mIsApplied, "Already marked as applied");
mIsFailed = true;
mErrorCode = errorCode;

View File

@@ -28,6 +28,7 @@ import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
import static org.xmlpull.v1.XmlPullParser.START_TAG;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageManager;
import android.platform.test.annotations.Presubmit;
import android.util.AtomicFile;
import android.util.Slog;
@@ -197,7 +198,7 @@ public class PackageInstallerSessionTest {
/* isFailed */ false,
/* isApplied */false,
/* stagedSessionErrorCode */
PackageInstaller.SessionInfo.SESSION_VERIFICATION_FAILED,
PackageManager.INSTALL_FAILED_VERIFICATION_FAILURE,
/* stagedSessionErrorMessage */ "some error");
}