OtaDexoptShellCommand.java revision dbce0ac3da5f3d56cb01bb710605d12614bf83cd
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; 24import java.util.Locale; 25 26class OtaDexoptShellCommand extends ShellCommand { 27 final IOtaDexopt mInterface; 28 29 OtaDexoptShellCommand(OtaDexoptService service) { 30 mInterface = service; 31 } 32 33 @Override 34 public int onCommand(String cmd) { 35 if (cmd == null) { 36 return handleDefaultCommands(null); 37 } 38 39 final PrintWriter pw = getOutPrintWriter(); 40 try { 41 switch(cmd) { 42 case "prepare": 43 return runOtaPrepare(); 44 case "cleanup": 45 return runOtaCleanup(); 46 case "done": 47 return runOtaDone(); 48 case "step": 49 return runOtaStep(); 50 case "next": 51 return runOtaNext(); 52 case "progress": 53 return runOtaProgress(); 54 default: 55 return handleDefaultCommands(cmd); 56 } 57 } catch (RemoteException e) { 58 pw.println("Remote exception: " + e); 59 } 60 return -1; 61 } 62 63 private int runOtaPrepare() throws RemoteException { 64 mInterface.prepare(); 65 getOutPrintWriter().println("Success"); 66 return 0; 67 } 68 69 private int runOtaCleanup() throws RemoteException { 70 mInterface.cleanup(); 71 return 0; 72 } 73 74 private int runOtaDone() throws RemoteException { 75 final PrintWriter pw = getOutPrintWriter(); 76 if (mInterface.isDone()) { 77 pw.println("OTA complete."); 78 } else { 79 pw.println("OTA incomplete."); 80 } 81 return 0; 82 } 83 84 private int runOtaStep() throws RemoteException { 85 mInterface.dexoptNextPackage(); 86 return 0; 87 } 88 89 private int runOtaNext() throws RemoteException { 90 getOutPrintWriter().println(mInterface.nextDexoptCommand()); 91 return 0; 92 } 93 94 private int runOtaProgress() throws RemoteException { 95 final float progress = mInterface.getProgress(); 96 final PrintWriter pw = getOutPrintWriter(); 97 // Note: The float output is parsed by update_engine. It does needs to be non-localized, 98 // as it's always expected to be "0.xy," never "0,xy" or similar. So use the ROOT 99 // Locale for formatting. (b/37760573) 100 pw.format(Locale.ROOT, "%.2f", progress); 101 return 0; 102 } 103 104 @Override 105 public void onHelp() { 106 final PrintWriter pw = getOutPrintWriter(); 107 pw.println("OTA Dexopt (ota) commands:"); 108 pw.println(" help"); 109 pw.println(" Print this help text."); 110 pw.println(""); 111 pw.println(" prepare"); 112 pw.println(" Prepare an OTA dexopt pass, collecting all packages."); 113 pw.println(" done"); 114 pw.println(" Replies whether the OTA is complete or not."); 115 pw.println(" step"); 116 pw.println(" OTA dexopt the next package."); 117 pw.println(" next"); 118 pw.println(" Get parameters for OTA dexopt of the next package."); 119 pw.println(" cleanup"); 120 pw.println(" Clean up internal states. Ends an OTA session."); 121 } 122} 123