Implement issue #1783881 (manifest option for adb-install-only apps)
You can now use android:testOnly="true" to not allow your .apk to be installed as a normal app. The only way to do so is with the pm command and giving the -t option, which sets a new INSTALL_ALLOW_TEST flag when installing. I also used this to clean up the install API... actually, mostly to hide it, since it is not accessible to apps so shouldn't be in the SDK. We will be doing some more work on it, so this will prevent adding yet another backwards-compatibility-for-no-reason version.
This commit is contained in:
@@ -3396,7 +3396,7 @@ class PackageManagerService extends IPackageManager.Stub {
|
||||
oldInstallerPackageName = mSettings.getInstallerPackageName(pkgName);
|
||||
}
|
||||
|
||||
int parseFlags = PackageManager.REPLACE_EXISTING_PACKAGE;
|
||||
int parseFlags = PackageManager.INSTALL_REPLACE_EXISTING;
|
||||
// First delete the existing package while retaining the data directory
|
||||
if (!deletePackageLI(pkgName, false, PackageManager.DONT_DELETE_DATA,
|
||||
res.removedInfo)) {
|
||||
@@ -3468,7 +3468,7 @@ class PackageManagerService extends IPackageManager.Stub {
|
||||
installPackageLI(
|
||||
Uri.fromFile(new File(deletedPackage.mPath)),
|
||||
isForwardLocked(deletedPackage)
|
||||
? PackageManager.FORWARD_LOCK_PACKAGE
|
||||
? PackageManager.INSTALL_FORWARD_LOCK
|
||||
: 0, false, oldInstallerPackageName);
|
||||
}
|
||||
}
|
||||
@@ -3481,7 +3481,7 @@ class PackageManagerService extends IPackageManager.Stub {
|
||||
String installerPackageName, PackageInstalledInfo res) {
|
||||
PackageParser.Package newPackage = null;
|
||||
boolean updatedSettings = false;
|
||||
int parseFlags = PackageManager.REPLACE_EXISTING_PACKAGE |
|
||||
int parseFlags = PackageManager.INSTALL_REPLACE_EXISTING |
|
||||
PackageParser.PARSE_IS_SYSTEM;
|
||||
String packageName = deletedPackage.packageName;
|
||||
res.returnCode = PackageManager.INSTALL_FAILED_REPLACE_COULDNT_DELETE;
|
||||
@@ -3697,13 +3697,13 @@ class PackageManagerService extends IPackageManager.Stub {
|
||||
res.name = pkgName;
|
||||
//initialize some variables before installing pkg
|
||||
final String pkgFileName = pkgName + ".apk";
|
||||
final File destDir = ((pFlags&PackageManager.FORWARD_LOCK_PACKAGE) != 0)
|
||||
final File destDir = ((pFlags&PackageManager.INSTALL_FORWARD_LOCK) != 0)
|
||||
? mDrmAppPrivateInstallDir
|
||||
: mAppInstallDir;
|
||||
final File destPackageFile = new File(destDir, pkgFileName);
|
||||
final String destFilePath = destPackageFile.getAbsolutePath();
|
||||
File destResourceFile;
|
||||
if ((pFlags&PackageManager.FORWARD_LOCK_PACKAGE) != 0) {
|
||||
if ((pFlags&PackageManager.INSTALL_FORWARD_LOCK) != 0) {
|
||||
final String publicZipFileName = pkgName + ".zip";
|
||||
destResourceFile = new File(mAppInstallDir, publicZipFileName);
|
||||
forwardLocked = true;
|
||||
@@ -3722,6 +3722,12 @@ class PackageManagerService extends IPackageManager.Stub {
|
||||
res.returnCode = pp.getParseError();
|
||||
break main_flow;
|
||||
}
|
||||
if ((pkg.applicationInfo.flags&ApplicationInfo.FLAG_TEST_ONLY) != 0) {
|
||||
if ((pFlags&PackageManager.INSTALL_ALLOW_TEST) == 0) {
|
||||
res.returnCode = PackageManager.INSTALL_FAILED_TEST_ONLY;
|
||||
break main_flow;
|
||||
}
|
||||
}
|
||||
if (GET_CERTIFICATES && !pp.collectCertificates(pkg, parseFlags)) {
|
||||
res.returnCode = pp.getParseError();
|
||||
break main_flow;
|
||||
@@ -3729,7 +3735,7 @@ class PackageManagerService extends IPackageManager.Stub {
|
||||
|
||||
synchronized (mPackages) {
|
||||
//check if installing already existing package
|
||||
if ((pFlags&PackageManager.REPLACE_EXISTING_PACKAGE) != 0
|
||||
if ((pFlags&PackageManager.INSTALL_REPLACE_EXISTING) != 0
|
||||
&& mPackages.containsKey(pkgName)) {
|
||||
replacingExistingPackage = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user