Loading services/usb/java/com/android/server/usb/UsbDeviceManager.java +3 −3 Original line number Diff line number Diff line Loading @@ -50,7 +50,6 @@ import android.hardware.usb.gadget.V1_0.Status; import android.hidl.manager.V1_0.IServiceManager; import android.hidl.manager.V1_0.IServiceNotification; import android.os.BatteryManager; import android.os.Binder; import android.os.Environment; import android.os.FileUtils; import android.os.Handler; Loading Loading @@ -1982,9 +1981,10 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser * opens the currently attached USB accessory. * * @param accessory accessory to be openened. * @param uid Uid of the caller */ public ParcelFileDescriptor openAccessory(UsbAccessory accessory, UsbUserSettingsManager settings) { UsbUserSettingsManager settings, int uid) { UsbAccessory currentAccessory = mHandler.getCurrentAccessory(); if (currentAccessory == null) { throw new IllegalArgumentException("no accessory attached"); Loading @@ -1995,7 +1995,7 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser + currentAccessory; throw new IllegalArgumentException(error); } settings.checkPermission(accessory, Binder.getCallingUid()); settings.checkPermission(accessory, uid); return nativeOpenAccessory(); } Loading services/usb/java/com/android/server/usb/UsbService.java +31 −39 Original line number Diff line number Diff line Loading @@ -230,43 +230,30 @@ public class UsbService extends IUsbManager.Stub { } } /** * Check if the calling user is in the same profile group as the {@link #mCurrentUserId * current user}. * * @return Iff the caller is in the current user's profile group */ @GuardedBy("mLock") private boolean isCallerInCurrentUserProfileGroupLocked() { int userIdInt = UserHandle.getCallingUserId(); long ident = clearCallingIdentity(); try { return mUserManager.isSameProfileGroup(userIdInt, mCurrentUserId); } finally { restoreCallingIdentity(ident); } } /* Opens the specified USB device (host mode) */ @Override public ParcelFileDescriptor openDevice(String deviceName, String packageName) { ParcelFileDescriptor fd = null; if (mHostManager != null) { synchronized (mLock) { if (deviceName != null) { int userIdInt = UserHandle.getCallingUserId(); boolean isCurrentUser = isCallerInCurrentUserProfileGroupLocked(); int uid = Binder.getCallingUid(); int user = UserHandle.getUserId(uid); if (isCurrentUser) { fd = mHostManager.openDevice(deviceName, getSettingsForUser(userIdInt), packageName, Binder.getCallingUid()); long ident = clearCallingIdentity(); try { synchronized (mLock) { if (mUserManager.isSameProfileGroup(user, mCurrentUserId)) { fd = mHostManager.openDevice(deviceName, getSettingsForUser(user), packageName, uid); } else { Slog.w(TAG, "Cannot open " + deviceName + " for user " + userIdInt + " as user is not active."); Slog.w(TAG, "Cannot open " + deviceName + " for user " + user + " as user is not active."); } } } finally { restoreCallingIdentity(ident); } } } Loading @@ -287,18 +274,23 @@ public class UsbService extends IUsbManager.Stub { @Override public ParcelFileDescriptor openAccessory(UsbAccessory accessory) { if (mDeviceManager != null) { int userIdInt = UserHandle.getCallingUserId(); int uid = Binder.getCallingUid(); int user = UserHandle.getUserId(uid); long ident = clearCallingIdentity(); try { synchronized (mLock) { boolean isCurrentUser = isCallerInCurrentUserProfileGroupLocked(); if (isCurrentUser) { return mDeviceManager.openAccessory(accessory, getSettingsForUser(userIdInt)); if (mUserManager.isSameProfileGroup(user, mCurrentUserId)) { return mDeviceManager.openAccessory(accessory, getSettingsForUser(user), uid); } else { Slog.w(TAG, "Cannot open " + accessory + " for user " + userIdInt + " as user is not active."); Slog.w(TAG, "Cannot open " + accessory + " for user " + user + " as user is not active."); } } } finally { restoreCallingIdentity(ident); } } return null; Loading Loading
services/usb/java/com/android/server/usb/UsbDeviceManager.java +3 −3 Original line number Diff line number Diff line Loading @@ -50,7 +50,6 @@ import android.hardware.usb.gadget.V1_0.Status; import android.hidl.manager.V1_0.IServiceManager; import android.hidl.manager.V1_0.IServiceNotification; import android.os.BatteryManager; import android.os.Binder; import android.os.Environment; import android.os.FileUtils; import android.os.Handler; Loading Loading @@ -1982,9 +1981,10 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser * opens the currently attached USB accessory. * * @param accessory accessory to be openened. * @param uid Uid of the caller */ public ParcelFileDescriptor openAccessory(UsbAccessory accessory, UsbUserSettingsManager settings) { UsbUserSettingsManager settings, int uid) { UsbAccessory currentAccessory = mHandler.getCurrentAccessory(); if (currentAccessory == null) { throw new IllegalArgumentException("no accessory attached"); Loading @@ -1995,7 +1995,7 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser + currentAccessory; throw new IllegalArgumentException(error); } settings.checkPermission(accessory, Binder.getCallingUid()); settings.checkPermission(accessory, uid); return nativeOpenAccessory(); } Loading
services/usb/java/com/android/server/usb/UsbService.java +31 −39 Original line number Diff line number Diff line Loading @@ -230,43 +230,30 @@ public class UsbService extends IUsbManager.Stub { } } /** * Check if the calling user is in the same profile group as the {@link #mCurrentUserId * current user}. * * @return Iff the caller is in the current user's profile group */ @GuardedBy("mLock") private boolean isCallerInCurrentUserProfileGroupLocked() { int userIdInt = UserHandle.getCallingUserId(); long ident = clearCallingIdentity(); try { return mUserManager.isSameProfileGroup(userIdInt, mCurrentUserId); } finally { restoreCallingIdentity(ident); } } /* Opens the specified USB device (host mode) */ @Override public ParcelFileDescriptor openDevice(String deviceName, String packageName) { ParcelFileDescriptor fd = null; if (mHostManager != null) { synchronized (mLock) { if (deviceName != null) { int userIdInt = UserHandle.getCallingUserId(); boolean isCurrentUser = isCallerInCurrentUserProfileGroupLocked(); int uid = Binder.getCallingUid(); int user = UserHandle.getUserId(uid); if (isCurrentUser) { fd = mHostManager.openDevice(deviceName, getSettingsForUser(userIdInt), packageName, Binder.getCallingUid()); long ident = clearCallingIdentity(); try { synchronized (mLock) { if (mUserManager.isSameProfileGroup(user, mCurrentUserId)) { fd = mHostManager.openDevice(deviceName, getSettingsForUser(user), packageName, uid); } else { Slog.w(TAG, "Cannot open " + deviceName + " for user " + userIdInt + " as user is not active."); Slog.w(TAG, "Cannot open " + deviceName + " for user " + user + " as user is not active."); } } } finally { restoreCallingIdentity(ident); } } } Loading @@ -287,18 +274,23 @@ public class UsbService extends IUsbManager.Stub { @Override public ParcelFileDescriptor openAccessory(UsbAccessory accessory) { if (mDeviceManager != null) { int userIdInt = UserHandle.getCallingUserId(); int uid = Binder.getCallingUid(); int user = UserHandle.getUserId(uid); long ident = clearCallingIdentity(); try { synchronized (mLock) { boolean isCurrentUser = isCallerInCurrentUserProfileGroupLocked(); if (isCurrentUser) { return mDeviceManager.openAccessory(accessory, getSettingsForUser(userIdInt)); if (mUserManager.isSameProfileGroup(user, mCurrentUserId)) { return mDeviceManager.openAccessory(accessory, getSettingsForUser(user), uid); } else { Slog.w(TAG, "Cannot open " + accessory + " for user " + userIdInt + " as user is not active."); Slog.w(TAG, "Cannot open " + accessory + " for user " + user + " as user is not active."); } } } finally { restoreCallingIdentity(ident); } } return null; Loading