Skip to content

Commit 59d3d86

Browse files
author
Robert Greenwalt
committed
Add Usb control to svc.
We used to have control over usb via ndc but recent changes removed that. The reverse_tether.sh script needs control (on rooted devices) to run so added this. bug:4208971 Change-Id: I722fc0e14540890be0d79a0b7d22f23b2d57f20c
1 parent 7725180 commit 59d3d86

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

cmds/svc/src/com/android/commands/svc/Svc.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public void run(String[] args) {
9494
COMMAND_HELP,
9595
new PowerCommand(),
9696
new DataCommand(),
97-
new WifiCommand()
97+
new WifiCommand(),
98+
new UsbCommand()
9899
};
99100
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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.os.RemoteException;
22+
import android.os.ServiceManager;
23+
import android.os.SystemProperties;
24+
25+
public 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+
}

0 commit comments

Comments
 (0)