Merge changes Ia233ca64,I2d0bc216,I94003873 into rvc-dev
* changes: Remove unused code (3/n) Use session id to search for rollbacks (2/n) Include session id when sending broadcasts (1/n)
This commit is contained in:
@@ -845,18 +845,11 @@ public abstract class PackageManagerInternal {
|
|||||||
"android.content.pm.extra.ENABLE_ROLLBACK_TOKEN";
|
"android.content.pm.extra.ENABLE_ROLLBACK_TOKEN";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extra field name for the installFlags of a request to enable rollback
|
* Extra field name for the session id of a request to enable rollback
|
||||||
* for a package.
|
* for a package.
|
||||||
*/
|
*/
|
||||||
public static final String EXTRA_ENABLE_ROLLBACK_INSTALL_FLAGS =
|
public static final String EXTRA_ENABLE_ROLLBACK_SESSION_ID =
|
||||||
"android.content.pm.extra.ENABLE_ROLLBACK_INSTALL_FLAGS";
|
"android.content.pm.extra.ENABLE_ROLLBACK_SESSION_ID";
|
||||||
|
|
||||||
/**
|
|
||||||
* Extra field name for the user id an install is associated with when
|
|
||||||
* enabling rollback.
|
|
||||||
*/
|
|
||||||
public static final String EXTRA_ENABLE_ROLLBACK_USER =
|
|
||||||
"android.content.pm.extra.ENABLE_ROLLBACK_USER";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used as the {@code enableRollbackCode} argument for
|
* Used as the {@code enableRollbackCode} argument for
|
||||||
|
|||||||
@@ -1689,8 +1689,8 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mRelinquished = true;
|
mRelinquished = true;
|
||||||
return new PackageManagerService.ActiveInstallSession(mPackageName, stageDir,
|
return new PackageManagerService.ActiveInstallSession(mPackageName, stageDir, localObserver,
|
||||||
localObserver, params, mInstallerUid, mInstallSource, user, mSigningDetails);
|
sessionId, params, mInstallerUid, mInstallSource, user, mSigningDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void maybeRenameFile(File from, File to) throws PackageManagerException {
|
private static void maybeRenameFile(File from, File to) throws PackageManagerException {
|
||||||
|
|||||||
@@ -1967,6 +1967,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
}
|
}
|
||||||
case ENABLE_ROLLBACK_TIMEOUT: {
|
case ENABLE_ROLLBACK_TIMEOUT: {
|
||||||
final int enableRollbackToken = msg.arg1;
|
final int enableRollbackToken = msg.arg1;
|
||||||
|
final int sessionId = msg.arg2;
|
||||||
final InstallParams params = mPendingEnableRollback.get(enableRollbackToken);
|
final InstallParams params = mPendingEnableRollback.get(enableRollbackToken);
|
||||||
if (params != null) {
|
if (params != null) {
|
||||||
final InstallArgs args = params.mArgs;
|
final InstallArgs args = params.mArgs;
|
||||||
@@ -1982,8 +1983,8 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
Intent rollbackTimeoutIntent = new Intent(
|
Intent rollbackTimeoutIntent = new Intent(
|
||||||
Intent.ACTION_CANCEL_ENABLE_ROLLBACK);
|
Intent.ACTION_CANCEL_ENABLE_ROLLBACK);
|
||||||
rollbackTimeoutIntent.putExtra(
|
rollbackTimeoutIntent.putExtra(
|
||||||
PackageManagerInternal.EXTRA_ENABLE_ROLLBACK_TOKEN,
|
PackageManagerInternal.EXTRA_ENABLE_ROLLBACK_SESSION_ID,
|
||||||
enableRollbackToken);
|
sessionId);
|
||||||
rollbackTimeoutIntent.addFlags(
|
rollbackTimeoutIntent.addFlags(
|
||||||
Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
|
Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
|
||||||
mContext.sendBroadcastAsUser(rollbackTimeoutIntent, UserHandle.SYSTEM,
|
mContext.sendBroadcastAsUser(rollbackTimeoutIntent, UserHandle.SYSTEM,
|
||||||
@@ -14260,6 +14261,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
final long requiredInstalledVersionCode;
|
final long requiredInstalledVersionCode;
|
||||||
final boolean forceQueryableOverride;
|
final boolean forceQueryableOverride;
|
||||||
final int mDataLoaderType;
|
final int mDataLoaderType;
|
||||||
|
final int mSessionId;
|
||||||
|
|
||||||
InstallParams(OriginInfo origin, MoveInfo move, IPackageInstallObserver2 observer,
|
InstallParams(OriginInfo origin, MoveInfo move, IPackageInstallObserver2 observer,
|
||||||
int installFlags, InstallSource installSource, String volumeUuid,
|
int installFlags, InstallSource installSource, String volumeUuid,
|
||||||
@@ -14283,6 +14285,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
this.requiredInstalledVersionCode = requiredInstalledVersionCode;
|
this.requiredInstalledVersionCode = requiredInstalledVersionCode;
|
||||||
this.forceQueryableOverride = false;
|
this.forceQueryableOverride = false;
|
||||||
this.mDataLoaderType = dataLoaderType;
|
this.mDataLoaderType = dataLoaderType;
|
||||||
|
this.mSessionId = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
InstallParams(ActiveInstallSession activeInstallSession) {
|
InstallParams(ActiveInstallSession activeInstallSession) {
|
||||||
@@ -14318,6 +14321,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
forceQueryableOverride = sessionParams.forceQueryableOverride;
|
forceQueryableOverride = sessionParams.forceQueryableOverride;
|
||||||
mDataLoaderType = (sessionParams.dataLoaderParams != null)
|
mDataLoaderType = (sessionParams.dataLoaderParams != null)
|
||||||
? sessionParams.dataLoaderParams.getType() : DataLoaderType.NONE;
|
? sessionParams.dataLoaderParams.getType() : DataLoaderType.NONE;
|
||||||
|
mSessionId = activeInstallSession.getSessionId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -14549,13 +14553,9 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
PackageManagerInternal.EXTRA_ENABLE_ROLLBACK_TOKEN,
|
PackageManagerInternal.EXTRA_ENABLE_ROLLBACK_TOKEN,
|
||||||
enableRollbackToken);
|
enableRollbackToken);
|
||||||
enableRollbackIntent.putExtra(
|
enableRollbackIntent.putExtra(
|
||||||
PackageManagerInternal.EXTRA_ENABLE_ROLLBACK_INSTALL_FLAGS,
|
PackageManagerInternal.EXTRA_ENABLE_ROLLBACK_SESSION_ID,
|
||||||
installFlags);
|
mSessionId);
|
||||||
enableRollbackIntent.putExtra(
|
enableRollbackIntent.setType(PACKAGE_MIME_TYPE);
|
||||||
PackageManagerInternal.EXTRA_ENABLE_ROLLBACK_USER,
|
|
||||||
getRollbackUser().getIdentifier());
|
|
||||||
enableRollbackIntent.setDataAndType(Uri.fromFile(new File(origin.resolvedPath)),
|
|
||||||
PACKAGE_MIME_TYPE);
|
|
||||||
enableRollbackIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
enableRollbackIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
|
|
||||||
// Allow the broadcast to be sent before boot complete.
|
// Allow the broadcast to be sent before boot complete.
|
||||||
@@ -14581,6 +14581,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
final Message msg = mHandler.obtainMessage(
|
final Message msg = mHandler.obtainMessage(
|
||||||
ENABLE_ROLLBACK_TIMEOUT);
|
ENABLE_ROLLBACK_TIMEOUT);
|
||||||
msg.arg1 = enableRollbackToken;
|
msg.arg1 = enableRollbackToken;
|
||||||
|
msg.arg2 = mSessionId;
|
||||||
mHandler.sendMessageDelayed(msg, rollbackTimeout);
|
mHandler.sendMessageDelayed(msg, rollbackTimeout);
|
||||||
}
|
}
|
||||||
}, null, 0, null, null);
|
}, null, 0, null, null);
|
||||||
@@ -24590,6 +24591,7 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
private final String mPackageName;
|
private final String mPackageName;
|
||||||
private final File mStagedDir;
|
private final File mStagedDir;
|
||||||
private final IPackageInstallObserver2 mObserver;
|
private final IPackageInstallObserver2 mObserver;
|
||||||
|
private final int mSessionId;
|
||||||
private final PackageInstaller.SessionParams mSessionParams;
|
private final PackageInstaller.SessionParams mSessionParams;
|
||||||
private final int mInstallerUid;
|
private final int mInstallerUid;
|
||||||
@NonNull private final InstallSource mInstallSource;
|
@NonNull private final InstallSource mInstallSource;
|
||||||
@@ -24597,11 +24599,12 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
private final SigningDetails mSigningDetails;
|
private final SigningDetails mSigningDetails;
|
||||||
|
|
||||||
ActiveInstallSession(String packageName, File stagedDir, IPackageInstallObserver2 observer,
|
ActiveInstallSession(String packageName, File stagedDir, IPackageInstallObserver2 observer,
|
||||||
PackageInstaller.SessionParams sessionParams, int installerUid,
|
int sessionId, PackageInstaller.SessionParams sessionParams, int installerUid,
|
||||||
InstallSource installSource, UserHandle user, SigningDetails signingDetails) {
|
InstallSource installSource, UserHandle user, SigningDetails signingDetails) {
|
||||||
mPackageName = packageName;
|
mPackageName = packageName;
|
||||||
mStagedDir = stagedDir;
|
mStagedDir = stagedDir;
|
||||||
mObserver = observer;
|
mObserver = observer;
|
||||||
|
mSessionId = sessionId;
|
||||||
mSessionParams = sessionParams;
|
mSessionParams = sessionParams;
|
||||||
mInstallerUid = installerUid;
|
mInstallerUid = installerUid;
|
||||||
mInstallSource = Preconditions.checkNotNull(installSource);
|
mInstallSource = Preconditions.checkNotNull(installSource);
|
||||||
@@ -24621,6 +24624,10 @@ public class PackageManagerService extends IPackageManager.Stub
|
|||||||
return mObserver;
|
return mObserver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getSessionId() {
|
||||||
|
return mSessionId;
|
||||||
|
}
|
||||||
|
|
||||||
public PackageInstaller.SessionParams getSessionParams() {
|
public PackageInstaller.SessionParams getSessionParams() {
|
||||||
return mSessionParams;
|
return mSessionParams;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,13 +158,6 @@ class Rollback {
|
|||||||
*/
|
*/
|
||||||
@Nullable public final String mInstallerPackageName;
|
@Nullable public final String mInstallerPackageName;
|
||||||
|
|
||||||
/**
|
|
||||||
* This array holds all of the rollback tokens associated with package sessions included in
|
|
||||||
* this rollback.
|
|
||||||
*/
|
|
||||||
@GuardedBy("mLock")
|
|
||||||
private final IntArray mTokens = new IntArray();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Session ids for all packages in the install. For multi-package sessions, this is the list
|
* Session ids for all packages in the install. For multi-package sessions, this is the list
|
||||||
* of child session ids. For normal sessions, this list is a single element with the normal
|
* of child session ids. For normal sessions, this list is a single element with the normal
|
||||||
@@ -768,26 +761,6 @@ class Rollback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a rollback token to be associated with this rollback. This may be used to
|
|
||||||
* identify which rollback should be removed in case {@link PackageManager} sends an
|
|
||||||
* {@link Intent#ACTION_CANCEL_ENABLE_ROLLBACK} intent.
|
|
||||||
*/
|
|
||||||
void addToken(int token) {
|
|
||||||
synchronized (mLock) {
|
|
||||||
mTokens.add(token);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if this rollback is associated with the provided {@code token}.
|
|
||||||
*/
|
|
||||||
boolean hasToken(int token) {
|
|
||||||
synchronized (mLock) {
|
|
||||||
return mTokens.indexOf(token) != -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if this rollback contains the provided {@code packageSessionId}.
|
* Returns true if this rollback contains the provided {@code packageSessionId}.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import android.Manifest;
|
|||||||
import android.annotation.AnyThread;
|
import android.annotation.AnyThread;
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.annotation.UserIdInt;
|
|
||||||
import android.annotation.WorkerThread;
|
import android.annotation.WorkerThread;
|
||||||
import android.app.AppOpsManager;
|
import android.app.AppOpsManager;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
@@ -201,18 +200,13 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
|
|||||||
if (Intent.ACTION_PACKAGE_ENABLE_ROLLBACK.equals(intent.getAction())) {
|
if (Intent.ACTION_PACKAGE_ENABLE_ROLLBACK.equals(intent.getAction())) {
|
||||||
int token = intent.getIntExtra(
|
int token = intent.getIntExtra(
|
||||||
PackageManagerInternal.EXTRA_ENABLE_ROLLBACK_TOKEN, -1);
|
PackageManagerInternal.EXTRA_ENABLE_ROLLBACK_TOKEN, -1);
|
||||||
int installFlags = intent.getIntExtra(
|
int sessionId = intent.getIntExtra(
|
||||||
PackageManagerInternal.EXTRA_ENABLE_ROLLBACK_INSTALL_FLAGS, 0);
|
PackageManagerInternal.EXTRA_ENABLE_ROLLBACK_SESSION_ID, -1);
|
||||||
int user = intent.getIntExtra(
|
|
||||||
PackageManagerInternal.EXTRA_ENABLE_ROLLBACK_USER, 0);
|
|
||||||
|
|
||||||
File newPackageCodePath = new File(intent.getData().getPath());
|
|
||||||
|
|
||||||
queueSleepIfNeeded();
|
queueSleepIfNeeded();
|
||||||
|
|
||||||
getHandler().post(() -> {
|
getHandler().post(() -> {
|
||||||
boolean success =
|
boolean success = enableRollback(sessionId);
|
||||||
enableRollback(installFlags, newPackageCodePath, user, token);
|
|
||||||
int ret = PackageManagerInternal.ENABLE_ROLLBACK_SUCCEEDED;
|
int ret = PackageManagerInternal.ENABLE_ROLLBACK_SUCCEEDED;
|
||||||
if (!success) {
|
if (!success) {
|
||||||
ret = PackageManagerInternal.ENABLE_ROLLBACK_FAILED;
|
ret = PackageManagerInternal.ENABLE_ROLLBACK_FAILED;
|
||||||
@@ -238,19 +232,16 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (Intent.ACTION_CANCEL_ENABLE_ROLLBACK.equals(intent.getAction())) {
|
if (Intent.ACTION_CANCEL_ENABLE_ROLLBACK.equals(intent.getAction())) {
|
||||||
int token = intent.getIntExtra(
|
int sessionId = intent.getIntExtra(
|
||||||
PackageManagerInternal.EXTRA_ENABLE_ROLLBACK_TOKEN, -1);
|
PackageManagerInternal.EXTRA_ENABLE_ROLLBACK_SESSION_ID, -1);
|
||||||
if (LOCAL_LOGV) {
|
if (LOCAL_LOGV) {
|
||||||
Slog.v(TAG, "broadcast=ACTION_CANCEL_ENABLE_ROLLBACK token=" + token);
|
Slog.v(TAG, "broadcast=ACTION_CANCEL_ENABLE_ROLLBACK id=" + sessionId);
|
||||||
}
|
}
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
for (int i = 0; i < mRollbacks.size(); ++i) {
|
Rollback rollback = getRollbackForSessionLocked(sessionId);
|
||||||
Rollback rollback = mRollbacks.get(i);
|
if (rollback != null && rollback.isEnabling()) {
|
||||||
if (rollback.hasToken(token) && rollback.isEnabling()) {
|
mRollbacks.remove(rollback);
|
||||||
mRollbacks.remove(i);
|
rollback.delete(mAppDataRollbackHelper);
|
||||||
rollback.delete(mAppDataRollbackHelper);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -684,24 +675,6 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
|
|||||||
return mHandlerThread.getThreadHandler();
|
return mHandlerThread.getThreadHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if <code>session</code> has installFlags and code path
|
|
||||||
// matching the installFlags and new package code path given to
|
|
||||||
// enableRollback.
|
|
||||||
@WorkerThread
|
|
||||||
private boolean sessionMatchesForEnableRollback(PackageInstaller.SessionInfo session,
|
|
||||||
int installFlags, File newPackageCodePath) {
|
|
||||||
if (session == null || session.resolvedBaseCodePath == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
File packageCodePath = new File(session.resolvedBaseCodePath).getParentFile();
|
|
||||||
if (newPackageCodePath.equals(packageCodePath) && installFlags == session.installFlags) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@AnyThread
|
@AnyThread
|
||||||
private Context getContextAsUser(UserHandle user) {
|
private Context getContextAsUser(UserHandle user) {
|
||||||
try {
|
try {
|
||||||
@@ -716,58 +689,26 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
|
|||||||
* staged for install with rollback enabled. Called before the package has
|
* staged for install with rollback enabled. Called before the package has
|
||||||
* been installed.
|
* been installed.
|
||||||
*
|
*
|
||||||
* @param installFlags information about what is being installed.
|
* @param sessionId the id of the install session
|
||||||
* @param newPackageCodePath path to the package about to be installed.
|
|
||||||
* @param user the user that owns the install session to enable rollback on.
|
|
||||||
* @param token the distinct rollback token sent by package manager.
|
|
||||||
* @return true if enabling the rollback succeeds, false otherwise.
|
* @return true if enabling the rollback succeeds, false otherwise.
|
||||||
*/
|
*/
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
private boolean enableRollback(
|
private boolean enableRollback(int sessionId) {
|
||||||
int installFlags, File newPackageCodePath, @UserIdInt int user, int token) {
|
|
||||||
if (LOCAL_LOGV) {
|
if (LOCAL_LOGV) {
|
||||||
Slog.v(TAG, "enableRollback user=" + user + " token=" + token
|
Slog.v(TAG, "enableRollback sessionId=" + sessionId);
|
||||||
+ " path=" + newPackageCodePath.getAbsolutePath());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the session id associated with this install.
|
PackageInstaller installer = mContext.getPackageManager().getPackageInstaller();
|
||||||
// TODO: It would be nice if package manager or package installer told
|
PackageInstaller.SessionInfo packageSession = installer.getSessionInfo(sessionId);
|
||||||
// us the session directly, rather than have to search for it
|
if (packageSession == null) {
|
||||||
// ourselves.
|
Slog.e(TAG, "Unable to find session for enabled rollback.");
|
||||||
|
|
||||||
// getAllSessions only returns sessions for the associated user.
|
|
||||||
// Create a context with the right user so we can find the matching
|
|
||||||
// session.
|
|
||||||
final Context context = getContextAsUser(UserHandle.of(user));
|
|
||||||
if (context == null) {
|
|
||||||
Slog.e(TAG, "Unable to create context for install session user.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PackageInstaller.SessionInfo parentSession = null;
|
PackageInstaller.SessionInfo parentSession = packageSession.hasParentSessionId()
|
||||||
PackageInstaller.SessionInfo packageSession = null;
|
? installer.getSessionInfo(packageSession.getParentSessionId()) : packageSession;
|
||||||
PackageInstaller installer = context.getPackageManager().getPackageInstaller();
|
if (parentSession == null) {
|
||||||
for (PackageInstaller.SessionInfo info : installer.getAllSessions()) {
|
Slog.e(TAG, "Unable to find parent session for enabled rollback.");
|
||||||
if (info.isMultiPackage()) {
|
|
||||||
for (int childId : info.getChildSessionIds()) {
|
|
||||||
PackageInstaller.SessionInfo child = installer.getSessionInfo(childId);
|
|
||||||
if (sessionMatchesForEnableRollback(child, installFlags, newPackageCodePath)) {
|
|
||||||
// TODO: Check we only have one matching session?
|
|
||||||
parentSession = info;
|
|
||||||
packageSession = child;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (sessionMatchesForEnableRollback(info, installFlags, newPackageCodePath)) {
|
|
||||||
// TODO: Check we only have one matching session?
|
|
||||||
parentSession = info;
|
|
||||||
packageSession = info;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parentSession == null || packageSession == null) {
|
|
||||||
Slog.e(TAG, "Unable to find session for enabled rollback.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -804,7 +745,6 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
|
|||||||
newRollback = createNewRollbackLocked(parentSession);
|
newRollback = createNewRollbackLocked(parentSession);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newRollback.addToken(token);
|
|
||||||
|
|
||||||
return enableRollbackForPackageSession(newRollback, packageSession);
|
return enableRollbackForPackageSession(newRollback, packageSession);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user