1 /*
2  * Copyright (C) 2010 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 android.hardware.usb;
18 
19 import android.app.PendingIntent;
20 import android.content.ComponentName;
21 import android.hardware.usb.UsbAccessory;
22 import android.hardware.usb.UsbDevice;
23 import android.hardware.usb.UsbPort;
24 import android.hardware.usb.UsbPortStatus;
25 import android.os.Bundle;
26 import android.os.ParcelFileDescriptor;
27 
28 /** @hide */
29 interface IUsbManager
30 {
31     /* Returns a list of all currently attached USB devices */
getDeviceList(out Bundle devices)32     void getDeviceList(out Bundle devices);
33 
34     /* Returns a file descriptor for communicating with the USB device.
35      * The native fd can be passed to usb_device_new() in libusbhost.
36      */
openDevice(String deviceName, String packageName)37     ParcelFileDescriptor openDevice(String deviceName, String packageName);
38 
39     /* Returns the currently attached USB accessory */
getCurrentAccessory()40     UsbAccessory getCurrentAccessory();
41 
42     /* Returns a file descriptor for communicating with the USB accessory.
43      * This file descriptor can be used with standard Java file operations.
44      */
openAccessory(in UsbAccessory accessory)45     ParcelFileDescriptor openAccessory(in UsbAccessory accessory);
46 
47     /* Sets the default package for a USB device
48      * (or clears it if the package name is null)
49      */
setDevicePackage(in UsbDevice device, String packageName, int userId)50     void setDevicePackage(in UsbDevice device, String packageName, int userId);
51 
52     /* Sets the default package for a USB accessory
53      * (or clears it if the package name is null)
54      */
setAccessoryPackage(in UsbAccessory accessory, String packageName, int userId)55     void setAccessoryPackage(in UsbAccessory accessory, String packageName, int userId);
56 
57     /* Returns true if the caller has permission to access the device. */
hasDevicePermission(in UsbDevice device, String packageName)58     boolean hasDevicePermission(in UsbDevice device, String packageName);
59 
60     /* Returns true if the caller has permission to access the accessory. */
hasAccessoryPermission(in UsbAccessory accessory)61     boolean hasAccessoryPermission(in UsbAccessory accessory);
62 
63     /* Requests permission for the given package to access the device.
64      * Will display a system dialog to query the user if permission
65      * had not already been given.
66      */
requestDevicePermission(in UsbDevice device, String packageName, in PendingIntent pi)67     void requestDevicePermission(in UsbDevice device, String packageName, in PendingIntent pi);
68 
69     /* Requests permission for the given package to access the accessory.
70      * Will display a system dialog to query the user if permission
71      * had not already been given. Result is returned via pi.
72      */
requestAccessoryPermission(in UsbAccessory accessory, String packageName, in PendingIntent pi)73     void requestAccessoryPermission(in UsbAccessory accessory, String packageName,
74             in PendingIntent pi);
75 
76     /* Grants permission for the given UID to access the device */
grantDevicePermission(in UsbDevice device, int uid)77     void grantDevicePermission(in UsbDevice device, int uid);
78 
79     /* Grants permission for the given UID to access the accessory */
grantAccessoryPermission(in UsbAccessory accessory, int uid)80     void grantAccessoryPermission(in UsbAccessory accessory, int uid);
81 
82     /* Returns true if the USB manager has default preferences or permissions for the package */
hasDefaults(String packageName, int userId)83     boolean hasDefaults(String packageName, int userId);
84 
85     /* Clears default preferences and permissions for the package */
clearDefaults(String packageName, int userId)86     void clearDefaults(String packageName, int userId);
87 
88     /* Returns true if the specified USB function is enabled. */
isFunctionEnabled(String function)89     boolean isFunctionEnabled(String function);
90 
91     /* Sets the current USB function. */
setCurrentFunctions(long functions)92     void setCurrentFunctions(long functions);
93 
94     /* Compatibility version of setCurrentFunctions(long). */
setCurrentFunction(String function, boolean usbDataUnlocked)95     void setCurrentFunction(String function, boolean usbDataUnlocked);
96 
97     /* Gets the current USB functions. */
getCurrentFunctions()98     long getCurrentFunctions();
99 
100     /* Sets the screen unlocked USB function(s), which will be set automatically
101      * when the screen is unlocked.
102      */
setScreenUnlockedFunctions(long functions)103     void setScreenUnlockedFunctions(long functions);
104 
105     /* Gets the current screen unlocked functions. */
getScreenUnlockedFunctions()106     long getScreenUnlockedFunctions();
107 
108     /* Get the functionfs control handle for the given function. Usb
109      * descriptors will already be written, and the handle will be
110      * ready to use.
111      */
getControlFd(long function)112     ParcelFileDescriptor getControlFd(long function);
113 
114     /* Allow USB debugging from the attached host. If alwaysAllow is true, add the
115      * the public key to list of host keys that the user has approved.
116      */
allowUsbDebugging(boolean alwaysAllow, String publicKey)117     void allowUsbDebugging(boolean alwaysAllow, String publicKey);
118 
119     /* Deny USB debugging from the attached host */
denyUsbDebugging()120     void denyUsbDebugging();
121 
122     /* Clear public keys installed for secure USB debugging */
clearUsbDebuggingKeys()123     void clearUsbDebuggingKeys();
124 
125     /* Gets the list of USB ports. */
getPorts()126     UsbPort[] getPorts();
127 
128     /* Gets the status of the specified USB port. */
getPortStatus(in String portId)129     UsbPortStatus getPortStatus(in String portId);
130 
131     /* Sets the port's current role. */
setPortRoles(in String portId, int powerRole, int dataRole)132     void setPortRoles(in String portId, int powerRole, int dataRole);
133 
134    /* Sets USB device connection handler. */
setUsbDeviceConnectionHandler(in ComponentName usbDeviceConnectionHandler)135    void setUsbDeviceConnectionHandler(in ComponentName usbDeviceConnectionHandler);
136 }
137