OtaDexoptShellCommand.java revision bf06232f4d440ced8230662a77ca0e8ece6383ca
1/* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.server.pm; 18 19import android.content.pm.IOtaDexopt; 20import android.os.RemoteException; 21import android.os.ShellCommand; 22 23import java.io.PrintWriter; 24 25class OtaDexoptShellCommand extends ShellCommand { 26 final IOtaDexopt mInterface; 27 28 OtaDexoptShellCommand(OtaDexoptService service) { 29 mInterface = service; 30 } 31 32 @Override 33 public int onCommand(String cmd) { 34 if (cmd == null) { 35 return handleDefaultCommands(null); 36 } 37 38 final PrintWriter pw = getOutPrintWriter(); 39 try { 40 switch(cmd) { 41 case "prepare": 42 return runOtaPrepare(); 43 case "cleanup": 44 return runOtaCleanup(); 45 case "done": 46 return runOtaDone(); 47 case "step": 48 return runOtaStep(); 49 case "progress": 50 return runOtaProgress(); 51 default: 52 return handleDefaultCommands(cmd); 53 } 54 } catch (RemoteException e) { 55 pw.println("Remote exception: " + e); 56 } 57 return -1; 58 } 59 60 private int runOtaPrepare() throws RemoteException { 61 mInterface.prepare(); 62 getOutPrintWriter().println("Success"); 63 return 0; 64 } 65 66 private int runOtaCleanup() throws RemoteException { 67 mInterface.cleanup(); 68 return 0; 69 } 70 71 private int runOtaDone() throws RemoteException { 72 final PrintWriter pw = getOutPrintWriter(); 73 if (mInterface.isDone()) { 74 pw.println("OTA complete."); 75 } else { 76 pw.println("OTA incomplete."); 77 } 78 return 0; 79 } 80 81 private int runOtaStep() throws RemoteException { 82 mInterface.dexoptNextPackage(); 83 return 0; 84 } 85 86 private int runOtaProgress() throws RemoteException { 87 final float progress = mInterface.getProgress(); 88 final PrintWriter pw = getOutPrintWriter(); 89 pw.format("%.2f", progress); 90 return 0; 91 } 92 93 @Override 94 public void onHelp() { 95 final PrintWriter pw = getOutPrintWriter(); 96 pw.println("OTA Dexopt (ota) commands:"); 97 pw.println(" help"); 98 pw.println(" Print this help text."); 99 pw.println(""); 100 pw.println(" prepare"); 101 pw.println(" Prepare an OTA dexopt pass, collecting all packages."); 102 pw.println(" done"); 103 pw.println(" Replies whether the OTA is complete or not."); 104 pw.println(" step"); 105 pw.println(" OTA dexopt the next package."); 106 pw.println(" cleanup"); 107 pw.println(" Clean up internal states. Ends an OTA session."); 108 } 109} 110