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 17 package com.android.commands.svc; 18 19 import android.content.Context; 20 import android.hardware.usb.IUsbManager; 21 import android.hardware.usb.UsbManager; 22 import android.os.RemoteException; 23 import android.os.ServiceManager; 24 25 public 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 setFunctions [function]\n" 40 + " Set the current usb function. If function is blank, sets to charging.\n" 41 + " svc usb setScreenUnlockedFunctions [function]\n" 42 + " Sets the functions which, if the device was charging, become current on" 43 + "screen unlock. If function is blank, turn off this feature.\n" 44 + " svc usb getFunctions\n" 45 + " Gets the list of currently enabled functions\n\n" 46 + "possible values of [function] are any of 'mtp', 'ptp', 'rndis', 'midi'\n"; 47 } 48 49 @Override 50 public void run(String[] args) { 51 if (args.length >= 2) { 52 IUsbManager usbMgr = IUsbManager.Stub.asInterface(ServiceManager.getService( 53 Context.USB_SERVICE)); 54 if ("setFunctions".equals(args[1])) { 55 try { 56 usbMgr.setCurrentFunctions(UsbManager.usbFunctionsFromString( 57 args.length >= 3 ? args[2] : "")); 58 } catch (RemoteException e) { 59 System.err.println("Error communicating with UsbManager: " + e); 60 } 61 return; 62 } else if ("getFunctions".equals(args[1])) { 63 try { 64 System.err.println( 65 UsbManager.usbFunctionsToString(usbMgr.getCurrentFunctions())); 66 } catch (RemoteException e) { 67 System.err.println("Error communicating with UsbManager: " + e); 68 } 69 return; 70 } else if ("setScreenUnlockedFunctions".equals(args[1])) { 71 try { 72 usbMgr.setScreenUnlockedFunctions(UsbManager.usbFunctionsFromString( 73 args.length >= 3 ? args[2] : "")); 74 } catch (RemoteException e) { 75 System.err.println("Error communicating with UsbManager: " + e); 76 } 77 return; 78 } 79 } 80 System.err.println(longHelp()); 81 } 82 } 83