blob: 575e0f9b73c447d279263b72c4472191e687073b [file] [log] [blame]
Andreas Gampea8908752015-11-10 08:58:14 -08001/*
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;
Andreas Gampedbce0ac2017-05-11 13:36:30 -070024import java.util.Locale;
Andreas Gampea8908752015-11-10 08:58:14 -080025
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();
Andreas Gampecc241a52016-06-23 20:27:12 -070050 case "next":
51 return runOtaNext();
Andreas Gampebf062322016-06-10 15:21:39 -070052 case "progress":
53 return runOtaProgress();
Andreas Gampea8908752015-11-10 08:58:14 -080054 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 Gampecc241a52016-06-23 20:27:12 -070089 private int runOtaNext() throws RemoteException {
90 getOutPrintWriter().println(mInterface.nextDexoptCommand());
91 return 0;
92 }
93
Andreas Gampebf062322016-06-10 15:21:39 -070094 private int runOtaProgress() throws RemoteException {
95 final float progress = mInterface.getProgress();
96 final PrintWriter pw = getOutPrintWriter();
Andreas Gampedbce0ac2017-05-11 13:36:30 -070097 // 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 Gampebf062322016-06-10 15:21:39 -0700101 return 0;
102 }
103
Andreas Gampea8908752015-11-10 08:58:14 -0800104 @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 Gampecc241a52016-06-23 20:27:12 -0700117 pw.println(" next");
118 pw.println(" Get parameters for OTA dexopt of the next package.");
Andreas Gampea8908752015-11-10 08:58:14 -0800119 pw.println(" cleanup");
120 pw.println(" Clean up internal states. Ends an OTA session.");
121 }
122}