code
stringlengths 11
173k
| docstring
stringlengths 2
593k
| func_name
stringlengths 2
189
| language
stringclasses 1
value | repo
stringclasses 844
values | path
stringlengths 11
294
| url
stringlengths 60
339
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
private SurfaceControl getWindowSurfaceControl() {
return mWindowManager.mSystemWindows.getViewSurface(this);
} |
Tries to grab a surface control from ViewRootImpl. If this isn't available for some reason
(ie. the window isn't ready yet), it will get the surfacecontrol that the WindowlessWM has
assigned to it.
| DividerView::getWindowSurfaceControl | java | Reginer/aosp-android-jar | android-33/src/com/android/wm/shell/legacysplitscreen/DividerView.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/wm/shell/legacysplitscreen/DividerView.java | MIT |
private int restrictDismissingTaskPosition(int taskPosition, int dockSide,
SnapTarget snapTarget) {
if (snapTarget.flag == SnapTarget.FLAG_DISMISS_START && dockSideTopLeft(dockSide)) {
return Math.max(mSplitLayout.getSnapAlgorithm().getFirstSplitTarget().position,
mStartPosition);
} else if (snapTarget.flag == SnapTarget.FLAG_DISMISS_END
&& dockSideBottomRight(dockSide)) {
return Math.min(mSplitLayout.getSnapAlgorithm().getLastSplitTarget().position,
mStartPosition);
} else {
return taskPosition;
}
} |
When the snap target is dismissing one side, make sure that the dismissing side doesn't get
0 size.
| DividerView::restrictDismissingTaskPosition | java | Reginer/aosp-android-jar | android-33/src/com/android/wm/shell/legacysplitscreen/DividerView.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/wm/shell/legacysplitscreen/DividerView.java | MIT |
private void applyDismissingParallax(Rect taskRect, int dockSide, SnapTarget snapTarget,
int position, int taskPosition) {
float fraction = Math.min(1, Math.max(0,
mSplitLayout.getSnapAlgorithm().calculateDismissingFraction(position)));
SnapTarget dismissTarget = null;
SnapTarget splitTarget = null;
int start = 0;
if (position <= mSplitLayout.getSnapAlgorithm().getLastSplitTarget().position
&& dockSideTopLeft(dockSide)) {
dismissTarget = mSplitLayout.getSnapAlgorithm().getDismissStartTarget();
splitTarget = mSplitLayout.getSnapAlgorithm().getFirstSplitTarget();
start = taskPosition;
} else if (position >= mSplitLayout.getSnapAlgorithm().getLastSplitTarget().position
&& dockSideBottomRight(dockSide)) {
dismissTarget = mSplitLayout.getSnapAlgorithm().getDismissEndTarget();
splitTarget = mSplitLayout.getSnapAlgorithm().getLastSplitTarget();
start = splitTarget.position;
}
if (dismissTarget != null && fraction > 0f
&& isDismissing(splitTarget, position, dockSide)) {
fraction = calculateParallaxDismissingFraction(fraction, dockSide);
int offsetPosition = (int) (start + fraction
* (dismissTarget.position - splitTarget.position));
int width = taskRect.width();
int height = taskRect.height();
switch (dockSide) {
case WindowManager.DOCKED_LEFT:
taskRect.left = offsetPosition - width;
taskRect.right = offsetPosition;
break;
case WindowManager.DOCKED_RIGHT:
taskRect.left = offsetPosition + mDividerSize;
taskRect.right = offsetPosition + width + mDividerSize;
break;
case WindowManager.DOCKED_TOP:
taskRect.top = offsetPosition - height;
taskRect.bottom = offsetPosition;
break;
case WindowManager.DOCKED_BOTTOM:
taskRect.top = offsetPosition + mDividerSize;
taskRect.bottom = offsetPosition + height + mDividerSize;
break;
}
}
} |
Applies a parallax to the task when dismissing.
| DividerView::applyDismissingParallax | java | Reginer/aosp-android-jar | android-33/src/com/android/wm/shell/legacysplitscreen/DividerView.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/wm/shell/legacysplitscreen/DividerView.java | MIT |
private static float calculateParallaxDismissingFraction(float fraction, int dockSide) {
float result = SLOWDOWN_INTERPOLATOR.getInterpolation(fraction) / 3.5f;
// Less parallax at the top, just because.
if (dockSide == WindowManager.DOCKED_TOP) {
result /= 2f;
}
return result;
} |
@return for a specified {@code fraction}, this returns an adjusted value that simulates a
slowing down parallax effect
| DividerView::calculateParallaxDismissingFraction | java | Reginer/aosp-android-jar | android-33/src/com/android/wm/shell/legacysplitscreen/DividerView.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/wm/shell/legacysplitscreen/DividerView.java | MIT |
private static boolean dockSideTopLeft(int dockSide) {
return dockSide == WindowManager.DOCKED_TOP || dockSide == WindowManager.DOCKED_LEFT;
} |
@return true if and only if {@code dockSide} is top or left
| DividerView::dockSideTopLeft | java | Reginer/aosp-android-jar | android-33/src/com/android/wm/shell/legacysplitscreen/DividerView.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/wm/shell/legacysplitscreen/DividerView.java | MIT |
private static boolean dockSideBottomRight(int dockSide) {
return dockSide == WindowManager.DOCKED_BOTTOM || dockSide == WindowManager.DOCKED_RIGHT;
} |
@return true if and only if {@code dockSide} is bottom or right
| DividerView::dockSideBottomRight | java | Reginer/aosp-android-jar | android-33/src/com/android/wm/shell/legacysplitscreen/DividerView.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/wm/shell/legacysplitscreen/DividerView.java | MIT |
private boolean shouldInvokeCallback(MidiDeviceInfo device) {
// UMP devices have protocols that are not PROTOCOL_UNKNOWN
if (mTransport == TRANSPORT_UNIVERSAL_MIDI_PACKETS) {
return (device.getDefaultProtocol() != MidiDeviceInfo.PROTOCOL_UNKNOWN);
} else if (mTransport == TRANSPORT_MIDI_BYTE_STREAM) {
return (device.getDefaultProtocol() == MidiDeviceInfo.PROTOCOL_UNKNOWN);
} else {
Log.e(TAG, "Invalid transport type: " + mTransport);
return false;
}
} |
Used to figure out whether callbacks should be invoked. Only invoke callbacks of
the correct type.
@param MidiDeviceInfo the device to check
@return whether to invoke a callback
| DeviceListener::shouldInvokeCallback | java | Reginer/aosp-android-jar | android-34/src/android/media/midi/MidiManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/media/midi/MidiManager.java | MIT |
public void onDeviceAdded(MidiDeviceInfo device) {
} |
Called to notify when a new MIDI device has been added
@param device a {@link MidiDeviceInfo} for the newly added device
| DeviceCallback::onDeviceAdded | java | Reginer/aosp-android-jar | android-34/src/android/media/midi/MidiManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/media/midi/MidiManager.java | MIT |
public void onDeviceRemoved(MidiDeviceInfo device) {
} |
Called to notify when a MIDI device has been removed
@param device a {@link MidiDeviceInfo} for the removed device
| DeviceCallback::onDeviceRemoved | java | Reginer/aosp-android-jar | android-34/src/android/media/midi/MidiManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/media/midi/MidiManager.java | MIT |
public void onDeviceStatusChanged(MidiDeviceStatus status) {
} |
Called to notify when the status of a MIDI device has changed
@param status a {@link MidiDeviceStatus} for the changed device
| DeviceCallback::onDeviceStatusChanged | java | Reginer/aosp-android-jar | android-34/src/android/media/midi/MidiManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/media/midi/MidiManager.java | MIT |
public MidiManager(IMidiManager service) {
mService = service;
} |
@hide
| DeviceCallback::MidiManager | java | Reginer/aosp-android-jar | android-34/src/android/media/midi/MidiManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/media/midi/MidiManager.java | MIT |
public void registerDeviceCallback(@Transport int transport,
@NonNull Executor executor, @NonNull DeviceCallback callback) {
Objects.requireNonNull(executor);
DeviceListener deviceListener = new DeviceListener(callback, executor, transport);
try {
mService.registerListener(mToken, deviceListener);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
mDeviceListeners.put(callback, deviceListener);
} |
Registers a callback to receive notifications when MIDI devices are added and removed
for a specific transport type.
The {@link DeviceCallback#onDeviceStatusChanged} method will be called immediately
for any devices that have open ports. This allows applications to know which input
ports are already in use and, therefore, unavailable.
Applications should call {@link #getDevicesForTransport} before registering the callback
to get a list of devices already added.
@param transport The transport to be used. This is either TRANSPORT_MIDI_BYTE_STREAM or
TRANSPORT_UNIVERSAL_MIDI_PACKETS.
@param executor The {@link Executor} that will be used for delivering the
device notifications.
@param callback a {@link DeviceCallback} for MIDI device notifications
| DeviceCallback::registerDeviceCallback | java | Reginer/aosp-android-jar | android-34/src/android/media/midi/MidiManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/media/midi/MidiManager.java | MIT |
public void unregisterDeviceCallback(DeviceCallback callback) {
DeviceListener deviceListener = mDeviceListeners.remove(callback);
if (deviceListener != null) {
try {
mService.unregisterListener(mToken, deviceListener);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
} |
Unregisters a {@link DeviceCallback}.
@param callback a {@link DeviceCallback} to unregister
| DeviceCallback::unregisterDeviceCallback | java | Reginer/aosp-android-jar | android-34/src/android/media/midi/MidiManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/media/midi/MidiManager.java | MIT |
public @NonNull Set<MidiDeviceInfo> getDevicesForTransport(@Transport int transport) {
try {
MidiDeviceInfo[] devices = mService.getDevicesForTransport(transport);
if (devices == null) {
return Collections.emptySet();
}
return new ArraySet<>(devices);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Gets a list of connected MIDI devices by transport. TRANSPORT_MIDI_BYTE_STREAM
is used for MIDI 1.0 and is the most common.
For devices with built in Universal MIDI Packet support, use
TRANSPORT_UNIVERSAL_MIDI_PACKETS instead.
@param transport The transport to be used. This is either TRANSPORT_MIDI_BYTE_STREAM or
TRANSPORT_UNIVERSAL_MIDI_PACKETS.
@return a collection of MIDI devices
| DeviceCallback::getDevicesForTransport | java | Reginer/aosp-android-jar | android-34/src/android/media/midi/MidiManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/media/midi/MidiManager.java | MIT |
public void openDevice(MidiDeviceInfo deviceInfo, OnDeviceOpenedListener listener,
Handler handler) {
final MidiDeviceInfo deviceInfoF = deviceInfo;
final OnDeviceOpenedListener listenerF = listener;
final Handler handlerF = handler;
IMidiDeviceOpenCallback callback = new IMidiDeviceOpenCallback.Stub() {
@Override
public void onDeviceOpened(IMidiDeviceServer server, IBinder deviceToken) {
MidiDevice device;
if (server != null) {
device = new MidiDevice(deviceInfoF, server, mService, mToken, deviceToken);
} else {
device = null;
}
sendOpenDeviceResponse(device, listenerF, handlerF);
}
};
try {
mService.openDevice(mToken, deviceInfo, callback);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Opens a MIDI device for reading and writing.
@param deviceInfo a {@link android.media.midi.MidiDeviceInfo} to open
@param listener a {@link MidiManager.OnDeviceOpenedListener} to be called
to receive the result
@param handler the {@link android.os.Handler Handler} that will be used for delivering
the result. If handler is null, then the thread used for the
listener is unspecified.
| DeviceCallback::openDevice | java | Reginer/aosp-android-jar | android-34/src/android/media/midi/MidiManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/media/midi/MidiManager.java | MIT |
public void openBluetoothDevice(BluetoothDevice bluetoothDevice,
OnDeviceOpenedListener listener, Handler handler) {
final OnDeviceOpenedListener listenerF = listener;
final Handler handlerF = handler;
Log.d(TAG, "openBluetoothDevice() " + bluetoothDevice);
IMidiDeviceOpenCallback callback = new IMidiDeviceOpenCallback.Stub() {
@Override
public void onDeviceOpened(IMidiDeviceServer server, IBinder deviceToken) {
Log.d(TAG, "onDeviceOpened() server:" + server);
MidiDevice device = null;
if (server != null) {
try {
// fetch MidiDeviceInfo from the server
MidiDeviceInfo deviceInfo = server.getDeviceInfo();
device = new MidiDevice(deviceInfo, server, mService, mToken, deviceToken);
} catch (RemoteException e) {
Log.e(TAG, "remote exception in getDeviceInfo()");
}
}
sendOpenDeviceResponse(device, listenerF, handlerF);
}
};
try {
mService.openBluetoothDevice(mToken, bluetoothDevice, callback);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Opens a Bluetooth MIDI device for reading and writing.
@param bluetoothDevice a {@link android.bluetooth.BluetoothDevice} to open as a MIDI device
@param listener a {@link MidiManager.OnDeviceOpenedListener} to be called to receive the
result
@param handler the {@link android.os.Handler Handler} that will be used for delivering
the result. If handler is null, then the thread used for the
listener is unspecified.
| DeviceCallback::openBluetoothDevice | java | Reginer/aosp-android-jar | android-34/src/android/media/midi/MidiManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/media/midi/MidiManager.java | MIT |
public MidiDeviceServer createDeviceServer(MidiReceiver[] inputPortReceivers,
int numOutputPorts, String[] inputPortNames, String[] outputPortNames,
Bundle properties, int type, int defaultProtocol,
MidiDeviceServer.Callback callback) {
try {
MidiDeviceServer server = new MidiDeviceServer(mService, inputPortReceivers,
numOutputPorts, callback);
MidiDeviceInfo deviceInfo = mService.registerDeviceServer(server.getBinderInterface(),
inputPortReceivers.length, numOutputPorts, inputPortNames, outputPortNames,
properties, type, defaultProtocol);
if (deviceInfo == null) {
Log.e(TAG, "registerVirtualDevice failed");
return null;
}
return server;
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} | @hide */ // for now
public void closeBluetoothDevice(@NonNull MidiDevice midiDevice) {
try {
midiDevice.close();
} catch (IOException ex) {
Log.e(TAG, "Exception closing BLE-MIDI device" + ex);
}
}
/** @hide | DeviceCallback::createDeviceServer | java | Reginer/aosp-android-jar | android-34/src/android/media/midi/MidiManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/media/midi/MidiManager.java | MIT |
public final void invalidateList(@Nullable String reason) {
if (mListener != null) {
if (Trace.isEnabled()) {
Trace.traceBegin(Trace.TRACE_TAG_APP, "Pluggable<" + mName + ">.invalidateList");
}
mListener.onPluggableInvalidated((This) this, reason);
Trace.endSection();
}
} |
Call this method when something has caused this pluggable's behavior to change. The pipeline
will be re-run.
| Pluggable::invalidateList | java | Reginer/aosp-android-jar | android-34/src/com/android/systemui/statusbar/notification/collection/listbuilder/pluggable/Pluggable.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/systemui/statusbar/notification/collection/listbuilder/pluggable/Pluggable.java | MIT |
public final void setInvalidationListener(PluggableListener<This> listener) {
mListener = listener;
} |
Call this method when something has caused this pluggable's behavior to change. The pipeline
will be re-run.
public final void invalidateList(@Nullable String reason) {
if (mListener != null) {
if (Trace.isEnabled()) {
Trace.traceBegin(Trace.TRACE_TAG_APP, "Pluggable<" + mName + ">.invalidateList");
}
mListener.onPluggableInvalidated((This) this, reason);
Trace.endSection();
}
}
/** Set a listener to be notified when a pluggable is invalidated. | Pluggable::setInvalidationListener | java | Reginer/aosp-android-jar | android-34/src/com/android/systemui/statusbar/notification/collection/listbuilder/pluggable/Pluggable.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/systemui/statusbar/notification/collection/listbuilder/pluggable/Pluggable.java | MIT |
public void onCleanup() { } |
Called on the pluggable once at the end of every pipeline run. Override this method to
perform any necessary cleanup.
| Pluggable::onCleanup | java | Reginer/aosp-android-jar | android-34/src/com/android/systemui/statusbar/notification/collection/listbuilder/pluggable/Pluggable.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/systemui/statusbar/notification/collection/listbuilder/pluggable/Pluggable.java | MIT |
default boolean onInterceptTouchEvent(MotionEvent ev) {
return false;
} | /*
Copyright (C) 2012 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
package com.android.systemui;
import android.view.MotionEvent;
// ACHTUNG!
public interface Gefingerpoken {
/** Called when a touch is being intercepted in a ViewGroup. | onInterceptTouchEvent | java | Reginer/aosp-android-jar | android-34/src/com/android/systemui/Gefingerpoken.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/systemui/Gefingerpoken.java | MIT |
default boolean onTouchEvent(MotionEvent ev) {
return false;
} | /*
Copyright (C) 2012 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
package com.android.systemui;
import android.view.MotionEvent;
// ACHTUNG!
public interface Gefingerpoken {
/** Called when a touch is being intercepted in a ViewGroup.
default boolean onInterceptTouchEvent(MotionEvent ev) {
return false;
}
/** Called when a touch is being handled by a view. | onTouchEvent | java | Reginer/aosp-android-jar | android-34/src/com/android/systemui/Gefingerpoken.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/systemui/Gefingerpoken.java | MIT |
public Type getType() {
return mType;
} |
Return the dynamic {@link Type} corresponding to the captured type {@code T}.
| TypeReference::getType | java | Reginer/aosp-android-jar | android-33/src/android/hardware/camera2/utils/TypeReference.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/hardware/camera2/utils/TypeReference.java | MIT |
public static <T> TypeReference<T> createSpecializedTypeReference(Class<T> klass) {
return new SpecializedTypeReference<T>(klass);
} |
Create a specialized type reference from a dynamic class instance,
bypassing the standard compile-time checks.
<p>As with a regular type reference, the {@code klass} must not contain
any type variables.</p>
@param klass a non-{@code null} {@link Class} instance
@return a type reference which captures {@code T} at runtime
@throws IllegalArgumentException if {@code T} had any type variables
| SpecializedBaseTypeReference::createSpecializedTypeReference | java | Reginer/aosp-android-jar | android-33/src/android/hardware/camera2/utils/TypeReference.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/hardware/camera2/utils/TypeReference.java | MIT |
public TypeReference<?> getComponentType() {
Type componentType = getComponentType(mType);
return (componentType != null) ?
createSpecializedTypeReference(componentType) :
null;
} |
Get the component type, e.g. {@code T} from {@code T[]}.
@return component type, or {@code null} if {@code T} is not an array
| SpecializedBaseTypeReference::getComponentType | java | Reginer/aosp-android-jar | android-33/src/android/hardware/camera2/utils/TypeReference.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/hardware/camera2/utils/TypeReference.java | MIT |
public static boolean containsTypeVariable(Type type) {
if (type == null) {
// Trivially false
return false;
} else if (type instanceof TypeVariable<?>) {
/*
* T -> trivially true
*/
return true;
} else if (type instanceof Class<?>) {
/*
* class Foo -> no type variable
* class Foo<T> - has a type variable
*
* This also covers the case of class Foo<T> extends ... / implements ...
* since everything on the right hand side would either include a type variable T
* or have no type variables.
*/
Class<?> klass = (Class<?>)type;
// Empty array => class is not generic
if (klass.getTypeParameters().length != 0) {
return true;
} else {
// Does the outer class(es) contain any type variables?
/*
* class Outer<T> {
* class Inner {
* T field;
* }
* }
*
* In this case 'Inner' has no type parameters itself, but it still has a type
* variable as part of the type definition.
*/
return containsTypeVariable(klass.getDeclaringClass());
}
} else if (type instanceof ParameterizedType) {
/*
* This is the "Foo<T1, T2, T3, ... Tn>" in the scope of a
*
* // no type variables here, T1-Tn are known at this definition
* class X extends Foo<T1, T2, T3, ... Tn>
*
* // T1 is a type variable, T2-Tn are known at this definition
* class X<T1> extends Foo<T1, T2, T3, ... Tn>
*/
ParameterizedType p = (ParameterizedType) type;
// This needs to be recursively checked
for (Type arg : p.getActualTypeArguments()) {
if (containsTypeVariable(arg)) {
return true;
}
}
return false;
} else if (type instanceof WildcardType) {
WildcardType wild = (WildcardType) type;
/*
* This is is the "?" inside of a
*
* Foo<?> --> unbounded; trivially no type variables
* Foo<? super T> --> lower bound; does T have a type variable?
* Foo<? extends T> --> upper bound; does T have a type variable?
*/
/*
* According to JLS 4.5.1
* (http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.5.1):
*
* - More than 1 lower/upper bound is illegal
* - Both a lower and upper bound is illegal
*
* However, we use this 'array OR array' approach for readability
*/
return containsTypeVariable(wild.getLowerBounds()) ||
containsTypeVariable(wild.getUpperBounds());
}
return false;
} |
Check if the {@code type} contains a {@link TypeVariable} recursively.
<p>Intuitively, a type variable is a type in a type expression that refers to a generic
type which is not known at the definition of the expression (commonly seen when
type parameters are used, e.g. {@code class Foo<T>}).</p>
<p>See <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.4">
http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.4</a>
for a more formal definition of a type variable</p>.
@param type a type object ({@code null} is allowed)
@return {@code true} if there were nested type variables; {@code false} otherwise
| SpecializedBaseTypeReference::containsTypeVariable | java | Reginer/aosp-android-jar | android-33/src/android/hardware/camera2/utils/TypeReference.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/hardware/camera2/utils/TypeReference.java | MIT |
private static boolean containsTypeVariable(Type[] typeArray) {
if (typeArray == null) {
return false;
}
for (Type type : typeArray) {
if (containsTypeVariable(type)) {
return true;
}
}
return false;
} |
Check if any of the elements in this array contained a type variable.
<p>Empty and null arrays trivially have no type variables.</p>
@param typeArray an array ({@code null} is ok) of types
@return true if any elements contained a type variable; false otherwise
| SpecializedBaseTypeReference::containsTypeVariable | java | Reginer/aosp-android-jar | android-33/src/android/hardware/camera2/utils/TypeReference.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/hardware/camera2/utils/TypeReference.java | MIT |
public String getClassName() {
return getName();
} |
A main component's name is a class name. This makes code slightly more readable.
| private::getClassName | java | Reginer/aosp-android-jar | android-31/src/android/content/pm/parsing/component/ParsedMainComponent.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/content/pm/parsing/component/ParsedMainComponent.java | MIT |
void initialize(CharSequence title, Drawable icon) {
setClickable(true);
setFocusable(true);
if (mTextAppearance != -1) {
setTextAppearance(mTextAppearanceContext, mTextAppearance);
}
setTitle(title);
setIcon(icon);
if (mItemData != null) {
final CharSequence contentDescription = mItemData.getContentDescription();
if (TextUtils.isEmpty(contentDescription)) {
setContentDescription(title);
} else {
setContentDescription(contentDescription);
}
setTooltipText(mItemData.getTooltipText());
}
} |
Initializes with the provided title and icon
@param title The title of this item
@param icon The icon of this item
| IconMenuItemView::initialize | java | Reginer/aosp-android-jar | android-34/src/com/android/internal/view/menu/IconMenuItemView.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/internal/view/menu/IconMenuItemView.java | MIT |
private void positionIcon() {
if (mIcon == null) {
return;
}
// We reuse the output rectangle as a temp rect
Rect tmpRect = mPositionIconOutput;
getLineBounds(0, tmpRect);
mPositionIconAvailable.set(0, 0, getWidth(), tmpRect.top);
final int layoutDirection = getLayoutDirection();
Gravity.apply(Gravity.CENTER_VERTICAL | Gravity.START, mIcon.getIntrinsicWidth(), mIcon
.getIntrinsicHeight(), mPositionIconAvailable, mPositionIconOutput,
layoutDirection);
mIcon.setBounds(mPositionIconOutput);
} |
Positions the icon vertically (horizontal centering is taken care of by
the TextView's gravity).
| IconMenuItemView::positionIcon | java | Reginer/aosp-android-jar | android-34/src/com/android/internal/view/menu/IconMenuItemView.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/internal/view/menu/IconMenuItemView.java | MIT |
void waitForQueuedThread(AbstractQueuedSynchronizer sync, Thread t) {
long startTime = System.nanoTime();
while (!sync.isQueued(t)) {
if (millisElapsedSince(startTime) > LONG_DELAY_MS)
throw new AssertionFailedError("timed out");
Thread.yield();
}
assertTrue(t.isAlive());
} |
Spin-waits until sync.isQueued(t) becomes true.
| InterruptedSyncRunnable::waitForQueuedThread | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
void assertHasQueuedThreads(AbstractQueuedSynchronizer sync,
Thread... expected) {
Collection<Thread> actual = sync.getQueuedThreads();
assertEquals(expected.length > 0, sync.hasQueuedThreads());
assertEquals(expected.length, sync.getQueueLength());
assertEquals(expected.length, actual.size());
assertEquals(expected.length == 0, actual.isEmpty());
assertEquals(new HashSet<Thread>(actual),
new HashSet<Thread>(Arrays.asList(expected)));
} |
Checks that sync has exactly the given queued threads.
| InterruptedSyncRunnable::assertHasQueuedThreads | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
void assertHasExclusiveQueuedThreads(AbstractQueuedSynchronizer sync,
Thread... expected) {
assertHasQueuedThreads(sync, expected);
assertEquals(new HashSet<Thread>(sync.getExclusiveQueuedThreads()),
new HashSet<Thread>(sync.getQueuedThreads()));
assertEquals(0, sync.getSharedQueuedThreads().size());
assertTrue(sync.getSharedQueuedThreads().isEmpty());
} |
Checks that sync has exactly the given (exclusive) queued threads.
| InterruptedSyncRunnable::assertHasExclusiveQueuedThreads | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
void assertHasSharedQueuedThreads(AbstractQueuedSynchronizer sync,
Thread... expected) {
assertHasQueuedThreads(sync, expected);
assertEquals(new HashSet<Thread>(sync.getSharedQueuedThreads()),
new HashSet<Thread>(sync.getQueuedThreads()));
assertEquals(0, sync.getExclusiveQueuedThreads().size());
assertTrue(sync.getExclusiveQueuedThreads().isEmpty());
} |
Checks that sync has exactly the given (shared) queued threads.
| InterruptedSyncRunnable::assertHasSharedQueuedThreads | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
void assertHasWaitersUnlocked(Mutex sync, ConditionObject c,
Thread... threads) {
sync.acquire();
assertHasWaitersLocked(sync, c, threads);
sync.release();
} |
Checks that condition c has exactly the given waiter threads,
after acquiring mutex.
| InterruptedSyncRunnable::assertHasWaitersUnlocked | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
void assertHasWaitersLocked(Mutex sync, ConditionObject c,
Thread... threads) {
assertEquals(threads.length > 0, sync.hasWaiters(c));
assertEquals(threads.length, sync.getWaitQueueLength(c));
assertEquals(threads.length == 0, sync.getWaitingThreads(c).isEmpty());
assertEquals(threads.length, sync.getWaitingThreads(c).size());
assertEquals(new HashSet<Thread>(sync.getWaitingThreads(c)),
new HashSet<Thread>(Arrays.asList(threads)));
} |
Checks that condition c has exactly the given waiter threads.
| InterruptedSyncRunnable::assertHasWaitersLocked | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
void await(ConditionObject c, AwaitMethod awaitMethod)
throws InterruptedException {
long timeoutMillis = 2 * LONG_DELAY_MS;
switch (awaitMethod) {
case await:
c.await();
break;
case awaitTimed:
assertTrue(c.await(timeoutMillis, MILLISECONDS));
break;
case awaitNanos:
long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis);
long nanosRemaining = c.awaitNanos(nanosTimeout);
assertTrue(nanosRemaining > 0);
break;
case awaitUntil:
assertTrue(c.awaitUntil(delayedDate(timeoutMillis)));
break;
default:
throw new AssertionError();
}
} |
Awaits condition using the specified AwaitMethod.
| AwaitMethod::await | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
void assertAwaitTimesOut(ConditionObject c, AwaitMethod awaitMethod) {
long timeoutMillis = timeoutMillis();
long startTime;
try {
switch (awaitMethod) {
case awaitTimed:
startTime = System.nanoTime();
assertFalse(c.await(timeoutMillis, MILLISECONDS));
assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
break;
case awaitNanos:
startTime = System.nanoTime();
long nanosTimeout = MILLISECONDS.toNanos(timeoutMillis);
long nanosRemaining = c.awaitNanos(nanosTimeout);
assertTrue(nanosRemaining <= 0);
assertTrue(nanosRemaining > -MILLISECONDS.toNanos(LONG_DELAY_MS));
assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
break;
case awaitUntil:
// We shouldn't assume that nanoTime and currentTimeMillis
// use the same time source, so don't use nanoTime here.
java.util.Date delayedDate = delayedDate(timeoutMillis());
assertFalse(c.awaitUntil(delayedDate(timeoutMillis)));
assertTrue(new java.util.Date().getTime() >= delayedDate.getTime());
break;
default:
throw new UnsupportedOperationException();
}
} catch (InterruptedException ie) { threadUnexpectedException(ie); }
} |
Checks that awaiting the given condition times out (using the
default timeout duration).
| AwaitMethod::assertAwaitTimesOut | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testIsHeldExclusively() {
Mutex sync = new Mutex();
assertFalse(sync.isHeldExclusively());
} |
isHeldExclusively is false upon construction
| AwaitMethod::testIsHeldExclusively | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testAcquire() {
Mutex sync = new Mutex();
sync.acquire();
assertTrue(sync.isHeldExclusively());
sync.release();
assertFalse(sync.isHeldExclusively());
} |
acquiring released sync succeeds
| AwaitMethod::testAcquire | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testTryAcquire() {
Mutex sync = new Mutex();
assertTrue(sync.tryAcquire());
assertTrue(sync.isHeldExclusively());
sync.release();
assertFalse(sync.isHeldExclusively());
} |
tryAcquire on a released sync succeeds
| AwaitMethod::testTryAcquire | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testHasQueuedThreads() {
final Mutex sync = new Mutex();
assertFalse(sync.hasQueuedThreads());
sync.acquire();
Thread t1 = newStartedThread(new InterruptedSyncRunnable(sync));
waitForQueuedThread(sync, t1);
assertTrue(sync.hasQueuedThreads());
Thread t2 = newStartedThread(new InterruptibleSyncRunnable(sync));
waitForQueuedThread(sync, t2);
assertTrue(sync.hasQueuedThreads());
t1.interrupt();
awaitTermination(t1);
assertTrue(sync.hasQueuedThreads());
sync.release();
awaitTermination(t2);
assertFalse(sync.hasQueuedThreads());
} |
hasQueuedThreads reports whether there are waiting threads
| AwaitMethod::testHasQueuedThreads | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testIsQueuedNPE() {
final Mutex sync = new Mutex();
try {
sync.isQueued(null);
shouldThrow();
} catch (NullPointerException success) {}
} |
isQueued(null) throws NullPointerException
| AwaitMethod::testIsQueuedNPE | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testIsQueued() {
final Mutex sync = new Mutex();
Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
assertFalse(sync.isQueued(t1));
assertFalse(sync.isQueued(t2));
sync.acquire();
t1.start();
waitForQueuedThread(sync, t1);
assertTrue(sync.isQueued(t1));
assertFalse(sync.isQueued(t2));
t2.start();
waitForQueuedThread(sync, t2);
assertTrue(sync.isQueued(t1));
assertTrue(sync.isQueued(t2));
t1.interrupt();
awaitTermination(t1);
assertFalse(sync.isQueued(t1));
assertTrue(sync.isQueued(t2));
sync.release();
awaitTermination(t2);
assertFalse(sync.isQueued(t1));
assertFalse(sync.isQueued(t2));
} |
isQueued reports whether a thread is queued
| AwaitMethod::testIsQueued | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testGetFirstQueuedThread() {
final Mutex sync = new Mutex();
assertNull(sync.getFirstQueuedThread());
sync.acquire();
Thread t1 = newStartedThread(new InterruptedSyncRunnable(sync));
waitForQueuedThread(sync, t1);
assertEquals(t1, sync.getFirstQueuedThread());
Thread t2 = newStartedThread(new InterruptibleSyncRunnable(sync));
waitForQueuedThread(sync, t2);
assertEquals(t1, sync.getFirstQueuedThread());
t1.interrupt();
awaitTermination(t1);
assertEquals(t2, sync.getFirstQueuedThread());
sync.release();
awaitTermination(t2);
assertNull(sync.getFirstQueuedThread());
} |
getFirstQueuedThread returns first waiting thread or null if none
| AwaitMethod::testGetFirstQueuedThread | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testHasContended() {
final Mutex sync = new Mutex();
assertFalse(sync.hasContended());
sync.acquire();
assertFalse(sync.hasContended());
Thread t1 = newStartedThread(new InterruptedSyncRunnable(sync));
waitForQueuedThread(sync, t1);
assertTrue(sync.hasContended());
Thread t2 = newStartedThread(new InterruptibleSyncRunnable(sync));
waitForQueuedThread(sync, t2);
assertTrue(sync.hasContended());
t1.interrupt();
awaitTermination(t1);
assertTrue(sync.hasContended());
sync.release();
awaitTermination(t2);
assertTrue(sync.hasContended());
} |
hasContended reports false if no thread has ever blocked, else true
| AwaitMethod::testHasContended | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testGetQueuedThreads() {
final Mutex sync = new Mutex();
Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
assertHasExclusiveQueuedThreads(sync, NO_THREADS);
sync.acquire();
assertHasExclusiveQueuedThreads(sync, NO_THREADS);
t1.start();
waitForQueuedThread(sync, t1);
assertHasExclusiveQueuedThreads(sync, t1);
assertTrue(sync.getQueuedThreads().contains(t1));
assertFalse(sync.getQueuedThreads().contains(t2));
t2.start();
waitForQueuedThread(sync, t2);
assertHasExclusiveQueuedThreads(sync, t1, t2);
assertTrue(sync.getQueuedThreads().contains(t1));
assertTrue(sync.getQueuedThreads().contains(t2));
t1.interrupt();
awaitTermination(t1);
assertHasExclusiveQueuedThreads(sync, t2);
sync.release();
awaitTermination(t2);
assertHasExclusiveQueuedThreads(sync, NO_THREADS);
} |
getQueuedThreads returns all waiting threads
| AwaitMethod::testGetQueuedThreads | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testGetExclusiveQueuedThreads() {
final Mutex sync = new Mutex();
Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
assertHasExclusiveQueuedThreads(sync, NO_THREADS);
sync.acquire();
assertHasExclusiveQueuedThreads(sync, NO_THREADS);
t1.start();
waitForQueuedThread(sync, t1);
assertHasExclusiveQueuedThreads(sync, t1);
assertTrue(sync.getExclusiveQueuedThreads().contains(t1));
assertFalse(sync.getExclusiveQueuedThreads().contains(t2));
t2.start();
waitForQueuedThread(sync, t2);
assertHasExclusiveQueuedThreads(sync, t1, t2);
assertTrue(sync.getExclusiveQueuedThreads().contains(t1));
assertTrue(sync.getExclusiveQueuedThreads().contains(t2));
t1.interrupt();
awaitTermination(t1);
assertHasExclusiveQueuedThreads(sync, t2);
sync.release();
awaitTermination(t2);
assertHasExclusiveQueuedThreads(sync, NO_THREADS);
} |
getExclusiveQueuedThreads returns all exclusive waiting threads
| AwaitMethod::testGetExclusiveQueuedThreads | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testGetSharedQueuedThreads_Exclusive() {
final Mutex sync = new Mutex();
assertTrue(sync.getSharedQueuedThreads().isEmpty());
sync.acquire();
assertTrue(sync.getSharedQueuedThreads().isEmpty());
Thread t1 = newStartedThread(new InterruptedSyncRunnable(sync));
waitForQueuedThread(sync, t1);
assertTrue(sync.getSharedQueuedThreads().isEmpty());
Thread t2 = newStartedThread(new InterruptibleSyncRunnable(sync));
waitForQueuedThread(sync, t2);
assertTrue(sync.getSharedQueuedThreads().isEmpty());
t1.interrupt();
awaitTermination(t1);
assertTrue(sync.getSharedQueuedThreads().isEmpty());
sync.release();
awaitTermination(t2);
assertTrue(sync.getSharedQueuedThreads().isEmpty());
} |
getSharedQueuedThreads does not include exclusively waiting threads
| AwaitMethod::testGetSharedQueuedThreads_Exclusive | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testGetSharedQueuedThreads_Shared() {
final BooleanLatch l = new BooleanLatch();
assertHasSharedQueuedThreads(l, NO_THREADS);
Thread t1 = newStartedThread(new CheckedInterruptedRunnable() {
public void realRun() throws InterruptedException {
l.acquireSharedInterruptibly(0);
}});
waitForQueuedThread(l, t1);
assertHasSharedQueuedThreads(l, t1);
Thread t2 = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
l.acquireSharedInterruptibly(0);
}});
waitForQueuedThread(l, t2);
assertHasSharedQueuedThreads(l, t1, t2);
t1.interrupt();
awaitTermination(t1);
assertHasSharedQueuedThreads(l, t2);
assertTrue(l.releaseShared(0));
awaitTermination(t2);
assertHasSharedQueuedThreads(l, NO_THREADS);
} |
getSharedQueuedThreads returns all shared waiting threads
| AwaitMethod::testGetSharedQueuedThreads_Shared | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testTryAcquireNanos_Interruptible() {
final Mutex sync = new Mutex();
sync.acquire();
Thread t = newStartedThread(new CheckedInterruptedRunnable() {
public void realRun() throws InterruptedException {
sync.tryAcquireNanos(MILLISECONDS.toNanos(2 * LONG_DELAY_MS));
}});
waitForQueuedThread(sync, t);
t.interrupt();
awaitTermination(t);
} |
tryAcquireNanos is interruptible
| AwaitMethod::testTryAcquireNanos_Interruptible | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testTryAcquireWhenSynced() {
final Mutex sync = new Mutex();
sync.acquire();
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() {
assertFalse(sync.tryAcquire());
}});
awaitTermination(t);
sync.release();
} |
tryAcquire on exclusively held sync fails
| AwaitMethod::testTryAcquireWhenSynced | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testAcquireNanos_Timeout() {
final Mutex sync = new Mutex();
sync.acquire();
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
long startTime = System.nanoTime();
long nanos = MILLISECONDS.toNanos(timeoutMillis());
assertFalse(sync.tryAcquireNanos(nanos));
assertTrue(millisElapsedSince(startTime) >= timeoutMillis());
}});
awaitTermination(t);
sync.release();
} |
tryAcquireNanos on an exclusively held sync times out
| AwaitMethod::testAcquireNanos_Timeout | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testGetState() {
final Mutex sync = new Mutex();
sync.acquire();
assertTrue(sync.isHeldExclusively());
sync.release();
assertFalse(sync.isHeldExclusively());
final BooleanLatch acquired = new BooleanLatch();
final BooleanLatch done = new BooleanLatch();
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
sync.acquire();
assertTrue(acquired.releaseShared(0));
done.acquireShared(0);
sync.release();
}});
acquired.acquireShared(0);
assertTrue(sync.isHeldExclusively());
assertTrue(done.releaseShared(0));
awaitTermination(t);
assertFalse(sync.isHeldExclusively());
} |
getState is true when acquired and false when not
| AwaitMethod::testGetState | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testAcquireInterruptibly() throws InterruptedException {
final Mutex sync = new Mutex();
final BooleanLatch threadStarted = new BooleanLatch();
sync.acquireInterruptibly();
Thread t = newStartedThread(new CheckedInterruptedRunnable() {
public void realRun() throws InterruptedException {
assertTrue(threadStarted.releaseShared(0));
sync.acquireInterruptibly();
}});
threadStarted.acquireShared(0);
waitForQueuedThread(sync, t);
t.interrupt();
awaitTermination(t);
assertTrue(sync.isHeldExclusively());
} |
acquireInterruptibly succeeds when released, else is interruptible
| AwaitMethod::testAcquireInterruptibly | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testOwns() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
final Mutex sync2 = new Mutex();
assertTrue(sync.owns(c));
assertFalse(sync2.owns(c));
} |
owns is true for a condition created by sync else false
| AwaitMethod::testOwns | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testAwait_IMSE() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
for (AwaitMethod awaitMethod : AwaitMethod.values()) {
long startTime = System.nanoTime();
try {
await(c, awaitMethod);
shouldThrow();
} catch (IllegalMonitorStateException success) {
} catch (InterruptedException e) { threadUnexpectedException(e); }
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
}
} |
Calling await without holding sync throws IllegalMonitorStateException
| AwaitMethod::testAwait_IMSE | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testSignal_IMSE() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
try {
c.signal();
shouldThrow();
} catch (IllegalMonitorStateException success) {}
assertHasWaitersUnlocked(sync, c, NO_THREADS);
} |
Calling signal without holding sync throws IllegalMonitorStateException
| AwaitMethod::testSignal_IMSE | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testSignalAll_IMSE() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
try {
c.signalAll();
shouldThrow();
} catch (IllegalMonitorStateException success) {}
} |
Calling signalAll without holding sync throws IllegalMonitorStateException
| AwaitMethod::testSignalAll_IMSE | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testAwaitTimed_Timeout() { testAwait_Timeout(AwaitMethod.awaitTimed); } |
await/awaitNanos/awaitUntil without a signal times out
| AwaitMethod::testAwaitTimed_Timeout | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testSignal_await() { testSignal(AwaitMethod.await); } |
await/awaitNanos/awaitUntil returns when signalled
| AwaitMethod::testSignal_await | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testHasWaitersNPE() {
final Mutex sync = new Mutex();
try {
sync.hasWaiters(null);
shouldThrow();
} catch (NullPointerException success) {}
} |
hasWaiters(null) throws NullPointerException
| AwaitMethod::testHasWaitersNPE | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testGetWaitQueueLengthNPE() {
final Mutex sync = new Mutex();
try {
sync.getWaitQueueLength(null);
shouldThrow();
} catch (NullPointerException success) {}
} |
getWaitQueueLength(null) throws NullPointerException
| AwaitMethod::testGetWaitQueueLengthNPE | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testGetWaitingThreadsNPE() {
final Mutex sync = new Mutex();
try {
sync.getWaitingThreads(null);
shouldThrow();
} catch (NullPointerException success) {}
} |
getWaitingThreads(null) throws NullPointerException
| AwaitMethod::testGetWaitingThreadsNPE | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testHasWaitersIAE() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
final Mutex sync2 = new Mutex();
try {
sync2.hasWaiters(c);
shouldThrow();
} catch (IllegalArgumentException success) {}
assertHasWaitersUnlocked(sync, c, NO_THREADS);
} |
hasWaiters throws IllegalArgumentException if not owned
| AwaitMethod::testHasWaitersIAE | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testHasWaitersIMSE() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
try {
sync.hasWaiters(c);
shouldThrow();
} catch (IllegalMonitorStateException success) {}
assertHasWaitersUnlocked(sync, c, NO_THREADS);
} |
hasWaiters throws IllegalMonitorStateException if not synced
| AwaitMethod::testHasWaitersIMSE | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testGetWaitQueueLengthIAE() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
final Mutex sync2 = new Mutex();
try {
sync2.getWaitQueueLength(c);
shouldThrow();
} catch (IllegalArgumentException success) {}
assertHasWaitersUnlocked(sync, c, NO_THREADS);
} |
getWaitQueueLength throws IllegalArgumentException if not owned
| AwaitMethod::testGetWaitQueueLengthIAE | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testGetWaitQueueLengthIMSE() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
try {
sync.getWaitQueueLength(c);
shouldThrow();
} catch (IllegalMonitorStateException success) {}
assertHasWaitersUnlocked(sync, c, NO_THREADS);
} |
getWaitQueueLength throws IllegalMonitorStateException if not synced
| AwaitMethod::testGetWaitQueueLengthIMSE | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testGetWaitingThreadsIAE() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
final Mutex sync2 = new Mutex();
try {
sync2.getWaitingThreads(c);
shouldThrow();
} catch (IllegalArgumentException success) {}
assertHasWaitersUnlocked(sync, c, NO_THREADS);
} |
getWaitingThreads throws IllegalArgumentException if not owned
| AwaitMethod::testGetWaitingThreadsIAE | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testGetWaitingThreadsIMSE() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
try {
sync.getWaitingThreads(c);
shouldThrow();
} catch (IllegalMonitorStateException success) {}
assertHasWaitersUnlocked(sync, c, NO_THREADS);
} |
getWaitingThreads throws IllegalMonitorStateException if not synced
| AwaitMethod::testGetWaitingThreadsIMSE | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testHasWaiters() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
final BooleanLatch acquired = new BooleanLatch();
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
sync.acquire();
assertHasWaitersLocked(sync, c, NO_THREADS);
assertFalse(sync.hasWaiters(c));
assertTrue(acquired.releaseShared(0));
c.await();
sync.release();
}});
acquired.acquireShared(0);
sync.acquire();
assertHasWaitersLocked(sync, c, t);
assertHasExclusiveQueuedThreads(sync, NO_THREADS);
assertTrue(sync.hasWaiters(c));
c.signal();
assertHasWaitersLocked(sync, c, NO_THREADS);
assertHasExclusiveQueuedThreads(sync, t);
assertFalse(sync.hasWaiters(c));
sync.release();
awaitTermination(t);
assertHasWaitersUnlocked(sync, c, NO_THREADS);
} |
hasWaiters returns true when a thread is waiting, else false
| AwaitMethod::testHasWaiters | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testGetWaitQueueLength() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
final BooleanLatch acquired1 = new BooleanLatch();
final BooleanLatch acquired2 = new BooleanLatch();
final Thread t1 = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
sync.acquire();
assertHasWaitersLocked(sync, c, NO_THREADS);
assertEquals(0, sync.getWaitQueueLength(c));
assertTrue(acquired1.releaseShared(0));
c.await();
sync.release();
}});
acquired1.acquireShared(0);
sync.acquire();
assertHasWaitersLocked(sync, c, t1);
assertEquals(1, sync.getWaitQueueLength(c));
sync.release();
final Thread t2 = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
sync.acquire();
assertHasWaitersLocked(sync, c, t1);
assertEquals(1, sync.getWaitQueueLength(c));
assertTrue(acquired2.releaseShared(0));
c.await();
sync.release();
}});
acquired2.acquireShared(0);
sync.acquire();
assertHasWaitersLocked(sync, c, t1, t2);
assertHasExclusiveQueuedThreads(sync, NO_THREADS);
assertEquals(2, sync.getWaitQueueLength(c));
c.signalAll();
assertHasWaitersLocked(sync, c, NO_THREADS);
assertHasExclusiveQueuedThreads(sync, t1, t2);
assertEquals(0, sync.getWaitQueueLength(c));
sync.release();
awaitTermination(t1);
awaitTermination(t2);
assertHasWaitersUnlocked(sync, c, NO_THREADS);
} |
getWaitQueueLength returns number of waiting threads
| AwaitMethod::testGetWaitQueueLength | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testGetWaitingThreads() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
final BooleanLatch acquired1 = new BooleanLatch();
final BooleanLatch acquired2 = new BooleanLatch();
final Thread t1 = new Thread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
sync.acquire();
assertHasWaitersLocked(sync, c, NO_THREADS);
assertTrue(sync.getWaitingThreads(c).isEmpty());
assertTrue(acquired1.releaseShared(0));
c.await();
sync.release();
}});
final Thread t2 = new Thread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
sync.acquire();
assertHasWaitersLocked(sync, c, t1);
assertTrue(sync.getWaitingThreads(c).contains(t1));
assertFalse(sync.getWaitingThreads(c).isEmpty());
assertEquals(1, sync.getWaitingThreads(c).size());
assertTrue(acquired2.releaseShared(0));
c.await();
sync.release();
}});
sync.acquire();
assertHasWaitersLocked(sync, c, NO_THREADS);
assertFalse(sync.getWaitingThreads(c).contains(t1));
assertFalse(sync.getWaitingThreads(c).contains(t2));
assertTrue(sync.getWaitingThreads(c).isEmpty());
assertEquals(0, sync.getWaitingThreads(c).size());
sync.release();
t1.start();
acquired1.acquireShared(0);
sync.acquire();
assertHasWaitersLocked(sync, c, t1);
assertTrue(sync.getWaitingThreads(c).contains(t1));
assertFalse(sync.getWaitingThreads(c).contains(t2));
assertFalse(sync.getWaitingThreads(c).isEmpty());
assertEquals(1, sync.getWaitingThreads(c).size());
sync.release();
t2.start();
acquired2.acquireShared(0);
sync.acquire();
assertHasWaitersLocked(sync, c, t1, t2);
assertHasExclusiveQueuedThreads(sync, NO_THREADS);
assertTrue(sync.getWaitingThreads(c).contains(t1));
assertTrue(sync.getWaitingThreads(c).contains(t2));
assertFalse(sync.getWaitingThreads(c).isEmpty());
assertEquals(2, sync.getWaitingThreads(c).size());
c.signalAll();
assertHasWaitersLocked(sync, c, NO_THREADS);
assertHasExclusiveQueuedThreads(sync, t1, t2);
assertFalse(sync.getWaitingThreads(c).contains(t1));
assertFalse(sync.getWaitingThreads(c).contains(t2));
assertTrue(sync.getWaitingThreads(c).isEmpty());
assertEquals(0, sync.getWaitingThreads(c).size());
sync.release();
awaitTermination(t1);
awaitTermination(t2);
assertHasWaitersUnlocked(sync, c, NO_THREADS);
} |
getWaitingThreads returns only and all waiting threads
| AwaitMethod::testGetWaitingThreads | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testAwaitUninterruptibly() {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
final BooleanLatch pleaseInterrupt = new BooleanLatch();
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() {
sync.acquire();
assertTrue(pleaseInterrupt.releaseShared(0));
c.awaitUninterruptibly();
assertTrue(Thread.interrupted());
assertHasWaitersLocked(sync, c, NO_THREADS);
sync.release();
}});
pleaseInterrupt.acquireShared(0);
sync.acquire();
assertHasWaitersLocked(sync, c, t);
sync.release();
t.interrupt();
assertHasWaitersUnlocked(sync, c, t);
assertThreadStaysAlive(t);
sync.acquire();
assertHasWaitersLocked(sync, c, t);
assertHasExclusiveQueuedThreads(sync, NO_THREADS);
c.signal();
assertHasWaitersLocked(sync, c, NO_THREADS);
assertHasExclusiveQueuedThreads(sync, t);
sync.release();
awaitTermination(t);
} |
awaitUninterruptibly is uninterruptible
| AwaitMethod::testAwaitUninterruptibly | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testInterruptible_await() { testInterruptible(AwaitMethod.await); } |
await/awaitNanos/awaitUntil is interruptible
| AwaitMethod::testInterruptible_await | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testSignalAll_await() { testSignalAll(AwaitMethod.await); } |
signalAll wakes up all threads
| AwaitMethod::testSignalAll_await | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testToString() {
Mutex sync = new Mutex();
assertTrue(sync.toString().contains("State = " + Mutex.UNLOCKED));
sync.acquire();
assertTrue(sync.toString().contains("State = " + Mutex.LOCKED));
} |
toString indicates current state
| AwaitMethod::testToString | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testSerialization() {
Mutex sync = new Mutex();
assertFalse(serialClone(sync).isHeldExclusively());
sync.acquire();
Thread t = newStartedThread(new InterruptedSyncRunnable(sync));
waitForQueuedThread(sync, t);
assertTrue(sync.isHeldExclusively());
Mutex clone = serialClone(sync);
assertTrue(clone.isHeldExclusively());
assertHasExclusiveQueuedThreads(sync, t);
assertHasExclusiveQueuedThreads(clone, NO_THREADS);
t.interrupt();
awaitTermination(t);
sync.release();
assertFalse(sync.isHeldExclusively());
assertTrue(clone.isHeldExclusively());
assertHasExclusiveQueuedThreads(sync, NO_THREADS);
assertHasExclusiveQueuedThreads(clone, NO_THREADS);
} |
A serialized AQS deserializes with current state, but no queued threads
| AwaitMethod::testSerialization | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testGetStateWithReleaseShared() {
final BooleanLatch l = new BooleanLatch();
assertFalse(l.isSignalled());
assertTrue(l.releaseShared(0));
assertTrue(l.isSignalled());
} |
tryReleaseShared setting state changes getState
| AwaitMethod::testGetStateWithReleaseShared | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testReleaseShared() {
final BooleanLatch l = new BooleanLatch();
assertFalse(l.isSignalled());
assertTrue(l.releaseShared(0));
assertTrue(l.isSignalled());
assertTrue(l.releaseShared(0));
assertTrue(l.isSignalled());
} |
releaseShared has no effect when already signalled
| AwaitMethod::testReleaseShared | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testAcquireSharedInterruptibly() {
final BooleanLatch l = new BooleanLatch();
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
assertFalse(l.isSignalled());
l.acquireSharedInterruptibly(0);
assertTrue(l.isSignalled());
l.acquireSharedInterruptibly(0);
assertTrue(l.isSignalled());
}});
waitForQueuedThread(l, t);
assertFalse(l.isSignalled());
assertThreadStaysAlive(t);
assertHasSharedQueuedThreads(l, t);
assertTrue(l.releaseShared(0));
assertTrue(l.isSignalled());
awaitTermination(t);
} |
acquireSharedInterruptibly returns after release, but not before
| AwaitMethod::testAcquireSharedInterruptibly | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testTryAcquireSharedNanos() {
final BooleanLatch l = new BooleanLatch();
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
assertFalse(l.isSignalled());
long nanos = MILLISECONDS.toNanos(2 * LONG_DELAY_MS);
assertTrue(l.tryAcquireSharedNanos(0, nanos));
assertTrue(l.isSignalled());
assertTrue(l.tryAcquireSharedNanos(0, nanos));
assertTrue(l.isSignalled());
}});
waitForQueuedThread(l, t);
assertFalse(l.isSignalled());
assertThreadStaysAlive(t);
assertTrue(l.releaseShared(0));
assertTrue(l.isSignalled());
awaitTermination(t);
} |
tryAcquireSharedNanos returns after release, but not before
| AwaitMethod::testTryAcquireSharedNanos | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testAcquireSharedInterruptibly_Interruptible() {
final BooleanLatch l = new BooleanLatch();
Thread t = newStartedThread(new CheckedInterruptedRunnable() {
public void realRun() throws InterruptedException {
assertFalse(l.isSignalled());
l.acquireSharedInterruptibly(0);
}});
waitForQueuedThread(l, t);
assertFalse(l.isSignalled());
t.interrupt();
awaitTermination(t);
assertFalse(l.isSignalled());
} |
acquireSharedInterruptibly is interruptible
| AwaitMethod::testAcquireSharedInterruptibly_Interruptible | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testTryAcquireSharedNanos_Interruptible() {
final BooleanLatch l = new BooleanLatch();
Thread t = newStartedThread(new CheckedInterruptedRunnable() {
public void realRun() throws InterruptedException {
assertFalse(l.isSignalled());
long nanos = MILLISECONDS.toNanos(2 * LONG_DELAY_MS);
l.tryAcquireSharedNanos(0, nanos);
}});
waitForQueuedThread(l, t);
assertFalse(l.isSignalled());
t.interrupt();
awaitTermination(t);
assertFalse(l.isSignalled());
} |
tryAcquireSharedNanos is interruptible
| AwaitMethod::testTryAcquireSharedNanos_Interruptible | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testTryAcquireSharedNanos_Timeout() {
final BooleanLatch l = new BooleanLatch();
final BooleanLatch observedQueued = new BooleanLatch();
Thread t = newStartedThread(new CheckedRunnable() {
public void realRun() throws InterruptedException {
assertFalse(l.isSignalled());
for (long millis = timeoutMillis();
!observedQueued.isSignalled();
millis *= 2) {
long nanos = MILLISECONDS.toNanos(millis);
long startTime = System.nanoTime();
assertFalse(l.tryAcquireSharedNanos(0, nanos));
assertTrue(millisElapsedSince(startTime) >= millis);
}
assertFalse(l.isSignalled());
}});
waitForQueuedThread(l, t);
observedQueued.releaseShared(0);
assertFalse(l.isSignalled());
awaitTermination(t);
assertFalse(l.isSignalled());
} |
tryAcquireSharedNanos times out if not released before timeout
| AwaitMethod::testTryAcquireSharedNanos_Timeout | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testAwait_Zero() throws InterruptedException {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
sync.acquire();
assertTrue(c.awaitNanos(0L) <= 0);
assertFalse(c.await(0L, NANOSECONDS));
sync.release();
} |
awaitNanos/timed await with 0 wait times out immediately
| AwaitMethod::testAwait_Zero | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public void testAwait_NegativeInfinity() throws InterruptedException {
final Mutex sync = new Mutex();
final ConditionObject c = sync.newCondition();
sync.acquire();
assertTrue(c.awaitNanos(Long.MIN_VALUE) <= 0);
assertFalse(c.await(Long.MIN_VALUE, NANOSECONDS));
sync.release();
} |
awaitNanos/timed await with maximum negative wait times does not underflow
| AwaitMethod::testAwait_NegativeInfinity | java | Reginer/aosp-android-jar | android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/jsr166/AbstractQueuedSynchronizerTest.java | MIT |
public SSLHandshakeException(String reason)
{
super(reason);
} |
Constructs an exception reporting an error found by
an SSL subsystem during handshaking.
@param reason describes the problem.
| SSLHandshakeException::SSLHandshakeException | java | Reginer/aosp-android-jar | android-32/src/javax/net/ssl/SSLHandshakeException.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/javax/net/ssl/SSLHandshakeException.java | MIT |
public static int messagesInLooper(Looper looper, Predicate<Message> messageFilter) {
MessageQueue queue = looper.getQueue();
int i = 0;
for (Message m = shadowOf(queue).getHead(); m != null; m = shadowOf(m).getNext()) {
if (messageFilter.test(m)) {
i += 1;
}
}
return i;
} |
Counts the number of messages in the looper {@code looper} that satisfy {@code
messageFilter}.
| TestUtils::messagesInLooper | java | Reginer/aosp-android-jar | android-32/src/com/android/server/backup/testing/TestUtils.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/com/android/server/backup/testing/TestUtils.java | MIT |
public static void runToEndOfTasks(Looper looper) {
ShadowLooper shadowLooper = shadowOf(looper);
shadowLooper.runToEndOfTasks();
// Handler instances have their own clock, so advancing looper (with runToEndOfTasks())
// above does NOT advance the handlers' clock, hence whenever a handler post messages with
// specific time to the looper the time of those messages will be before the looper's time.
// To fix this we advance SystemClock as well since that is from where the handlers read
// time.
SystemClock.setCurrentTimeMillis(shadowLooper.getScheduler().getCurrentTime());
} |
Counts the number of messages in the looper {@code looper} that satisfy {@code
messageFilter}.
public static int messagesInLooper(Looper looper, Predicate<Message> messageFilter) {
MessageQueue queue = looper.getQueue();
int i = 0;
for (Message m = shadowOf(queue).getHead(); m != null; m = shadowOf(m).getNext()) {
if (messageFilter.test(m)) {
i += 1;
}
}
return i;
}
public static void waitUntil(Supplier<Boolean> condition)
throws InterruptedException, TimeoutException {
waitUntil(condition, STEP_MS, TIMEOUT_MS);
}
public static void waitUntil(Supplier<Boolean> condition, long stepMs, long timeoutMs)
throws InterruptedException, TimeoutException {
long deadline = System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(timeoutMs);
while (true) {
if (condition.get()) {
return;
}
if (System.nanoTime() > deadline) {
throw new TimeoutException("Test timed-out waiting for condition");
}
Thread.sleep(stepMs);
}
}
/** Version of {@link ShadowLooper#runToEndOfTasks()} that also advances the system clock. | TestUtils::runToEndOfTasks | java | Reginer/aosp-android-jar | android-32/src/com/android/server/backup/testing/TestUtils.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/com/android/server/backup/testing/TestUtils.java | MIT |
public static void assertLogcatAtMost(String tag, int level) {
assertWithMessage("All logs <= " + level).that(
ShadowLog.getLogsForTag(tag).stream().allMatch(logItem -> logItem.type <= level))
.isTrue();
} |
Reset logcat with {@link ShadowLog#reset()} before the test case if you do anything that uses
logcat before that.
| TestUtils::assertLogcatAtMost | java | Reginer/aosp-android-jar | android-32/src/com/android/server/backup/testing/TestUtils.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/com/android/server/backup/testing/TestUtils.java | MIT |
public static void assertLogcatAtLeast(String tag, int level) {
assertWithMessage("Any log >= " + level).that(
ShadowLog.getLogsForTag(tag).stream().anyMatch(logItem -> logItem.type >= level))
.isTrue();
} |
Reset logcat with {@link ShadowLog#reset()} before the test case if you do anything that uses
logcat before that.
| TestUtils::assertLogcatAtLeast | java | Reginer/aosp-android-jar | android-32/src/com/android/server/backup/testing/TestUtils.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/com/android/server/backup/testing/TestUtils.java | MIT |
public static void assertLogcat(String tag, int... logs) {
assertWithMessage("Log items (specified per level)").that(
ShadowLog.getLogsForTag(tag).stream()
.map(logItem -> logItem.type)
.collect(toSet()))
.containsExactly(IntStream.of(logs).boxed().toArray());
} |
Verifies that logcat has produced log items as specified per level in {@code logs} (with
repetition).
<p>So, if you call {@code assertLogcat(TAG, Log.ERROR, Log.ERROR)}, you assert that there are
exactly 2 log items, each with level ERROR.
<p>Reset logcat with {@link ShadowLog#reset()} before the test case if you do anything
that uses logcat before that.
| TestUtils::assertLogcat | java | Reginer/aosp-android-jar | android-32/src/com/android/server/backup/testing/TestUtils.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/com/android/server/backup/testing/TestUtils.java | MIT |
public static void assertEventLogged(int tag, Object... values) {
assertWithMessage("Event logs").that(ShadowEventLog.getEntries())
.contains(new ShadowEventLog.Entry(tag, Arrays.asList(values)));
} |
Verifies that logcat has produced log items as specified per level in {@code logs} (with
repetition).
<p>So, if you call {@code assertLogcat(TAG, Log.ERROR, Log.ERROR)}, you assert that there are
exactly 2 log items, each with level ERROR.
<p>Reset logcat with {@link ShadowLog#reset()} before the test case if you do anything
that uses logcat before that.
public static void assertLogcat(String tag, int... logs) {
assertWithMessage("Log items (specified per level)").that(
ShadowLog.getLogsForTag(tag).stream()
.map(logItem -> logItem.type)
.collect(toSet()))
.containsExactly(IntStream.of(logs).boxed().toArray());
}
public static void assertLogcatContains(String tag, Predicate<ShadowLog.LogItem> predicate) {
assertThat(ShadowLog.getLogsForTag(tag).stream().anyMatch(predicate)).isTrue();
}
/** Declare shadow {@link ShadowEventLog} to use this. | TestUtils::assertEventLogged | java | Reginer/aosp-android-jar | android-32/src/com/android/server/backup/testing/TestUtils.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/com/android/server/backup/testing/TestUtils.java | MIT |
public static void assertEventNotLogged(int tag, Object... values) {
assertWithMessage("Event logs").that(ShadowEventLog.getEntries())
.doesNotContain(new ShadowEventLog.Entry(tag, Arrays.asList(values)));
} |
Verifies that logcat has produced log items as specified per level in {@code logs} (with
repetition).
<p>So, if you call {@code assertLogcat(TAG, Log.ERROR, Log.ERROR)}, you assert that there are
exactly 2 log items, each with level ERROR.
<p>Reset logcat with {@link ShadowLog#reset()} before the test case if you do anything
that uses logcat before that.
public static void assertLogcat(String tag, int... logs) {
assertWithMessage("Log items (specified per level)").that(
ShadowLog.getLogsForTag(tag).stream()
.map(logItem -> logItem.type)
.collect(toSet()))
.containsExactly(IntStream.of(logs).boxed().toArray());
}
public static void assertLogcatContains(String tag, Predicate<ShadowLog.LogItem> predicate) {
assertThat(ShadowLog.getLogsForTag(tag).stream().anyMatch(predicate)).isTrue();
}
/** Declare shadow {@link ShadowEventLog} to use this.
public static void assertEventLogged(int tag, Object... values) {
assertWithMessage("Event logs").that(ShadowEventLog.getEntries())
.contains(new ShadowEventLog.Entry(tag, Arrays.asList(values)));
}
/** Declare shadow {@link ShadowEventLog} to use this. | TestUtils::assertEventNotLogged | java | Reginer/aosp-android-jar | android-32/src/com/android/server/backup/testing/TestUtils.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/com/android/server/backup/testing/TestUtils.java | MIT |
public static void uncheck(ThrowingRunnable runnable) {
try {
runnable.runOrThrow();
} catch (Exception e) {
throw wrapIfChecked(e);
}
} |
Calls {@link Runnable#run()} and returns if no exception is thrown. Otherwise, if the
exception is unchecked, rethrow it; if it's checked wrap in a {@link RuntimeException} and
throw.
<p><b>Warning:</b>DON'T use this outside tests. A wrapped checked exception is just a failure
in a test.
| TestUtils::uncheck | java | Reginer/aosp-android-jar | android-32/src/com/android/server/backup/testing/TestUtils.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/com/android/server/backup/testing/TestUtils.java | MIT |
public static <T> T uncheck(Callable<T> callable) {
try {
return callable.call();
} catch (Exception e) {
throw wrapIfChecked(e);
}
} |
Calls {@link Callable#call()} and returns the value if no exception is thrown. Otherwise, if
the exception is unchecked, rethrow it; if it's checked wrap in a {@link RuntimeException}
and throw.
<p><b>Warning:</b>DON'T use this outside tests. A wrapped checked exception is just a failure
in a test.
| TestUtils::uncheck | java | Reginer/aosp-android-jar | android-32/src/com/android/server/backup/testing/TestUtils.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/com/android/server/backup/testing/TestUtils.java | MIT |
public static RuntimeException wrapIfChecked(Exception e) {
if (e instanceof RuntimeException) {
return (RuntimeException) e;
}
return new RuntimeException(e);
} |
Wrap {@code e} in a {@link RuntimeException} only if it's not one already, in which case it's
returned.
| TestUtils::wrapIfChecked | java | Reginer/aosp-android-jar | android-32/src/com/android/server/backup/testing/TestUtils.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/com/android/server/backup/testing/TestUtils.java | MIT |
public static Bundle putMonitoringExtra(Bundle extras, String key, String value) {
if (extras == null) {
extras = new Bundle();
}
extras.putString(key, value);
return extras;
} |
Adds given key-value pair in the bundle and returns the bundle. If bundle was null it will
be created.
@param extras - bundle where to add key-value to, if null a new bundle will be created.
@param key - key.
@param value - value.
@return extras if it was not null and new bundle otherwise.
| BackupManagerMonitorUtils::putMonitoringExtra | java | Reginer/aosp-android-jar | android-32/src/com/android/server/backup/utils/BackupManagerMonitorUtils.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/com/android/server/backup/utils/BackupManagerMonitorUtils.java | MIT |
public static Bundle putMonitoringExtra(Bundle extras, String key, long value) {
if (extras == null) {
extras = new Bundle();
}
extras.putLong(key, value);
return extras;
} |
Adds given key-value pair in the bundle and returns the bundle. If bundle was null it will
be created.
@param extras - bundle where to add key-value to, if null a new bundle will be created.
@param key - key.
@param value - value.
@return extras if it was not null and new bundle otherwise.
| BackupManagerMonitorUtils::putMonitoringExtra | java | Reginer/aosp-android-jar | android-32/src/com/android/server/backup/utils/BackupManagerMonitorUtils.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/com/android/server/backup/utils/BackupManagerMonitorUtils.java | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.