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