1/*
2 * Copyright (C) 2008 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.commands.svc;
18
19import android.content.Context;
20import android.hardware.usb.IUsbManager;
21import android.os.RemoteException;
22import android.os.ServiceManager;
23import android.os.SystemProperties;
24
25public class UsbCommand extends Svc.Command {
26    public UsbCommand() {
27        super("usb");
28    }
29
30    @Override
31    public String shortHelp() {
32        return "Control Usb state";
33    }
34
35    @Override
36    public String longHelp() {
37        return shortHelp() + "\n"
38                + "\n"
39                + "usage: svc usb setFunction [function]\n"
40                + "         Set the current usb function.\n\n"
41                + "       svc usb getFunction\n"
42                + "          Gets the list of currently enabled functions\n";
43    }
44
45    @Override
46    public void run(String[] args) {
47        boolean validCommand = false;
48        if (args.length >= 2) {
49            if ("setFunction".equals(args[1])) {
50                IUsbManager usbMgr = IUsbManager.Stub.asInterface(ServiceManager.getService(
51                        Context.USB_SERVICE));
52                try {
53                    usbMgr.setCurrentFunction((args.length >=3 ? args[2] : null));
54                } catch (RemoteException e) {
55                    System.err.println("Error communicating with UsbManager: " + e);
56                }
57                return;
58            } else if ("getFunction".equals(args[1])) {
59                System.err.println(SystemProperties.get("sys.usb.config"));
60                return;
61            }
62        }
63        System.err.println(longHelp());
64    }
65}
66