UsbCommand.java revision 59d3d868112f8bbd14f466d0096789548b176d34
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 public String shortHelp() { 31 return "Control Usb state"; 32 } 33 34 public String longHelp() { 35 return shortHelp() + "\n" 36 + "\n" 37 + "usage: svc usb setFunction [function]\n" 38 + " Set the current usb function.\n\n" 39 + " svc usb getFunction\n" 40 + " Gets the list of currently enabled functions\n"; 41 } 42 43 public void run(String[] args) { 44 boolean validCommand = false; 45 if (args.length >= 2) { 46 if ("setFunction".equals(args[1])) { 47 IUsbManager usbMgr = IUsbManager.Stub.asInterface(ServiceManager.getService( 48 Context.USB_SERVICE)); 49 try { 50 usbMgr.setCurrentFunction((args.length >=3 ? args[2] : null), false); 51 } catch (RemoteException e) { 52 System.err.println("Error communicating with UsbManager: " + e); 53 } 54 return; 55 } else if ("getFunction".equals(args[1])) { 56 System.err.println(SystemProperties.get("sys.usb.config")); 57 return; 58 } 59 } 60 System.err.println(longHelp()); 61 } 62} 63