Loading core/java/android/hardware/usb/IUsbManager.aidl +15 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,7 @@ interface IUsbManager boolean hasDevicePermission(in UsbDevice device, String packageName); /* Returns true if the given package/pid/uid has permission to access the device. */ @EnforcePermission("MANAGE_USB") @JavaPassthrough(annotation= "@android.annotation.RequiresPermission(android.Manifest.permission.MANAGE_USB)") boolean hasDevicePermissionWithIdentity(in UsbDevice device, String packageName, Loading @@ -90,6 +91,7 @@ interface IUsbManager boolean hasAccessoryPermission(in UsbAccessory accessory); /* Returns true if the given pid/uid has permission to access the accessory. */ @EnforcePermission("MANAGE_USB") @JavaPassthrough(annotation= "@android.annotation.RequiresPermission(android.Manifest.permission.MANAGE_USB)") boolean hasAccessoryPermissionWithIdentity(in UsbAccessory accessory, int pid, int uid); Loading @@ -108,9 +110,11 @@ interface IUsbManager in PendingIntent pi); /* Grants permission for the given UID to access the device */ @EnforcePermission("MANAGE_USB") void grantDevicePermission(in UsbDevice device, int uid); /* Grants permission for the given UID to access the accessory */ @EnforcePermission("MANAGE_USB") void grantAccessoryPermission(in UsbAccessory accessory, int uid); /* Returns true if the USB manager has default preferences or permissions for the package */ Loading @@ -123,29 +127,36 @@ interface IUsbManager boolean isFunctionEnabled(String function); /* Sets the current USB function. */ @EnforcePermission("MANAGE_USB") void setCurrentFunctions(long functions, int operationId); /* Compatibility version of setCurrentFunctions(long). */ void setCurrentFunction(String function, boolean usbDataUnlocked, int operationId); /* Gets the current USB functions. */ @EnforcePermission("MANAGE_USB") long getCurrentFunctions(); /* Gets the current USB Speed. */ @EnforcePermission("MANAGE_USB") int getCurrentUsbSpeed(); /* Gets the Gadget Hal Version. */ @EnforcePermission("MANAGE_USB") int getGadgetHalVersion(); /* Sets the screen unlocked USB function(s), which will be set automatically * when the screen is unlocked. */ @EnforcePermission("MANAGE_USB") void setScreenUnlockedFunctions(long functions); /* Gets the current screen unlocked functions. */ @EnforcePermission("MANAGE_USB") long getScreenUnlockedFunctions(); /* Resets the USB gadget. */ @EnforcePermission("MANAGE_USB") void resetUsbGadget(); /* Resets the USB port. */ Loading @@ -158,15 +169,18 @@ interface IUsbManager void enableUsbDataWhileDocked(in String portId, int operationId, in IUsbOperationInternal callback); /* Gets the USB Hal Version. */ @EnforcePermission("MANAGE_USB") int getUsbHalVersion(); /* Get the functionfs control handle for the given function. Usb * descriptors will already be written, and the handle will be * ready to use. */ @EnforcePermission("ACCESS_MTP") ParcelFileDescriptor getControlFd(long function); /* Gets the list of USB ports. */ @EnforcePermission("MANAGE_USB") List<ParcelableUsbPort> getPorts(); /* Gets the status of the specified USB port. */ Loading @@ -184,6 +198,7 @@ interface IUsbManager void enableContaminantDetection(in String portId, boolean enable); /* Sets USB device connection handler. */ @EnforcePermission("MANAGE_USB") void setUsbDeviceConnectionHandler(in ComponentName usbDeviceConnectionHandler); /* Registers callback for Usb events */ Loading services/usb/java/com/android/server/usb/UsbService.java +30 −15 Original line number Diff line number Diff line Loading @@ -347,10 +347,11 @@ public class UsbService extends IUsbManager.Stub { return null; } @android.annotation.EnforcePermission(android.Manifest.permission.ACCESS_MTP) /* Returns a dup of the control file descriptor for the given function. */ @Override public ParcelFileDescriptor getControlFd(long function) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_MTP, null); getControlFd_enforcePermission(); return mDeviceManager.getControlFd(function); } Loading Loading @@ -507,10 +508,11 @@ public class UsbService extends IUsbManager.Stub { } } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public boolean hasDevicePermissionWithIdentity(UsbDevice device, String packageName, int pid, int uid) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); hasDevicePermissionWithIdentity_enforcePermission(); final int userId = UserHandle.getUserId(uid); return getPermissionsForUser(userId).hasPermission(device, packageName, pid, uid); Loading @@ -530,9 +532,10 @@ public class UsbService extends IUsbManager.Stub { } } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public boolean hasAccessoryPermissionWithIdentity(UsbAccessory accessory, int pid, int uid) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); hasAccessoryPermissionWithIdentity_enforcePermission(); final int userId = UserHandle.getUserId(uid); return getPermissionsForUser(userId).hasPermission(accessory, pid, uid); Loading Loading @@ -567,9 +570,10 @@ public class UsbService extends IUsbManager.Stub { } } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public void grantDevicePermission(UsbDevice device, int uid) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); grantDevicePermission_enforcePermission(); final int userId = UserHandle.getUserId(uid); final long token = Binder.clearCallingIdentity(); Loading @@ -580,9 +584,10 @@ public class UsbService extends IUsbManager.Stub { } } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public void grantAccessoryPermission(UsbAccessory accessory, int uid) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); grantAccessoryPermission_enforcePermission(); final int userId = UserHandle.getUserId(uid); final long token = Binder.clearCallingIdentity(); Loading Loading @@ -625,9 +630,10 @@ public class UsbService extends IUsbManager.Stub { } } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public void setCurrentFunctions(long functions, int operationId) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); setCurrentFunctions_enforcePermission(); Preconditions.checkArgument(UsbManager.areSettableFunctions(functions)); Preconditions.checkState(mDeviceManager != null); mDeviceManager.setCurrentFunctions(functions, operationId); Loading @@ -643,32 +649,36 @@ public class UsbService extends IUsbManager.Stub { return (getCurrentFunctions() & UsbManager.usbFunctionsFromString(function)) != 0; } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public long getCurrentFunctions() { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); getCurrentFunctions_enforcePermission(); Preconditions.checkState(mDeviceManager != null); return mDeviceManager.getCurrentFunctions(); } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public void setScreenUnlockedFunctions(long functions) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); setScreenUnlockedFunctions_enforcePermission(); Preconditions.checkArgument(UsbManager.areSettableFunctions(functions)); Preconditions.checkState(mDeviceManager != null); mDeviceManager.setScreenUnlockedFunctions(functions); } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public long getScreenUnlockedFunctions() { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); getScreenUnlockedFunctions_enforcePermission(); Preconditions.checkState(mDeviceManager != null); return mDeviceManager.getScreenUnlockedFunctions(); } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public int getCurrentUsbSpeed() { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); getCurrentUsbSpeed_enforcePermission(); Preconditions.checkNotNull(mDeviceManager, "DeviceManager must not be null"); final long ident = Binder.clearCallingIdentity(); Loading @@ -679,9 +689,10 @@ public class UsbService extends IUsbManager.Stub { } } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public int getGadgetHalVersion() { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); getGadgetHalVersion_enforcePermission(); Preconditions.checkNotNull(mDeviceManager, "DeviceManager must not be null"); final long ident = Binder.clearCallingIdentity(); Loading @@ -692,9 +703,10 @@ public class UsbService extends IUsbManager.Stub { } } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public void resetUsbGadget() { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); resetUsbGadget_enforcePermission(); Preconditions.checkNotNull(mDeviceManager, "DeviceManager must not be null"); final long ident = Binder.clearCallingIdentity(); Loading Loading @@ -731,9 +743,10 @@ public class UsbService extends IUsbManager.Stub { } } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public List<ParcelableUsbPort> getPorts() { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); getPorts_enforcePermission(); final long ident = Binder.clearCallingIdentity(); try { Loading Loading @@ -822,9 +835,10 @@ public class UsbService extends IUsbManager.Stub { } } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public int getUsbHalVersion() { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); getUsbHalVersion_enforcePermission(); final long ident = Binder.clearCallingIdentity(); try { Loading Loading @@ -891,9 +905,10 @@ public class UsbService extends IUsbManager.Stub { } } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public void setUsbDeviceConnectionHandler(ComponentName usbDeviceConnectionHandler) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); setUsbDeviceConnectionHandler_enforcePermission(); synchronized (mLock) { if (mCurrentUserId == UserHandle.getCallingUserId()) { if (mHostManager != null) { Loading Loading
core/java/android/hardware/usb/IUsbManager.aidl +15 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,7 @@ interface IUsbManager boolean hasDevicePermission(in UsbDevice device, String packageName); /* Returns true if the given package/pid/uid has permission to access the device. */ @EnforcePermission("MANAGE_USB") @JavaPassthrough(annotation= "@android.annotation.RequiresPermission(android.Manifest.permission.MANAGE_USB)") boolean hasDevicePermissionWithIdentity(in UsbDevice device, String packageName, Loading @@ -90,6 +91,7 @@ interface IUsbManager boolean hasAccessoryPermission(in UsbAccessory accessory); /* Returns true if the given pid/uid has permission to access the accessory. */ @EnforcePermission("MANAGE_USB") @JavaPassthrough(annotation= "@android.annotation.RequiresPermission(android.Manifest.permission.MANAGE_USB)") boolean hasAccessoryPermissionWithIdentity(in UsbAccessory accessory, int pid, int uid); Loading @@ -108,9 +110,11 @@ interface IUsbManager in PendingIntent pi); /* Grants permission for the given UID to access the device */ @EnforcePermission("MANAGE_USB") void grantDevicePermission(in UsbDevice device, int uid); /* Grants permission for the given UID to access the accessory */ @EnforcePermission("MANAGE_USB") void grantAccessoryPermission(in UsbAccessory accessory, int uid); /* Returns true if the USB manager has default preferences or permissions for the package */ Loading @@ -123,29 +127,36 @@ interface IUsbManager boolean isFunctionEnabled(String function); /* Sets the current USB function. */ @EnforcePermission("MANAGE_USB") void setCurrentFunctions(long functions, int operationId); /* Compatibility version of setCurrentFunctions(long). */ void setCurrentFunction(String function, boolean usbDataUnlocked, int operationId); /* Gets the current USB functions. */ @EnforcePermission("MANAGE_USB") long getCurrentFunctions(); /* Gets the current USB Speed. */ @EnforcePermission("MANAGE_USB") int getCurrentUsbSpeed(); /* Gets the Gadget Hal Version. */ @EnforcePermission("MANAGE_USB") int getGadgetHalVersion(); /* Sets the screen unlocked USB function(s), which will be set automatically * when the screen is unlocked. */ @EnforcePermission("MANAGE_USB") void setScreenUnlockedFunctions(long functions); /* Gets the current screen unlocked functions. */ @EnforcePermission("MANAGE_USB") long getScreenUnlockedFunctions(); /* Resets the USB gadget. */ @EnforcePermission("MANAGE_USB") void resetUsbGadget(); /* Resets the USB port. */ Loading @@ -158,15 +169,18 @@ interface IUsbManager void enableUsbDataWhileDocked(in String portId, int operationId, in IUsbOperationInternal callback); /* Gets the USB Hal Version. */ @EnforcePermission("MANAGE_USB") int getUsbHalVersion(); /* Get the functionfs control handle for the given function. Usb * descriptors will already be written, and the handle will be * ready to use. */ @EnforcePermission("ACCESS_MTP") ParcelFileDescriptor getControlFd(long function); /* Gets the list of USB ports. */ @EnforcePermission("MANAGE_USB") List<ParcelableUsbPort> getPorts(); /* Gets the status of the specified USB port. */ Loading @@ -184,6 +198,7 @@ interface IUsbManager void enableContaminantDetection(in String portId, boolean enable); /* Sets USB device connection handler. */ @EnforcePermission("MANAGE_USB") void setUsbDeviceConnectionHandler(in ComponentName usbDeviceConnectionHandler); /* Registers callback for Usb events */ Loading
services/usb/java/com/android/server/usb/UsbService.java +30 −15 Original line number Diff line number Diff line Loading @@ -347,10 +347,11 @@ public class UsbService extends IUsbManager.Stub { return null; } @android.annotation.EnforcePermission(android.Manifest.permission.ACCESS_MTP) /* Returns a dup of the control file descriptor for the given function. */ @Override public ParcelFileDescriptor getControlFd(long function) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_MTP, null); getControlFd_enforcePermission(); return mDeviceManager.getControlFd(function); } Loading Loading @@ -507,10 +508,11 @@ public class UsbService extends IUsbManager.Stub { } } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public boolean hasDevicePermissionWithIdentity(UsbDevice device, String packageName, int pid, int uid) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); hasDevicePermissionWithIdentity_enforcePermission(); final int userId = UserHandle.getUserId(uid); return getPermissionsForUser(userId).hasPermission(device, packageName, pid, uid); Loading @@ -530,9 +532,10 @@ public class UsbService extends IUsbManager.Stub { } } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public boolean hasAccessoryPermissionWithIdentity(UsbAccessory accessory, int pid, int uid) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); hasAccessoryPermissionWithIdentity_enforcePermission(); final int userId = UserHandle.getUserId(uid); return getPermissionsForUser(userId).hasPermission(accessory, pid, uid); Loading Loading @@ -567,9 +570,10 @@ public class UsbService extends IUsbManager.Stub { } } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public void grantDevicePermission(UsbDevice device, int uid) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); grantDevicePermission_enforcePermission(); final int userId = UserHandle.getUserId(uid); final long token = Binder.clearCallingIdentity(); Loading @@ -580,9 +584,10 @@ public class UsbService extends IUsbManager.Stub { } } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public void grantAccessoryPermission(UsbAccessory accessory, int uid) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); grantAccessoryPermission_enforcePermission(); final int userId = UserHandle.getUserId(uid); final long token = Binder.clearCallingIdentity(); Loading Loading @@ -625,9 +630,10 @@ public class UsbService extends IUsbManager.Stub { } } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public void setCurrentFunctions(long functions, int operationId) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); setCurrentFunctions_enforcePermission(); Preconditions.checkArgument(UsbManager.areSettableFunctions(functions)); Preconditions.checkState(mDeviceManager != null); mDeviceManager.setCurrentFunctions(functions, operationId); Loading @@ -643,32 +649,36 @@ public class UsbService extends IUsbManager.Stub { return (getCurrentFunctions() & UsbManager.usbFunctionsFromString(function)) != 0; } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public long getCurrentFunctions() { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); getCurrentFunctions_enforcePermission(); Preconditions.checkState(mDeviceManager != null); return mDeviceManager.getCurrentFunctions(); } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public void setScreenUnlockedFunctions(long functions) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); setScreenUnlockedFunctions_enforcePermission(); Preconditions.checkArgument(UsbManager.areSettableFunctions(functions)); Preconditions.checkState(mDeviceManager != null); mDeviceManager.setScreenUnlockedFunctions(functions); } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public long getScreenUnlockedFunctions() { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); getScreenUnlockedFunctions_enforcePermission(); Preconditions.checkState(mDeviceManager != null); return mDeviceManager.getScreenUnlockedFunctions(); } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public int getCurrentUsbSpeed() { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); getCurrentUsbSpeed_enforcePermission(); Preconditions.checkNotNull(mDeviceManager, "DeviceManager must not be null"); final long ident = Binder.clearCallingIdentity(); Loading @@ -679,9 +689,10 @@ public class UsbService extends IUsbManager.Stub { } } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public int getGadgetHalVersion() { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); getGadgetHalVersion_enforcePermission(); Preconditions.checkNotNull(mDeviceManager, "DeviceManager must not be null"); final long ident = Binder.clearCallingIdentity(); Loading @@ -692,9 +703,10 @@ public class UsbService extends IUsbManager.Stub { } } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public void resetUsbGadget() { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); resetUsbGadget_enforcePermission(); Preconditions.checkNotNull(mDeviceManager, "DeviceManager must not be null"); final long ident = Binder.clearCallingIdentity(); Loading Loading @@ -731,9 +743,10 @@ public class UsbService extends IUsbManager.Stub { } } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public List<ParcelableUsbPort> getPorts() { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); getPorts_enforcePermission(); final long ident = Binder.clearCallingIdentity(); try { Loading Loading @@ -822,9 +835,10 @@ public class UsbService extends IUsbManager.Stub { } } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public int getUsbHalVersion() { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); getUsbHalVersion_enforcePermission(); final long ident = Binder.clearCallingIdentity(); try { Loading Loading @@ -891,9 +905,10 @@ public class UsbService extends IUsbManager.Stub { } } @android.annotation.EnforcePermission(android.Manifest.permission.MANAGE_USB) @Override public void setUsbDeviceConnectionHandler(ComponentName usbDeviceConnectionHandler) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null); setUsbDeviceConnectionHandler_enforcePermission(); synchronized (mLock) { if (mCurrentUserId == UserHandle.getCallingUserId()) { if (mHostManager != null) { Loading