OtaDexoptShellCommand.java revision a89087542f774c585b6a6ec535fc294721710521
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 default: 50 return handleDefaultCommands(cmd); 51 } 52 } catch (RemoteException e) { 53 pw.println("Remote exception: " + e); 54 } 55 return -1; 56 } 57 58 private int runOtaPrepare() throws RemoteException { 59 mInterface.prepare(); 60 getOutPrintWriter().println("Success"); 61 return 0; 62 } 63 64 private int runOtaCleanup() throws RemoteException { 65 mInterface.cleanup(); 66 return 0; 67 } 68 69 private int runOtaDone() throws RemoteException { 70 final PrintWriter pw = getOutPrintWriter(); 71 if (mInterface.isDone()) { 72 pw.println("OTA complete."); 73 } else { 74 pw.println("OTA incomplete."); 75 } 76 return 0; 77 } 78 79 private int runOtaStep() throws RemoteException { 80 mInterface.dexoptNextPackage(); 81 return 0; 82 } 83 84 @Override 85 public void onHelp() { 86 final PrintWriter pw = getOutPrintWriter(); 87 pw.println("OTA Dexopt (ota) commands:"); 88 pw.println(" help"); 89 pw.println(" Print this help text."); 90 pw.println(""); 91 pw.println(" prepare"); 92 pw.println(" Prepare an OTA dexopt pass, collecting all packages."); 93 pw.println(" done"); 94 pw.println(" Replies whether the OTA is complete or not."); 95 pw.println(" step"); 96 pw.println(" OTA dexopt the next package."); 97 pw.println(" cleanup"); 98 pw.println(" Clean up internal states. Ends an OTA session."); 99 } 100} 101