Use allocatable space when measuring for install.

The system is often willing to clear cached data to make room for
incoming installs, so use StorageManager.getAllocatableBytes() when
making "does it fit?" style decisions.

Add new INSTALL_ALLOCATE_AGGRESSIVE flag, which will flow through
to use StorageManager.FLAG_ALLOCATE_AGGRESSIVE when making allocation
related requests.  (This can be used by installers to indicate
packages that are critical to system health or security.

Test: runtest -x frameworks/base/core/tests/coretests/src/android/content/pm/PackageHelperTests.java
Bug: 36131437
Change-Id: If8118762fd1ca1f497d2cdd1787bdb3c9759dcc0
This commit is contained in:
Jeff Sharkey
2017-03-18 17:54:51 -06:00
parent cf2c279a23
commit 683bcd30ef
7 changed files with 135 additions and 76 deletions

View File

@@ -1152,6 +1152,16 @@ public class PackageInstaller {
this.installReason = installReason;
}
/** {@hide} */
@SystemApi
public void setAllocateAggressive(boolean allocateAggressive) {
if (allocateAggressive) {
installFlags |= PackageManager.INSTALL_ALLOCATE_AGGRESSIVE;
} else {
installFlags &= ~PackageManager.INSTALL_ALLOCATE_AGGRESSIVE;
}
}
/** {@hide} */
public void dump(IndentingPrintWriter pw) {
pw.printPair("mode", mode);

View File

@@ -51,6 +51,7 @@ import android.os.Handler;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.util.AndroidException;
import android.util.Log;
@@ -610,6 +611,9 @@ public abstract class PackageManager {
INSTALL_FORCE_PERMISSION_PROMPT,
INSTALL_INSTANT_APP,
INSTALL_DONT_KILL_APP,
INSTALL_FORCE_SDK,
INSTALL_FULL_APP,
INSTALL_ALLOCATE_AGGRESSIVE,
})
@Retention(RetentionPolicy.SOURCE)
public @interface InstallFlags {}
@@ -716,15 +720,6 @@ public abstract class PackageManager {
*/
public static final int INSTALL_INSTANT_APP = 0x00000800;
/**
* Flag parameter for {@link #installPackage} to indicate that this package is
* to be installed as a heavy weight app. This is fundamentally the opposite of
* {@link #INSTALL_INSTANT_APP}.
*
* @hide
*/
public static final int INSTALL_FULL_APP = 0x00004000;
/**
* Flag parameter for {@link #installPackage} to indicate that this package contains
* a feature split to an existing application and the existing application should not
@@ -742,6 +737,24 @@ public abstract class PackageManager {
*/
public static final int INSTALL_FORCE_SDK = 0x00002000;
/**
* Flag parameter for {@link #installPackage} to indicate that this package is
* to be installed as a heavy weight app. This is fundamentally the opposite of
* {@link #INSTALL_INSTANT_APP}.
*
* @hide
*/
public static final int INSTALL_FULL_APP = 0x00004000;
/**
* Flag parameter for {@link #installPackage} to indicate that this package
* is critical to system health or security, meaning the system should use
* {@link StorageManager#FLAG_ALLOCATE_AGGRESSIVE} internally.
*
* @hide
*/
public static final int INSTALL_ALLOCATE_AGGRESSIVE = 0x00008000;
/**
* Flag parameter for
* {@link #setComponentEnabledSetting(android.content.ComponentName, int, int)} to indicate