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.IDisplayPortAltModeInfoListener; 22 import android.hardware.usb.IUsbOperationInternal; 23 import android.hardware.usb.UsbAccessory; 24 import android.hardware.usb.UsbDevice; 25 import android.hardware.usb.ParcelableUsbPort; 26 import android.hardware.usb.UsbPortStatus; 27 import android.os.Bundle; 28 import android.os.ParcelFileDescriptor; 29 import android.os.UserHandle; 30 31 /** @hide */ 32 interface IUsbManager 33 { 34 /* Returns a list of all currently attached USB devices */ getDeviceList(out Bundle devices)35 void getDeviceList(out Bundle devices); 36 37 /* Returns a file descriptor for communicating with the USB device. 38 * The native fd can be passed to usb_device_new() in libusbhost. 39 */ openDevice(String deviceName, String packageName)40 ParcelFileDescriptor openDevice(String deviceName, String packageName); 41 42 /* Returns the currently attached USB accessory */ getCurrentAccessory()43 UsbAccessory getCurrentAccessory(); 44 45 /* Returns a file descriptor for communicating with the USB accessory. 46 * This file descriptor can be used with standard Java file operations. 47 */ openAccessory(in UsbAccessory accessory)48 ParcelFileDescriptor openAccessory(in UsbAccessory accessory); 49 50 /* Sets the default package for a USB device 51 * (or clears it if the package name is null) 52 */ setDevicePackage(in UsbDevice device, String packageName, int userId)53 void setDevicePackage(in UsbDevice device, String packageName, int userId); 54 55 /* Sets the default package for a USB accessory 56 * (or clears it if the package name is null) 57 */ setAccessoryPackage(in UsbAccessory accessory, String packageName, int userId)58 void setAccessoryPackage(in UsbAccessory accessory, String packageName, int userId); 59 60 /* Adds packages to the set of "denied and don't ask again" launch preferences for a device */ addDevicePackagesToPreferenceDenied(in UsbDevice device, in String[] packageNames, in UserHandle user)61 void addDevicePackagesToPreferenceDenied(in UsbDevice device, in String[] packageNames, in UserHandle user); 62 63 /* Adds packages to the set of "denied and don't ask again" launch preferences for an accessory */ addAccessoryPackagesToPreferenceDenied(in UsbAccessory accessory, in String[] packageNames, in UserHandle user)64 void addAccessoryPackagesToPreferenceDenied(in UsbAccessory accessory, in String[] packageNames, in UserHandle user); 65 66 /* Removes packages from the set of "denied and don't ask again" launch preferences for a device */ removeDevicePackagesFromPreferenceDenied(in UsbDevice device, in String[] packageNames, in UserHandle user)67 void removeDevicePackagesFromPreferenceDenied(in UsbDevice device, in String[] packageNames, in UserHandle user); 68 69 /* Removes packages from the set of "denied and don't ask again" launch preferences for an accessory */ removeAccessoryPackagesFromPreferenceDenied(in UsbAccessory device, in String[] packageNames, in UserHandle user)70 void removeAccessoryPackagesFromPreferenceDenied(in UsbAccessory device, in String[] packageNames, in UserHandle user); 71 72 /* Sets the persistent permission granted state for USB device 73 */ setDevicePersistentPermission(in UsbDevice device, int uid, in UserHandle user, boolean shouldBeGranted)74 void setDevicePersistentPermission(in UsbDevice device, int uid, in UserHandle user, boolean shouldBeGranted); 75 76 /* Sets the persistent permission granted state for USB accessory 77 */ setAccessoryPersistentPermission(in UsbAccessory accessory, int uid, in UserHandle user, boolean shouldBeGranted)78 void setAccessoryPersistentPermission(in UsbAccessory accessory, int uid, in UserHandle user, boolean shouldBeGranted); 79 80 /* Returns true if the caller has permission to access the device. */ hasDevicePermission(in UsbDevice device, String packageName)81 boolean hasDevicePermission(in UsbDevice device, String packageName); 82 83 /* Returns true if the given package/pid/uid has permission to access the device. */ 84 @JavaPassthrough(annotation= 85 "@android.annotation.RequiresPermission(android.Manifest.permission.MANAGE_USB)") hasDevicePermissionWithIdentity(in UsbDevice device, String packageName, int pid, int uid)86 boolean hasDevicePermissionWithIdentity(in UsbDevice device, String packageName, 87 int pid, int uid); 88 89 /* Returns true if the caller has permission to access the accessory. */ hasAccessoryPermission(in UsbAccessory accessory)90 boolean hasAccessoryPermission(in UsbAccessory accessory); 91 92 /* Returns true if the given pid/uid has permission to access the accessory. */ 93 @JavaPassthrough(annotation= 94 "@android.annotation.RequiresPermission(android.Manifest.permission.MANAGE_USB)") hasAccessoryPermissionWithIdentity(in UsbAccessory accessory, int pid, int uid)95 boolean hasAccessoryPermissionWithIdentity(in UsbAccessory accessory, int pid, int uid); 96 97 /* Requests permission for the given package to access the device. 98 * Will display a system dialog to query the user if permission 99 * had not already been given. 100 */ requestDevicePermission(in UsbDevice device, String packageName, in PendingIntent pi)101 void requestDevicePermission(in UsbDevice device, String packageName, in PendingIntent pi); 102 103 /* Requests permission for the given package to access the accessory. 104 * Will display a system dialog to query the user if permission 105 * had not already been given. Result is returned via pi. 106 */ requestAccessoryPermission(in UsbAccessory accessory, String packageName, in PendingIntent pi)107 void requestAccessoryPermission(in UsbAccessory accessory, String packageName, 108 in PendingIntent pi); 109 110 /* Grants permission for the given UID to access the device */ grantDevicePermission(in UsbDevice device, int uid)111 void grantDevicePermission(in UsbDevice device, int uid); 112 113 /* Grants permission for the given UID to access the accessory */ grantAccessoryPermission(in UsbAccessory accessory, int uid)114 void grantAccessoryPermission(in UsbAccessory accessory, int uid); 115 116 /* Returns true if the USB manager has default preferences or permissions for the package */ hasDefaults(String packageName, int userId)117 boolean hasDefaults(String packageName, int userId); 118 119 /* Clears default preferences and permissions for the package */ clearDefaults(String packageName, int userId)120 void clearDefaults(String packageName, int userId); 121 122 /* Returns true if the specified USB function is enabled. */ isFunctionEnabled(String function)123 boolean isFunctionEnabled(String function); 124 125 /* Sets the current USB function. */ setCurrentFunctions(long functions, int operationId)126 void setCurrentFunctions(long functions, int operationId); 127 128 /* Compatibility version of setCurrentFunctions(long). */ setCurrentFunction(String function, boolean usbDataUnlocked, int operationId)129 void setCurrentFunction(String function, boolean usbDataUnlocked, int operationId); 130 131 /* Gets the current USB functions. */ getCurrentFunctions()132 long getCurrentFunctions(); 133 134 /* Gets the current USB Speed. */ getCurrentUsbSpeed()135 int getCurrentUsbSpeed(); 136 137 /* Gets the Gadget Hal Version. */ getGadgetHalVersion()138 int getGadgetHalVersion(); 139 140 /* Sets the screen unlocked USB function(s), which will be set automatically 141 * when the screen is unlocked. 142 */ setScreenUnlockedFunctions(long functions)143 void setScreenUnlockedFunctions(long functions); 144 145 /* Gets the current screen unlocked functions. */ getScreenUnlockedFunctions()146 long getScreenUnlockedFunctions(); 147 148 /* Resets the USB gadget. */ resetUsbGadget()149 void resetUsbGadget(); 150 151 /* Resets the USB port. */ resetUsbPort(in String portId, int operationId, in IUsbOperationInternal callback)152 void resetUsbPort(in String portId, int operationId, in IUsbOperationInternal callback); 153 154 /* Set USB data on or off */ enableUsbData(in String portId, boolean enable, int operationId, in IUsbOperationInternal callback)155 boolean enableUsbData(in String portId, boolean enable, int operationId, in IUsbOperationInternal callback); 156 157 /* Enable USB data when disabled due to docking event */ enableUsbDataWhileDocked(in String portId, int operationId, in IUsbOperationInternal callback)158 void enableUsbDataWhileDocked(in String portId, int operationId, in IUsbOperationInternal callback); 159 160 /* Gets the USB Hal Version. */ getUsbHalVersion()161 int getUsbHalVersion(); 162 163 /* Get the functionfs control handle for the given function. Usb 164 * descriptors will already be written, and the handle will be 165 * ready to use. 166 */ getControlFd(long function)167 ParcelFileDescriptor getControlFd(long function); 168 169 /* Gets the list of USB ports. */ getPorts()170 List<ParcelableUsbPort> getPorts(); 171 172 /* Gets the status of the specified USB port. */ getPortStatus(in String portId)173 UsbPortStatus getPortStatus(in String portId); 174 175 /* Sets the port's current role. */ setPortRoles(in String portId, int powerRole, int dataRole)176 void setPortRoles(in String portId, int powerRole, int dataRole); 177 178 /* Limit power transfer in & out of the port within the allowed limit by the USB 179 * specification. 180 */ enableLimitPowerTransfer(in String portId, boolean limit, int operationId, in IUsbOperationInternal callback)181 void enableLimitPowerTransfer(in String portId, boolean limit, int operationId, in IUsbOperationInternal callback); 182 183 /* Enable/disable contaminant detection */ enableContaminantDetection(in String portId, boolean enable)184 void enableContaminantDetection(in String portId, boolean enable); 185 186 /* Sets USB device connection handler. */ setUsbDeviceConnectionHandler(in ComponentName usbDeviceConnectionHandler)187 void setUsbDeviceConnectionHandler(in ComponentName usbDeviceConnectionHandler); 188 189 /* Registers callback for Usb events */ 190 @JavaPassthrough(annotation= 191 "@android.annotation.RequiresPermission(android.Manifest.permission.MANAGE_USB)") registerForDisplayPortEvents(IDisplayPortAltModeInfoListener listener)192 boolean registerForDisplayPortEvents(IDisplayPortAltModeInfoListener listener); 193 194 /* Unregisters Usb event callback */ 195 @JavaPassthrough(annotation= 196 "@android.annotation.RequiresPermission(android.Manifest.permission.MANAGE_USB)") unregisterForDisplayPortEvents(IDisplayPortAltModeInfoListener listener)197 void unregisterForDisplayPortEvents(IDisplayPortAltModeInfoListener listener); 198 199 } 200