Loading core/java/android/os/BasicShellCommandHandler.java +10 −0 Original line number Diff line number Diff line Loading @@ -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 * no arguments left, throws an IllegalArgumentException to report this to the user. Loading services/core/java/com/android/server/pm/PackageManagerShellCommand.java +80 −37 Original line number Diff line number Diff line Loading @@ -1278,12 +1278,32 @@ class PackageManagerShellCommand extends ShellCommand { pw.println("Success"); return 0; } return doWaitForStagedSessionRead(sessionId, params.timeoutMs, pw); } finally { if (abandonSession) { try { doAbandonSession(sessionId, false /*logSuccess*/); } catch (Exception ignore) { } } } } long timeoutMs = params.timeoutMs <= 0 ? DEFAULT_WAIT_MS : params.timeoutMs; private int doWaitForStagedSessionRead(int sessionId, long timeoutMs, PrintWriter pw) throws RemoteException { if (timeoutMs <= 0) { timeoutMs = DEFAULT_WAIT_MS; } PackageInstaller.SessionInfo si = mInterface.getPackageInstaller() .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 endTime = currentTime + timeoutMs; // Using a loop instead of BroadcastReceiver since we can receive session update Loading @@ -1291,8 +1311,7 @@ class PackageManagerShellCommand extends ShellCommand { // "android" as packageIntallerName, e.g, rollback auto implies // "-i com.android.shell". while (currentTime < endTime) { if (si != null && (si.isStagedSessionReady() || si.isStagedSessionFailed())) { if (si != null && (si.isStagedSessionReady() || si.isStagedSessionFailed())) { break; } SystemClock.sleep(Math.min(endTime - currentTime, 100)); Loading @@ -1314,14 +1333,6 @@ class PackageManagerShellCommand extends ShellCommand { } pw.println("Success. Reboot device to apply staged session"); return 0; } finally { if (abandonSession) { try { doAbandonSession(sessionId, false /*logSuccess*/); } catch (Exception ignore) { } } } } private int runInstallAbandon() throws RemoteException { Loading @@ -1330,8 +1341,40 @@ class PackageManagerShellCommand extends ShellCommand { } 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()); 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 { Loading Loading
core/java/android/os/BasicShellCommandHandler.java +10 −0 Original line number Diff line number Diff line Loading @@ -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 * no arguments left, throws an IllegalArgumentException to report this to the user. Loading
services/core/java/com/android/server/pm/PackageManagerShellCommand.java +80 −37 Original line number Diff line number Diff line Loading @@ -1278,12 +1278,32 @@ class PackageManagerShellCommand extends ShellCommand { pw.println("Success"); return 0; } return doWaitForStagedSessionRead(sessionId, params.timeoutMs, pw); } finally { if (abandonSession) { try { doAbandonSession(sessionId, false /*logSuccess*/); } catch (Exception ignore) { } } } } long timeoutMs = params.timeoutMs <= 0 ? DEFAULT_WAIT_MS : params.timeoutMs; private int doWaitForStagedSessionRead(int sessionId, long timeoutMs, PrintWriter pw) throws RemoteException { if (timeoutMs <= 0) { timeoutMs = DEFAULT_WAIT_MS; } PackageInstaller.SessionInfo si = mInterface.getPackageInstaller() .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 endTime = currentTime + timeoutMs; // Using a loop instead of BroadcastReceiver since we can receive session update Loading @@ -1291,8 +1311,7 @@ class PackageManagerShellCommand extends ShellCommand { // "android" as packageIntallerName, e.g, rollback auto implies // "-i com.android.shell". while (currentTime < endTime) { if (si != null && (si.isStagedSessionReady() || si.isStagedSessionFailed())) { if (si != null && (si.isStagedSessionReady() || si.isStagedSessionFailed())) { break; } SystemClock.sleep(Math.min(endTime - currentTime, 100)); Loading @@ -1314,14 +1333,6 @@ class PackageManagerShellCommand extends ShellCommand { } pw.println("Success. Reboot device to apply staged session"); return 0; } finally { if (abandonSession) { try { doAbandonSession(sessionId, false /*logSuccess*/); } catch (Exception ignore) { } } } } private int runInstallAbandon() throws RemoteException { Loading @@ -1330,8 +1341,40 @@ class PackageManagerShellCommand extends ShellCommand { } 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()); 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 { Loading