Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 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 | |
Mike Lockwood | c4308f0 | 2011-03-01 08:04:54 -0800 | [diff] [blame] | 17 | package android.hardware.usb; |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 18 | |
Mike Lockwood | 3a68b83 | 2011-03-08 10:08:59 -0500 | [diff] [blame] | 19 | import android.app.PendingIntent; |
Mike Lockwood | c4308f0 | 2011-03-01 08:04:54 -0800 | [diff] [blame] | 20 | import android.hardware.usb.UsbAccessory; |
| 21 | import android.hardware.usb.UsbDevice; |
Jeff Brown | 76c4c66 | 2015-07-07 12:44:17 -0700 | [diff] [blame] | 22 | import android.hardware.usb.UsbPort; |
| 23 | import android.hardware.usb.UsbPortStatus; |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 24 | import android.os.Bundle; |
| 25 | import android.os.ParcelFileDescriptor; |
| 26 | |
| 27 | /** @hide */ |
| 28 | interface IUsbManager |
| 29 | { |
| 30 | /* Returns a list of all currently attached USB devices */ |
| 31 | void getDeviceList(out Bundle devices); |
Mike Lockwood | 02eb874 | 2011-02-27 09:10:37 -0800 | [diff] [blame] | 32 | |
| 33 | /* Returns a file descriptor for communicating with the USB device. |
| 34 | * The native fd can be passed to usb_device_new() in libusbhost. |
| 35 | */ |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 36 | ParcelFileDescriptor openDevice(String deviceName); |
Mike Lockwood | 02eb874 | 2011-02-27 09:10:37 -0800 | [diff] [blame] | 37 | |
| 38 | /* Returns the currently attached USB accessory */ |
Mike Lockwood | 9182d3c | 2011-02-15 09:50:22 -0500 | [diff] [blame] | 39 | UsbAccessory getCurrentAccessory(); |
Mike Lockwood | 02eb874 | 2011-02-27 09:10:37 -0800 | [diff] [blame] | 40 | |
| 41 | /* Returns a file descriptor for communicating with the USB accessory. |
| 42 | * This file descriptor can be used with standard Java file operations. |
| 43 | */ |
| 44 | ParcelFileDescriptor openAccessory(in UsbAccessory accessory); |
| 45 | |
| 46 | /* Sets the default package for a USB device |
| 47 | * (or clears it if the package name is null) |
| 48 | */ |
Jeff Sharkey | fc3f24b | 2012-10-01 21:45:52 -0700 | [diff] [blame] | 49 | void setDevicePackage(in UsbDevice device, String packageName, int userId); |
Mike Lockwood | 02eb874 | 2011-02-27 09:10:37 -0800 | [diff] [blame] | 50 | |
Mike Lockwood | 62cfeeb | 2011-03-11 18:39:03 -0500 | [diff] [blame] | 51 | /* Sets the default package for a USB accessory |
Mike Lockwood | 02eb874 | 2011-02-27 09:10:37 -0800 | [diff] [blame] | 52 | * (or clears it if the package name is null) |
| 53 | */ |
Jeff Sharkey | fc3f24b | 2012-10-01 21:45:52 -0700 | [diff] [blame] | 54 | void setAccessoryPackage(in UsbAccessory accessory, String packageName, int userId); |
Mike Lockwood | 02eb874 | 2011-02-27 09:10:37 -0800 | [diff] [blame] | 55 | |
Mike Lockwood | 3a68b83 | 2011-03-08 10:08:59 -0500 | [diff] [blame] | 56 | /* Returns true if the caller has permission to access the device. */ |
| 57 | boolean hasDevicePermission(in UsbDevice device); |
| 58 | |
| 59 | /* Returns true if the caller has permission to access the accessory. */ |
| 60 | boolean hasAccessoryPermission(in UsbAccessory accessory); |
| 61 | |
| 62 | /* Requests permission for the given package to access the device. |
| 63 | * Will display a system dialog to query the user if permission |
| 64 | * had not already been given. |
| 65 | */ |
| 66 | void requestDevicePermission(in UsbDevice device, String packageName, in PendingIntent pi); |
| 67 | |
| 68 | /* Requests permission for the given package to access the accessory. |
| 69 | * Will display a system dialog to query the user if permission |
| 70 | * had not already been given. Result is returned via pi. |
| 71 | */ |
| 72 | void requestAccessoryPermission(in UsbAccessory accessory, String packageName, |
| 73 | in PendingIntent pi); |
| 74 | |
Mike Lockwood | 02eb874 | 2011-02-27 09:10:37 -0800 | [diff] [blame] | 75 | /* Grants permission for the given UID to access the device */ |
| 76 | void grantDevicePermission(in UsbDevice device, int uid); |
| 77 | |
| 78 | /* Grants permission for the given UID to access the accessory */ |
| 79 | void grantAccessoryPermission(in UsbAccessory accessory, int uid); |
| 80 | |
| 81 | /* Returns true if the USB manager has default preferences or permissions for the package */ |
Jeff Sharkey | fc3f24b | 2012-10-01 21:45:52 -0700 | [diff] [blame] | 82 | boolean hasDefaults(String packageName, int userId); |
Mike Lockwood | 02eb874 | 2011-02-27 09:10:37 -0800 | [diff] [blame] | 83 | |
| 84 | /* Clears default preferences and permissions for the package */ |
Jeff Sharkey | fc3f24b | 2012-10-01 21:45:52 -0700 | [diff] [blame] | 85 | void clearDefaults(String packageName, int userId); |
Mike Lockwood | 02e4569 | 2011-06-14 15:43:51 -0400 | [diff] [blame] | 86 | |
Jeff Brown | 460a146 | 2015-06-30 17:57:12 -0700 | [diff] [blame] | 87 | /* Returns true if the specified USB function is enabled. */ |
| 88 | boolean isFunctionEnabled(String function); |
| 89 | |
Jerry Zhang | 4882496 | 2016-10-12 15:49:32 -0700 | [diff] [blame] | 90 | /* Sets the current USB function as well as whether USB data |
| 91 | * (for example, MTP exposed pictures) should be made available |
| 92 | * on the USB connection. Unlocking data should only be done with |
| 93 | * user involvement, since exposing pictures or other data could |
| 94 | * leak sensitive user information. |
Nick Kralevich | 6740190 | 2015-06-10 09:38:42 -0700 | [diff] [blame] | 95 | */ |
Jerry Zhang | 4882496 | 2016-10-12 15:49:32 -0700 | [diff] [blame] | 96 | void setCurrentFunction(String function, boolean usbDataUnlocked); |
Nick Kralevich | 6740190 | 2015-06-10 09:38:42 -0700 | [diff] [blame] | 97 | |
Benoit Goby | 4e68bd4 | 2012-04-25 18:06:00 -0700 | [diff] [blame] | 98 | /* Allow USB debugging from the attached host. If alwaysAllow is true, add the |
| 99 | * the public key to list of host keys that the user has approved. |
| 100 | */ |
| 101 | void allowUsbDebugging(boolean alwaysAllow, String publicKey); |
| 102 | |
| 103 | /* Deny USB debugging from the attached host */ |
| 104 | void denyUsbDebugging(); |
Benoit Goby | cd7a17c | 2012-12-21 16:44:50 -0800 | [diff] [blame] | 105 | |
| 106 | /* Clear public keys installed for secure USB debugging */ |
| 107 | void clearUsbDebuggingKeys(); |
Jeff Brown | 76c4c66 | 2015-07-07 12:44:17 -0700 | [diff] [blame] | 108 | |
| 109 | /* Gets the list of USB ports. */ |
| 110 | UsbPort[] getPorts(); |
| 111 | |
| 112 | /* Gets the status of the specified USB port. */ |
| 113 | UsbPortStatus getPortStatus(in String portId); |
| 114 | |
| 115 | /* Sets the port's current role. */ |
| 116 | void setPortRoles(in String portId, int powerRole, int dataRole); |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 117 | } |