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