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 @EnforcePermission("MANAGE_USB") 85 @JavaPassthrough(annotation= 86 "@android.annotation.RequiresPermission(android.Manifest.permission.MANAGE_USB)") hasDevicePermissionWithIdentity(in UsbDevice device, String packageName, int pid, int uid)87 boolean hasDevicePermissionWithIdentity(in UsbDevice device, String packageName, 88 int pid, int uid); 89 90 /* Returns true if the caller has permission to access the accessory. */ hasAccessoryPermission(in UsbAccessory accessory)91 boolean hasAccessoryPermission(in UsbAccessory accessory); 92 93 /* Returns true if the given pid/uid has permission to access the accessory. */ 94 @EnforcePermission("MANAGE_USB") 95 @JavaPassthrough(annotation= 96 "@android.annotation.RequiresPermission(android.Manifest.permission.MANAGE_USB)") hasAccessoryPermissionWithIdentity(in UsbAccessory accessory, int pid, int uid)97 boolean hasAccessoryPermissionWithIdentity(in UsbAccessory accessory, int pid, int uid); 98 99 /* Requests permission for the given package to access the device. 100 * Will display a system dialog to query the user if permission 101 * had not already been given. 102 */ requestDevicePermission(in UsbDevice device, String packageName, in PendingIntent pi)103 void requestDevicePermission(in UsbDevice device, String packageName, in PendingIntent pi); 104 105 /* Requests permission for the given package to access the accessory. 106 * Will display a system dialog to query the user if permission 107 * had not already been given. Result is returned via pi. 108 */ requestAccessoryPermission(in UsbAccessory accessory, String packageName, in PendingIntent pi)109 void requestAccessoryPermission(in UsbAccessory accessory, String packageName, 110 in PendingIntent pi); 111 112 /* Grants permission for the given UID to access the device */ 113 @EnforcePermission("MANAGE_USB") grantDevicePermission(in UsbDevice device, int uid)114 void grantDevicePermission(in UsbDevice device, int uid); 115 116 /* Grants permission for the given UID to access the accessory */ 117 @EnforcePermission("MANAGE_USB") grantAccessoryPermission(in UsbAccessory accessory, int uid)118 void grantAccessoryPermission(in UsbAccessory accessory, int uid); 119 120 /* Returns true if the USB manager has default preferences or permissions for the package */ hasDefaults(String packageName, int userId)121 boolean hasDefaults(String packageName, int userId); 122 123 /* Clears default preferences and permissions for the package */ clearDefaults(String packageName, int userId)124 void clearDefaults(String packageName, int userId); 125 126 /* Returns true if the specified USB function is enabled. */ isFunctionEnabled(String function)127 boolean isFunctionEnabled(String function); 128 129 /* Sets the current USB function. */ 130 @EnforcePermission("MANAGE_USB") setCurrentFunctions(long functions, int operationId)131 void setCurrentFunctions(long functions, int operationId); 132 133 /* Compatibility version of setCurrentFunctions(long). */ setCurrentFunction(String function, boolean usbDataUnlocked, int operationId)134 void setCurrentFunction(String function, boolean usbDataUnlocked, int operationId); 135 136 /* Gets the current USB functions. */ 137 @EnforcePermission("MANAGE_USB") getCurrentFunctions()138 long getCurrentFunctions(); 139 140 /* Gets the current USB Speed. */ 141 @EnforcePermission("MANAGE_USB") getCurrentUsbSpeed()142 int getCurrentUsbSpeed(); 143 144 /* Gets the Gadget Hal Version. */ 145 @EnforcePermission("MANAGE_USB") getGadgetHalVersion()146 int getGadgetHalVersion(); 147 148 /* Sets the screen unlocked USB function(s), which will be set automatically 149 * when the screen is unlocked. 150 */ 151 @EnforcePermission("MANAGE_USB") setScreenUnlockedFunctions(long functions)152 void setScreenUnlockedFunctions(long functions); 153 154 /* Gets the current screen unlocked functions. */ 155 @EnforcePermission("MANAGE_USB") getScreenUnlockedFunctions()156 long getScreenUnlockedFunctions(); 157 158 /* Resets the USB gadget. */ 159 @EnforcePermission("MANAGE_USB") resetUsbGadget()160 void resetUsbGadget(); 161 162 /* Resets the USB port. */ resetUsbPort(in String portId, int operationId, in IUsbOperationInternal callback)163 void resetUsbPort(in String portId, int operationId, in IUsbOperationInternal callback); 164 165 /* Set USB data on or off */ enableUsbData(in String portId, boolean enable, int operationId, in IUsbOperationInternal callback)166 boolean enableUsbData(in String portId, boolean enable, int operationId, in IUsbOperationInternal callback); 167 168 /* Enable USB data when disabled due to docking event */ enableUsbDataWhileDocked(in String portId, int operationId, in IUsbOperationInternal callback)169 void enableUsbDataWhileDocked(in String portId, int operationId, in IUsbOperationInternal callback); 170 171 /* Gets the USB Hal Version. */ 172 @EnforcePermission("MANAGE_USB") getUsbHalVersion()173 int getUsbHalVersion(); 174 175 /* Get the functionfs control handle for the given function. Usb 176 * descriptors will already be written, and the handle will be 177 * ready to use. 178 */ 179 @EnforcePermission("ACCESS_MTP") getControlFd(long function)180 ParcelFileDescriptor getControlFd(long function); 181 182 /* Gets the list of USB ports. */ 183 @EnforcePermission("MANAGE_USB") getPorts()184 List<ParcelableUsbPort> getPorts(); 185 186 /* Gets the status of the specified USB port. */ getPortStatus(in String portId)187 UsbPortStatus getPortStatus(in String portId); 188 189 /* Returns if the specified USB port supports mode change. */ 190 @EnforcePermission("MANAGE_USB") isModeChangeSupported(in String portId)191 boolean isModeChangeSupported(in String portId); 192 193 /* Sets the port's current role. */ setPortRoles(in String portId, int powerRole, int dataRole)194 void setPortRoles(in String portId, int powerRole, int dataRole); 195 196 /* Limit power transfer in & out of the port within the allowed limit by the USB 197 * specification. 198 */ enableLimitPowerTransfer(in String portId, boolean limit, int operationId, in IUsbOperationInternal callback)199 void enableLimitPowerTransfer(in String portId, boolean limit, int operationId, in IUsbOperationInternal callback); 200 201 /* Enable/disable contaminant detection */ enableContaminantDetection(in String portId, boolean enable)202 void enableContaminantDetection(in String portId, boolean enable); 203 204 /* Sets USB device connection handler. */ 205 @EnforcePermission("MANAGE_USB") setUsbDeviceConnectionHandler(in ComponentName usbDeviceConnectionHandler)206 void setUsbDeviceConnectionHandler(in ComponentName usbDeviceConnectionHandler); 207 208 /* Registers callback for Usb events */ 209 @JavaPassthrough(annotation= 210 "@android.annotation.RequiresPermission(android.Manifest.permission.MANAGE_USB)") registerForDisplayPortEvents(IDisplayPortAltModeInfoListener listener)211 boolean registerForDisplayPortEvents(IDisplayPortAltModeInfoListener listener); 212 213 /* Unregisters Usb event callback */ 214 @JavaPassthrough(annotation= 215 "@android.annotation.RequiresPermission(android.Manifest.permission.MANAGE_USB)") unregisterForDisplayPortEvents(IDisplayPortAltModeInfoListener listener)216 void unregisterForDisplayPortEvents(IDisplayPortAltModeInfoListener listener); 217 218 } 219