俗话说的好,得中原者,得天下,那么想要了解Android的安装了流程就不得不提及一个重要的类"PackageManager"我们就先来了解这两个类
Android系统为我们提供了很多服务的管理类,比如ActivityManager、PowrManager,那么和安装APK有关就是PackageManager了,它负责管理应用程序包,通过它就可以获取应用程序信息。
这个类已经5000多行,我们就不详细介绍了,我们来看下这个类
/**
* Class for retrieving various kinds of information related to the application
* packages that are currently installed on the device.
*
* You can find this class through {@link Context#getPackageManager}.
*/
public abstract class PackageManager {
...
}
通过上面代码我们知道这个类是抽象类,那我们来看下注释
PackageManager这个类是检测当前已经安装在当前设备上的应用程序包的信息。你可以调用Context类的getPackageManager()方法来获取PackageManager方法。
PackageManager是一个实际上管理应用程序安装、卸载和升级的API。当我们安装APK文件时,PackageManager会解析APK包文件和显示确认信息。当我们点击OK按钮后,PackageManager会调用一个叫"InstallPackage"的方法,这个方法有4个参数,也就是uri、installFlags、observer、installPackagename。PackageManager会启动一个叫"package"的servcie服务,现在所有模糊的东西会发生在这个service中。
APK安装流程.png
通过包名获取该包名对应的应用程序的PackageInfo对象
代码在PackageManager.java2031行
/**
* Retrieve overall information about an application package that is
* installed on the system.
* <p>
* Throws {@link NameNotFoundException} if a package with the given name can
* not be found on the system.
*
* @param packageName The full name (i.e. com.google.apps.contacts) of the
* desired package.
* @param flags Additional option flags. Use any combination of
* {@link #GET_ACTIVITIES}, {@link #GET_GIDS},
* {@link #GET_CONFIGURATIONS}, {@link #GET_INSTRUMENTATION},
* {@link #GET_PERMISSIONS}, {@link #GET_PROVIDERS},
* {@link #GET_RECEIVERS}, {@link #GET_SERVICES},
* {@link #GET_SIGNATURES}, {@link #GET_UNINSTALLED_PACKAGES} to
* modify the data returned.
* @return Returns a PackageInfo object containing information about the
* package. If flag GET_UNINSTALLED_PACKAGES is set and if the
* package is not found in the list of installed applications, the
* package information is retrieved from the list of uninstalled
* applications (which includes installed applications as well as
* applications with data directory i.e. applications which had been
* deleted with {@code DONT_DELETE_DATA} flag set).
* @see #GET_ACTIVITIES
* @see #GET_GIDS
* @see #GET_CONFIGURATIONS
* @see #GET_INSTRUMENTATION
* @see #GET_PERMISSIONS
* @see #GET_PROVIDERS
* @see #GET_RECEIVERS
* @see #GET_SERVICES
* @see #GET_SIGNATURES
* @see #GET_UNINSTALLED_PACKAGES
*/
public abstract PackageInfo getPackageInfo(String packageName, int flags)
throws NameNotFoundException;
先翻译一下注释:
检索出有关系统上安装应用程序包的总体信息
关于PackageInfo这各类请参考APK安装流程详解1——有关"安装ing"的实体类概述
。它表示检索有关系统上安装的应用程序包的总体信息。
代码在PackageManager.java2041行
/**
* Map from the current package names in use on the device to whatever
* the current canonical name of that package is.
* @param names Array of current names to be mapped.
* @return Returns an array of the same size as the original, containing
* the canonical name for each package.
*/
public abstract String[] currentToCanonicalPackageNames(String[] names);
简单翻译注释如下:
从设备上使用当前包名映射到该软件包名的当前规范名称。
如果修改包名会用到,没有修改过包名一般不会用到
主要是相对于上面的方法
代码在PackageManager.java2049行
/**
* Map from a packages canonical name to the current name in use on the device.
* @param names Array of new names to be mapped.
* @return Returns an array of the same size as the original, containing
* the current name for each package.
*/
public abstract String[] canonicalToCurrentPackageNames(String[] names);
简单翻译注释如下:
将软件包规范名称映射到设备上正在使用的当前名称。
其中canonicalToCurrentPackageNames()和currentToCanonicalPackageNames()方法是相反的两个方法
获取一个应用程序的Lauch的Intent
代码在PackageManager.java 2066行
/**
* Returns a "good" intent to launch a front-door activity in a package.
* This is used, for example, to implement an "open" button when browsing
* through packages. The current implementation looks first for a main
* activity in the category {@link Intent#CATEGORY_INFO}, and next for a
* main activity in the category {@link Intent#CATEGORY_LAUNCHER}. Returns
* <code>null</code> if neither are found.
*
* @param packageName The name of the package to inspect.
*
* @return A fully-qualified {@link Intent} that can be used to launch the
* main activity in the package. Returns <code>null</code> if the package
* does not contain such an activity, or if <em>packageName</em> is not
* recognized.
*/
public abstract Intent getLaunchIntentForPackage(String packageName);
返回一个"包"中的"入口"Activity的Intent,例如,这是类似于在浏览包的"打开"按钮。这个当前的安装启动第一步在category(CATEGORY_INFO)中寻找main Activity,然后在category(CATEGORY_LAUNCHER)寻找main Activity。如果找不到就返回null。
入参是包名
获取一个TV应用的Leanback的Intent
代码在PackageManager.java2083行
/**
* Return a "good" intent to launch a front-door Leanback activity in a
* package, for use for example to implement an "open" button when browsing
* through packages. The current implementation will look for a main
* activity in the category {@link * return null if no main leanback activities are found.
* <p>
* Throws {@link NameNotFoundException} if a package with the given name
* cannot be found on the system.
*
* @param packageName The name of the package to inspect.
* @return Returns either a fully-qualified Intent that can be used to launch
* the main Leanback activity in the package, or null if the package
* does not contain such an activity.
*/
public abstract Intent getLeanbackLaunchIntentForPackage(String packageName);
Leanback activity一般在TV上使用的比较多,上面这个方法返回的Intent的一般在AndroidManifest如下:
<activity
android:name="com.example.android.TvActivity"
android:label="@string/app_name"
android:theme="@style/Theme.Leanback">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>
其实就是返回的是com.example.android.TvActivity的打开Intent
翻译注释如下:
返回一个"合适的"Intent,这个Intent是打开LeanbackActivity的入口Intent。例如,类似于在浏览包的"打开"按钮。这个将找匹配CATEGORY_LEANBACK_LAUNCHER的Activity。如果没有找到则返回null。
获取相应包的Group ids
代码在PackageManager.java2097行
/**
* Return an array of all of the POSIX secondary group IDs that have been
* assigned to the given package.
* <p>
* Note that the same package may have different GIDs under different
* {@link UserHandle} on the same device.
*
* @param packageName The full name (i.e. com.google.apps.contacts) of the
* desired package.
* @return Returns an int array of the assigned GIDs, or null if there are
* none.
* @throws NameNotFoundException if a package with the given name cannot be
* found on the system.
*/
public abstract int[] getPackageGids(String packageName)
throws NameNotFoundException;
翻译注释如下:
获取相应包的UID
代码在PackageManager.java2113行
/**
* Return the UID associated with the given package name.
* <p>
* Note that the same package will have different UIDs under different
* {@link UserHandle} on the same device.
*
* @param packageName The full name (i.e. com.google.apps.contacts) of the
* desired package.
* @return Returns an integer UID who owns the given package name.
* @throws NameNotFoundException if a package with the given name can not be
* found on the system.
*/
public abstract int getPackageUid(String packageName, @PackageInfoFlags int flags)
throws NameNotFoundException;
翻译注释如下:
根据包名和指定的flags获取指定的授权信息
代码在PackageManager.java2130行
/**
* Retrieve all of the information we know about a particular permission.
*
* @param name The fully qualified name (i.e. com.google.permission.LOGIN)
* of the permission you are interested in.
* @param flags Additional option flags. Use {@link #GET_META_DATA} to
* retrieve any meta-data associated with the permission.
*
* @return Returns a {@link PermissionInfo} containing information about the
* permission.
* @throws NameNotFoundException if a package with the given name cannot be
* found on the system.
*
* @see #GET_META_DATA
*/
public abstract PermissionInfo getPermissionInfo(String name, int flags)
throws NameNotFoundException;
翻译注释如下:
获取所有的PermissionInfo集合
代码在PackageManager.java2148行
/**
* Query for all of the permissions associated with a particular group.
*
* @param group The fully qualified name (i.e. com.google.permission.LOGIN)
* of the permission group you are interested in. Use null to
* find all of the permissions not associated with a group.
* @param flags Additional option flags. Use {@link #GET_META_DATA} to
* retrieve any meta-data associated with the permissions.
*
* @return Returns a list of {@link PermissionInfo} containing information
* about all of the permissions in the given group.
* @throws NameNotFoundException if a package with the given name cannot be
* found on the system.
*
* @see #GET_META_DATA
*/
public abstract List<PermissionInfo> queryPermissionsByGroup(String group,int flags) throws NameNotFoundException;
翻译注释如下:
根据指定Group明和获取PermissionGroupInfo对象。 代码在PackageManager.java2166行
/**
* Retrieve all of the information we know about a particular group of
* permissions.
*
* @param name The fully qualified name (i.e. com.google.permission_group.APPS)
* of the permission you are interested in.
* @param flags Additional option flags. Use {@link #GET_META_DATA} to
* retrieve any meta-data associated with the permission group.
*
* @return Returns a {@link PermissionGroupInfo} containing information
* about the permission.
* @throws NameNotFoundException if a package with the given name cannot be
* found on the system.
*
* @see #GET_META_DATA
*/
public abstract PermissionGroupInfo getPermissionGroupInfo(String name,int flags) throws NameNotFoundException;
翻译注释如下:
获取所有的PermissGroup集合
代码在PackageManager.java2178行
/**
* Retrieve all of the known permission groups in the system.
*
* @param flags Additional option flags. Use {@link #GET_META_DATA} to
* retrieve any meta-data associated with the permission group.
*
* @return Returns a list of {@link PermissionGroupInfo} containing
* information about all of the known permission groups.
*
* @see #GET_META_DATA
*/
public abstract List<PermissionGroupInfo> getAllPermissionGroups(
@PermissionGroupInfoFlags int flags);
翻译注释如下:
根据包名返回其对应的ApplicationInfo信息
代码在PackageManager.java2207行
/**
* Retrieve all of the information we know about a particular
* package/application.
*
* @param packageName The full name (i.e. com.google.apps.contacts) of an
* application.
* @param flags Additional option flags. Use any combination of
* {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
* {@link #MATCH_SYSTEM_ONLY}, {@link #MATCH_UNINSTALLED_PACKAGES}
* to modify the data returned.
*
* @return An {@link ApplicationInfo} containing information about the
* package. If flag {@code MATCH_UNINSTALLED_PACKAGES} is set and if the
* package is not found in the list of installed applications, the
* application information is retrieved from the list of uninstalled
* applications (which includes installed applications as well as
* applications with data directory i.e. applications which had been
* deleted with {@code DONT_DELETE_DATA} flag set).
* @throws NameNotFoundException if a package with the given name cannot be
* found on the system.
*
* @see #GET_META_DATA
* @see #GET_SHARED_LIBRARY_FILES
* @see #MATCH_DISABLED_UNTIL_USED_COMPONENTS
* @see #MATCH_SYSTEM_ONLY
* @see #MATCH_UNINSTALLED_PACKAGES
*/
public abstract ApplicationInfo getApplicationInfo(String packageName,
int flags) throws NameNotFoundException;
翻译注释如下:
根据组件和要求返回特定的ActivityInfo
代码在PackageManager.java2230行
/**
* Retrieve all of the information we know about a particular activity
* class.
*
* @param component The full component name (i.e.
* com.google.apps.contacts/com.google.apps.contacts.
* ContactsList) of an Activity class.
* @param flags Additional option flags. Use any combination of
* {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},{@GET_INTENT_FILTERS}
*
* returned.
* @return An {@link ActivityInfo} containing information about the
* activity.
* @throws NameNotFoundException if a package with the given name cannot be
* found on the system.
*/
public abstract ActivityInfo getActivityInfo(ComponentName component,int flags) throws NameNotFoundException;
翻译注释如下:
根据组件和要求返回特定的ActivityInfo
代码在PackageManager.java2253行
/**
* Retrieve all of the information we know about a particular receiver
* class.
*
* <p>Throws {@link NameNotFoundException} if a receiver with the given
* class name cannot be found on the system.
*
* @param component The full component name (i.e.
* com.google.apps.calendar/com.google.apps.calendar.CalendarAlarm) of a Receiver
* class.
* @param flags Additional option flags. Use any combination of
* {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
* to modify the data returned.
*
* @return {@link ActivityInfo} containing information about the receiver.
*
* @see #GET_INTENT_FILTERS
* @see #GET_META_DATA
* @see #GET_SHARED_LIBRARY_FILES
*/
public abstract ActivityInfo getReceiverInfo(ComponentName component,
int flags) throws NameNotFoundException;
翻译注释如下:
根据组件和要求返回特定的ServiceInfo
代码在PackageManager.java2275行
/**
* Retrieve all of the information we know about a particular service
* class.
*
* <p>Throws {@link NameNotFoundException} if a service with the given
* class name cannot be found on the system.
*
* @param component The full component name (i.e.
* com.google.apps.media/com.google.apps.media.BackgroundPlayback) of a Service
* class.
* @param flags Additional option flags. Use any combination of
* {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
* to modify the data returned.
*
* @return ServiceInfo containing information about the service.
*
* @see #GET_META_DATA
* @see #GET_SHARED_LIBRARY_FILES
*/
public abstract ServiceInfo getServiceInfo(ComponentName component,
int flags) throws NameNotFoundException;
翻译注释如下:
根据组件和要求返回特定的ProviderInfo
代码在PackageManager.java2297行
/**
* Retrieve all of the information we know about a particular content
* provider class.
*
* <p>Throws {@link NameNotFoundException} if a provider with the given
* class name cannot be found on the system.
*
* @param component The full component name (i.e.
* com.google.providers.media/com.google.providers.media.MediaProvider) of a
* ContentProvider class.
* @param flags Additional option flags. Use any combination of
* {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
* to modify the data returned.
*
* @return ProviderInfo containing information about the service.
*
* @see #GET_META_DATA
* @see #GET_SHARED_LIBRARY_FILES
*/
public abstract ProviderInfo getProviderInfo(ComponentName component,
int flags) throws NameNotFoundException;
翻译注释如下:
获取设备上安装的所有软件包
代码在PackageManager.java2334行
/**
* Return a List of all packages that are installed
* on the device.
*
* @param flags Additional option flags. Use any combination of
* {@link #GET_ACTIVITIES},
* {@link #GET_GIDS},
* {@link #GET_CONFIGURATIONS},
* {@link #GET_INSTRUMENTATION},
* {@link #GET_PERMISSIONS},
* {@link #GET_PROVIDERS},
* {@link #GET_RECEIVERS},
* {@link #GET_SERVICES},
* {@link #GET_SIGNATURES},
* {@link #GET_UNINSTALLED_PACKAGES} to modify the data returned.
*
* @return A List of PackageInfo objects, one for each package that is
* installed on the device. In the unlikely case of there being no
* installed packages, an empty list is returned.
* If flag GET_UNINSTALLED_PACKAGES is set, a list of all
* applications including those deleted with {@code DONT_DELETE_DATA}
* (partially installed apps with data directory) will be returned.
*
* @see #GET_ACTIVITIES
* @see #GET_GIDS
* @see #GET_CONFIGURATIONS
* @see #GET_INSTRUMENTATION
* @see #GET_PERMISSIONS
* @see #GET_PROVIDERS
* @see #GET_RECEIVERS
* @see #GET_SERVICES
* @see #GET_SIGNATURES
* @see #GET_UNINSTALLED_PACKAGES
*/
public abstract List<PackageInfo> getInstalledPackages(int flags);
翻译注释如下:
获取具有特定权限的PackageInfo
代码在PackageManager.java2366行
/**
* Return a List of all installed packages that are currently
* holding any of the given permissions.
*
* @param flags Additional option flags. Use any combination of
* {@link #GET_ACTIVITIES},
* {@link #GET_GIDS},
* {@link #GET_CONFIGURATIONS},
* {@link #GET_INSTRUMENTATION},
* {@link #GET_PERMISSIONS},
* {@link #GET_PROVIDERS},
* {@link #GET_RECEIVERS},
* {@link #GET_SERVICES},
* {@link #GET_SIGNATURES},
* {@link #GET_UNINSTALLED_PACKAGES} to modify the data returned.
*
* @return Returns a List of PackageInfo objects, one for each installed
* application that is holding any of the permissions that were provided.
*
* @see #GET_ACTIVITIES
* @see #GET_GIDS
* @see #GET_CONFIGURATIONS
* @see #GET_INSTRUMENTATION
* @see #GET_PERMISSIONS
* @see #GET_PROVIDERS
* @see #GET_RECEIVERS
* @see #GET_SERVICES
* @see #GET_SIGNATURES
* @see #GET_UNINSTALLED_PACKAGES
*/
public abstract List<PackageInfo> getPackagesHoldingPermissions(
String[] permissions, int flags);
翻译注释如下:
获取具有特定用户的PackageInfo
代码在PackageManager.java2406行
/**
* Return a List of all packages that are installed on the device, for a specific user.
* Requesting a list of installed packages for another user
* will require the permission INTERACT_ACROSS_USERS_FULL.
* @param flags Additional option flags. Use any combination of
* {@link #GET_ACTIVITIES},
* {@link #GET_GIDS},
* {@link #GET_CONFIGURATIONS},
* {@link #GET_INSTRUMENTATION},
* {@link #GET_PERMISSIONS},
* {@link #GET_PROVIDERS},
* {@link #GET_RECEIVERS},
* {@link #GET_SERVICES},
* {@link #GET_SIGNATURES},
* {@link #GET_UNINSTALLED_PACKAGES} to modify the data returned.
* @param userId The user for whom the installed packages are to be listed
*
* @return A List of PackageInfo objects, one for each package that is
* installed on the device. In the unlikely case of there being no
* installed packages, an empty list is returned.
* If flag GET_UNINSTALLED_PACKAGES is set, a list of all
* applications including those deleted with {@code DONT_DELETE_DATA}
* (partially installed apps with data directory) will be returned.
*
* @see #GET_ACTIVITIES
* @see #GET_GIDS
* @see #GET_CONFIGURATIONS
* @see #GET_INSTRUMENTATION
* @see #GET_PERMISSIONS
* @see #GET_PROVIDERS
* @see #GET_RECEIVERS
* @see #GET_SERVICES
* @see #GET_SIGNATURES
* @see #GET_UNINSTALLED_PACKAGES
*
* @hide
*/
public abstract List<PackageInfo> getInstalledPackages(int flags, int userId);
翻译注释如下:
获取所有已经安装的应用程序集合
代码在PackageManager.java2746行
/**
* Return a List of all application packages that are installed on the
* device. If flag GET_UNINSTALLED_PACKAGES has been set, a list of all
* applications including those deleted with {@code DONT_DELETE_DATA} (partially
* installed apps with data directory) will be returned.
*
* @param flags Additional option flags. Use any combination of
* {@link #GET_META_DATA}, {@link #GET_SHARED_LIBRARY_FILES},
* {@link #GET_UNINSTALLED_PACKAGES} to modify the data returned.
*
* @return Returns a List of ApplicationInfo objects, one for each application that
* is installed on the device. In the unlikely case of there being
* no installed applications, an empty list is returned.
* If flag GET_UNINSTALLED_PACKAGES is set, a list of all
* applications including those deleted with {@code DONT_DELETE_DATA}
* (partially installed apps with data directory) will be returned.
*
* @see #GET_META_DATA
* @see #GET_SHARED_LIBRARY_FILES
* @see #GET_UNINSTALLED_PACKAGES
*/
public abstract List<ApplicationInfo> getInstalledApplications(int flags);
翻译注释如下:
代码在PackageManager.java 3586行
/**
* @hide Install a package. Since this may take a little while, the result
* will be posted back to the given observer. An installation will
* fail if the calling context lacks the
* {@link android.Manifest.permission#INSTALL_PACKAGES} permission, if
* the package named in the package file's manifest is already
* installed, or if there's no space available on the device.
* @param packageURI The location of the package file to install. This can
* be a 'file:' or a 'content:' URI.
* @param observer An observer callback to get notified when the package
* installation is complete.
* {@link IPackageInstallObserver#packageInstalled(String, int)}
* will be called when that happens. This parameter must not be
* null.
* @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
* {@link #INSTALL_REPLACE_EXISTING},
* {@link #INSTALL_ALLOW_TEST}.
* @param installerPackageName Optional package name of the application that
* is performing the installation. This identifies which market
* the package came from.
* @deprecated Use {@link #installPackage(Uri, PackageInstallObserver, int,
* String)} instead. This method will continue to be supported
* but the older observer interface will not get additional
* failure details.
*/
// @SystemApi
public abstract void installPackage(
Uri packageURI, IPackageInstallObserver observer, int flags,
String installerPackageName);
通过代码我们发现它是一个 系统API(SystemApi)
翻译注释如下:
代码在PackageManager.java 3624行
/**
* Similar to
* {@link #installPackage(Uri, IPackageInstallObserver, int, String)} but
* with an extra verification file provided.
*
* @param packageURI The location of the package file to install. This can
* be a 'file:' or a 'content:' URI.
* @param observer An observer callback to get notified when the package
* installation is complete.
* {@link IPackageInstallObserver#packageInstalled(String, int)}
* will be called when that happens. This parameter must not be
* null.
* @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
* {@link #INSTALL_REPLACE_EXISTING},
* {@link #INSTALL_ALLOW_TEST}.
* @param installerPackageName Optional package name of the application that
* is performing the installation. This identifies which market
* the package came from.
* @param verificationURI The location of the supplementary verification
* file. This can be a 'file:' or a 'content:' URI. May be
* {@code null}.
* @param manifestDigest an object that holds the digest of the package
* which can be used to verify ownership. May be {@code null}.
* @param encryptionParams if the package to be installed is encrypted,
* these parameters describing the encryption and authentication
* used. May be {@code null}.
* @hide
* @deprecated Use {@link #installPackageWithVerification(Uri,
* PackageInstallObserver, int, String, Uri, ManifestDigest,
* ContainerEncryptionParams)} instead. This method will
* continue to be supported but the older observer interface
* will not get additional failure details.
*/
// @SystemApi
public abstract void installPackageWithVerification(Uri packageURI,
IPackageInstallObserver observer, int flags, String installerPackageName,
Uri verificationURI, ManifestDigest manifestDigest,
ContainerEncryptionParams encryptionParams);
通过代码我们发现它是一个 系统API(SystemApi)
翻译注释如下:
代码在PackageManager.java 3660行
/**
* Similar to
* {@link #installPackage(Uri, IPackageInstallObserver, int, String)} but
* with an extra verification information provided.
*
* @param packageURI The location of the package file to install. This can
* be a 'file:' or a 'content:' URI.
* @param observer An observer callback to get notified when the package
* installation is complete.
* {@link IPackageInstallObserver#packageInstalled(String, int)}
* will be called when that happens. This parameter must not be
* null.
* @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
* {@link #INSTALL_REPLACE_EXISTING},
* {@link #INSTALL_ALLOW_TEST}.
* @param installerPackageName Optional package name of the application that
* is performing the installation. This identifies which market
* the package came from.
* @param verificationParams an object that holds signal information to
* assist verification. May be {@code null}.
* @param encryptionParams if the package to be installed is encrypted,
* these parameters describing the encryption and authentication
* used. May be {@code null}.
* @hide
* @deprecated Use {@link #installPackageWithVerificationAndEncryption(Uri,
* PackageInstallObserver, int, String, VerificationParams,
* ContainerEncryptionParams)} instead. This method will
* continue to be supported but the older observer interface
* will not get additional failure details.
*/
@Deprecated
public abstract void installPackageWithVerificationAndEncryption(Uri packageURI,
IPackageInstallObserver observer, int flags, String installerPackageName,
VerificationParams verificationParams,
ContainerEncryptionParams encryptionParams);
通过代码我们发现它是一个 系统API(SystemApi)
翻译注释如下:
代码在PackageManager.java 3688行
/**
* @hide
*
* Install a package. Since this may take a little while, the result will
* be posted back to the given observer. An installation will fail if the calling context
* lacks the {@link android.Manifest.permission#INSTALL_PACKAGES} permission, if the
* package named in the package file's manifest is already installed, or if there's no space
* available on the device.
*
* @param packageURI The location of the package file to install. This can be a 'file:' or a
* 'content:' URI.
* @param observer An observer callback to get notified when the package installation is
* complete. {@link PackageInstallObserver#packageInstalled(String, Bundle, int)} will be
* called when that happens. This parameter must not be null.
* @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
* {@link #INSTALL_REPLACE_EXISTING}, {@link #INSTALL_ALLOW_TEST}.
* @param installerPackageName Optional package name of the application that is performing the
* installation. This identifies which market the package came from.
*/
public abstract void installPackage(
Uri packageURI, PackageInstallObserver observer,
int flags, String installerPackageName);
翻译注释如下:
代码在PackageManager.java 3717行
/**
* Similar to
* {@link #installPackage(Uri, IPackageInstallObserver, int, String)} but
* with an extra verification file provided.
*
* @param packageURI The location of the package file to install. This can
* be a 'file:' or a 'content:' URI.
* @param observer An observer callback to get notified when the package installation is
* complete. {@link PackageInstallObserver#packageInstalled(String, Bundle, int)} will be
* called when that happens. This parameter must not be null.
* @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
* {@link #INSTALL_REPLACE_EXISTING}, {@link #INSTALL_ALLOW_TEST}.
* @param installerPackageName Optional package name of the application that
* is performing the installation. This identifies which market
* the package came from.
* @param verificationURI The location of the supplementary verification
* file. This can be a 'file:' or a 'content:' URI. May be
* {@code null}.
* @param manifestDigest an object that holds the digest of the package
* which can be used to verify ownership. May be {@code null}.
* @param encryptionParams if the package to be installed is encrypted,
* these parameters describing the encryption and authentication
* used. May be {@code null}.
* @hide
*/
public abstract void installPackageWithVerification(Uri packageURI,
PackageInstallObserver observer, int flags, String installerPackageName,
Uri verificationURI, ManifestDigest manifestDigest,
ContainerEncryptionParams encryptionParams);
翻译注释如下:
代码在PackageManager.java 3745行
/**
* Similar to
* {@link #installPackage(Uri, IPackageInstallObserver, int, String)} but
* with an extra verification information provided.
*
* @param packageURI The location of the package file to install. This can
* be a 'file:' or a 'content:' URI.
* @param observer An observer callback to get notified when the package installation is
* complete. {@link PackageInstallObserver#packageInstalled(String, Bundle, int)} will be
* called when that happens. This parameter must not be null.
* @param flags - possible values: {@link #INSTALL_FORWARD_LOCK},
* {@link #INSTALL_REPLACE_EXISTING}, {@link #INSTALL_ALLOW_TEST}.
* @param installerPackageName Optional package name of the application that
* is performing the installation. This identifies which market
* the package came from.
* @param verificationParams an object that holds signal information to
* assist verification. May be {@code null}.
* @param encryptionParams if the package to be installed is encrypted,
* these parameters describing the encryption and authentication
* used. May be {@code null}.
*
* @hide
*/
public abstract void installPackageWithVerificationAndEncryption(Uri packageURI,
PackageInstallObserver observer, int flags, String installerPackageName,
VerificationParams verificationParams, ContainerEncryptionParams encryptionParams);
翻译注释如下:
代码在PackageManager.java 3755行
/**
* If there is already an application with the given package name installed
* on the system for other users, also install it for the calling user.
* @hide
*/
// @SystemApi
public abstract int installExistingPackage(String packageName)
throws NameNotFoundException;
翻译注释如下: