summaryrefslogtreecommitdiffstats
path: root/services/java/com/android/server/PackageManagerService.java
diff options
context:
space:
mode:
authorSuchi Amalapurapu <asuchitra@google.com>2010-02-12 09:43:29 -0800
committerSuchi Amalapurapu <asuchitra@google.com>2010-02-12 18:50:47 -0800
commit5b993ce7bc29e43a3215a50ce6ce5d6550d4e5e2 (patch)
treefc25f9f6adee005c287454a74837f6cbc1a072a0 /services/java/com/android/server/PackageManagerService.java
parent70251b1704b9bb81443e7533d365400645dd5eaa (diff)
downloadframeworks_base-5b993ce7bc29e43a3215a50ce6ce5d6550d4e5e2.zip
frameworks_base-5b993ce7bc29e43a3215a50ce6ce5d6550d4e5e2.tar.gz
frameworks_base-5b993ce7bc29e43a3215a50ce6ce5d6550d4e5e2.tar.bz2
Include install location preference when installing packages.
Changes include Add new remote call in default container service to determine install location. Rename INSTALL_ON_SDCARD Remove recommentAppInstall method Add some additional flags used in remote stubs. Move check for protected apps prior to copy. Unit tests DefaultContainerService first parses the file uri(if content uri is specified it returns a default install internal only value) and returns a recommended location. Based on which the temporary id is determined either a file name or a container id and the file is copied there. This is then later renamed during install. Todo's light weight parsing of package when determining location since we just need the install location attribute only when finding out recomended location. This will also enable to move the check for updated system apps(cannot be on sdcard) prior to copying.
Diffstat (limited to 'services/java/com/android/server/PackageManagerService.java')
-rw-r--r--services/java/com/android/server/PackageManagerService.java168
1 files changed, 107 insertions, 61 deletions
diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java
index a5213a0..812ff64 100644
--- a/services/java/com/android/server/PackageManagerService.java
+++ b/services/java/com/android/server/PackageManagerService.java
@@ -20,6 +20,7 @@ import com.android.internal.app.IMediaContainerService;
import com.android.internal.app.ResolverActivity;
import com.android.common.FastXmlSerializer;
import com.android.common.XmlUtils;
+import com.android.internal.content.PackageHelper;
import com.android.server.JournaledFile;
import org.xmlpull.v1.XmlPullParser;
@@ -304,6 +305,7 @@ class PackageManagerService extends IPackageManager.Stub {
static final int INIT_COPY = 5;
static final int MCS_UNBIND = 6;
static final int START_CLEANING_PACKAGE = 7;
+ static final int FIND_INSTALL_LOC = 8;
// Delay time in millisecs
static final int BROADCAST_DELAY = 10 * 1000;
private ServiceConnection mDefContainerConn = new ServiceConnection() {
@@ -319,8 +321,8 @@ class PackageManagerService extends IPackageManager.Stub {
};
class PackageHandler extends Handler {
- final ArrayList<InstallArgs> mPendingInstalls =
- new ArrayList<InstallArgs>();
+ final ArrayList<InstallParams> mPendingInstalls =
+ new ArrayList<InstallParams>();
// Service Connection to remote media container service to copy
// package uri's from external media onto secure containers
// or internal storage.
@@ -332,21 +334,20 @@ class PackageManagerService extends IPackageManager.Stub {
public void handleMessage(Message msg) {
switch (msg.what) {
case INIT_COPY: {
- InstallArgs args = (InstallArgs) msg.obj;
- args.createCopyFile();
+ InstallParams params = (InstallParams) msg.obj;
Intent service = new Intent().setComponent(DEFAULT_CONTAINER_COMPONENT);
if (mContainerService != null) {
// No need to add to pending list. Use remote stub directly
- handleStartCopy(args);
+ handleStartCopy(params);
} else {
if (mContext.bindService(service, mDefContainerConn,
Context.BIND_AUTO_CREATE)) {
- mPendingInstalls.add(args);
+ mPendingInstalls.add(params);
} else {
Log.e(TAG, "Failed to bind to media container service");
// Indicate install failure TODO add new error code
- processPendingInstall(args,
- PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE);
+ processPendingInstall(createInstallArgs(params),
+ PackageManager.INSTALL_FAILED_INTERNAL_ERROR);
}
}
break;
@@ -357,9 +358,9 @@ class PackageManagerService extends IPackageManager.Stub {
mContainerService = (IMediaContainerService) msg.obj;
}
if (mPendingInstalls.size() > 0) {
- InstallArgs args = mPendingInstalls.remove(0);
- if (args != null) {
- handleStartCopy(args);
+ InstallParams params = mPendingInstalls.remove(0);
+ if (params != null) {
+ handleStartCopy(params);
}
}
break;
@@ -423,22 +424,56 @@ class PackageManagerService extends IPackageManager.Stub {
// Utility method to initiate copying apk via media
// container service.
- private void handleStartCopy(InstallArgs args) {
- int ret = PackageManager.INSTALL_SUCCEEDED;
- if (mContainerService == null) {
- // Install error
- ret = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
- } else {
- ret = args.copyApk(mContainerService);
+ private void handleStartCopy(InstallParams params) {
+ int ret = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
+ if (mContainerService != null) {
+ // Remote call to find out default install location
+ int loc = params.getInstallLocation(mContainerService);
+ // Use install location to create InstallArgs and temporary
+ // install location
+ if (loc == PackageHelper.RECOMMEND_FAILED_INSUFFICIENT_STORAGE){
+ ret = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
+ } else if (loc == PackageHelper.RECOMMEND_FAILED_INVALID_APK) {
+ ret = PackageManager.INSTALL_FAILED_INVALID_APK;
+ } else {
+ if ((params.flags & PackageManager.INSTALL_EXTERNAL) == 0){
+ if (loc == PackageHelper.RECOMMEND_INSTALL_EXTERNAL) {
+ // Set the flag to install on external media.
+ params.flags |= PackageManager.INSTALL_EXTERNAL;
+ } else {
+ // Make sure the flag for installing on external
+ // media is unset
+ params.flags &= ~PackageManager.INSTALL_EXTERNAL;
+ }
+ }
+ // Disable forward locked apps on sdcard.
+ if ((params.flags & PackageManager.INSTALL_FORWARD_LOCK) != 0 &&
+ (params.flags & PackageManager.INSTALL_EXTERNAL) != 0) {
+ // Make sure forward locked apps can only be installed
+ // on internal storage
+ Log.w(TAG, "Cannot install protected apps on sdcard");
+ ret = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION;
+ } else {
+ ret = PackageManager.INSTALL_SUCCEEDED;
+ }
+ }
}
mHandler.sendEmptyMessage(MCS_UNBIND);
+ // Create the file args now.
+ InstallArgs args = createInstallArgs(params);
+ if (ret == PackageManager.INSTALL_SUCCEEDED) {
+ // Create copy only if we are not in an erroneous state.
+ args.createCopyFile();
+ // Remote call to initiate copy
+ ret = args.copyApk(mContainerService);
+ }
processPendingInstall(args, ret);
}
}
static boolean installOnSd(int flags) {
if (((flags & PackageManager.INSTALL_FORWARD_LOCK) != 0) ||
- ((flags & PackageManager.INSTALL_ON_SDCARD) == 0)) {
+ ((flags & PackageManager.INSTALL_EXTERNAL) == 0)) {
return false;
}
return true;
@@ -4249,29 +4284,11 @@ class PackageManagerService extends IPackageManager.Stub {
android.Manifest.permission.INSTALL_PACKAGES, null);
Message msg = mHandler.obtainMessage(INIT_COPY);
- msg.obj = createInstallArgs(packageURI, observer, flags, installerPackageName);
+ msg.obj = new InstallParams(packageURI, observer, flags,
+ installerPackageName);
mHandler.sendMessage(msg);
}
- private InstallArgs createInstallArgs(Uri packageURI, IPackageInstallObserver observer,
- int flags, String installerPackageName) {
- if (installOnSd(flags)) {
- return new SdInstallArgs(packageURI, observer, flags,
- installerPackageName);
- } else {
- return new FileInstallArgs(packageURI, observer, flags,
- installerPackageName);
- }
- }
-
- private InstallArgs createInstallArgs(int flags, String fullCodePath, String fullResourcePath) {
- if (installOnSd(flags)) {
- return new SdInstallArgs(fullCodePath, fullResourcePath);
- } else {
- return new FileInstallArgs(fullCodePath, fullResourcePath);
- }
- }
-
private void processPendingInstall(final InstallArgs args, final int currentStatus) {
// Queue up an async operation since the package installation may take a little while.
mHandler.post(new Runnable() {
@@ -4327,6 +4344,45 @@ class PackageManagerService extends IPackageManager.Stub {
});
}
+ static final class InstallParams {
+ final IPackageInstallObserver observer;
+ int flags;
+ final Uri packageURI;
+ final String installerPackageName;
+ InstallParams(Uri packageURI,
+ IPackageInstallObserver observer, int flags,
+ String installerPackageName) {
+ this.packageURI = packageURI;
+ this.flags = flags;
+ this.observer = observer;
+ this.installerPackageName = installerPackageName;
+ }
+
+ public int getInstallLocation(IMediaContainerService imcs) {
+ try {
+ return imcs.getRecommendedInstallLocation(packageURI);
+ } catch (RemoteException e) {
+ }
+ return -1;
+ }
+ };
+
+ private InstallArgs createInstallArgs(InstallParams params) {
+ if (installOnSd(params.flags)) {
+ return new SdInstallArgs(params);
+ } else {
+ return new FileInstallArgs(params);
+ }
+ }
+
+ private InstallArgs createInstallArgs(int flags, String fullCodePath, String fullResourcePath) {
+ if (installOnSd(flags)) {
+ return new SdInstallArgs(fullCodePath, fullResourcePath);
+ } else {
+ return new FileInstallArgs(fullCodePath, fullResourcePath);
+ }
+ }
+
static abstract class InstallArgs {
final IPackageInstallObserver observer;
final int flags;
@@ -4359,10 +4415,9 @@ class PackageManagerService extends IPackageManager.Stub {
String codeFileName;
String resourceFileName;
- FileInstallArgs(Uri packageURI,
- IPackageInstallObserver observer, int flags,
- String installerPackageName) {
- super(packageURI, observer, flags, installerPackageName);
+ FileInstallArgs(InstallParams params) {
+ super(params.packageURI, params.observer,
+ params.flags, params.installerPackageName);
}
FileInstallArgs(String fullCodePath, String fullResourcePath) {
@@ -4373,6 +4428,10 @@ class PackageManagerService extends IPackageManager.Stub {
resourceFileName = fullResourcePath;
}
+ String getCodePath() {
+ return codeFileName;
+ }
+
void createCopyFile() {
boolean fwdLocked = isFwdLocked(flags);
installDir = fwdLocked ? mDrmAppPrivateInstallDir : mAppInstallDir;
@@ -4380,10 +4439,6 @@ class PackageManagerService extends IPackageManager.Stub {
resourceFileName = getResourcePathFromCodePath();
}
- String getCodePath() {
- return codeFileName;
- }
-
int copyApk(IMediaContainerService imcs) {
// Get a ParcelFileDescriptor to write to the output file
File codeFile = new File(codeFileName);
@@ -4528,10 +4583,9 @@ class PackageManagerService extends IPackageManager.Stub {
String cachePath;
static final String RES_FILE_NAME = "pkg.apk";
- SdInstallArgs(Uri packageURI,
- IPackageInstallObserver observer, int flags,
- String installerPackageName) {
- super(packageURI, observer, flags, installerPackageName);
+ SdInstallArgs(InstallParams params) {
+ super(params.packageURI, params.observer,
+ params.flags, params.installerPackageName);
}
SdInstallArgs(String fullCodePath, String fullResourcePath) {
@@ -5105,7 +5159,7 @@ class PackageManagerService extends IPackageManager.Stub {
String installerPackageName = args.installerPackageName;
File tmpPackageFile = new File(args.getCodePath());
boolean forwardLocked = ((pFlags & PackageManager.INSTALL_FORWARD_LOCK) != 0);
- boolean onSd = ((pFlags & PackageManager.INSTALL_ON_SDCARD) != 0);
+ boolean onSd = ((pFlags & PackageManager.INSTALL_EXTERNAL) != 0);
boolean replace = false;
int scanMode = SCAN_MONITOR | SCAN_FORCE_DEX | SCAN_UPDATE_SIGNATURE
| (newInstall ? SCAN_NEW_INSTALL : 0);
@@ -5136,14 +5190,6 @@ class PackageManagerService extends IPackageManager.Stub {
res.returnCode = pp.getParseError();
return;
}
- // Some preinstall checks
- if (forwardLocked && onSd) {
- // Make sure forward locked apps can only be installed
- // on internal storage
- Log.w(TAG, "Cannot install protected apps on sdcard");
- res.returnCode = PackageManager.INSTALL_FAILED_INVALID_INSTALL_LOCATION;
- return;
- }
// Get rid of all references to package scan path via parser.
pp = null;
String oldCodePath = null;
@@ -5560,7 +5606,7 @@ class PackageManagerService extends IPackageManager.Stub {
if (deleteCodeAndResources) {
// TODO can pick up from PackageSettings as well
int installFlags = ((p.applicationInfo.flags & ApplicationInfo.FLAG_ON_SDCARD)!=0) ?
- PackageManager.INSTALL_ON_SDCARD : 0;
+ PackageManager.INSTALL_EXTERNAL : 0;
installFlags |= ((p.applicationInfo.flags & ApplicationInfo.FLAG_FORWARD_LOCK)!=0) ?
PackageManager.INSTALL_FORWARD_LOCK : 0;
outInfo.args = createInstallArgs(installFlags,