Merge "[pm/metrics] log internal error code for install failures"
This commit is contained in:
committed by
Android (Google) Code Review
commit
404de3bb26
@@ -485,18 +485,22 @@ public class AppDataHelper {
|
||||
String packageName, int userId) throws PackageManagerException {
|
||||
final PackageStateInternal packageState = snapshot.getPackageStateInternal(packageName);
|
||||
if (packageState == null) {
|
||||
throw new PackageManagerException("Package " + packageName + " is unknown");
|
||||
throw PackageManagerException.ofInternalError("Package " + packageName + " is unknown",
|
||||
PackageManagerException.INTERNAL_ERROR_STORAGE_INVALID_PACKAGE_UNKNOWN);
|
||||
} else if (!TextUtils.equals(volumeUuid, packageState.getVolumeUuid())) {
|
||||
throw new PackageManagerException(
|
||||
throw PackageManagerException.ofInternalError(
|
||||
"Package " + packageName + " found on unknown volume " + volumeUuid
|
||||
+ "; expected volume " + packageState.getVolumeUuid());
|
||||
+ "; expected volume " + packageState.getVolumeUuid(),
|
||||
PackageManagerException.INTERNAL_ERROR_STORAGE_INVALID_VOLUME_UNKNOWN);
|
||||
} else if (!packageState.getUserStateOrDefault(userId).isInstalled()) {
|
||||
throw new PackageManagerException(
|
||||
"Package " + packageName + " not installed for user " + userId);
|
||||
throw PackageManagerException.ofInternalError(
|
||||
"Package " + packageName + " not installed for user " + userId,
|
||||
PackageManagerException.INTERNAL_ERROR_STORAGE_INVALID_NOT_INSTALLED_FOR_USER);
|
||||
} else if (packageState.getPkg() != null
|
||||
&& !shouldHaveAppStorage(packageState.getPkg())) {
|
||||
throw new PackageManagerException(
|
||||
"Package " + packageName + " shouldn't have storage");
|
||||
throw PackageManagerException.ofInternalError(
|
||||
"Package " + packageName + " shouldn't have storage",
|
||||
PackageManagerException.INTERNAL_ERROR_STORAGE_INVALID_SHOULD_NOT_HAVE_STORAGE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import static android.content.pm.PackageManager.INSTALL_FAILED_DEPRECATED_SDK_VE
|
||||
import static android.content.pm.PackageManager.INSTALL_FAILED_DUPLICATE_PACKAGE;
|
||||
import static android.content.pm.PackageManager.INSTALL_FAILED_DUPLICATE_PERMISSION;
|
||||
import static android.content.pm.PackageManager.INSTALL_FAILED_DUPLICATE_PERMISSION_GROUP;
|
||||
import static android.content.pm.PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
|
||||
import static android.content.pm.PackageManager.INSTALL_FAILED_INVALID_APK;
|
||||
import static android.content.pm.PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION;
|
||||
import static android.content.pm.PackageManager.INSTALL_FAILED_PACKAGE_CHANGED;
|
||||
@@ -1490,8 +1489,9 @@ final class InstallPackageHelper {
|
||||
synchronized (mPm.mLock) {
|
||||
final PackageSetting ps = mPm.mSettings.getPackageLPr(pkgName);
|
||||
if (ps == null) {
|
||||
request.setError(INSTALL_FAILED_INTERNAL_ERROR,
|
||||
"Missing settings for moved package " + pkgName);
|
||||
request.setError(PackageManagerException.ofInternalError(
|
||||
"Missing settings for moved package " + pkgName,
|
||||
PackageManagerException.INTERNAL_ERROR_MISSING_SETTING_FOR_MOVE));
|
||||
}
|
||||
|
||||
// We moved the entire application as-is, so bring over the
|
||||
@@ -1523,8 +1523,9 @@ final class InstallPackageHelper {
|
||||
derivedAbi.second.applyTo(parsedPackage);
|
||||
} catch (PackageManagerException pme) {
|
||||
Slog.e(TAG, "Error deriving application ABI", pme);
|
||||
throw new PrepareFailure(INSTALL_FAILED_INTERNAL_ERROR,
|
||||
"Error deriving application ABI: " + pme.getMessage());
|
||||
throw PrepareFailure.ofInternalError(
|
||||
"Error deriving application ABI: " + pme.getMessage(),
|
||||
PackageManagerException.INTERNAL_ERROR_DERIVING_ABI);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1535,8 +1536,9 @@ final class InstallPackageHelper {
|
||||
setUpFsVerity(parsedPackage);
|
||||
} catch (Installer.InstallerException | IOException | DigestException
|
||||
| NoSuchAlgorithmException e) {
|
||||
throw new PrepareFailure(INSTALL_FAILED_INTERNAL_ERROR,
|
||||
"Failed to set up verity: " + e);
|
||||
throw PrepareFailure.ofInternalError(
|
||||
"Failed to set up verity: " + e,
|
||||
PackageManagerException.INTERNAL_ERROR_VERITY_SETUP);
|
||||
}
|
||||
} else {
|
||||
// Use the path returned by apexd
|
||||
@@ -3215,8 +3217,9 @@ final class InstallPackageHelper {
|
||||
// uncompress the binary to its eventual destination on /data
|
||||
final File scanFile = decompressPackage(stubPkg.getPackageName(), stubPkg.getPath());
|
||||
if (scanFile == null) {
|
||||
throw new PackageManagerException(
|
||||
"Unable to decompress stub at " + stubPkg.getPath());
|
||||
throw PackageManagerException.ofInternalError(
|
||||
"Unable to decompress stub at " + stubPkg.getPath(),
|
||||
PackageManagerException.INTERNAL_ERROR_DECOMPRESS_STUB);
|
||||
}
|
||||
synchronized (mPm.mLock) {
|
||||
mPm.mSettings.disableSystemPackageLPw(stubPkg.getPackageName(), true /*replaced*/);
|
||||
@@ -4174,10 +4177,12 @@ final class InstallPackageHelper {
|
||||
// This is relevant for cases where the disabled system package is used for flags or
|
||||
// other metadata.
|
||||
parsedPackage.hideAsFinal();
|
||||
throw new PackageManagerException(Log.WARN, "Package " + parsedPackage.getPackageName()
|
||||
throw PackageManagerException.ofInternalError(
|
||||
"Package " + parsedPackage.getPackageName()
|
||||
+ " at " + parsedPackage.getPath() + " ignored: updated version "
|
||||
+ (pkgAlreadyExists ? String.valueOf(pkgSetting.getVersionCode()) : "unknown")
|
||||
+ " better than this " + parsedPackage.getLongVersionCode());
|
||||
+ " better than this " + parsedPackage.getLongVersionCode(),
|
||||
PackageManagerException.INTERNAL_ERROR_UPDATED_VERSION_BETTER_THAN_SYSTEM);
|
||||
}
|
||||
|
||||
// Verify certificates against what was last scanned. Force re-collecting certificate in two
|
||||
@@ -4449,8 +4454,9 @@ final class InstallPackageHelper {
|
||||
// but we still want the base name to be unique.
|
||||
if ((scanFlags & SCAN_NEW_INSTALL) == 0
|
||||
&& mPm.mPackages.containsKey(pkg.getManifestPackageName())) {
|
||||
throw new PackageManagerException(
|
||||
"Duplicate static shared lib provider package");
|
||||
throw PackageManagerException.ofInternalError(
|
||||
"Duplicate static shared lib provider package",
|
||||
PackageManagerException.INTERNAL_ERROR_DUP_STATIC_SHARED_LIB_PROVIDER);
|
||||
}
|
||||
ScanPackageUtils.assertStaticSharedLibraryIsValid(pkg, scanFlags);
|
||||
assertStaticSharedLibraryVersionCodeIsValid(pkg);
|
||||
@@ -4543,8 +4549,9 @@ final class InstallPackageHelper {
|
||||
}
|
||||
if (pkg.getLongVersionCode() < minVersionCode
|
||||
|| pkg.getLongVersionCode() > maxVersionCode) {
|
||||
throw new PackageManagerException("Static shared"
|
||||
+ " lib version codes must be ordered as lib versions");
|
||||
throw PackageManagerException.ofInternalError("Static shared"
|
||||
+ " lib version codes must be ordered as lib versions",
|
||||
PackageManagerException.INTERNAL_ERROR_STATIC_SHARED_LIB_VERSION_CODES_ORDER);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4559,9 +4566,10 @@ final class InstallPackageHelper {
|
||||
// This must be an update to a system overlay. Immutable overlays cannot be
|
||||
// upgraded.
|
||||
if (!mPm.isOverlayMutable(pkg.getPackageName())) {
|
||||
throw new PackageManagerException("Overlay "
|
||||
throw PackageManagerException.ofInternalError("Overlay "
|
||||
+ pkg.getPackageName()
|
||||
+ " is static and cannot be upgraded.");
|
||||
+ " is static and cannot be upgraded.",
|
||||
PackageManagerException.INTERNAL_ERROR_SYSTEM_OVERLAY_STATIC);
|
||||
}
|
||||
} else {
|
||||
if ((scanFlags & SCAN_AS_VENDOR) != 0) {
|
||||
@@ -4591,10 +4599,11 @@ final class InstallPackageHelper {
|
||||
}
|
||||
if (!comparePackageSignatures(platformPkgSetting,
|
||||
pkg.getSigningDetails().getSignatures())) {
|
||||
throw new PackageManagerException("Overlay "
|
||||
throw PackageManagerException.ofInternalError("Overlay "
|
||||
+ pkg.getPackageName()
|
||||
+ " must target Q or later, "
|
||||
+ "or be signed with the platform certificate");
|
||||
+ "or be signed with the platform certificate",
|
||||
PackageManagerException.INTERNAL_ERROR_OVERLAY_LOW_TARGET_SDK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4615,11 +4624,12 @@ final class InstallPackageHelper {
|
||||
pkg.getSigningDetails().getSignatures())) {
|
||||
// check reference signature
|
||||
if (mPm.mOverlayConfigSignaturePackage == null) {
|
||||
throw new PackageManagerException("Overlay "
|
||||
throw PackageManagerException.ofInternalError("Overlay "
|
||||
+ pkg.getPackageName() + " and target "
|
||||
+ pkg.getOverlayTarget() + " signed with"
|
||||
+ " different certificates, and the overlay lacks"
|
||||
+ " <overlay android:targetName>");
|
||||
+ " <overlay android:targetName>",
|
||||
PackageManagerException.INTERNAL_ERROR_OVERLAY_SIGNATURE1);
|
||||
}
|
||||
final PackageSetting refPkgSetting;
|
||||
synchronized (mPm.mLock) {
|
||||
@@ -4628,11 +4638,12 @@ final class InstallPackageHelper {
|
||||
}
|
||||
if (!comparePackageSignatures(refPkgSetting,
|
||||
pkg.getSigningDetails().getSignatures())) {
|
||||
throw new PackageManagerException("Overlay "
|
||||
throw PackageManagerException.ofInternalError("Overlay "
|
||||
+ pkg.getPackageName() + " signed with a different "
|
||||
+ "certificate than both the reference package and "
|
||||
+ "target " + pkg.getOverlayTarget() + ", and the "
|
||||
+ "overlay lacks <overlay android:targetName>");
|
||||
+ "overlay lacks <overlay android:targetName>",
|
||||
PackageManagerException.INTERNAL_ERROR_OVERLAY_SIGNATURE2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4659,10 +4670,11 @@ final class InstallPackageHelper {
|
||||
}
|
||||
if (!comparePackageSignatures(platformPkgSetting,
|
||||
pkg.getSigningDetails().getSignatures())) {
|
||||
throw new PackageManagerException("Apps that share a user with a "
|
||||
throw PackageManagerException.ofInternalError("Apps that share a user with a "
|
||||
+ "privileged app must themselves be marked as privileged. "
|
||||
+ pkg.getPackageName() + " shares privileged user "
|
||||
+ pkg.getSharedUserId() + ".");
|
||||
+ pkg.getSharedUserId() + ".",
|
||||
PackageManagerException.INTERNAL_ERROR_NOT_PRIV_SHARED_USER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@ final class InstallRequest {
|
||||
@Nullable
|
||||
private AndroidPackage mPkg;
|
||||
private int mReturnCode;
|
||||
private int mInternalErrorCode;
|
||||
@Nullable
|
||||
private String mReturnMsg;
|
||||
// The set of packages consuming this shared library or null if no consumers exist.
|
||||
@@ -227,6 +228,10 @@ final class InstallRequest {
|
||||
return mReturnCode;
|
||||
}
|
||||
|
||||
public int getInternalErrorCode() {
|
||||
return mInternalErrorCode;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public IPackageInstallObserver2 getObserver() {
|
||||
return mInstallArgs == null ? null : mInstallArgs.mObserver;
|
||||
@@ -635,7 +640,12 @@ final class InstallRequest {
|
||||
}
|
||||
}
|
||||
|
||||
public void setError(PackageManagerException e) {
|
||||
setError(null, e);
|
||||
}
|
||||
|
||||
public void setError(String msg, PackageManagerException e) {
|
||||
mInternalErrorCode = e.internalErrorCode;
|
||||
mReturnCode = e.error;
|
||||
setReturnMessage(ExceptionUtils.getCompleteMessage(msg, e));
|
||||
Slog.w(TAG, msg, e);
|
||||
|
||||
@@ -19,7 +19,6 @@ package com.android.server.pm;
|
||||
import static android.app.AppOpsManager.MODE_DEFAULT;
|
||||
import static android.content.pm.PackageInstaller.SessionParams.MODE_INHERIT_EXISTING;
|
||||
import static android.content.pm.PackageInstaller.SessionParams.USER_ACTION_UNSPECIFIED;
|
||||
import static android.content.pm.PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
|
||||
import static android.content.pm.PackageManager.INSTALL_STAGED;
|
||||
import static android.content.pm.PackageManager.INSTALL_SUCCEEDED;
|
||||
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||
@@ -341,11 +340,15 @@ class InstallingSession {
|
||||
handle = NativeLibraryHelper.Handle.create(request.getCodeFile());
|
||||
ret = NativeLibraryHelper.copyNativeBinariesWithOverride(handle, libraryRoot,
|
||||
request.getAbiOverride(), isIncremental);
|
||||
if (ret != PackageManager.INSTALL_SUCCEEDED) {
|
||||
final String errorMessage = "Failed to copy native libraries";
|
||||
request.setError(ret, errorMessage);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
final String errorMessage = "Copying native libraries failed";
|
||||
Slog.e(TAG, errorMessage, e);
|
||||
ret = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
|
||||
request.setError(ret, errorMessage);
|
||||
request.setError(PackageManagerException.ofInternalError(errorMessage,
|
||||
PackageManagerException.INTERNAL_ERROR_NATIVE_LIBRARY_COPY));
|
||||
} finally {
|
||||
IoUtils.closeQuietly(handle);
|
||||
}
|
||||
@@ -368,10 +371,10 @@ class InstallingSession {
|
||||
mMoveInfo.mTargetSdkVersion, mMoveInfo.mFromCodePath);
|
||||
} catch (Installer.InstallerException e) {
|
||||
final String errorMessage = "Failed to move app";
|
||||
final int ret = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
|
||||
request.setError(ret, errorMessage);
|
||||
request.setError(PackageManagerException.ofInternalError(errorMessage,
|
||||
PackageManagerException.INTERNAL_ERROR_MOVE));
|
||||
Slog.w(TAG, errorMessage, e);
|
||||
return ret;
|
||||
return PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -594,13 +597,15 @@ class InstallingSession {
|
||||
final File dir = request.getOriginInfo().mResolvedFile;
|
||||
final File[] apexes = dir.listFiles();
|
||||
if (apexes == null) {
|
||||
throw new PackageManagerException(INSTALL_FAILED_INTERNAL_ERROR,
|
||||
dir.getAbsolutePath() + " is not a directory");
|
||||
throw PackageManagerException.ofInternalError(
|
||||
dir.getAbsolutePath() + " is not a directory",
|
||||
PackageManagerException.INTERNAL_ERROR_APEX_NOT_DIRECTORY);
|
||||
}
|
||||
if (apexes.length != 1) {
|
||||
throw new PackageManagerException(INSTALL_FAILED_INTERNAL_ERROR,
|
||||
throw PackageManagerException.ofInternalError(
|
||||
"Expected exactly one .apex file under " + dir.getAbsolutePath()
|
||||
+ " got: " + apexes.length);
|
||||
+ " got: " + apexes.length,
|
||||
PackageManagerException.INTERNAL_ERROR_APEX_MORE_THAN_ONE_FILE);
|
||||
}
|
||||
try (PackageParser2 packageParser = mPm.mInjector.getScanningPackageParser()) {
|
||||
ApexInfo apexInfo = mPm.mApexManager.installPackage(apexes[0]);
|
||||
@@ -638,7 +643,8 @@ class InstallingSession {
|
||||
PackageManagerService pm)
|
||||
throws PackageManagerException {
|
||||
if (childInstallingSessions.size() == 0) {
|
||||
throw new PackageManagerException("No child sessions found!");
|
||||
throw PackageManagerException.ofInternalError("No child sessions found!",
|
||||
PackageManagerException.INTERNAL_ERROR_INSTALL_MISSING_CHILD_SESSIONS);
|
||||
}
|
||||
mPm = pm;
|
||||
mUser = user;
|
||||
|
||||
@@ -47,7 +47,8 @@ final class MultiPackageVerifyingSession {
|
||||
throws PackageManagerException {
|
||||
mUser = parent.getUser();
|
||||
if (children.size() == 0) {
|
||||
throw new PackageManagerException("No child sessions found!");
|
||||
throw PackageManagerException.ofInternalError("No child sessions found!",
|
||||
PackageManagerException.INTERNAL_ERROR_VERIFY_MISSING_CHILD_SESSIONS);
|
||||
}
|
||||
mChildVerifyingSessions = children;
|
||||
// Provide every child with reference to this object as parent
|
||||
|
||||
@@ -16,32 +16,138 @@
|
||||
|
||||
package com.android.server.pm;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import com.android.server.pm.Installer.InstallerException;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/** {@hide} */
|
||||
public class PackageManagerException extends Exception {
|
||||
public final int error;
|
||||
public static final int INTERNAL_ERROR_NATIVE_LIBRARY_COPY = -1;
|
||||
public static final int INTERNAL_ERROR_MOVE = -2;
|
||||
public static final int INTERNAL_ERROR_MISSING_SETTING_FOR_MOVE = -3;
|
||||
public static final int INTERNAL_ERROR_DERIVING_ABI = -4;
|
||||
public static final int INTERNAL_ERROR_VERITY_SETUP = -5;
|
||||
public static final int INTERNAL_ERROR_SHARED_LIB_INSTALLED_TWICE = -6;
|
||||
public static final int INTERNAL_ERROR_STORAGE_INVALID_PACKAGE_UNKNOWN = -7;
|
||||
public static final int INTERNAL_ERROR_STORAGE_INVALID_VOLUME_UNKNOWN = -8;
|
||||
public static final int INTERNAL_ERROR_STORAGE_INVALID_NOT_INSTALLED_FOR_USER = -9;
|
||||
public static final int INTERNAL_ERROR_STORAGE_INVALID_SHOULD_NOT_HAVE_STORAGE = -10;
|
||||
public static final int INTERNAL_ERROR_DECOMPRESS_STUB = -11;
|
||||
public static final int INTERNAL_ERROR_UPDATED_VERSION_BETTER_THAN_SYSTEM = -12;
|
||||
public static final int INTERNAL_ERROR_DUP_STATIC_SHARED_LIB_PROVIDER = -13;
|
||||
public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_VERSION_CODES_ORDER = -14;
|
||||
public static final int INTERNAL_ERROR_SYSTEM_OVERLAY_STATIC = -15;
|
||||
public static final int INTERNAL_ERROR_OVERLAY_LOW_TARGET_SDK = -16;
|
||||
public static final int INTERNAL_ERROR_OVERLAY_SIGNATURE1 = -17;
|
||||
public static final int INTERNAL_ERROR_OVERLAY_SIGNATURE2 = -18;
|
||||
public static final int INTERNAL_ERROR_NOT_PRIV_SHARED_USER = -19;
|
||||
public static final int INTERNAL_ERROR_INSTALL_MISSING_CHILD_SESSIONS = -20;
|
||||
public static final int INTERNAL_ERROR_VERIFY_MISSING_CHILD_SESSIONS = -21;
|
||||
public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_LOW_SDK = -22;
|
||||
public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_INSTANT = -23;
|
||||
public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_RENAMED = -24;
|
||||
public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_DYNAMIC = -25;
|
||||
public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_SHARED_USER = -26;
|
||||
public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_ACTIVITY = -27;
|
||||
public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_SERVICE = -28;
|
||||
public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_CONTENT_PROVIDER = -29;
|
||||
public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_BROADCAST_RECEIVER = -30;
|
||||
public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_PERMISSION_GROUP = -31;
|
||||
public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_FEATURE = -32;
|
||||
public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_PERMISSION = -33;
|
||||
public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_PROTECTED_BROADCAST = -34;
|
||||
public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_OVERLAY_TARGETS = -35;
|
||||
public static final int INTERNAL_ERROR_APEX_NOT_DIRECTORY = -36;
|
||||
public static final int INTERNAL_ERROR_APEX_MORE_THAN_ONE_FILE = -37;
|
||||
|
||||
public PackageManagerException(String detailMessage) {
|
||||
@IntDef(prefix = { "INTERNAL_ERROR_" }, value = {
|
||||
INTERNAL_ERROR_NATIVE_LIBRARY_COPY,
|
||||
INTERNAL_ERROR_MOVE,
|
||||
INTERNAL_ERROR_MISSING_SETTING_FOR_MOVE,
|
||||
INTERNAL_ERROR_DERIVING_ABI,
|
||||
INTERNAL_ERROR_VERITY_SETUP,
|
||||
INTERNAL_ERROR_SHARED_LIB_INSTALLED_TWICE,
|
||||
INTERNAL_ERROR_STORAGE_INVALID_PACKAGE_UNKNOWN,
|
||||
INTERNAL_ERROR_STORAGE_INVALID_VOLUME_UNKNOWN,
|
||||
INTERNAL_ERROR_STORAGE_INVALID_NOT_INSTALLED_FOR_USER,
|
||||
INTERNAL_ERROR_STORAGE_INVALID_SHOULD_NOT_HAVE_STORAGE,
|
||||
INTERNAL_ERROR_DECOMPRESS_STUB,
|
||||
INTERNAL_ERROR_UPDATED_VERSION_BETTER_THAN_SYSTEM,
|
||||
INTERNAL_ERROR_DUP_STATIC_SHARED_LIB_PROVIDER,
|
||||
INTERNAL_ERROR_STATIC_SHARED_LIB_VERSION_CODES_ORDER,
|
||||
INTERNAL_ERROR_SYSTEM_OVERLAY_STATIC,
|
||||
INTERNAL_ERROR_OVERLAY_LOW_TARGET_SDK,
|
||||
INTERNAL_ERROR_OVERLAY_SIGNATURE1,
|
||||
INTERNAL_ERROR_OVERLAY_SIGNATURE2,
|
||||
INTERNAL_ERROR_NOT_PRIV_SHARED_USER,
|
||||
INTERNAL_ERROR_INSTALL_MISSING_CHILD_SESSIONS,
|
||||
INTERNAL_ERROR_VERIFY_MISSING_CHILD_SESSIONS,
|
||||
INTERNAL_ERROR_STATIC_SHARED_LIB_LOW_SDK,
|
||||
INTERNAL_ERROR_STATIC_SHARED_LIB_INSTANT,
|
||||
INTERNAL_ERROR_STATIC_SHARED_LIB_RENAMED,
|
||||
INTERNAL_ERROR_STATIC_SHARED_LIB_DYNAMIC,
|
||||
INTERNAL_ERROR_STATIC_SHARED_LIB_SHARED_USER,
|
||||
INTERNAL_ERROR_STATIC_SHARED_LIB_ACTIVITY,
|
||||
INTERNAL_ERROR_STATIC_SHARED_LIB_SERVICE,
|
||||
INTERNAL_ERROR_STATIC_SHARED_LIB_CONTENT_PROVIDER,
|
||||
INTERNAL_ERROR_STATIC_SHARED_LIB_BROADCAST_RECEIVER,
|
||||
INTERNAL_ERROR_STATIC_SHARED_LIB_PERMISSION_GROUP,
|
||||
INTERNAL_ERROR_STATIC_SHARED_LIB_FEATURE,
|
||||
INTERNAL_ERROR_STATIC_SHARED_LIB_PERMISSION,
|
||||
INTERNAL_ERROR_STATIC_SHARED_LIB_PROTECTED_BROADCAST,
|
||||
INTERNAL_ERROR_STATIC_SHARED_LIB_OVERLAY_TARGETS,
|
||||
INTERNAL_ERROR_APEX_NOT_DIRECTORY,
|
||||
INTERNAL_ERROR_APEX_MORE_THAN_ONE_FILE
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface InternalErrorCode {}
|
||||
|
||||
public final int error;
|
||||
public final int internalErrorCode;
|
||||
|
||||
/**
|
||||
* Default constructor without specifying the public return code of this exception.
|
||||
* The public error code will be {@link PackageManager.INSTALL_FAILED_INTERNAL_ERROR}.
|
||||
*
|
||||
* Note for developers: if you use this constructor, assuming you have a different case where
|
||||
* the exception should be thrown with {@link PackageManager.INSTALL_FAILED_INTERNAL_ERROR},
|
||||
* please create a new {@link InternalErrorCode} constant.
|
||||
*
|
||||
* @param detailMessage Details about the cause of the exception.
|
||||
* @param internalErrorCode Used for logging and analysis.
|
||||
*/
|
||||
public static PackageManagerException ofInternalError(String detailMessage,
|
||||
@InternalErrorCode int internalErrorCode) {
|
||||
return new PackageManagerException(
|
||||
PackageManager.INSTALL_FAILED_INTERNAL_ERROR, detailMessage, internalErrorCode);
|
||||
}
|
||||
|
||||
protected PackageManagerException(int error, String detailMessage, int internalErrorCode) {
|
||||
super(detailMessage);
|
||||
this.error = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
|
||||
this.error = error;
|
||||
this.internalErrorCode = internalErrorCode;
|
||||
}
|
||||
|
||||
public PackageManagerException(int error, String detailMessage) {
|
||||
super(detailMessage);
|
||||
this.error = error;
|
||||
this.internalErrorCode = 0;
|
||||
}
|
||||
|
||||
public PackageManagerException(int error, String detailMessage, Throwable throwable) {
|
||||
super(detailMessage, throwable);
|
||||
this.error = error;
|
||||
this.internalErrorCode = 0;
|
||||
}
|
||||
|
||||
public PackageManagerException(Throwable e) {
|
||||
super(e);
|
||||
this.error = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
|
||||
this.internalErrorCode = 0;
|
||||
}
|
||||
|
||||
public static PackageManagerException from(InstallerException e)
|
||||
|
||||
@@ -122,7 +122,7 @@ final class PackageMetrics {
|
||||
originalUsers /* original_user_ids */,
|
||||
userManagerInternal.getUserTypesForStatsd(originalUsers) /* original_user_types */,
|
||||
mInstallRequest.getReturnCode() /* public_return_code */,
|
||||
0 /* internal_error_code */,
|
||||
mInstallRequest.getInternalErrorCode() /* internal_error_code */,
|
||||
apksSize /* apks_size_bytes */,
|
||||
versionCode /* version_code */,
|
||||
stepDurations.first /* install_steps */,
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.server.pm;
|
||||
|
||||
import android.content.pm.PackageManager;
|
||||
import android.util.ExceptionUtils;
|
||||
|
||||
final class PrepareFailure extends PackageManagerException {
|
||||
@@ -31,6 +32,15 @@ final class PrepareFailure extends PackageManagerException {
|
||||
super(error, detailMessage);
|
||||
}
|
||||
|
||||
public static PrepareFailure ofInternalError(String detailMessage, int internalErrorCode) {
|
||||
return new PrepareFailure(PackageManager.INSTALL_FAILED_INTERNAL_ERROR, detailMessage,
|
||||
internalErrorCode);
|
||||
}
|
||||
|
||||
private PrepareFailure(int error, String message, int internalErrorCode) {
|
||||
super(error, message, internalErrorCode);
|
||||
}
|
||||
|
||||
PrepareFailure(String message, Exception e) {
|
||||
super(((PackageManagerException) e).error,
|
||||
ExceptionUtils.getCompleteMessage(message, e));
|
||||
|
||||
@@ -16,10 +16,18 @@
|
||||
|
||||
package com.android.server.pm;
|
||||
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
final class ReconcileFailure extends PackageManagerException {
|
||||
ReconcileFailure(String message) {
|
||||
super("Reconcile failed: " + message);
|
||||
public static ReconcileFailure ofInternalError(String message, int internalErrorCode) {
|
||||
return new ReconcileFailure(message, internalErrorCode);
|
||||
}
|
||||
|
||||
private ReconcileFailure(String message, int internalErrorCode) {
|
||||
super(PackageManager.INSTALL_FAILED_INTERNAL_ERROR, "Reconcile failed: " + message,
|
||||
internalErrorCode);
|
||||
}
|
||||
|
||||
ReconcileFailure(int reason, String message) {
|
||||
super(reason, "Reconcile failed: " + message);
|
||||
}
|
||||
|
||||
@@ -82,8 +82,10 @@ final class ReconcilePackageUtils {
|
||||
for (SharedLibraryInfo info : allowedSharedLibInfos) {
|
||||
if (!SharedLibraryUtils.addSharedLibraryToPackageVersionMap(
|
||||
incomingSharedLibraries, info)) {
|
||||
throw new ReconcileFailure("Shared Library " + info.getName()
|
||||
+ " is being installed twice in this set!");
|
||||
throw ReconcileFailure.ofInternalError(
|
||||
"Shared Library " + info.getName()
|
||||
+ " is being installed twice in this set!",
|
||||
PackageManagerException.INTERNAL_ERROR_SHARED_LIB_INSTALLED_TWICE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -569,87 +569,101 @@ final class ScanPackageUtils {
|
||||
@PackageManagerService.ScanFlags int scanFlags) throws PackageManagerException {
|
||||
// Static shared libraries should have at least O target SDK
|
||||
if (pkg.getTargetSdkVersion() < Build.VERSION_CODES.O) {
|
||||
throw new PackageManagerException(
|
||||
"Packages declaring static-shared libs must target O SDK or higher");
|
||||
throw PackageManagerException.ofInternalError(
|
||||
"Packages declaring static-shared libs must target O SDK or higher",
|
||||
PackageManagerException.INTERNAL_ERROR_STATIC_SHARED_LIB_LOW_SDK);
|
||||
}
|
||||
|
||||
// Package declaring static a shared lib cannot be instant apps
|
||||
if ((scanFlags & SCAN_AS_INSTANT_APP) != 0) {
|
||||
throw new PackageManagerException(
|
||||
"Packages declaring static-shared libs cannot be instant apps");
|
||||
throw PackageManagerException.ofInternalError(
|
||||
"Packages declaring static-shared libs cannot be instant apps",
|
||||
PackageManagerException.INTERNAL_ERROR_STATIC_SHARED_LIB_INSTANT);
|
||||
}
|
||||
|
||||
// Package declaring static a shared lib cannot be renamed since the package
|
||||
// name is synthetic and apps can't code around package manager internals.
|
||||
if (!ArrayUtils.isEmpty(pkg.getOriginalPackages())) {
|
||||
throw new PackageManagerException(
|
||||
"Packages declaring static-shared libs cannot be renamed");
|
||||
throw PackageManagerException.ofInternalError(
|
||||
"Packages declaring static-shared libs cannot be renamed",
|
||||
PackageManagerException.INTERNAL_ERROR_STATIC_SHARED_LIB_RENAMED);
|
||||
}
|
||||
|
||||
// Package declaring static a shared lib cannot declare dynamic libs
|
||||
if (!ArrayUtils.isEmpty(pkg.getLibraryNames())) {
|
||||
throw new PackageManagerException(
|
||||
"Packages declaring static-shared libs cannot declare dynamic libs");
|
||||
throw PackageManagerException.ofInternalError(
|
||||
"Packages declaring static-shared libs cannot declare dynamic libs",
|
||||
PackageManagerException.INTERNAL_ERROR_STATIC_SHARED_LIB_DYNAMIC);
|
||||
}
|
||||
|
||||
// Package declaring static a shared lib cannot declare shared users
|
||||
if (pkg.getSharedUserId() != null) {
|
||||
throw new PackageManagerException(
|
||||
"Packages declaring static-shared libs cannot declare shared users");
|
||||
throw PackageManagerException.ofInternalError(
|
||||
"Packages declaring static-shared libs cannot declare shared users",
|
||||
PackageManagerException.INTERNAL_ERROR_STATIC_SHARED_LIB_SHARED_USER);
|
||||
}
|
||||
|
||||
// Static shared libs cannot declare activities
|
||||
if (!pkg.getActivities().isEmpty()) {
|
||||
throw new PackageManagerException(
|
||||
"Static shared libs cannot declare activities");
|
||||
throw PackageManagerException.ofInternalError(
|
||||
"Static shared libs cannot declare activities",
|
||||
PackageManagerException.INTERNAL_ERROR_STATIC_SHARED_LIB_ACTIVITY);
|
||||
}
|
||||
|
||||
// Static shared libs cannot declare services
|
||||
if (!pkg.getServices().isEmpty()) {
|
||||
throw new PackageManagerException(
|
||||
"Static shared libs cannot declare services");
|
||||
throw PackageManagerException.ofInternalError(
|
||||
"Static shared libs cannot declare services",
|
||||
PackageManagerException.INTERNAL_ERROR_STATIC_SHARED_LIB_SERVICE);
|
||||
}
|
||||
|
||||
// Static shared libs cannot declare providers
|
||||
if (!pkg.getProviders().isEmpty()) {
|
||||
throw new PackageManagerException(
|
||||
"Static shared libs cannot declare content providers");
|
||||
throw PackageManagerException.ofInternalError(
|
||||
"Static shared libs cannot declare content providers",
|
||||
PackageManagerException.INTERNAL_ERROR_STATIC_SHARED_LIB_CONTENT_PROVIDER);
|
||||
}
|
||||
|
||||
// Static shared libs cannot declare receivers
|
||||
if (!pkg.getReceivers().isEmpty()) {
|
||||
throw new PackageManagerException(
|
||||
"Static shared libs cannot declare broadcast receivers");
|
||||
throw PackageManagerException.ofInternalError(
|
||||
"Static shared libs cannot declare broadcast receivers",
|
||||
PackageManagerException.INTERNAL_ERROR_STATIC_SHARED_LIB_BROADCAST_RECEIVER);
|
||||
}
|
||||
|
||||
// Static shared libs cannot declare permission groups
|
||||
if (!pkg.getPermissionGroups().isEmpty()) {
|
||||
throw new PackageManagerException(
|
||||
"Static shared libs cannot declare permission groups");
|
||||
throw PackageManagerException.ofInternalError(
|
||||
"Static shared libs cannot declare permission groups",
|
||||
PackageManagerException.INTERNAL_ERROR_STATIC_SHARED_LIB_PERMISSION_GROUP);
|
||||
}
|
||||
|
||||
// Static shared libs cannot declare attributions
|
||||
if (!pkg.getAttributions().isEmpty()) {
|
||||
throw new PackageManagerException(
|
||||
"Static shared libs cannot declare features");
|
||||
throw PackageManagerException.ofInternalError(
|
||||
"Static shared libs cannot declare features",
|
||||
PackageManagerException.INTERNAL_ERROR_STATIC_SHARED_LIB_FEATURE);
|
||||
}
|
||||
|
||||
// Static shared libs cannot declare permissions
|
||||
if (!pkg.getPermissions().isEmpty()) {
|
||||
throw new PackageManagerException(
|
||||
"Static shared libs cannot declare permissions");
|
||||
throw PackageManagerException.ofInternalError(
|
||||
"Static shared libs cannot declare permissions",
|
||||
PackageManagerException.INTERNAL_ERROR_STATIC_SHARED_LIB_PERMISSION);
|
||||
}
|
||||
|
||||
// Static shared libs cannot declare protected broadcasts
|
||||
if (!pkg.getProtectedBroadcasts().isEmpty()) {
|
||||
throw new PackageManagerException(
|
||||
"Static shared libs cannot declare protected broadcasts");
|
||||
throw PackageManagerException.ofInternalError(
|
||||
"Static shared libs cannot declare protected broadcasts",
|
||||
PackageManagerException.INTERNAL_ERROR_STATIC_SHARED_LIB_PROTECTED_BROADCAST);
|
||||
}
|
||||
|
||||
// Static shared libs cannot be overlay targets
|
||||
if (pkg.getOverlayTarget() != null) {
|
||||
throw new PackageManagerException(
|
||||
"Static shared libs cannot be overlay targets");
|
||||
throw PackageManagerException.ofInternalError(
|
||||
"Static shared libs cannot be overlay targets",
|
||||
PackageManagerException.INTERNAL_ERROR_STATIC_SHARED_LIB_OVERLAY_TARGETS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user