问题
Question: How to write meta information about a package OR Where is the installation intent handled in PackageManagerService
in android source? (Description follows.)
I'm modifying Android source to save some meta information about a package during installation. It can be stored in any location but has to be readable by the system. My first attempt was to use /sdcard
(Android source error reading file from sdcard) But that does not seem to work because of permissions.
Now, I want to be able to send the meta information to the PackageManagerService
so that it can write it before install. If it writes it itself, it should be able to read it later.
I've identified the point in PackageInstallerActivity
, the place where the installation intent is raised:
if(v == mOk) {
// Start subactivity to actually install the application
Intent newIntent = new Intent();
newIntent.putExtra(PackageUtil.INTENT_ATTR_APPLICATION_INFO,
mPkgInfo.applicationInfo);
newIntent.setData(mPackageURI);
newIntent.setClass(this, InstallAppProgress.class);
String installerPackageName = getIntent().getStringExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME);
if (installerPackageName != null) {
newIntent.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME, installerPackageName);
}
if(localLOGV) Log.i(TAG, "downloaded app uri="+mPackageURI);
I can put an "extra" in the intent but I don't know where in the PackageManagerService this intent is handled.
So, the qustion: Where is the installation intent handled in PackageManagerService in android source?
回答1:
As you see, the intent is an explicit intent with a component: InstallAppProgress.class
.
So that intent will be handled first by InstallAppProgress. It is also a component in PackageInstaller. It is responsible for displaying the installation progress(initView() in InstallAppProgress.java). And in the initView() method, it will call PackageManagerService:
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
Intent intent = getIntent();
mAppInfo = intent.getParcelableExtra(PackageUtil.INTENT_ATTR_APPLICATION_INFO);
mPackageURI = intent.getData();
initView();
}
public void initView() {
...
String installerPackageName = getIntent().getStringExtra(
Intent.EXTRA_INSTALLER_PACKAGE_NAME);
PackageInstallObserver observer = new PackageInstallObserver();
pm.installPackage(mPackageURI, observer, installFlags, installerPackageName);
}
So the intent is not handled by PackageManagerService, it is handled by the InstallAppProgress, then it simply call PackageManagerService to install that app.
I used to working on a partial permission granting system on Android. What I did is to add an argument to installPackage method in PMS, so I think you can do it like that, too. PackageManager is an aidl service, so you also need to modify the aidl file too. It is under framework/base/core/java/android/content/pm/
来源:https://stackoverflow.com/questions/15426802/write-meta-information-during-android-package-install