Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 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 | |
| 17 | package com.android.server.pm; |
| 18 | |
| 19 | import android.content.pm.IOtaDexopt; |
| 20 | import android.os.RemoteException; |
| 21 | import android.os.ShellCommand; |
| 22 | |
| 23 | import java.io.PrintWriter; |
Andreas Gampe | dbce0ac | 2017-05-11 13:36:30 -0700 | [diff] [blame] | 24 | import java.util.Locale; |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 25 | |
| 26 | class 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(); |
Andreas Gampe | cc241a5 | 2016-06-23 20:27:12 -0700 | [diff] [blame] | 50 | case "next": |
| 51 | return runOtaNext(); |
Andreas Gampe | bf06232 | 2016-06-10 15:21:39 -0700 | [diff] [blame] | 52 | case "progress": |
| 53 | return runOtaProgress(); |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 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 | |
Andreas Gampe | cc241a5 | 2016-06-23 20:27:12 -0700 | [diff] [blame] | 89 | private int runOtaNext() throws RemoteException { |
| 90 | getOutPrintWriter().println(mInterface.nextDexoptCommand()); |
| 91 | return 0; |
| 92 | } |
| 93 | |
Andreas Gampe | bf06232 | 2016-06-10 15:21:39 -0700 | [diff] [blame] | 94 | private int runOtaProgress() throws RemoteException { |
| 95 | final float progress = mInterface.getProgress(); |
| 96 | final PrintWriter pw = getOutPrintWriter(); |
Andreas Gampe | dbce0ac | 2017-05-11 13:36:30 -0700 | [diff] [blame] | 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); |
Andreas Gampe | bf06232 | 2016-06-10 15:21:39 -0700 | [diff] [blame] | 101 | return 0; |
| 102 | } |
| 103 | |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 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."); |
Andreas Gampe | cc241a5 | 2016-06-23 20:27:12 -0700 | [diff] [blame] | 117 | pw.println(" next"); |
| 118 | pw.println(" Get parameters for OTA dexopt of the next package."); |
Andreas Gampe | a890875 | 2015-11-10 08:58:14 -0800 | [diff] [blame] | 119 | pw.println(" cleanup"); |
| 120 | pw.println(" Clean up internal states. Ends an OTA session."); |
| 121 | } |
| 122 | } |