Merge "pm install-commit supports waiting for staged session to be ready" into rvc-dev am: 810c90c70e am: f84fe6738a am: bcdc84a7d9
Change-Id: I5df1f4bdce853ec6f322ebcff662e78305bfbf71
This commit is contained in:
@@ -263,6 +263,16 @@ public abstract class BasicShellCommandHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns number of arguments that haven't been processed yet.
|
||||||
|
*/
|
||||||
|
public int getRemainingArgsCount() {
|
||||||
|
if (mArgPos >= mArgs.length) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return mArgs.length - mArgPos;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the next argument on the command line, whatever it is; if there are
|
* Return the next argument on the command line, whatever it is; if there are
|
||||||
* no arguments left, throws an IllegalArgumentException to report this to the user.
|
* no arguments left, throws an IllegalArgumentException to report this to the user.
|
||||||
|
|||||||
@@ -1278,12 +1278,32 @@ class PackageManagerShellCommand extends ShellCommand {
|
|||||||
pw.println("Success");
|
pw.println("Success");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
return doWaitForStagedSessionRead(sessionId, params.timeoutMs, pw);
|
||||||
|
} finally {
|
||||||
|
if (abandonSession) {
|
||||||
|
try {
|
||||||
|
doAbandonSession(sessionId, false /*logSuccess*/);
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
long timeoutMs = params.timeoutMs <= 0
|
private int doWaitForStagedSessionRead(int sessionId, long timeoutMs, PrintWriter pw)
|
||||||
? DEFAULT_WAIT_MS
|
throws RemoteException {
|
||||||
: params.timeoutMs;
|
if (timeoutMs <= 0) {
|
||||||
|
timeoutMs = DEFAULT_WAIT_MS;
|
||||||
|
}
|
||||||
PackageInstaller.SessionInfo si = mInterface.getPackageInstaller()
|
PackageInstaller.SessionInfo si = mInterface.getPackageInstaller()
|
||||||
.getSessionInfo(sessionId);
|
.getSessionInfo(sessionId);
|
||||||
|
if (si == null) {
|
||||||
|
pw.println("Failure [Unknown session " + sessionId + "]");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (!si.isStaged()) {
|
||||||
|
pw.println("Failure [Session " + sessionId + " is not a staged session]");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.currentTimeMillis();
|
||||||
long endTime = currentTime + timeoutMs;
|
long endTime = currentTime + timeoutMs;
|
||||||
// Using a loop instead of BroadcastReceiver since we can receive session update
|
// Using a loop instead of BroadcastReceiver since we can receive session update
|
||||||
@@ -1291,8 +1311,7 @@ class PackageManagerShellCommand extends ShellCommand {
|
|||||||
// "android" as packageIntallerName, e.g, rollback auto implies
|
// "android" as packageIntallerName, e.g, rollback auto implies
|
||||||
// "-i com.android.shell".
|
// "-i com.android.shell".
|
||||||
while (currentTime < endTime) {
|
while (currentTime < endTime) {
|
||||||
if (si != null
|
if (si != null && (si.isStagedSessionReady() || si.isStagedSessionFailed())) {
|
||||||
&& (si.isStagedSessionReady() || si.isStagedSessionFailed())) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
SystemClock.sleep(Math.min(endTime - currentTime, 100));
|
SystemClock.sleep(Math.min(endTime - currentTime, 100));
|
||||||
@@ -1314,14 +1333,6 @@ class PackageManagerShellCommand extends ShellCommand {
|
|||||||
}
|
}
|
||||||
pw.println("Success. Reboot device to apply staged session");
|
pw.println("Success. Reboot device to apply staged session");
|
||||||
return 0;
|
return 0;
|
||||||
} finally {
|
|
||||||
if (abandonSession) {
|
|
||||||
try {
|
|
||||||
doAbandonSession(sessionId, false /*logSuccess*/);
|
|
||||||
} catch (Exception ignore) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int runInstallAbandon() throws RemoteException {
|
private int runInstallAbandon() throws RemoteException {
|
||||||
@@ -1330,8 +1341,40 @@ class PackageManagerShellCommand extends ShellCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int runInstallCommit() throws RemoteException {
|
private int runInstallCommit() throws RemoteException {
|
||||||
|
final PrintWriter pw = getOutPrintWriter();
|
||||||
|
String opt;
|
||||||
|
boolean waitForStagedSessionReady = true;
|
||||||
|
long timeoutMs = -1;
|
||||||
|
while ((opt = getNextOption()) != null) {
|
||||||
|
switch (opt) {
|
||||||
|
case "--wait":
|
||||||
|
waitForStagedSessionReady = true;
|
||||||
|
// If there is only one remaining argument, then it represents the sessionId, we
|
||||||
|
// shouldn't try to parse it as timeoutMs.
|
||||||
|
if (getRemainingArgsCount() > 1) {
|
||||||
|
try {
|
||||||
|
timeoutMs = Long.parseLong(peekNextArg());
|
||||||
|
getNextArg();
|
||||||
|
} catch (NumberFormatException ignore) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "--no-wait":
|
||||||
|
waitForStagedSessionReady = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
final int sessionId = Integer.parseInt(getNextArg());
|
final int sessionId = Integer.parseInt(getNextArg());
|
||||||
return doCommitSession(sessionId, true /*logSuccess*/);
|
if (doCommitSession(sessionId, false /*logSuccess*/) != PackageInstaller.STATUS_SUCCESS) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
final PackageInstaller.SessionInfo si = mInterface.getPackageInstaller()
|
||||||
|
.getSessionInfo(sessionId);
|
||||||
|
if (si == null || !si.isStaged() || !waitForStagedSessionReady) {
|
||||||
|
pw.println("Success");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return doWaitForStagedSessionRead(sessionId, timeoutMs, pw);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int runInstallCreate() throws RemoteException {
|
private int runInstallCreate() throws RemoteException {
|
||||||
|
|||||||
Reference in New Issue
Block a user