Loading core/java/android/app/AutomaticZenRule.java +1 −1 Original line number Diff line number Diff line Loading @@ -125,7 +125,7 @@ public final class AutomaticZenRule implements Parcelable { name = getTrimmedString(source.readString()); } interruptionFilter = source.readInt(); conditionId = source.readParcelable(null); conditionId = getTrimmedUri(source.readParcelable(null)); owner = getTrimmedComponentName(source.readParcelable(null)); configurationActivity = getTrimmedComponentName(source.readParcelable(null)); creationTime = source.readLong(); Loading core/java/android/content/pm/parsing/ParsingPackageImpl.java +3 −0 Original line number Diff line number Diff line Loading @@ -1584,6 +1584,9 @@ public class ParsingPackageImpl implements ParsingPackage, Parcelable { for (int i = component.getIntents().size() - 1; i >= 0; i--) { IntentFilter filter = component.getIntents().get(i); for (int groupIndex = filter.countMimeGroups() - 1; groupIndex >= 0; groupIndex--) { if (mimeGroups != null && mimeGroups.size() > 500) { throw new IllegalStateException("Max limit on number of MIME Groups reached"); } mimeGroups = ArrayUtils.add(mimeGroups, filter.getMimeGroup(groupIndex)); } } Loading core/java/android/hardware/usb/UsbDeviceConnection.java +28 −0 Original line number Diff line number Diff line Loading @@ -107,6 +107,34 @@ public class UsbDeviceConnection { } } /** * This is meant to be called by UsbRequest's queue() in order to synchronize on * UsbDeviceConnection's mLock to prevent the connection being closed while queueing. */ /* package */ boolean queueRequest(UsbRequest request, ByteBuffer buffer, int length) { synchronized (mLock) { if (!isOpen()) { return false; } return request.queueIfConnectionOpen(buffer, length); } } /** * This is meant to be called by UsbRequest's queue() in order to synchronize on * UsbDeviceConnection's mLock to prevent the connection being closed while queueing. */ /* package */ boolean queueRequest(UsbRequest request, @Nullable ByteBuffer buffer) { synchronized (mLock) { if (!isOpen()) { return false; } return request.queueIfConnectionOpen(buffer); } } /** * Releases all system resources related to the device. * Once the object is closed it cannot be used again. Loading core/java/android/hardware/usb/UsbRequest.java +58 −10 Original line number Diff line number Diff line Loading @@ -113,6 +113,7 @@ public class UsbRequest { * Releases all resources related to this request. */ public void close() { synchronized (mLock) { if (mNativeContext != 0) { mEndpoint = null; mConnection = null; Loading @@ -120,6 +121,7 @@ public class UsbRequest { mCloseGuard.close(); } } } @Override protected void finalize() throws Throwable { Loading Loading @@ -191,10 +193,32 @@ public class UsbRequest { */ @Deprecated public boolean queue(ByteBuffer buffer, int length) { UsbDeviceConnection connection = mConnection; if (connection == null) { // The expected exception by CTS Verifier - USB Device test throw new NullPointerException("invalid connection"); } // Calling into the underlying UsbDeviceConnection to synchronize on its lock, to prevent // the connection being closed while queueing. return connection.queueRequest(this, buffer, length); } /** * This is meant to be called from UsbDeviceConnection after synchronizing using the lock over * there, to prevent the connection being closed while queueing. */ /* package */ boolean queueIfConnectionOpen(ByteBuffer buffer, int length) { UsbDeviceConnection connection = mConnection; if (connection == null || !connection.isOpen()) { // The expected exception by CTS Verifier - USB Device test throw new NullPointerException("invalid connection"); } boolean out = (mEndpoint.getDirection() == UsbConstants.USB_DIR_OUT); boolean result; if (mConnection.getContext().getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.P if (connection.getContext().getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.P && length > MAX_USBFS_BUFFER_SIZE) { length = MAX_USBFS_BUFFER_SIZE; } Loading Loading @@ -243,6 +267,28 @@ public class UsbRequest { * @return true if the queueing operation succeeded */ public boolean queue(@Nullable ByteBuffer buffer) { UsbDeviceConnection connection = mConnection; if (connection == null) { // The expected exception by CTS Verifier - USB Device test throw new IllegalStateException("invalid connection"); } // Calling into the underlying UsbDeviceConnection to synchronize on its lock, to prevent // the connection being closed while queueing. return connection.queueRequest(this, buffer); } /** * This is meant to be called from UsbDeviceConnection after synchronizing using the lock over * there, to prevent the connection being closed while queueing. */ /* package */ boolean queueIfConnectionOpen(@Nullable ByteBuffer buffer) { UsbDeviceConnection connection = mConnection; if (connection == null || !connection.isOpen()) { // The expected exception by CTS Verifier - USB Device test throw new IllegalStateException("invalid connection"); } // Request need to be initialized Preconditions.checkState(mNativeContext != 0, "request is not initialized"); Loading @@ -260,7 +306,7 @@ public class UsbRequest { mIsUsingNewQueue = true; wasQueued = native_queue(null, 0, 0); } else { if (mConnection.getContext().getApplicationInfo().targetSdkVersion if (connection.getContext().getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.P) { // Can only send/receive MAX_USBFS_BUFFER_SIZE bytes at once Preconditions.checkArgumentInRange(buffer.remaining(), 0, MAX_USBFS_BUFFER_SIZE, Loading Loading @@ -363,11 +409,12 @@ public class UsbRequest { * @return true if cancelling succeeded */ public boolean cancel() { if (mConnection == null) { UsbDeviceConnection connection = mConnection; if (connection == null) { return false; } return mConnection.cancelRequest(this); return connection.cancelRequest(this); } /** Loading @@ -382,7 +429,8 @@ public class UsbRequest { * @return true if cancelling succeeded. */ /* package */ boolean cancelIfOpen() { if (mNativeContext == 0 || (mConnection != null && !mConnection.isOpen())) { UsbDeviceConnection connection = mConnection; if (mNativeContext == 0 || (connection != null && !connection.isOpen())) { Log.w(TAG, "Detected attempt to cancel a request on a connection which isn't open"); return false; Loading core/java/android/service/notification/Condition.java +34 −4 Original line number Diff line number Diff line Loading @@ -89,6 +89,12 @@ public final class Condition implements Parcelable { public final int flags; public final int icon; /** * The maximum string length for any string contained in this condition. * @hide */ public static final int MAX_STRING_LENGTH = 1000; /** * An object representing the current state of a {@link android.app.AutomaticZenRule}. * @param id the {@link android.app.AutomaticZenRule#getConditionId()} of the zen rule Loading @@ -103,16 +109,19 @@ public final class Condition implements Parcelable { if (id == null) throw new IllegalArgumentException("id is required"); if (summary == null) throw new IllegalArgumentException("summary is required"); if (!isValidState(state)) throw new IllegalArgumentException("state is invalid: " + state); this.id = id; this.summary = summary; this.line1 = line1; this.line2 = line2; this.id = getTrimmedUri(id); this.summary = getTrimmedString(summary); this.line1 = getTrimmedString(line1); this.line2 = getTrimmedString(line2); this.icon = icon; this.state = state; this.flags = flags; } public Condition(Parcel source) { // This constructor passes all fields directly into the constructor that takes all the // fields as arguments; that constructor will trim each of the input strings to // max length if necessary. this((Uri)source.readParcelable(Condition.class.getClassLoader()), source.readString(), source.readString(), Loading Loading @@ -239,4 +248,25 @@ public final class Condition implements Parcelable { return new Condition[size]; } }; /** * Returns a truncated copy of the string if the string is longer than MAX_STRING_LENGTH. */ private static String getTrimmedString(String input) { if (input != null && input.length() > MAX_STRING_LENGTH) { return input.substring(0, MAX_STRING_LENGTH); } return input; } /** * Returns a truncated copy of the Uri by trimming the string representation to the maximum * string length. */ private static Uri getTrimmedUri(Uri input) { if (input != null && input.toString().length() > MAX_STRING_LENGTH) { return Uri.parse(getTrimmedString(input.toString())); } return input; } } Loading
core/java/android/app/AutomaticZenRule.java +1 −1 Original line number Diff line number Diff line Loading @@ -125,7 +125,7 @@ public final class AutomaticZenRule implements Parcelable { name = getTrimmedString(source.readString()); } interruptionFilter = source.readInt(); conditionId = source.readParcelable(null); conditionId = getTrimmedUri(source.readParcelable(null)); owner = getTrimmedComponentName(source.readParcelable(null)); configurationActivity = getTrimmedComponentName(source.readParcelable(null)); creationTime = source.readLong(); Loading
core/java/android/content/pm/parsing/ParsingPackageImpl.java +3 −0 Original line number Diff line number Diff line Loading @@ -1584,6 +1584,9 @@ public class ParsingPackageImpl implements ParsingPackage, Parcelable { for (int i = component.getIntents().size() - 1; i >= 0; i--) { IntentFilter filter = component.getIntents().get(i); for (int groupIndex = filter.countMimeGroups() - 1; groupIndex >= 0; groupIndex--) { if (mimeGroups != null && mimeGroups.size() > 500) { throw new IllegalStateException("Max limit on number of MIME Groups reached"); } mimeGroups = ArrayUtils.add(mimeGroups, filter.getMimeGroup(groupIndex)); } } Loading
core/java/android/hardware/usb/UsbDeviceConnection.java +28 −0 Original line number Diff line number Diff line Loading @@ -107,6 +107,34 @@ public class UsbDeviceConnection { } } /** * This is meant to be called by UsbRequest's queue() in order to synchronize on * UsbDeviceConnection's mLock to prevent the connection being closed while queueing. */ /* package */ boolean queueRequest(UsbRequest request, ByteBuffer buffer, int length) { synchronized (mLock) { if (!isOpen()) { return false; } return request.queueIfConnectionOpen(buffer, length); } } /** * This is meant to be called by UsbRequest's queue() in order to synchronize on * UsbDeviceConnection's mLock to prevent the connection being closed while queueing. */ /* package */ boolean queueRequest(UsbRequest request, @Nullable ByteBuffer buffer) { synchronized (mLock) { if (!isOpen()) { return false; } return request.queueIfConnectionOpen(buffer); } } /** * Releases all system resources related to the device. * Once the object is closed it cannot be used again. Loading
core/java/android/hardware/usb/UsbRequest.java +58 −10 Original line number Diff line number Diff line Loading @@ -113,6 +113,7 @@ public class UsbRequest { * Releases all resources related to this request. */ public void close() { synchronized (mLock) { if (mNativeContext != 0) { mEndpoint = null; mConnection = null; Loading @@ -120,6 +121,7 @@ public class UsbRequest { mCloseGuard.close(); } } } @Override protected void finalize() throws Throwable { Loading Loading @@ -191,10 +193,32 @@ public class UsbRequest { */ @Deprecated public boolean queue(ByteBuffer buffer, int length) { UsbDeviceConnection connection = mConnection; if (connection == null) { // The expected exception by CTS Verifier - USB Device test throw new NullPointerException("invalid connection"); } // Calling into the underlying UsbDeviceConnection to synchronize on its lock, to prevent // the connection being closed while queueing. return connection.queueRequest(this, buffer, length); } /** * This is meant to be called from UsbDeviceConnection after synchronizing using the lock over * there, to prevent the connection being closed while queueing. */ /* package */ boolean queueIfConnectionOpen(ByteBuffer buffer, int length) { UsbDeviceConnection connection = mConnection; if (connection == null || !connection.isOpen()) { // The expected exception by CTS Verifier - USB Device test throw new NullPointerException("invalid connection"); } boolean out = (mEndpoint.getDirection() == UsbConstants.USB_DIR_OUT); boolean result; if (mConnection.getContext().getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.P if (connection.getContext().getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.P && length > MAX_USBFS_BUFFER_SIZE) { length = MAX_USBFS_BUFFER_SIZE; } Loading Loading @@ -243,6 +267,28 @@ public class UsbRequest { * @return true if the queueing operation succeeded */ public boolean queue(@Nullable ByteBuffer buffer) { UsbDeviceConnection connection = mConnection; if (connection == null) { // The expected exception by CTS Verifier - USB Device test throw new IllegalStateException("invalid connection"); } // Calling into the underlying UsbDeviceConnection to synchronize on its lock, to prevent // the connection being closed while queueing. return connection.queueRequest(this, buffer); } /** * This is meant to be called from UsbDeviceConnection after synchronizing using the lock over * there, to prevent the connection being closed while queueing. */ /* package */ boolean queueIfConnectionOpen(@Nullable ByteBuffer buffer) { UsbDeviceConnection connection = mConnection; if (connection == null || !connection.isOpen()) { // The expected exception by CTS Verifier - USB Device test throw new IllegalStateException("invalid connection"); } // Request need to be initialized Preconditions.checkState(mNativeContext != 0, "request is not initialized"); Loading @@ -260,7 +306,7 @@ public class UsbRequest { mIsUsingNewQueue = true; wasQueued = native_queue(null, 0, 0); } else { if (mConnection.getContext().getApplicationInfo().targetSdkVersion if (connection.getContext().getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.P) { // Can only send/receive MAX_USBFS_BUFFER_SIZE bytes at once Preconditions.checkArgumentInRange(buffer.remaining(), 0, MAX_USBFS_BUFFER_SIZE, Loading Loading @@ -363,11 +409,12 @@ public class UsbRequest { * @return true if cancelling succeeded */ public boolean cancel() { if (mConnection == null) { UsbDeviceConnection connection = mConnection; if (connection == null) { return false; } return mConnection.cancelRequest(this); return connection.cancelRequest(this); } /** Loading @@ -382,7 +429,8 @@ public class UsbRequest { * @return true if cancelling succeeded. */ /* package */ boolean cancelIfOpen() { if (mNativeContext == 0 || (mConnection != null && !mConnection.isOpen())) { UsbDeviceConnection connection = mConnection; if (mNativeContext == 0 || (connection != null && !connection.isOpen())) { Log.w(TAG, "Detected attempt to cancel a request on a connection which isn't open"); return false; Loading
core/java/android/service/notification/Condition.java +34 −4 Original line number Diff line number Diff line Loading @@ -89,6 +89,12 @@ public final class Condition implements Parcelable { public final int flags; public final int icon; /** * The maximum string length for any string contained in this condition. * @hide */ public static final int MAX_STRING_LENGTH = 1000; /** * An object representing the current state of a {@link android.app.AutomaticZenRule}. * @param id the {@link android.app.AutomaticZenRule#getConditionId()} of the zen rule Loading @@ -103,16 +109,19 @@ public final class Condition implements Parcelable { if (id == null) throw new IllegalArgumentException("id is required"); if (summary == null) throw new IllegalArgumentException("summary is required"); if (!isValidState(state)) throw new IllegalArgumentException("state is invalid: " + state); this.id = id; this.summary = summary; this.line1 = line1; this.line2 = line2; this.id = getTrimmedUri(id); this.summary = getTrimmedString(summary); this.line1 = getTrimmedString(line1); this.line2 = getTrimmedString(line2); this.icon = icon; this.state = state; this.flags = flags; } public Condition(Parcel source) { // This constructor passes all fields directly into the constructor that takes all the // fields as arguments; that constructor will trim each of the input strings to // max length if necessary. this((Uri)source.readParcelable(Condition.class.getClassLoader()), source.readString(), source.readString(), Loading Loading @@ -239,4 +248,25 @@ public final class Condition implements Parcelable { return new Condition[size]; } }; /** * Returns a truncated copy of the string if the string is longer than MAX_STRING_LENGTH. */ private static String getTrimmedString(String input) { if (input != null && input.length() > MAX_STRING_LENGTH) { return input.substring(0, MAX_STRING_LENGTH); } return input; } /** * Returns a truncated copy of the Uri by trimming the string representation to the maximum * string length. */ private static Uri getTrimmedUri(Uri input) { if (input != null && input.toString().length() > MAX_STRING_LENGTH) { return Uri.parse(getTrimmedString(input.toString())); } return input; } }