1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.pm; 18 19 import android.annotation.IntDef; 20 import android.content.pm.PackageManager; 21 22 import com.android.server.pm.Installer.InstallerException; 23 24 import java.lang.annotation.Retention; 25 import java.lang.annotation.RetentionPolicy; 26 27 /** {@hide} */ 28 public class PackageManagerException extends Exception { 29 public static final int INTERNAL_ERROR_NATIVE_LIBRARY_COPY = -1; 30 public static final int INTERNAL_ERROR_MOVE = -2; 31 public static final int INTERNAL_ERROR_MISSING_SETTING_FOR_MOVE = -3; 32 public static final int INTERNAL_ERROR_DERIVING_ABI = -4; 33 public static final int INTERNAL_ERROR_VERITY_SETUP = -5; 34 public static final int INTERNAL_ERROR_SHARED_LIB_INSTALLED_TWICE = -6; 35 public static final int INTERNAL_ERROR_STORAGE_INVALID_PACKAGE_UNKNOWN = -7; 36 public static final int INTERNAL_ERROR_STORAGE_INVALID_VOLUME_UNKNOWN = -8; 37 public static final int INTERNAL_ERROR_STORAGE_INVALID_NOT_INSTALLED_FOR_USER = -9; 38 public static final int INTERNAL_ERROR_STORAGE_INVALID_SHOULD_NOT_HAVE_STORAGE = -10; 39 public static final int INTERNAL_ERROR_DECOMPRESS_STUB = -11; 40 public static final int INTERNAL_ERROR_UPDATED_VERSION_BETTER_THAN_SYSTEM = -12; 41 public static final int INTERNAL_ERROR_DUP_STATIC_SHARED_LIB_PROVIDER = -13; 42 public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_VERSION_CODES_ORDER = -14; 43 public static final int INTERNAL_ERROR_SYSTEM_OVERLAY_STATIC = -15; 44 public static final int INTERNAL_ERROR_OVERLAY_LOW_TARGET_SDK = -16; 45 public static final int INTERNAL_ERROR_OVERLAY_SIGNATURE1 = -17; 46 public static final int INTERNAL_ERROR_OVERLAY_SIGNATURE2 = -18; 47 public static final int INTERNAL_ERROR_NOT_PRIV_SHARED_USER = -19; 48 public static final int INTERNAL_ERROR_INSTALL_MISSING_CHILD_SESSIONS = -20; 49 public static final int INTERNAL_ERROR_VERIFY_MISSING_CHILD_SESSIONS = -21; 50 public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_LOW_SDK = -22; 51 public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_INSTANT = -23; 52 public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_RENAMED = -24; 53 public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_DYNAMIC = -25; 54 public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_SHARED_USER = -26; 55 public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_ACTIVITY = -27; 56 public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_SERVICE = -28; 57 public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_CONTENT_PROVIDER = -29; 58 public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_BROADCAST_RECEIVER = -30; 59 public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_PERMISSION_GROUP = -31; 60 public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_FEATURE = -32; 61 public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_PERMISSION = -33; 62 public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_PROTECTED_BROADCAST = -34; 63 public static final int INTERNAL_ERROR_STATIC_SHARED_LIB_OVERLAY_TARGETS = -35; 64 public static final int INTERNAL_ERROR_APEX_NOT_DIRECTORY = -36; 65 public static final int INTERNAL_ERROR_APEX_MORE_THAN_ONE_FILE = -37; 66 public static final int INTERNAL_ERROR_MISSING_USER = -38; 67 public static final int INTERNAL_ERROR_ARCHIVE_NO_INSTALLER_TITLE = -39; 68 69 @IntDef(prefix = { "INTERNAL_ERROR_" }, value = { 70 INTERNAL_ERROR_NATIVE_LIBRARY_COPY, 71 INTERNAL_ERROR_MOVE, 72 INTERNAL_ERROR_MISSING_SETTING_FOR_MOVE, 73 INTERNAL_ERROR_DERIVING_ABI, 74 INTERNAL_ERROR_VERITY_SETUP, 75 INTERNAL_ERROR_SHARED_LIB_INSTALLED_TWICE, 76 INTERNAL_ERROR_STORAGE_INVALID_PACKAGE_UNKNOWN, 77 INTERNAL_ERROR_STORAGE_INVALID_VOLUME_UNKNOWN, 78 INTERNAL_ERROR_STORAGE_INVALID_NOT_INSTALLED_FOR_USER, 79 INTERNAL_ERROR_STORAGE_INVALID_SHOULD_NOT_HAVE_STORAGE, 80 INTERNAL_ERROR_DECOMPRESS_STUB, 81 INTERNAL_ERROR_UPDATED_VERSION_BETTER_THAN_SYSTEM, 82 INTERNAL_ERROR_DUP_STATIC_SHARED_LIB_PROVIDER, 83 INTERNAL_ERROR_STATIC_SHARED_LIB_VERSION_CODES_ORDER, 84 INTERNAL_ERROR_SYSTEM_OVERLAY_STATIC, 85 INTERNAL_ERROR_OVERLAY_LOW_TARGET_SDK, 86 INTERNAL_ERROR_OVERLAY_SIGNATURE1, 87 INTERNAL_ERROR_OVERLAY_SIGNATURE2, 88 INTERNAL_ERROR_NOT_PRIV_SHARED_USER, 89 INTERNAL_ERROR_INSTALL_MISSING_CHILD_SESSIONS, 90 INTERNAL_ERROR_VERIFY_MISSING_CHILD_SESSIONS, 91 INTERNAL_ERROR_STATIC_SHARED_LIB_LOW_SDK, 92 INTERNAL_ERROR_STATIC_SHARED_LIB_INSTANT, 93 INTERNAL_ERROR_STATIC_SHARED_LIB_RENAMED, 94 INTERNAL_ERROR_STATIC_SHARED_LIB_DYNAMIC, 95 INTERNAL_ERROR_STATIC_SHARED_LIB_SHARED_USER, 96 INTERNAL_ERROR_STATIC_SHARED_LIB_ACTIVITY, 97 INTERNAL_ERROR_STATIC_SHARED_LIB_SERVICE, 98 INTERNAL_ERROR_STATIC_SHARED_LIB_CONTENT_PROVIDER, 99 INTERNAL_ERROR_STATIC_SHARED_LIB_BROADCAST_RECEIVER, 100 INTERNAL_ERROR_STATIC_SHARED_LIB_PERMISSION_GROUP, 101 INTERNAL_ERROR_STATIC_SHARED_LIB_FEATURE, 102 INTERNAL_ERROR_STATIC_SHARED_LIB_PERMISSION, 103 INTERNAL_ERROR_STATIC_SHARED_LIB_PROTECTED_BROADCAST, 104 INTERNAL_ERROR_STATIC_SHARED_LIB_OVERLAY_TARGETS, 105 INTERNAL_ERROR_APEX_NOT_DIRECTORY, 106 INTERNAL_ERROR_APEX_MORE_THAN_ONE_FILE, 107 INTERNAL_ERROR_MISSING_USER, 108 INTERNAL_ERROR_ARCHIVE_NO_INSTALLER_TITLE 109 }) 110 @Retention(RetentionPolicy.SOURCE) 111 public @interface InternalErrorCode {} 112 113 public final int error; 114 public final int internalErrorCode; 115 116 /** 117 * Default constructor without specifying the public return code of this exception. 118 * The public error code will be {@link PackageManager.INSTALL_FAILED_INTERNAL_ERROR}. 119 * 120 * Note for developers: if you use this constructor, assuming you have a different case where 121 * the exception should be thrown with {@link PackageManager.INSTALL_FAILED_INTERNAL_ERROR}, 122 * please create a new {@link InternalErrorCode} constant. 123 * 124 * @param detailMessage Details about the cause of the exception. 125 * @param internalErrorCode Used for logging and analysis. 126 */ ofInternalError(String detailMessage, @InternalErrorCode int internalErrorCode)127 public static PackageManagerException ofInternalError(String detailMessage, 128 @InternalErrorCode int internalErrorCode) { 129 return new PackageManagerException( 130 PackageManager.INSTALL_FAILED_INTERNAL_ERROR, detailMessage, internalErrorCode); 131 } 132 PackageManagerException(int error, String detailMessage, int internalErrorCode)133 protected PackageManagerException(int error, String detailMessage, int internalErrorCode) { 134 super(detailMessage); 135 this.error = error; 136 this.internalErrorCode = internalErrorCode; 137 } 138 PackageManagerException(int error, String detailMessage)139 public PackageManagerException(int error, String detailMessage) { 140 super(detailMessage); 141 this.error = error; 142 this.internalErrorCode = 0; 143 } 144 PackageManagerException(int error, String detailMessage, Throwable throwable)145 public PackageManagerException(int error, String detailMessage, Throwable throwable) { 146 super(detailMessage, throwable); 147 this.error = error; 148 this.internalErrorCode = 0; 149 } 150 PackageManagerException(Throwable e)151 public PackageManagerException(Throwable e) { 152 super(e); 153 this.error = PackageManager.INSTALL_FAILED_INTERNAL_ERROR; 154 this.internalErrorCode = 0; 155 } 156 from(InstallerException e)157 public static PackageManagerException from(InstallerException e) 158 throws PackageManagerException { 159 throw new PackageManagerException(PackageManager.INSTALL_FAILED_INTERNAL_ERROR, 160 e.getMessage(), e.getCause()); 161 } 162 } 163