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 |
---|---|---|---|---|---|---|---|
public void dump(Printer pw, String prefix, int dumpFlags) {
super.dumpFront(pw, prefix);
if (permission != null) {
pw.println(prefix + "permission=" + permission);
}
if ((dumpFlags & DUMP_FLAG_DETAILS) != 0) {
pw.println(prefix + "taskAffinity=" + taskAffinity
+ " targetActivity=" + targetActivity
+ " persistableMode=" + persistableModeToString());
}
if (launchMode != 0 || flags != 0 || privateFlags != 0 || theme != 0) {
pw.println(prefix + "launchMode=" + launchMode
+ " flags=0x" + Integer.toHexString(flags)
+ " privateFlags=0x" + Integer.toHexString(privateFlags)
+ " theme=0x" + Integer.toHexString(theme));
}
if (screenOrientation != SCREEN_ORIENTATION_UNSPECIFIED
|| configChanges != 0 || softInputMode != 0) {
pw.println(prefix + "screenOrientation=" + screenOrientation
+ " configChanges=0x" + Integer.toHexString(configChanges)
+ " softInputMode=0x" + Integer.toHexString(softInputMode));
}
if (uiOptions != 0) {
pw.println(prefix + " uiOptions=0x" + Integer.toHexString(uiOptions));
}
if ((dumpFlags & DUMP_FLAG_DETAILS) != 0) {
pw.println(prefix + "lockTaskLaunchMode="
+ lockTaskLaunchModeToString(lockTaskLaunchMode));
}
if (windowLayout != null) {
pw.println(prefix + "windowLayout=" + windowLayout.width + "|"
+ windowLayout.widthFraction + ", " + windowLayout.height + "|"
+ windowLayout.heightFraction + ", " + windowLayout.gravity);
}
pw.println(prefix + "resizeMode=" + resizeModeToString(resizeMode));
if (requestedVrComponent != null) {
pw.println(prefix + "requestedVrComponent=" + requestedVrComponent);
}
if (getMaxAspectRatio() != 0) {
pw.println(prefix + "maxAspectRatio=" + getMaxAspectRatio());
}
final float minAspectRatio = getMinAspectRatio(screenOrientation);
if (minAspectRatio != 0) {
pw.println(prefix + "minAspectRatio=" + minAspectRatio);
if (getManifestMinAspectRatio() != minAspectRatio) {
pw.println(prefix + "getManifestMinAspectRatio=" + getManifestMinAspectRatio());
}
}
if (supportsSizeChanges) {
pw.println(prefix + "supportsSizeChanges=true");
}
super.dumpBack(pw, prefix, dumpFlags);
} |
Whether we should compare activity window layout min width/height with require space for
multi window to determine if it can be put into multi window mode.
@hide
public boolean shouldCheckMinWidthHeightForMultiWindow() {
return isChangeEnabled(CHECK_MIN_WIDTH_HEIGHT_FOR_MULTI_WINDOW);
}
public void dump(Printer pw, String prefix) {
dump(pw, prefix, DUMP_FLAG_ALL);
}
/** @hide | ActivityInfo::dump | java | Reginer/aosp-android-jar | android-32/src/android/content/pm/ActivityInfo.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/android/content/pm/ActivityInfo.java | MIT |
public static String screenOrientationToString(int orientation) {
switch (orientation) {
case SCREEN_ORIENTATION_UNSET:
return "SCREEN_ORIENTATION_UNSET";
case SCREEN_ORIENTATION_UNSPECIFIED:
return "SCREEN_ORIENTATION_UNSPECIFIED";
case SCREEN_ORIENTATION_LANDSCAPE:
return "SCREEN_ORIENTATION_LANDSCAPE";
case SCREEN_ORIENTATION_PORTRAIT:
return "SCREEN_ORIENTATION_PORTRAIT";
case SCREEN_ORIENTATION_USER:
return "SCREEN_ORIENTATION_USER";
case SCREEN_ORIENTATION_BEHIND:
return "SCREEN_ORIENTATION_BEHIND";
case SCREEN_ORIENTATION_SENSOR:
return "SCREEN_ORIENTATION_SENSOR";
case SCREEN_ORIENTATION_NOSENSOR:
return "SCREEN_ORIENTATION_NOSENSOR";
case SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
return "SCREEN_ORIENTATION_SENSOR_LANDSCAPE";
case SCREEN_ORIENTATION_SENSOR_PORTRAIT:
return "SCREEN_ORIENTATION_SENSOR_PORTRAIT";
case SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
return "SCREEN_ORIENTATION_REVERSE_LANDSCAPE";
case SCREEN_ORIENTATION_REVERSE_PORTRAIT:
return "SCREEN_ORIENTATION_REVERSE_PORTRAIT";
case SCREEN_ORIENTATION_FULL_SENSOR:
return "SCREEN_ORIENTATION_FULL_SENSOR";
case SCREEN_ORIENTATION_USER_LANDSCAPE:
return "SCREEN_ORIENTATION_USER_LANDSCAPE";
case SCREEN_ORIENTATION_USER_PORTRAIT:
return "SCREEN_ORIENTATION_USER_PORTRAIT";
case SCREEN_ORIENTATION_FULL_USER:
return "SCREEN_ORIENTATION_FULL_USER";
case SCREEN_ORIENTATION_LOCKED:
return "SCREEN_ORIENTATION_LOCKED";
default:
return Integer.toString(orientation);
}
} |
Convert the screen orientation constant to a human readable format.
@hide
| ActivityInfo::screenOrientationToString | java | Reginer/aosp-android-jar | android-32/src/android/content/pm/ActivityInfo.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/android/content/pm/ActivityInfo.java | MIT |
public static String colorModeToString(@ColorMode int colorMode) {
switch (colorMode) {
case COLOR_MODE_DEFAULT:
return "COLOR_MODE_DEFAULT";
case COLOR_MODE_WIDE_COLOR_GAMUT:
return "COLOR_MODE_WIDE_COLOR_GAMUT";
case COLOR_MODE_HDR:
return "COLOR_MODE_HDR";
default:
return Integer.toString(colorMode);
}
} |
@hide
| ActivityInfo::colorModeToString | java | Reginer/aosp-android-jar | android-32/src/android/content/pm/ActivityInfo.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/android/content/pm/ActivityInfo.java | MIT |
public WindowLayout(int width, float widthFraction, int height, float heightFraction,
int gravity, int minWidth, int minHeight, String windowLayoutAffinity) {
this.width = width;
this.widthFraction = widthFraction;
this.height = height;
this.heightFraction = heightFraction;
this.gravity = gravity;
this.minWidth = minWidth;
this.minHeight = minHeight;
this.windowLayoutAffinity = windowLayoutAffinity;
} |
Contains information about position and size of the activity on the display.
Used in freeform mode to set desired position when activity is first launched.
It describes how big the activity wants to be in both width and height,
the minimal allowed size, and the gravity to be applied.
@attr ref android.R.styleable#AndroidManifestLayout_defaultWidth
@attr ref android.R.styleable#AndroidManifestLayout_defaultHeight
@attr ref android.R.styleable#AndroidManifestLayout_gravity
@attr ref android.R.styleable#AndroidManifestLayout_minWidth
@attr ref android.R.styleable#AndroidManifestLayout_minHeight
public static final class WindowLayout {
public WindowLayout(int width, float widthFraction, int height, float heightFraction,
int gravity, int minWidth, int minHeight) {
this(width, widthFraction, height, heightFraction, gravity, minWidth, minHeight,
null /* windowLayoutAffinity */);
}
/** @hide | WindowLayout::WindowLayout | java | Reginer/aosp-android-jar | android-32/src/android/content/pm/ActivityInfo.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/android/content/pm/ActivityInfo.java | MIT |
public WindowLayout(Parcel source) {
width = source.readInt();
widthFraction = source.readFloat();
height = source.readInt();
heightFraction = source.readFloat();
gravity = source.readInt();
minWidth = source.readInt();
minHeight = source.readInt();
windowLayoutAffinity = source.readString8();
} |
Contains information about position and size of the activity on the display.
Used in freeform mode to set desired position when activity is first launched.
It describes how big the activity wants to be in both width and height,
the minimal allowed size, and the gravity to be applied.
@attr ref android.R.styleable#AndroidManifestLayout_defaultWidth
@attr ref android.R.styleable#AndroidManifestLayout_defaultHeight
@attr ref android.R.styleable#AndroidManifestLayout_gravity
@attr ref android.R.styleable#AndroidManifestLayout_minWidth
@attr ref android.R.styleable#AndroidManifestLayout_minHeight
public static final class WindowLayout {
public WindowLayout(int width, float widthFraction, int height, float heightFraction,
int gravity, int minWidth, int minHeight) {
this(width, widthFraction, height, heightFraction, gravity, minWidth, minHeight,
null /* windowLayoutAffinity */);
}
/** @hide
public WindowLayout(int width, float widthFraction, int height, float heightFraction,
int gravity, int minWidth, int minHeight, String windowLayoutAffinity) {
this.width = width;
this.widthFraction = widthFraction;
this.height = height;
this.heightFraction = heightFraction;
this.gravity = gravity;
this.minWidth = minWidth;
this.minHeight = minHeight;
this.windowLayoutAffinity = windowLayoutAffinity;
}
/** @hide | WindowLayout::WindowLayout | java | Reginer/aosp-android-jar | android-32/src/android/content/pm/ActivityInfo.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/android/content/pm/ActivityInfo.java | MIT |
public boolean hasSpecifiedSize() {
return width >= 0 || height >= 0 || widthFraction >= 0 || heightFraction >= 0;
} |
Returns if this {@link WindowLayout} has specified bounds.
@hide
| WindowLayout::hasSpecifiedSize | java | Reginer/aosp-android-jar | android-32/src/android/content/pm/ActivityInfo.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/android/content/pm/ActivityInfo.java | MIT |
public void writeToParcel(Parcel dest) {
dest.writeInt(width);
dest.writeFloat(widthFraction);
dest.writeInt(height);
dest.writeFloat(heightFraction);
dest.writeInt(gravity);
dest.writeInt(minWidth);
dest.writeInt(minHeight);
dest.writeString8(windowLayoutAffinity);
} |
Returns if this {@link WindowLayout} has specified bounds.
@hide
public boolean hasSpecifiedSize() {
return width >= 0 || height >= 0 || widthFraction >= 0 || heightFraction >= 0;
}
/** @hide | WindowLayout::writeToParcel | java | Reginer/aosp-android-jar | android-32/src/android/content/pm/ActivityInfo.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/android/content/pm/ActivityInfo.java | MIT |
public StreamingService(int subscriptionId,
IMbmsStreamingService service,
MbmsStreamingSession session,
StreamingServiceInfo streamingServiceInfo,
InternalStreamingServiceCallback callback) {
mSubscriptionId = subscriptionId;
mParentSession = session;
mService = service;
mServiceInfo = streamingServiceInfo;
mCallback = callback;
} |
@hide
| StreamingService::StreamingService | java | Reginer/aosp-android-jar | android-32/src/android/telephony/mbms/StreamingService.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/android/telephony/mbms/StreamingService.java | MIT |
public @Nullable Uri getPlaybackUri() {
if (mService == null) {
throw new IllegalStateException("No streaming service attached");
}
try {
return mService.getPlaybackUri(mSubscriptionId, mServiceInfo.getServiceId());
} catch (RemoteException e) {
Log.w(LOG_TAG, "Remote process died");
mService = null;
mParentSession.onStreamingServiceStopped(this);
sendErrorToApp(MbmsErrors.ERROR_MIDDLEWARE_LOST, null);
return null;
}
} |
Retrieve the Uri used to play this stream.
May throw an {@link IllegalArgumentException} or an {@link IllegalStateException}.
@return The {@link Uri} to pass to the streaming client, or {@code null} if an error
occurred.
| StreamingService::getPlaybackUri | java | Reginer/aosp-android-jar | android-32/src/android/telephony/mbms/StreamingService.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/android/telephony/mbms/StreamingService.java | MIT |
public StreamingServiceInfo getInfo() {
return mServiceInfo;
} |
Retrieve the {@link StreamingServiceInfo} corresponding to this stream.
| StreamingService::getInfo | java | Reginer/aosp-android-jar | android-32/src/android/telephony/mbms/StreamingService.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/android/telephony/mbms/StreamingService.java | MIT |
public InternalStreamingServiceCallback getCallback() {
return mCallback;
} |
Stop streaming this service. Further operations on this object will fail with an
{@link IllegalStateException}.
May throw an {@link IllegalArgumentException} or an {@link IllegalStateException}
@Override
public void close() {
if (mService == null) {
throw new IllegalStateException("No streaming service attached");
}
try {
mService.stopStreaming(mSubscriptionId, mServiceInfo.getServiceId());
} catch (RemoteException e) {
Log.w(LOG_TAG, "Remote process died");
mService = null;
sendErrorToApp(MbmsErrors.ERROR_MIDDLEWARE_LOST, null);
} finally {
mParentSession.onStreamingServiceStopped(this);
}
}
/** @hide | StreamingService::getCallback | java | Reginer/aosp-android-jar | android-32/src/android/telephony/mbms/StreamingService.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/android/telephony/mbms/StreamingService.java | MIT |
void putScale(float scale, int displayId) {
if (displayId == Display.DEFAULT_DISPLAY) {
BackgroundThread.getHandler().post(
() -> Settings.Secure.putFloatForUser(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE, scale,
mCurrentUserId));
} else {
synchronized (mLock) {
getScalesWithCurrentUser().put(displayId, scale);
}
}
} |
Stores the user settings scale associated to the given display. Only the scale of the
default display is persistent.
@param scale the magnification scale
@param displayId the id of the display
| MagnificationScaleProvider::putScale | java | Reginer/aosp-android-jar | android-33/src/com/android/server/accessibility/magnification/MagnificationScaleProvider.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/server/accessibility/magnification/MagnificationScaleProvider.java | MIT |
float getScale(int displayId) {
if (displayId == Display.DEFAULT_DISPLAY) {
return Settings.Secure.getFloatForUser(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_SCALE,
DEFAULT_MAGNIFICATION_SCALE, mCurrentUserId);
} else {
synchronized (mLock) {
return getScalesWithCurrentUser().get(displayId, DEFAULT_MAGNIFICATION_SCALE);
}
}
} |
Gets the user settings scale with the given display.
@param displayId the id of the display
@return the magnification scale.
| MagnificationScaleProvider::getScale | java | Reginer/aosp-android-jar | android-33/src/com/android/server/accessibility/magnification/MagnificationScaleProvider.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/com/android/server/accessibility/magnification/MagnificationScaleProvider.java | MIT |
public AccessibilityRecord() {
} |
Creates a new {@link AccessibilityRecord}.
| AccessibilityRecord::AccessibilityRecord | java | Reginer/aosp-android-jar | android-34/src/android/view/accessibility/AccessibilityRecord.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/view/accessibility/AccessibilityRecord.java | MIT |
public AccessibilityRecord(@NonNull AccessibilityRecord record) {
init(record);
} |
Copy constructor. Creates a new {@link AccessibilityRecord}, and this instance is initialized
with data from the given <code>record</code>.
@param record The other record.
| AccessibilityRecord::AccessibilityRecord | java | Reginer/aosp-android-jar | android-34/src/android/view/accessibility/AccessibilityRecord.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/view/accessibility/AccessibilityRecord.java | MIT |
public isSupported05(final DOMTestDocumentBuilderFactory factory) throws org.w3c.domts.DOMTestIncompatibleException {
super(factory);
//
// check if loaded documents are supported for content type
//
String contentType = getContentType();
preload(contentType, "staff", false);
} |
Constructor.
@param factory document factory, may not be null
@throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration
| isSupported05::isSupported05 | java | Reginer/aosp-android-jar | android-34/src/org/w3c/domts/level2/core/isSupported05.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/org/w3c/domts/level2/core/isSupported05.java | MIT |
public void runTest() throws Throwable {
Document doc;
Node rootNode;
boolean state;
doc = (Document) load("staff", false);
rootNode = doc.getDocumentElement();
state = rootNode.isSupported("core", "2.0");
assertTrue("throw_True", state);
} |
Runs the test case.
@throws Throwable Any uncaught exception causes test to fail
| isSupported05::runTest | java | Reginer/aosp-android-jar | android-34/src/org/w3c/domts/level2/core/isSupported05.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/org/w3c/domts/level2/core/isSupported05.java | MIT |
public String getTargetURI() {
return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/isSupported05";
} |
Gets URI that identifies the test.
@return uri identifier of test
| isSupported05::getTargetURI | java | Reginer/aosp-android-jar | android-34/src/org/w3c/domts/level2/core/isSupported05.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/org/w3c/domts/level2/core/isSupported05.java | MIT |
public static void main(final String[] args) {
DOMTestCase.doMain(isSupported05.class, args);
} |
Runs this test from the command line.
@param args command line arguments
| isSupported05::main | java | Reginer/aosp-android-jar | android-34/src/org/w3c/domts/level2/core/isSupported05.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/org/w3c/domts/level2/core/isSupported05.java | MIT |
public static int v(@Nullable String tag, @NonNull String msg, @Nullable Throwable tr) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.VERBOSE, tag,
msg + '\n' + Log.getStackTraceString(tr));
} |
Logs {@code msg} at {@link Log#VERBOSE} level, attaching stack trace of the {@code tr} to
the end of the log statement.
@param tag identifies the source of a log message. It usually represents system service,
e.g. {@code PackageManager}.
@param msg the message to log.
@param tr an exception to log.
@see Log#v(String, String, Throwable)
| Slog::v | java | Reginer/aosp-android-jar | android-34/src/android/util/Slog.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/util/Slog.java | MIT |
public static int i(@Nullable String tag, @NonNull String msg, @Nullable Throwable tr) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.INFO, tag,
msg + '\n' + Log.getStackTraceString(tr));
} |
Logs {@code msg} at {@link Log#INFO} level, attaching stack trace of the {@code tr} to
the end of the log statement.
@param tag identifies the source of a log message. It usually represents system service,
e.g. {@code PackageManager}.
@param msg the message to log.
@param tr an exception to log.
@see Log#i(String, String, Throwable)
| Slog::i | java | Reginer/aosp-android-jar | android-34/src/android/util/Slog.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/util/Slog.java | MIT |
public static int w(@Nullable String tag, @Nullable Throwable tr) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.WARN, tag, Log.getStackTraceString(tr));
} |
Logs stack trace of {@code tr} at {@link Log#WARN} level.
@param tag identifies the source of a log message. It usually represents system service,
e.g. {@code PackageManager}.
@param tr an exception to log.
@see Log#w(String, Throwable)
| Slog::w | java | Reginer/aosp-android-jar | android-34/src/android/util/Slog.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/util/Slog.java | MIT |
public static void wtfQuiet(@Nullable String tag, @NonNull String msg) {
Log.wtfQuiet(Log.LOG_ID_SYSTEM, tag, msg, true);
} |
Similar to {@link #wtf(String, String)}, but does not output anything to the log.
| Slog::wtfQuiet | java | Reginer/aosp-android-jar | android-34/src/android/util/Slog.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/util/Slog.java | MIT |
public static int wtf(@Nullable String tag, @Nullable Throwable tr) {
return Log.wtf(Log.LOG_ID_SYSTEM, tag, tr.getMessage(), tr, false, true);
} |
Logs a condition that should never happen, attaching stack trace of the {@code tr} to the
end of the log statement.
<p>
Similar to {@link Log#wtf(String, Throwable)}, but will never cause the caller to crash,
and will always be handled asynchronously. Primarily to be used by the system server.
@param tag identifies the source of a log message. It usually represents system service,
e.g. {@code PackageManager}.
@param tr an exception to log.
@see Log#wtf(String, Throwable)
| Slog::wtf | java | Reginer/aosp-android-jar | android-34/src/android/util/Slog.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/util/Slog.java | MIT |
public int getStreamId() {
return mStreamId;
} |
Gets stream ID.
| PesEvent::getStreamId | java | Reginer/aosp-android-jar | android-31/src/android/media/tv/tuner/filter/PesEvent.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/media/tv/tuner/filter/PesEvent.java | MIT |
public int getDataLength() {
return mDataLength;
} |
Gets data size in bytes of filtered data.
| PesEvent::getDataLength | java | Reginer/aosp-android-jar | android-31/src/android/media/tv/tuner/filter/PesEvent.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/media/tv/tuner/filter/PesEvent.java | MIT |
private void putStringAndNotify(String value) {
Settings.Global.putString(mContentResolver, BackupAgentTimeoutParameters.SETTING, value);
// We pass null as the observer since notifyChange iterates over all available observers and
// we don't have access to the local observer.
mContentResolver.notifyChange(
Settings.Global.getUriFor(BackupAgentTimeoutParameters.SETTING), /*observer*/ null);
} |
Robolectric does not notify observers of changes to settings so we have to trigger it here.
Currently, the mock of {@link Settings.Secure#putString(ContentResolver, String, String)}
only stores the value. TODO: Implement properly in ShadowSettings.
| Presubmit::putStringAndNotify | java | Reginer/aosp-android-jar | android-32/src/com/android/server/backup/BackupAgentTimeoutParametersTest.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/com/android/server/backup/BackupAgentTimeoutParametersTest.java | MIT |
public TextReportCanvas(UsbDescriptorParser parser, StringBuilder stringBuilder) {
super(parser);
mStringBuilder = stringBuilder;
} |
Constructor. Connects plain-text output to the provided StringBuilder.
@param connection The USB connection object used to retrieve strings
from the USB device.
@param stringBuilder Generated output gets written into this object.
| TextReportCanvas::TextReportCanvas | java | Reginer/aosp-android-jar | android-34/src/com/android/server/usb/descriptors/report/TextReportCanvas.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/server/usb/descriptors/report/TextReportCanvas.java | MIT |
private void resetServiceConnectionTimeout() {
mHandler.removeMessages(MSG_TIMEOUT_SERVICE);
mHandler.postDelayed(
() -> disconnectInternal(true),
MSG_TIMEOUT_SERVICE,
SERVICE_CONNECTION_TIMEOUT_MS);
} |
Resets the idle timeout for this connection by removing any pending timeout messages and
posting a new delayed message.
| QuickAccessWalletClientImpl::resetServiceConnectionTimeout | java | Reginer/aosp-android-jar | android-31/src/android/service/quickaccesswallet/QuickAccessWalletClientImpl.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/service/quickaccesswallet/QuickAccessWalletClientImpl.java | MIT |
public FileSystemLoopException(String file) {
super(file);
} |
Constructs an instance of this class.
@param file
a string identifying the file causing the cycle or {@code null} if
not known
| FileSystemLoopException::FileSystemLoopException | java | Reginer/aosp-android-jar | android-35/src/java/nio/file/FileSystemLoopException.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-35/src/java/nio/file/FileSystemLoopException.java | MIT |
public nodeappendchildchildexists(final DOMTestDocumentBuilderFactory factory) throws org.w3c.domts.DOMTestIncompatibleException {
super(factory);
//
// check if loaded documents are supported for content type
//
String contentType = getContentType();
preload(contentType, "staff", true);
} |
Constructor.
@param factory document factory, may not be null
@throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration
| nodeappendchildchildexists::nodeappendchildchildexists | java | Reginer/aosp-android-jar | android-32/src/org/w3c/domts/level1/core/nodeappendchildchildexists.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/org/w3c/domts/level1/core/nodeappendchildchildexists.java | MIT |
public void runTest() throws Throwable {
Document doc;
NodeList elementList;
Node childNode;
Node newChild;
Node lchild;
Node fchild;
String lchildName;
String fchildName;
Node appendedChild;
String initialName;
doc = (Document) load("staff", true);
elementList = doc.getElementsByTagName("employee");
childNode = elementList.item(1);
newChild = childNode.getFirstChild();
initialName = newChild.getNodeName();
appendedChild = childNode.appendChild(newChild);
fchild = childNode.getFirstChild();
fchildName = fchild.getNodeName();
lchild = childNode.getLastChild();
lchildName = lchild.getNodeName();
if (equals("employeeId", initialName)) {
assertEquals("assert1_nowhitespace", "name", fchildName);
assertEquals("assert2_nowhitespace", "employeeId", lchildName);
} else {
assertEquals("assert1", "employeeId", fchildName);
assertEquals("assert2", "#text", lchildName);
}
} |
Runs the test case.
@throws Throwable Any uncaught exception causes test to fail
| nodeappendchildchildexists::runTest | java | Reginer/aosp-android-jar | android-32/src/org/w3c/domts/level1/core/nodeappendchildchildexists.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/org/w3c/domts/level1/core/nodeappendchildchildexists.java | MIT |
public String getTargetURI() {
return "http://www.w3.org/2001/DOM-Test-Suite/level1/core/nodeappendchildchildexists";
} |
Gets URI that identifies the test.
@return uri identifier of test
| nodeappendchildchildexists::getTargetURI | java | Reginer/aosp-android-jar | android-32/src/org/w3c/domts/level1/core/nodeappendchildchildexists.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/org/w3c/domts/level1/core/nodeappendchildchildexists.java | MIT |
public static void main(final String[] args) {
DOMTestCase.doMain(nodeappendchildchildexists.class, args);
} |
Runs this test from the command line.
@param args command line arguments
| nodeappendchildchildexists::main | java | Reginer/aosp-android-jar | android-32/src/org/w3c/domts/level1/core/nodeappendchildchildexists.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/org/w3c/domts/level1/core/nodeappendchildchildexists.java | MIT |
public static NFSubstitution makeSubstitution(int pos,
NFRule rule,
NFRule rulePredecessor,
NFRuleSet ruleSet,
RuleBasedNumberFormat formatter,
String description) {
// if the description is empty, return a NullSubstitution
if (description.length() == 0) {
return null;
}
switch (description.charAt(0)) {
case '<':
if (rule.getBaseValue() == NFRule.NEGATIVE_NUMBER_RULE) {
// throw an exception if the rule is a negative number rule
///CLOVER:OFF
// If you look at the call hierarchy of this method, the rule would
// never be directly modified by the user and therefore makes the
// following pointless unless the user changes the ruleset.
throw new IllegalArgumentException("<< not allowed in negative-number rule");
///CLOVER:ON
}
else if (rule.getBaseValue() == NFRule.IMPROPER_FRACTION_RULE
|| rule.getBaseValue() == NFRule.PROPER_FRACTION_RULE
|| rule.getBaseValue() == NFRule.DEFAULT_RULE)
{
// if the rule is a fraction rule, return an IntegralPartSubstitution
return new IntegralPartSubstitution(pos, ruleSet, description);
}
else if (ruleSet.isFractionSet()) {
// if the rule set containing the rule is a fraction
// rule set, return a NumeratorSubstitution
return new NumeratorSubstitution(pos, rule.getBaseValue(),
formatter.getDefaultRuleSet(), description);
}
else {
// otherwise, return a MultiplierSubstitution
return new MultiplierSubstitution(pos, rule, ruleSet,
description);
}
case '>':
if (rule.getBaseValue() == NFRule.NEGATIVE_NUMBER_RULE) {
// if the rule is a negative-number rule, return
// an AbsoluteValueSubstitution
return new AbsoluteValueSubstitution(pos, ruleSet, description);
}
else if (rule.getBaseValue() == NFRule.IMPROPER_FRACTION_RULE
|| rule.getBaseValue() == NFRule.PROPER_FRACTION_RULE
|| rule.getBaseValue() == NFRule.DEFAULT_RULE)
{
// if the rule is a fraction rule, return a
// FractionalPartSubstitution
return new FractionalPartSubstitution(pos, ruleSet, description);
}
else if (ruleSet.isFractionSet()) {
// if the rule set owning the rule is a fraction rule set,
// throw an exception
///CLOVER:OFF
// If you look at the call hierarchy of this method, the rule would
// never be directly modified by the user and therefore makes the
// following pointless unless the user changes the ruleset.
throw new IllegalArgumentException(">> not allowed in fraction rule set");
///CLOVER:ON
}
else {
// otherwise, return a ModulusSubstitution
return new ModulusSubstitution(pos, rule, rulePredecessor,
ruleSet, description);
}
case '=':
return new SameValueSubstitution(pos, ruleSet, description);
default:
// and if it's anything else, throw an exception
///CLOVER:OFF
// If you look at the call hierarchy of this method, the rule would
// never be directly modified by the user and therefore makes the
// following pointless unless the user changes the ruleset.
throw new IllegalArgumentException("Illegal substitution character");
///CLOVER:ON
}
} |
Parses the description, creates the right kind of substitution,
and initializes it based on the description.
@param pos The substitution's position in the rule text of the
rule that owns it.
@param rule The rule containing this substitution
@param rulePredecessor The rule preceding the one that contains
this substitution in the rule set's rule list (this is used
only for >>> substitutions).
@param ruleSet The rule set containing the rule containing this
substitution
@param formatter The RuleBasedNumberFormat that ultimately owns
this substitution
@param description The description to parse to build the substitution
(this is just the substring of the rule's description containing
the substitution token itself)
@return A new substitution constructed according to the description
| NFSubstitution::makeSubstitution | java | Reginer/aosp-android-jar | android-34/src/android/icu/text/NFSubstitution.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/icu/text/NFSubstitution.java | MIT |
NFSubstitution(int pos,
NFRuleSet ruleSet,
String description) {
// initialize the substitution's position in its parent rule
this.pos = pos;
int descriptionLen = description.length();
// the description should begin and end with the same character.
// If it doesn't that's a syntax error. Otherwise,
// makeSubstitution() was the only thing that needed to know
// about these characters, so strip them off
if (descriptionLen >= 2 && description.charAt(0) == description.charAt(descriptionLen - 1)) {
description = description.substring(1, descriptionLen - 1);
}
else if (descriptionLen != 0) {
throw new IllegalArgumentException("Illegal substitution syntax");
}
// if the description was just two paired token characters
// (i.e., "<<" or ">>"), it uses the rule set it belongs to to
// format its result
if (description.length() == 0) {
this.ruleSet = ruleSet;
this.numberFormat = null;
}
else if (description.charAt(0) == '%') {
// if the description contains a rule set name, that's the rule
// set we use to format the result: get a reference to the
// names rule set
this.ruleSet = ruleSet.owner.findRuleSet(description);
this.numberFormat = null;
}
else if (description.charAt(0) == '#' || description.charAt(0) == '0') {
// if the description begins with 0 or #, treat it as a
// DecimalFormat pattern, and initialize a DecimalFormat with
// that pattern (then set it to use the DecimalFormatSymbols
// belonging to our formatter)
this.ruleSet = null;
this.numberFormat = (DecimalFormat) ruleSet.owner.getDecimalFormat().clone();
this.numberFormat.applyPattern(description);
}
else if (description.charAt(0) == '>') {
// if the description is ">>>", this substitution bypasses the
// usual rule-search process and always uses the rule that precedes
// it in its own rule set's rule list (this is used for place-value
// notations: formats where you want to see a particular part of
// a number even when it's 0)
this.ruleSet = ruleSet; // was null, thai rules added to control space
this.numberFormat = null;
}
else {
// and of the description is none of these things, it's a syntax error
throw new IllegalArgumentException("Illegal substitution syntax");
}
} |
Base constructor for substitutions. This constructor sets up the
fields which are common to all substitutions.
@param pos The substitution's position in the owning rule's rule
text
@param ruleSet The rule set that owns this substitution
@param description The substitution descriptor (i.e., the text
inside the token characters)
| NFSubstitution::NFSubstitution | java | Reginer/aosp-android-jar | android-34/src/android/icu/text/NFSubstitution.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/icu/text/NFSubstitution.java | MIT |
public void setDivisor(int radix, short exponent) {
// a no-op for all substitutions except multiplier and modulus substitutions
} |
Set's the substitution's divisor. Used by NFRule.setBaseValue().
A no-op for all substitutions except multiplier and modulus
substitutions.
@param radix The radix of the divisor
@param exponent The exponent of the divisor
| NFSubstitution::setDivisor | java | Reginer/aosp-android-jar | android-34/src/android/icu/text/NFSubstitution.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/icu/text/NFSubstitution.java | MIT |
public void doSubstitution(long number, StringBuilder toInsertInto, int position, int recursionCount) {
if (ruleSet != null) {
// Perform a transformation on the number that is dependent
// on the type of substitution this is, then just call its
// rule set's format() method to format the result
long numberToFormat = transformNumber(number);
ruleSet.format(numberToFormat, toInsertInto, position + pos, recursionCount);
} else {
if (number <= MAX_INT64_IN_DOUBLE) {
// or perform the transformation on the number (preserving
// the result's fractional part if the formatter it set
// to show it), then use that formatter's format() method
// to format the result
double numberToFormat = transformNumber((double) number);
if (numberFormat.getMaximumFractionDigits() == 0) {
numberToFormat = Math.floor(numberToFormat);
}
toInsertInto.insert(position + pos, numberFormat.format(numberToFormat));
}
else {
// We have gone beyond double precision. Something has to give.
// We're favoring accuracy of the large number over potential rules
// that round like a CompactDecimalFormat, which is not a common use case.
//
// Perform a transformation on the number that is dependent
// on the type of substitution this is, then just call its
// rule set's format() method to format the result
long numberToFormat = transformNumber(number);
toInsertInto.insert(position + pos, numberFormat.format(numberToFormat));
}
}
} |
Performs a mathematical operation on the number, formats it using
either ruleSet or decimalFormat, and inserts the result into
toInsertInto.
@param number The number being formatted.
@param toInsertInto The string we insert the result into
@param position The position in toInsertInto where the owning rule's
rule text begins (this value is added to this substitution's
position to determine exactly where to insert the new text)
| NFSubstitution::doSubstitution | java | Reginer/aosp-android-jar | android-34/src/android/icu/text/NFSubstitution.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/icu/text/NFSubstitution.java | MIT |
public void doSubstitution(double number, StringBuilder toInsertInto, int position, int recursionCount) {
// perform a transformation on the number being formatted that
// is dependent on the type of substitution this is
double numberToFormat = transformNumber(number);
if (Double.isInfinite(numberToFormat)) {
// This is probably a minus rule. Combine it with an infinite rule.
NFRule infiniteRule = ruleSet.findRule(Double.POSITIVE_INFINITY);
infiniteRule.doFormat(numberToFormat, toInsertInto, position + pos, recursionCount);
return;
}
// if the result is an integer, from here on out we work in integer
// space (saving time and memory and preserving accuracy)
if (numberToFormat == Math.floor(numberToFormat) && ruleSet != null) {
ruleSet.format((long)numberToFormat, toInsertInto, position + pos, recursionCount);
// if the result isn't an integer, then call either our rule set's
// format() method or our DecimalFormat's format() method to
// format the result
} else {
if (ruleSet != null) {
ruleSet.format(numberToFormat, toInsertInto, position + pos, recursionCount);
} else {
toInsertInto.insert(position + this.pos, numberFormat.format(numberToFormat));
}
}
} |
Performs a mathematical operation on the number, formats it using
either ruleSet or decimalFormat, and inserts the result into
toInsertInto.
@param number The number being formatted.
@param toInsertInto The string we insert the result into
@param position The position in toInsertInto where the owning rule's
rule text begins (this value is added to this substitution's
position to determine exactly where to insert the new text)
| NFSubstitution::doSubstitution | java | Reginer/aosp-android-jar | android-34/src/android/icu/text/NFSubstitution.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/icu/text/NFSubstitution.java | MIT |
public Number doParse(String text, ParsePosition parsePosition, double baseValue,
double upperBound, boolean lenientParse, int nonNumericalExecutedRuleMask) {
Number tempResult;
// figure out the highest base value a rule can have and match
// the text being parsed (this varies according to the type of
// substitutions: multiplier, modulus, and numerator substitutions
// restrict the search to rules with base values lower than their
// own; same-value substitutions leave the upper bound wherever
// it was, and the others allow any rule to match
upperBound = calcUpperBound(upperBound);
// use our rule set to parse the text. If that fails and
// lenient parsing is enabled (this is always false if the
// formatter's lenient-parsing mode is off, but it may also
// be false even when the formatter's lenient-parse mode is
// on), then also try parsing the text using a default-
// constructed NumberFormat
if (ruleSet != null) {
tempResult = ruleSet.parse(text, parsePosition, upperBound, nonNumericalExecutedRuleMask);
if (lenientParse && !ruleSet.isFractionSet() && parsePosition.getIndex() == 0) {
tempResult = ruleSet.owner.getDecimalFormat().parse(text, parsePosition);
}
// ...or use our DecimalFormat to parse the text
} else {
tempResult = numberFormat.parse(text, parsePosition);
}
// if the parse was successful, we've already advanced the caller's
// parse position (this is the one function that doesn't have one
// of its own). Derive a parse result and return it as a Long,
// if possible, or a Double
if (parsePosition.getIndex() != 0) {
double result = tempResult.doubleValue();
// composeRuleValue() produces a full parse result from
// the partial parse result passed to this function from
// the caller (this is either the owning rule's base value
// or the partial result obtained from composing the
// owning rule's base value with its other substitution's
// parse result) and the partial parse result obtained by
// matching the substitution (which will be the same value
// the caller would get by parsing just this part of the
// text with RuleBasedNumberFormat.parse() ). How the two
// values are used to derive the full parse result depends
// on the types of substitutions: For a regular rule, the
// ultimate result is its multiplier substitution's result
// times the rule's divisor (or the rule's base value) plus
// the modulus substitution's result (which will actually
// supersede part of the rule's base value). For a negative-
// number rule, the result is the negative of its substitution's
// result. For a fraction rule, it's the sum of its two
// substitution results. For a rule in a fraction rule set,
// it's the numerator substitution's result divided by
// the rule's base value. Results from same-value substitutions
// propagate back upward, and null substitutions don't affect
// the result.
result = composeRuleValue(result, baseValue);
if (result == (long)result) {
return Long.valueOf((long)result);
} else {
return new Double(result);
}
// if the parse was UNsuccessful, return 0
} else {
return tempResult;
}
} |
Parses a string using the rule set or DecimalFormat belonging
to this substitution. If there's a match, a mathematical
operation (the inverse of the one used in formatting) is
performed on the result of the parse and the value passed in
and returned as the result. The parse position is updated to
point to the first unmatched character in the string.
@param text The string to parse
@param parsePosition On entry, ignored, but assumed to be 0.
On exit, this is updated to point to the first unmatched
character (or 0 if the substitution didn't match)
@param baseValue A partial parse result that should be
combined with the result of this parse
@param upperBound When searching the rule set for a rule
matching the string passed in, only rules with base values
lower than this are considered
@param lenientParse If true and matching against rules fails,
the substitution will also try matching the text against
numerals using a default-constructed NumberFormat. If false,
no extra work is done. (This value is false whenever the
formatter isn't in lenient-parse mode, but is also false
under some conditions even when the formatter _is_ in
lenient-parse mode.)
@return If there's a match, this is the result of composing
baseValue with whatever was returned from matching the
characters. This will be either a Long or a Double. If there's
no match this is new Long(0) (not null), and parsePosition
is left unchanged.
| NFSubstitution::doParse | java | Reginer/aosp-android-jar | android-34/src/android/icu/text/NFSubstitution.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/icu/text/NFSubstitution.java | MIT |
public final int getPos() {
return pos;
} |
Returns the substitution's position in the rule that owns it.
@return The substitution's position in the rule that owns it.
| NFSubstitution::getPos | java | Reginer/aosp-android-jar | android-34/src/android/icu/text/NFSubstitution.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/icu/text/NFSubstitution.java | MIT |
public boolean isModulusSubstitution() {
return false;
} |
Returns true if this is a modulus substitution. (We didn't do this
with instanceof partially because it causes source files to
proliferate and partially because we have to port this to C++.)
@return true if this object is an instance of ModulusSubstitution
| NFSubstitution::isModulusSubstitution | java | Reginer/aosp-android-jar | android-34/src/android/icu/text/NFSubstitution.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/icu/text/NFSubstitution.java | MIT |
SameValueSubstitution(int pos,
NFRuleSet ruleSet,
String description) {
super(pos, ruleSet, description);
if (description.equals("==")) {
throw new IllegalArgumentException("== is not a legal token");
}
} |
Constructs a SameValueSubstution. This function just uses the
superclass constructor, but it performs a check that this
substitution doesn't call the rule set that owns it, since that
would lead to infinite recursion.
| SameValueSubstitution::SameValueSubstitution | java | Reginer/aosp-android-jar | android-34/src/android/icu/text/NFSubstitution.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/icu/text/NFSubstitution.java | MIT |
MultiplierSubstitution(int pos,
NFRule rule,
NFRuleSet ruleSet,
String description) {
super(pos, ruleSet, description);
// the owning rule's divisor affects the behavior of this
// substitution. Rather than keeping a back-pointer to the
// rule, we keep a copy of the divisor
this.divisor = rule.getDivisor();
if (divisor == 0) { // this will cause recursion
throw new IllegalStateException("Substitution with divisor 0 " + description.substring(0, pos) +
" | " + description.substring(pos));
}
} |
Constructs a MultiplierSubstitution. This uses the superclass
constructor to initialize most members, but this substitution
also maintains its own copy of its rule's divisor.
@param pos The substitution's position in its rule's rule text
@param rule The rule that owns this substitution
@param ruleSet The ruleSet this substitution uses to format its result
@param description The description describing this substitution
| MultiplierSubstitution::MultiplierSubstitution | java | Reginer/aosp-android-jar | android-34/src/android/icu/text/NFSubstitution.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/icu/text/NFSubstitution.java | MIT |
ModulusSubstitution(int pos,
NFRule rule,
NFRule rulePredecessor,
NFRuleSet ruleSet,
String description)
{
super(pos, ruleSet, description);
// the owning rule's divisor controls the behavior of this
// substitution: rather than keeping a backpointer to the rule,
// we keep a copy of the divisor
this.divisor = rule.getDivisor();
if (divisor == 0) { // this will cause recursion
throw new IllegalStateException("Substitution with bad divisor (" + divisor + ") "+ description.substring(0, pos) +
" | " + description.substring(pos));
}
// the >>> token doesn't alter how this substitution calculates the
// values it uses for formatting and parsing, but it changes
// what's done with that value after it's obtained: >>> short-
// circuits the rule-search process and goes straight to the
// specified rule to format the substitution value
if (description.equals(">>>")) {
ruleToUse = rulePredecessor;
} else {
ruleToUse = null;
}
} |
Constructs a ModulusSubstitution. In addition to the inherited
members, a ModulusSubstitution keeps track of the divisor of the
rule that owns it, and may also keep a reference to the rule
that precedes the rule containing this substitution in the rule
set's rule list.
@param pos The substitution's position in its rule's rule text
@param rule The rule that owns this substitution
@param rulePredecessor The rule that precedes this substitution's
rule in its rule set's rule list
@param description The description for this substitution
| ModulusSubstitution::ModulusSubstitution | java | Reginer/aosp-android-jar | android-34/src/android/icu/text/NFSubstitution.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/icu/text/NFSubstitution.java | MIT |
IntegralPartSubstitution(int pos,
NFRuleSet ruleSet,
String description) {
super(pos, ruleSet, description);
} |
Constructs an IntegralPartSubstitution. This just calls
the superclass constructor.
| IntegralPartSubstitution::IntegralPartSubstitution | java | Reginer/aosp-android-jar | android-34/src/android/icu/text/NFSubstitution.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/icu/text/NFSubstitution.java | MIT |
FractionalPartSubstitution(int pos,
NFRuleSet ruleSet,
String description) {
super(pos, ruleSet, description);
if (description.equals(">>") || description.equals(">>>") || ruleSet == this.ruleSet) {
byDigits = true;
useSpaces = !description.equals(">>>");
} else {
byDigits = false;
useSpaces = true;
this.ruleSet.makeIntoFractionRuleSet();
}
} |
Constructs a FractionalPartSubstitution. This object keeps a flag
telling whether it should format by digits or not. In addition,
it marks the rule set it calls (if any) as a fraction rule set.
| FractionalPartSubstitution::FractionalPartSubstitution | java | Reginer/aosp-android-jar | android-34/src/android/icu/text/NFSubstitution.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/icu/text/NFSubstitution.java | MIT |
AbsoluteValueSubstitution(int pos,
NFRuleSet ruleSet,
String description) {
super(pos, ruleSet, description);
} |
Constructs an AbsoluteValueSubstitution. This just uses the
superclass constructor.
| AbsoluteValueSubstitution::AbsoluteValueSubstitution | java | Reginer/aosp-android-jar | android-34/src/android/icu/text/NFSubstitution.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/icu/text/NFSubstitution.java | MIT |
NumeratorSubstitution(int pos,
double denominator,
NFRuleSet ruleSet,
String description) {
super(pos, ruleSet, fixdesc(description));
// this substitution's behavior depends on the rule's base value
// Rather than keeping a backpointer to the rule, we copy its
// base value here
this.denominator = denominator;
this.withZeros = description.endsWith("<<");
} |
Constructs a NumeratorSubstitution. In addition to the inherited
fields, a NumeratorSubstitution keeps track of a denominator, which
is merely the base value of the rule that owns it.
| NumeratorSubstitution::NumeratorSubstitution | java | Reginer/aosp-android-jar | android-34/src/android/icu/text/NFSubstitution.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/android/icu/text/NFSubstitution.java | MIT |
public synchronized void setUserDataEnabled(boolean enabled,
boolean notifyMultiSimSettingController) {
// Can't disable data for stand alone opportunistic subscription.
if (isStandAloneOpportunistic(mPhone.getSubId(), mPhone.getContext()) && !enabled) return;
boolean changed = GlobalSettingsHelper.setInt(mPhone.getContext(),
Settings.Global.MOBILE_DATA, mPhone.getSubId(), (enabled ? 1 : 0));
if (changed) {
localLog("UserDataEnabled", enabled);
mPhone.notifyUserMobileDataStateChanged(enabled);
updateDataEnabledAndNotify(REASON_USER_DATA_ENABLED);
if (notifyMultiSimSettingController) {
MultiSimSettingController.getInstance().notifyUserDataEnabled(
mPhone.getSubId(), enabled);
}
}
} |
@param notifyMultiSimSettingController if setUserDataEnabled is already from propagating
from MultiSimSettingController, don't notify MultiSimSettingController again.
For example, if sub1 and sub2 are in the same group and user enables data for sub
1, sub 2 will also be enabled but with propagateToGroup = false.
| DataEnabledSettings::setUserDataEnabled | java | Reginer/aosp-android-jar | android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | MIT |
public synchronized void setDataEnabled(@TelephonyManager.DataEnabledReason int reason,
boolean enabled) {
switch (reason) {
case TelephonyManager.DATA_ENABLED_REASON_USER:
setUserDataEnabled(enabled);
break;
case TelephonyManager.DATA_ENABLED_REASON_CARRIER:
setCarrierDataEnabled(enabled);
break;
case TelephonyManager.DATA_ENABLED_REASON_POLICY:
setPolicyDataEnabled(enabled);
break;
case TelephonyManager.DATA_ENABLED_REASON_THERMAL:
setThermalDataEnabled(enabled);
break;
default:
log("Invalid data enable reason " + reason);
break;
}
} |
Policy control of data connection with reason
@param reason the reason the data enable change is taking place
@param enabled True if enabling the data, otherwise disabling.
| DataEnabledSettings::setDataEnabled | java | Reginer/aosp-android-jar | android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | MIT |
public synchronized boolean setAlwaysAllowMmsData(boolean alwaysAllow) {
localLog("setAlwaysAllowMmsData", alwaysAllow);
mDataEnabledOverride.setAlwaysAllowMms(alwaysAllow);
boolean changed = SubscriptionController.getInstance()
.setDataEnabledOverrideRules(mPhone.getSubId(), mDataEnabledOverride.getRules());
if (changed) {
updateDataEnabledAndNotify(REASON_OVERRIDE_RULE_CHANGED);
notifyDataEnabledOverrideChanged();
}
return changed;
} |
Set whether always allowing MMS data connection.
@param alwaysAllow {@code true} if MMS data is always allowed.
@return {@code false} if the setting is changed.
| DataEnabledSettings::setAlwaysAllowMmsData | java | Reginer/aosp-android-jar | android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | MIT |
public synchronized boolean setAllowDataDuringVoiceCall(boolean allow) {
localLog("setAllowDataDuringVoiceCall", allow);
if (allow == isDataAllowedInVoiceCall()) {
return true;
}
mDataEnabledOverride.setDataAllowedInVoiceCall(allow);
boolean changed = SubscriptionController.getInstance()
.setDataEnabledOverrideRules(mPhone.getSubId(), mDataEnabledOverride.getRules());
if (changed) {
updateDataEnabledAndNotify(REASON_OVERRIDE_RULE_CHANGED);
notifyDataEnabledOverrideChanged();
}
return changed;
} |
Set allowing mobile data during voice call. This is used for allowing data on the non-default
data SIM. When a voice call is placed on the non-default data SIM on DSDS devices, users will
not be able to use mobile data. By calling this API, data will be temporarily enabled on the
non-default data SIM during the life cycle of the voice call.
@param allow {@code true} if allowing using data during voice call, {@code false} if
disallowed
@return {@code true} if operation is successful. otherwise {@code false}.
| DataEnabledSettings::setAllowDataDuringVoiceCall | java | Reginer/aosp-android-jar | android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | MIT |
public synchronized boolean isDataAllowedInVoiceCall() {
return mDataEnabledOverride.isDataAllowedInVoiceCall();
} |
Check if data is allowed during voice call.
@return {@code true} if data is allowed during voice call.
| DataEnabledSettings::isDataAllowedInVoiceCall | java | Reginer/aosp-android-jar | android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | MIT |
public synchronized boolean isDataEnabledForReason(
@TelephonyManager.DataEnabledReason int reason) {
switch (reason) {
case TelephonyManager.DATA_ENABLED_REASON_USER:
return isUserDataEnabled();
case TelephonyManager.DATA_ENABLED_REASON_CARRIER:
return isCarrierDataEnabled();
case TelephonyManager.DATA_ENABLED_REASON_POLICY:
return isPolicyDataEnabled();
case TelephonyManager.DATA_ENABLED_REASON_THERMAL:
return isThermalDataEnabled();
default:
return false;
}
} |
Check if data is enabled for a specific reason {@@TelephonyManager.DataEnabledReason}
@return {@code true} if the overall data is enabled; {@code false} if not.
| DataEnabledSettings::isDataEnabledForReason | java | Reginer/aosp-android-jar | android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | MIT |
public boolean isProvisioningDataEnabled() {
final String prov_property = SystemProperties.get("ro.com.android.prov_mobiledata",
"false");
boolean retVal = "true".equalsIgnoreCase(prov_property);
final int prov_mobile_data = Settings.Global.getInt(mResolver,
Settings.Global.DEVICE_PROVISIONING_MOBILE_DATA_ENABLED,
retVal ? 1 : 0);
retVal = prov_mobile_data != 0;
log("getDataEnabled during provisioning retVal=" + retVal + " - (" + prov_property
+ ", " + prov_mobile_data + ")");
return retVal;
} |
In provisioning, we might want to have enable mobile data during provisioning. It depends
on value of Settings.Global.DEVICE_PROVISIONING_MOBILE_DATA_ENABLED which is set by
setupwizard. It only matters if it's in provisioning stage.
@return whether we are enabling userData during provisioning stage.
| DataEnabledSettings::isProvisioningDataEnabled | java | Reginer/aosp-android-jar | android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | MIT |
public synchronized boolean getDataRoamingEnabled() {
return GlobalSettingsHelper.getBoolean(mPhone.getContext(),
Settings.Global.DATA_ROAMING, mPhone.getSubId(), getDefaultDataRoamingEnabled());
} |
Return current {@link android.provider.Settings.Global#DATA_ROAMING} value.
| DataEnabledSettings::getDataRoamingEnabled | java | Reginer/aosp-android-jar | android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | MIT |
public synchronized boolean getDefaultDataRoamingEnabled() {
final CarrierConfigManager configMgr = (CarrierConfigManager)
mPhone.getContext().getSystemService(Context.CARRIER_CONFIG_SERVICE);
boolean isDataRoamingEnabled = "true".equalsIgnoreCase(SystemProperties.get(
"ro.com.android.dataroaming", "false"));
isDataRoamingEnabled |= configMgr.getConfigForSubId(mPhone.getSubId()).getBoolean(
CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
return isDataRoamingEnabled;
} |
get default values for {@link Settings.Global#DATA_ROAMING}
return {@code true} if either
{@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} or
system property ro.com.android.dataroaming is set to true. otherwise return {@code false}
| DataEnabledSettings::getDefaultDataRoamingEnabled | java | Reginer/aosp-android-jar | android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | MIT |
public void registerForDataEnabledOverrideChanged(Handler h, int what) {
mOverallDataEnabledOverrideChangedRegistrants.addUnique(h, what, null);
notifyDataEnabledOverrideChanged();
} |
Register for data enabled override changed event.
@param h The handler
@param what The event
| DataEnabledSettings::registerForDataEnabledOverrideChanged | java | Reginer/aosp-android-jar | android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | MIT |
public void unregisterForDataEnabledOverrideChanged(Handler h) {
mOverallDataEnabledOverrideChangedRegistrants.remove(h);
} |
Unregistered for data enabled override changed event.
@param h The handler
| DataEnabledSettings::unregisterForDataEnabledOverrideChanged | java | Reginer/aosp-android-jar | android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/com/android/internal/telephony/dataconnection/DataEnabledSettings.java | MIT |
public void halInit() {
nativeInit();
} |
Wrapper around the static-native methods from native.
This class exists to allow us to mock static native methods in our tests. If mocking static
methods becomes easier than this in the future, we can delete this class.
@VisibleForTesting
public static class NativeWrapper {
private native void nativeInit();
private static native long nativeCreateHintSession(int tgid, int uid, int[] tids,
long durationNanos);
private static native void nativePauseHintSession(long halPtr);
private static native void nativeResumeHintSession(long halPtr);
private static native void nativeCloseHintSession(long halPtr);
private static native void nativeUpdateTargetWorkDuration(
long halPtr, long targetDurationNanos);
private static native void nativeReportActualWorkDuration(
long halPtr, long[] actualDurationNanos, long[] timeStampNanos);
private static native void nativeSendHint(long halPtr, int hint);
private static native void nativeSetThreads(long halPtr, int[] tids);
private static native long nativeGetHintSessionPreferredRate();
/** Wrapper for HintManager.nativeInit | NativeWrapper::halInit | java | Reginer/aosp-android-jar | android-34/src/com/android/server/power/hint/HintManagerService.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/server/power/hint/HintManagerService.java | MIT |
public long halCreateHintSession(int tgid, int uid, int[] tids, long durationNanos) {
return nativeCreateHintSession(tgid, uid, tids, durationNanos);
} |
Wrapper around the static-native methods from native.
This class exists to allow us to mock static native methods in our tests. If mocking static
methods becomes easier than this in the future, we can delete this class.
@VisibleForTesting
public static class NativeWrapper {
private native void nativeInit();
private static native long nativeCreateHintSession(int tgid, int uid, int[] tids,
long durationNanos);
private static native void nativePauseHintSession(long halPtr);
private static native void nativeResumeHintSession(long halPtr);
private static native void nativeCloseHintSession(long halPtr);
private static native void nativeUpdateTargetWorkDuration(
long halPtr, long targetDurationNanos);
private static native void nativeReportActualWorkDuration(
long halPtr, long[] actualDurationNanos, long[] timeStampNanos);
private static native void nativeSendHint(long halPtr, int hint);
private static native void nativeSetThreads(long halPtr, int[] tids);
private static native long nativeGetHintSessionPreferredRate();
/** Wrapper for HintManager.nativeInit
public void halInit() {
nativeInit();
}
/** Wrapper for HintManager.nativeCreateHintSession | NativeWrapper::halCreateHintSession | java | Reginer/aosp-android-jar | android-34/src/com/android/server/power/hint/HintManagerService.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/server/power/hint/HintManagerService.java | MIT |
public void halPauseHintSession(long halPtr) {
nativePauseHintSession(halPtr);
} |
Wrapper around the static-native methods from native.
This class exists to allow us to mock static native methods in our tests. If mocking static
methods becomes easier than this in the future, we can delete this class.
@VisibleForTesting
public static class NativeWrapper {
private native void nativeInit();
private static native long nativeCreateHintSession(int tgid, int uid, int[] tids,
long durationNanos);
private static native void nativePauseHintSession(long halPtr);
private static native void nativeResumeHintSession(long halPtr);
private static native void nativeCloseHintSession(long halPtr);
private static native void nativeUpdateTargetWorkDuration(
long halPtr, long targetDurationNanos);
private static native void nativeReportActualWorkDuration(
long halPtr, long[] actualDurationNanos, long[] timeStampNanos);
private static native void nativeSendHint(long halPtr, int hint);
private static native void nativeSetThreads(long halPtr, int[] tids);
private static native long nativeGetHintSessionPreferredRate();
/** Wrapper for HintManager.nativeInit
public void halInit() {
nativeInit();
}
/** Wrapper for HintManager.nativeCreateHintSession
public long halCreateHintSession(int tgid, int uid, int[] tids, long durationNanos) {
return nativeCreateHintSession(tgid, uid, tids, durationNanos);
}
/** Wrapper for HintManager.nativePauseHintSession | NativeWrapper::halPauseHintSession | java | Reginer/aosp-android-jar | android-34/src/com/android/server/power/hint/HintManagerService.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/server/power/hint/HintManagerService.java | MIT |
public void halResumeHintSession(long halPtr) {
nativeResumeHintSession(halPtr);
} |
Wrapper around the static-native methods from native.
This class exists to allow us to mock static native methods in our tests. If mocking static
methods becomes easier than this in the future, we can delete this class.
@VisibleForTesting
public static class NativeWrapper {
private native void nativeInit();
private static native long nativeCreateHintSession(int tgid, int uid, int[] tids,
long durationNanos);
private static native void nativePauseHintSession(long halPtr);
private static native void nativeResumeHintSession(long halPtr);
private static native void nativeCloseHintSession(long halPtr);
private static native void nativeUpdateTargetWorkDuration(
long halPtr, long targetDurationNanos);
private static native void nativeReportActualWorkDuration(
long halPtr, long[] actualDurationNanos, long[] timeStampNanos);
private static native void nativeSendHint(long halPtr, int hint);
private static native void nativeSetThreads(long halPtr, int[] tids);
private static native long nativeGetHintSessionPreferredRate();
/** Wrapper for HintManager.nativeInit
public void halInit() {
nativeInit();
}
/** Wrapper for HintManager.nativeCreateHintSession
public long halCreateHintSession(int tgid, int uid, int[] tids, long durationNanos) {
return nativeCreateHintSession(tgid, uid, tids, durationNanos);
}
/** Wrapper for HintManager.nativePauseHintSession
public void halPauseHintSession(long halPtr) {
nativePauseHintSession(halPtr);
}
/** Wrapper for HintManager.nativeResumeHintSession | NativeWrapper::halResumeHintSession | java | Reginer/aosp-android-jar | android-34/src/com/android/server/power/hint/HintManagerService.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/server/power/hint/HintManagerService.java | MIT |
public void halCloseHintSession(long halPtr) {
nativeCloseHintSession(halPtr);
} |
Wrapper around the static-native methods from native.
This class exists to allow us to mock static native methods in our tests. If mocking static
methods becomes easier than this in the future, we can delete this class.
@VisibleForTesting
public static class NativeWrapper {
private native void nativeInit();
private static native long nativeCreateHintSession(int tgid, int uid, int[] tids,
long durationNanos);
private static native void nativePauseHintSession(long halPtr);
private static native void nativeResumeHintSession(long halPtr);
private static native void nativeCloseHintSession(long halPtr);
private static native void nativeUpdateTargetWorkDuration(
long halPtr, long targetDurationNanos);
private static native void nativeReportActualWorkDuration(
long halPtr, long[] actualDurationNanos, long[] timeStampNanos);
private static native void nativeSendHint(long halPtr, int hint);
private static native void nativeSetThreads(long halPtr, int[] tids);
private static native long nativeGetHintSessionPreferredRate();
/** Wrapper for HintManager.nativeInit
public void halInit() {
nativeInit();
}
/** Wrapper for HintManager.nativeCreateHintSession
public long halCreateHintSession(int tgid, int uid, int[] tids, long durationNanos) {
return nativeCreateHintSession(tgid, uid, tids, durationNanos);
}
/** Wrapper for HintManager.nativePauseHintSession
public void halPauseHintSession(long halPtr) {
nativePauseHintSession(halPtr);
}
/** Wrapper for HintManager.nativeResumeHintSession
public void halResumeHintSession(long halPtr) {
nativeResumeHintSession(halPtr);
}
/** Wrapper for HintManager.nativeCloseHintSession | NativeWrapper::halCloseHintSession | java | Reginer/aosp-android-jar | android-34/src/com/android/server/power/hint/HintManagerService.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/server/power/hint/HintManagerService.java | MIT |
public void halUpdateTargetWorkDuration(long halPtr, long targetDurationNanos) {
nativeUpdateTargetWorkDuration(halPtr, targetDurationNanos);
} |
Wrapper around the static-native methods from native.
This class exists to allow us to mock static native methods in our tests. If mocking static
methods becomes easier than this in the future, we can delete this class.
@VisibleForTesting
public static class NativeWrapper {
private native void nativeInit();
private static native long nativeCreateHintSession(int tgid, int uid, int[] tids,
long durationNanos);
private static native void nativePauseHintSession(long halPtr);
private static native void nativeResumeHintSession(long halPtr);
private static native void nativeCloseHintSession(long halPtr);
private static native void nativeUpdateTargetWorkDuration(
long halPtr, long targetDurationNanos);
private static native void nativeReportActualWorkDuration(
long halPtr, long[] actualDurationNanos, long[] timeStampNanos);
private static native void nativeSendHint(long halPtr, int hint);
private static native void nativeSetThreads(long halPtr, int[] tids);
private static native long nativeGetHintSessionPreferredRate();
/** Wrapper for HintManager.nativeInit
public void halInit() {
nativeInit();
}
/** Wrapper for HintManager.nativeCreateHintSession
public long halCreateHintSession(int tgid, int uid, int[] tids, long durationNanos) {
return nativeCreateHintSession(tgid, uid, tids, durationNanos);
}
/** Wrapper for HintManager.nativePauseHintSession
public void halPauseHintSession(long halPtr) {
nativePauseHintSession(halPtr);
}
/** Wrapper for HintManager.nativeResumeHintSession
public void halResumeHintSession(long halPtr) {
nativeResumeHintSession(halPtr);
}
/** Wrapper for HintManager.nativeCloseHintSession
public void halCloseHintSession(long halPtr) {
nativeCloseHintSession(halPtr);
}
/** Wrapper for HintManager.nativeUpdateTargetWorkDuration | NativeWrapper::halUpdateTargetWorkDuration | java | Reginer/aosp-android-jar | android-34/src/com/android/server/power/hint/HintManagerService.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/server/power/hint/HintManagerService.java | MIT |
public void halReportActualWorkDuration(
long halPtr, long[] actualDurationNanos, long[] timeStampNanos) {
nativeReportActualWorkDuration(halPtr, actualDurationNanos,
timeStampNanos);
} |
Wrapper around the static-native methods from native.
This class exists to allow us to mock static native methods in our tests. If mocking static
methods becomes easier than this in the future, we can delete this class.
@VisibleForTesting
public static class NativeWrapper {
private native void nativeInit();
private static native long nativeCreateHintSession(int tgid, int uid, int[] tids,
long durationNanos);
private static native void nativePauseHintSession(long halPtr);
private static native void nativeResumeHintSession(long halPtr);
private static native void nativeCloseHintSession(long halPtr);
private static native void nativeUpdateTargetWorkDuration(
long halPtr, long targetDurationNanos);
private static native void nativeReportActualWorkDuration(
long halPtr, long[] actualDurationNanos, long[] timeStampNanos);
private static native void nativeSendHint(long halPtr, int hint);
private static native void nativeSetThreads(long halPtr, int[] tids);
private static native long nativeGetHintSessionPreferredRate();
/** Wrapper for HintManager.nativeInit
public void halInit() {
nativeInit();
}
/** Wrapper for HintManager.nativeCreateHintSession
public long halCreateHintSession(int tgid, int uid, int[] tids, long durationNanos) {
return nativeCreateHintSession(tgid, uid, tids, durationNanos);
}
/** Wrapper for HintManager.nativePauseHintSession
public void halPauseHintSession(long halPtr) {
nativePauseHintSession(halPtr);
}
/** Wrapper for HintManager.nativeResumeHintSession
public void halResumeHintSession(long halPtr) {
nativeResumeHintSession(halPtr);
}
/** Wrapper for HintManager.nativeCloseHintSession
public void halCloseHintSession(long halPtr) {
nativeCloseHintSession(halPtr);
}
/** Wrapper for HintManager.nativeUpdateTargetWorkDuration
public void halUpdateTargetWorkDuration(long halPtr, long targetDurationNanos) {
nativeUpdateTargetWorkDuration(halPtr, targetDurationNanos);
}
/** Wrapper for HintManager.nativeReportActualWorkDuration | NativeWrapper::halReportActualWorkDuration | java | Reginer/aosp-android-jar | android-34/src/com/android/server/power/hint/HintManagerService.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/server/power/hint/HintManagerService.java | MIT |
public void halSendHint(long halPtr, int hint) {
nativeSendHint(halPtr, hint);
} |
Wrapper around the static-native methods from native.
This class exists to allow us to mock static native methods in our tests. If mocking static
methods becomes easier than this in the future, we can delete this class.
@VisibleForTesting
public static class NativeWrapper {
private native void nativeInit();
private static native long nativeCreateHintSession(int tgid, int uid, int[] tids,
long durationNanos);
private static native void nativePauseHintSession(long halPtr);
private static native void nativeResumeHintSession(long halPtr);
private static native void nativeCloseHintSession(long halPtr);
private static native void nativeUpdateTargetWorkDuration(
long halPtr, long targetDurationNanos);
private static native void nativeReportActualWorkDuration(
long halPtr, long[] actualDurationNanos, long[] timeStampNanos);
private static native void nativeSendHint(long halPtr, int hint);
private static native void nativeSetThreads(long halPtr, int[] tids);
private static native long nativeGetHintSessionPreferredRate();
/** Wrapper for HintManager.nativeInit
public void halInit() {
nativeInit();
}
/** Wrapper for HintManager.nativeCreateHintSession
public long halCreateHintSession(int tgid, int uid, int[] tids, long durationNanos) {
return nativeCreateHintSession(tgid, uid, tids, durationNanos);
}
/** Wrapper for HintManager.nativePauseHintSession
public void halPauseHintSession(long halPtr) {
nativePauseHintSession(halPtr);
}
/** Wrapper for HintManager.nativeResumeHintSession
public void halResumeHintSession(long halPtr) {
nativeResumeHintSession(halPtr);
}
/** Wrapper for HintManager.nativeCloseHintSession
public void halCloseHintSession(long halPtr) {
nativeCloseHintSession(halPtr);
}
/** Wrapper for HintManager.nativeUpdateTargetWorkDuration
public void halUpdateTargetWorkDuration(long halPtr, long targetDurationNanos) {
nativeUpdateTargetWorkDuration(halPtr, targetDurationNanos);
}
/** Wrapper for HintManager.nativeReportActualWorkDuration
public void halReportActualWorkDuration(
long halPtr, long[] actualDurationNanos, long[] timeStampNanos) {
nativeReportActualWorkDuration(halPtr, actualDurationNanos,
timeStampNanos);
}
/** Wrapper for HintManager.sendHint | NativeWrapper::halSendHint | java | Reginer/aosp-android-jar | android-34/src/com/android/server/power/hint/HintManagerService.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/server/power/hint/HintManagerService.java | MIT |
public long halGetHintSessionPreferredRate() {
return nativeGetHintSessionPreferredRate();
} |
Wrapper around the static-native methods from native.
This class exists to allow us to mock static native methods in our tests. If mocking static
methods becomes easier than this in the future, we can delete this class.
@VisibleForTesting
public static class NativeWrapper {
private native void nativeInit();
private static native long nativeCreateHintSession(int tgid, int uid, int[] tids,
long durationNanos);
private static native void nativePauseHintSession(long halPtr);
private static native void nativeResumeHintSession(long halPtr);
private static native void nativeCloseHintSession(long halPtr);
private static native void nativeUpdateTargetWorkDuration(
long halPtr, long targetDurationNanos);
private static native void nativeReportActualWorkDuration(
long halPtr, long[] actualDurationNanos, long[] timeStampNanos);
private static native void nativeSendHint(long halPtr, int hint);
private static native void nativeSetThreads(long halPtr, int[] tids);
private static native long nativeGetHintSessionPreferredRate();
/** Wrapper for HintManager.nativeInit
public void halInit() {
nativeInit();
}
/** Wrapper for HintManager.nativeCreateHintSession
public long halCreateHintSession(int tgid, int uid, int[] tids, long durationNanos) {
return nativeCreateHintSession(tgid, uid, tids, durationNanos);
}
/** Wrapper for HintManager.nativePauseHintSession
public void halPauseHintSession(long halPtr) {
nativePauseHintSession(halPtr);
}
/** Wrapper for HintManager.nativeResumeHintSession
public void halResumeHintSession(long halPtr) {
nativeResumeHintSession(halPtr);
}
/** Wrapper for HintManager.nativeCloseHintSession
public void halCloseHintSession(long halPtr) {
nativeCloseHintSession(halPtr);
}
/** Wrapper for HintManager.nativeUpdateTargetWorkDuration
public void halUpdateTargetWorkDuration(long halPtr, long targetDurationNanos) {
nativeUpdateTargetWorkDuration(halPtr, targetDurationNanos);
}
/** Wrapper for HintManager.nativeReportActualWorkDuration
public void halReportActualWorkDuration(
long halPtr, long[] actualDurationNanos, long[] timeStampNanos) {
nativeReportActualWorkDuration(halPtr, actualDurationNanos,
timeStampNanos);
}
/** Wrapper for HintManager.sendHint
public void halSendHint(long halPtr, int hint) {
nativeSendHint(halPtr, hint);
}
/** Wrapper for HintManager.nativeGetHintSessionPreferredRate | NativeWrapper::halGetHintSessionPreferredRate | java | Reginer/aosp-android-jar | android-34/src/com/android/server/power/hint/HintManagerService.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/server/power/hint/HintManagerService.java | MIT |
public void halSetThreads(long halPtr, int[] tids) {
nativeSetThreads(halPtr, tids);
} |
Wrapper around the static-native methods from native.
This class exists to allow us to mock static native methods in our tests. If mocking static
methods becomes easier than this in the future, we can delete this class.
@VisibleForTesting
public static class NativeWrapper {
private native void nativeInit();
private static native long nativeCreateHintSession(int tgid, int uid, int[] tids,
long durationNanos);
private static native void nativePauseHintSession(long halPtr);
private static native void nativeResumeHintSession(long halPtr);
private static native void nativeCloseHintSession(long halPtr);
private static native void nativeUpdateTargetWorkDuration(
long halPtr, long targetDurationNanos);
private static native void nativeReportActualWorkDuration(
long halPtr, long[] actualDurationNanos, long[] timeStampNanos);
private static native void nativeSendHint(long halPtr, int hint);
private static native void nativeSetThreads(long halPtr, int[] tids);
private static native long nativeGetHintSessionPreferredRate();
/** Wrapper for HintManager.nativeInit
public void halInit() {
nativeInit();
}
/** Wrapper for HintManager.nativeCreateHintSession
public long halCreateHintSession(int tgid, int uid, int[] tids, long durationNanos) {
return nativeCreateHintSession(tgid, uid, tids, durationNanos);
}
/** Wrapper for HintManager.nativePauseHintSession
public void halPauseHintSession(long halPtr) {
nativePauseHintSession(halPtr);
}
/** Wrapper for HintManager.nativeResumeHintSession
public void halResumeHintSession(long halPtr) {
nativeResumeHintSession(halPtr);
}
/** Wrapper for HintManager.nativeCloseHintSession
public void halCloseHintSession(long halPtr) {
nativeCloseHintSession(halPtr);
}
/** Wrapper for HintManager.nativeUpdateTargetWorkDuration
public void halUpdateTargetWorkDuration(long halPtr, long targetDurationNanos) {
nativeUpdateTargetWorkDuration(halPtr, targetDurationNanos);
}
/** Wrapper for HintManager.nativeReportActualWorkDuration
public void halReportActualWorkDuration(
long halPtr, long[] actualDurationNanos, long[] timeStampNanos) {
nativeReportActualWorkDuration(halPtr, actualDurationNanos,
timeStampNanos);
}
/** Wrapper for HintManager.sendHint
public void halSendHint(long halPtr, int hint) {
nativeSendHint(halPtr, hint);
}
/** Wrapper for HintManager.nativeGetHintSessionPreferredRate
public long halGetHintSessionPreferredRate() {
return nativeGetHintSessionPreferredRate();
}
/** Wrapper for HintManager.nativeSetThreads | NativeWrapper::halSetThreads | java | Reginer/aosp-android-jar | android-34/src/com/android/server/power/hint/HintManagerService.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/server/power/hint/HintManagerService.java | MIT |
static WakeLock createPartial(Context context, String tag, long maxTimeout) {
return wrap(createPartialInner(context, tag), maxTimeout);
} |
Creates a {@link WakeLock} that has a default release timeout.
* @see android.os.PowerManager.WakeLock#acquire(long) | createPartial | java | Reginer/aosp-android-jar | android-31/src/com/android/systemui/util/wakelock/WakeLock.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/com/android/systemui/util/wakelock/WakeLock.java | MIT |
public void acquire(String why) {
mActiveClients.putIfAbsent(why, 0);
mActiveClients.put(why, mActiveClients.get(why) + 1);
inner.acquire(maxTimeout);
} |
Create a {@link WakeLock} containing a {@link PowerManager.WakeLock}.
@param inner To be wrapped.
@param maxTimeout When to expire.
@return The new wake lock.
@VisibleForTesting
static WakeLock wrap(final PowerManager.WakeLock inner, long maxTimeout) {
return new WakeLock() {
private final HashMap<String, Integer> mActiveClients = new HashMap<>();
/** @see PowerManager.WakeLock#acquire() | (anonymous)::acquire | java | Reginer/aosp-android-jar | android-31/src/com/android/systemui/util/wakelock/WakeLock.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/com/android/systemui/util/wakelock/WakeLock.java | MIT |
public void release(String why) {
Integer count = mActiveClients.get(why);
if (count == null) {
Log.wtf(TAG, "Releasing WakeLock with invalid reason: " + why,
new Throwable());
return;
} else if (count == 1) {
mActiveClients.remove(why);
} else {
mActiveClients.put(why, count - 1);
}
inner.release();
} |
Create a {@link WakeLock} containing a {@link PowerManager.WakeLock}.
@param inner To be wrapped.
@param maxTimeout When to expire.
@return The new wake lock.
@VisibleForTesting
static WakeLock wrap(final PowerManager.WakeLock inner, long maxTimeout) {
return new WakeLock() {
private final HashMap<String, Integer> mActiveClients = new HashMap<>();
/** @see PowerManager.WakeLock#acquire()
public void acquire(String why) {
mActiveClients.putIfAbsent(why, 0);
mActiveClients.put(why, mActiveClients.get(why) + 1);
inner.acquire(maxTimeout);
}
/** @see PowerManager.WakeLock#release() | (anonymous)::release | java | Reginer/aosp-android-jar | android-31/src/com/android/systemui/util/wakelock/WakeLock.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/com/android/systemui/util/wakelock/WakeLock.java | MIT |
public Runnable wrap(Runnable runnable) {
return wrapImpl(this, runnable);
} |
Create a {@link WakeLock} containing a {@link PowerManager.WakeLock}.
@param inner To be wrapped.
@param maxTimeout When to expire.
@return The new wake lock.
@VisibleForTesting
static WakeLock wrap(final PowerManager.WakeLock inner, long maxTimeout) {
return new WakeLock() {
private final HashMap<String, Integer> mActiveClients = new HashMap<>();
/** @see PowerManager.WakeLock#acquire()
public void acquire(String why) {
mActiveClients.putIfAbsent(why, 0);
mActiveClients.put(why, mActiveClients.get(why) + 1);
inner.acquire(maxTimeout);
}
/** @see PowerManager.WakeLock#release()
public void release(String why) {
Integer count = mActiveClients.get(why);
if (count == null) {
Log.wtf(TAG, "Releasing WakeLock with invalid reason: " + why,
new Throwable());
return;
} else if (count == 1) {
mActiveClients.remove(why);
} else {
mActiveClients.put(why, count - 1);
}
inner.release();
}
/** @see PowerManager.WakeLock#wrap(Runnable) | (anonymous)::wrap | java | Reginer/aosp-android-jar | android-31/src/com/android/systemui/util/wakelock/WakeLock.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/com/android/systemui/util/wakelock/WakeLock.java | MIT |
private final IFaceServiceReceiver mReceiver = new IFaceServiceReceiver.Stub() {
@Override
public void onEnrollResult(Face face, int remaining) {
}
@Override
public void onAcquired(int acquireInfo, int vendorCode) {
}
@Override
public void onAuthenticationSucceeded(Face face, int userId, boolean isStrongBiometric) {
}
@Override
public void onFaceDetected(int sensorId, int userId, boolean isStrongBiometric) {
}
@Override
public void onAuthenticationFailed() {
}
@Override
public void onError(int error, int vendorCode) {
}
@Override
public void onRemoved(Face face, int remaining) {
}
@Override
public void onFeatureSet(boolean success, int feature) {
}
@Override
public void onFeatureGet(boolean success, int[] features, boolean[] featureState) {
}
@Override
public void onChallengeGenerated(int sensorId, int userId, long challenge) {
}
@Override
public void onAuthenticationFrame(FaceAuthenticationFrame frame) {
}
@Override
public void onEnrollmentFrame(FaceEnrollFrame frame) {
}
}; |
Internal receiver currently only used for enroll. Results do not need to be forwarded to the
test, since enrollment is a platform-only API. The authentication path is tested through
the public BiometricPrompt APIs and does not use this receiver.
| BiometricTestSessionImpl::Stub | java | Reginer/aosp-android-jar | android-34/src/com/android/server/biometrics/sensors/face/aidl/BiometricTestSessionImpl.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/server/biometrics/sensors/face/aidl/BiometricTestSessionImpl.java | MIT |
public static CodedInputStream newInstance(final InputStream input) {
return newInstance(input, DEFAULT_BUFFER_SIZE);
} |
Reads and decodes protocol message fields.
<p>This class contains two kinds of methods: methods that read specific protocol message
constructs and field types (e.g. {@link #readTag()} and {@link #readInt32()}) and methods that
read low-level values (e.g. {@link #readRawVarint32()} and {@link #readRawBytes}). If you are
reading encoded protocol messages, you should use the former methods, but if you are reading some
other format of your own design, use the latter.
@author [email protected] Kenton Varda
public abstract class CodedInputStream {
private static final int DEFAULT_BUFFER_SIZE = 4096;
// Integer.MAX_VALUE == 0x7FFFFFF == INT_MAX from limits.h
private static final int DEFAULT_SIZE_LIMIT = Integer.MAX_VALUE;
private static volatile int defaultRecursionLimit = 100;
/** Visible for subclasses. See setRecursionLimit()
int recursionDepth;
int recursionLimit = defaultRecursionLimit;
/** Visible for subclasses. See setSizeLimit()
int sizeLimit = DEFAULT_SIZE_LIMIT;
/** Used to adapt to the experimental {@link Reader} interface.
CodedInputStreamReader wrapper;
/** Create a new CodedInputStream wrapping the given InputStream. | CodedInputStream::newInstance | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
public static CodedInputStream newInstance(final InputStream input, int bufferSize) {
if (bufferSize <= 0) {
throw new IllegalArgumentException("bufferSize must be > 0");
}
if (input == null) {
// Ideally we would throw here. This is done for backward compatibility.
return newInstance(EMPTY_BYTE_ARRAY);
}
return new StreamDecoder(input, bufferSize);
} |
Reads and decodes protocol message fields.
<p>This class contains two kinds of methods: methods that read specific protocol message
constructs and field types (e.g. {@link #readTag()} and {@link #readInt32()}) and methods that
read low-level values (e.g. {@link #readRawVarint32()} and {@link #readRawBytes}). If you are
reading encoded protocol messages, you should use the former methods, but if you are reading some
other format of your own design, use the latter.
@author [email protected] Kenton Varda
public abstract class CodedInputStream {
private static final int DEFAULT_BUFFER_SIZE = 4096;
// Integer.MAX_VALUE == 0x7FFFFFF == INT_MAX from limits.h
private static final int DEFAULT_SIZE_LIMIT = Integer.MAX_VALUE;
private static volatile int defaultRecursionLimit = 100;
/** Visible for subclasses. See setRecursionLimit()
int recursionDepth;
int recursionLimit = defaultRecursionLimit;
/** Visible for subclasses. See setSizeLimit()
int sizeLimit = DEFAULT_SIZE_LIMIT;
/** Used to adapt to the experimental {@link Reader} interface.
CodedInputStreamReader wrapper;
/** Create a new CodedInputStream wrapping the given InputStream.
public static CodedInputStream newInstance(final InputStream input) {
return newInstance(input, DEFAULT_BUFFER_SIZE);
}
/** Create a new CodedInputStream wrapping the given InputStream, with a specified buffer size. | CodedInputStream::newInstance | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
public static CodedInputStream newInstance(final Iterable<ByteBuffer> input) {
if (!UnsafeDirectNioDecoder.isSupported()) {
return newInstance(new IterableByteBufferInputStream(input));
}
return newInstance(input, false);
} |
Reads and decodes protocol message fields.
<p>This class contains two kinds of methods: methods that read specific protocol message
constructs and field types (e.g. {@link #readTag()} and {@link #readInt32()}) and methods that
read low-level values (e.g. {@link #readRawVarint32()} and {@link #readRawBytes}). If you are
reading encoded protocol messages, you should use the former methods, but if you are reading some
other format of your own design, use the latter.
@author [email protected] Kenton Varda
public abstract class CodedInputStream {
private static final int DEFAULT_BUFFER_SIZE = 4096;
// Integer.MAX_VALUE == 0x7FFFFFF == INT_MAX from limits.h
private static final int DEFAULT_SIZE_LIMIT = Integer.MAX_VALUE;
private static volatile int defaultRecursionLimit = 100;
/** Visible for subclasses. See setRecursionLimit()
int recursionDepth;
int recursionLimit = defaultRecursionLimit;
/** Visible for subclasses. See setSizeLimit()
int sizeLimit = DEFAULT_SIZE_LIMIT;
/** Used to adapt to the experimental {@link Reader} interface.
CodedInputStreamReader wrapper;
/** Create a new CodedInputStream wrapping the given InputStream.
public static CodedInputStream newInstance(final InputStream input) {
return newInstance(input, DEFAULT_BUFFER_SIZE);
}
/** Create a new CodedInputStream wrapping the given InputStream, with a specified buffer size.
public static CodedInputStream newInstance(final InputStream input, int bufferSize) {
if (bufferSize <= 0) {
throw new IllegalArgumentException("bufferSize must be > 0");
}
if (input == null) {
// Ideally we would throw here. This is done for backward compatibility.
return newInstance(EMPTY_BYTE_ARRAY);
}
return new StreamDecoder(input, bufferSize);
}
/** Create a new CodedInputStream wrapping the given {@code Iterable <ByteBuffer>}. | CodedInputStream::newInstance | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
static CodedInputStream newInstance(
final Iterable<ByteBuffer> bufs, final boolean bufferIsImmutable) {
// flag is to check the type of input's ByteBuffers.
// flag equals 1: all ByteBuffers have array.
// flag equals 2: all ByteBuffers are direct ByteBuffers.
// flag equals 3: some ByteBuffers are direct and some have array.
// flag greater than 3: other cases.
int flag = 0;
// Total size of the input
int totalSize = 0;
for (ByteBuffer buf : bufs) {
totalSize += buf.remaining();
if (buf.hasArray()) {
flag |= 1;
} else if (buf.isDirect()) {
flag |= 2;
} else {
flag |= 4;
}
}
if (flag == 2) {
return new IterableDirectByteBufferDecoder(bufs, totalSize, bufferIsImmutable);
} else {
// TODO(yilunchong): add another decoders to deal case 1 and 3.
return newInstance(new IterableByteBufferInputStream(bufs));
}
} |
Reads and decodes protocol message fields.
<p>This class contains two kinds of methods: methods that read specific protocol message
constructs and field types (e.g. {@link #readTag()} and {@link #readInt32()}) and methods that
read low-level values (e.g. {@link #readRawVarint32()} and {@link #readRawBytes}). If you are
reading encoded protocol messages, you should use the former methods, but if you are reading some
other format of your own design, use the latter.
@author [email protected] Kenton Varda
public abstract class CodedInputStream {
private static final int DEFAULT_BUFFER_SIZE = 4096;
// Integer.MAX_VALUE == 0x7FFFFFF == INT_MAX from limits.h
private static final int DEFAULT_SIZE_LIMIT = Integer.MAX_VALUE;
private static volatile int defaultRecursionLimit = 100;
/** Visible for subclasses. See setRecursionLimit()
int recursionDepth;
int recursionLimit = defaultRecursionLimit;
/** Visible for subclasses. See setSizeLimit()
int sizeLimit = DEFAULT_SIZE_LIMIT;
/** Used to adapt to the experimental {@link Reader} interface.
CodedInputStreamReader wrapper;
/** Create a new CodedInputStream wrapping the given InputStream.
public static CodedInputStream newInstance(final InputStream input) {
return newInstance(input, DEFAULT_BUFFER_SIZE);
}
/** Create a new CodedInputStream wrapping the given InputStream, with a specified buffer size.
public static CodedInputStream newInstance(final InputStream input, int bufferSize) {
if (bufferSize <= 0) {
throw new IllegalArgumentException("bufferSize must be > 0");
}
if (input == null) {
// Ideally we would throw here. This is done for backward compatibility.
return newInstance(EMPTY_BYTE_ARRAY);
}
return new StreamDecoder(input, bufferSize);
}
/** Create a new CodedInputStream wrapping the given {@code Iterable <ByteBuffer>}.
public static CodedInputStream newInstance(final Iterable<ByteBuffer> input) {
if (!UnsafeDirectNioDecoder.isSupported()) {
return newInstance(new IterableByteBufferInputStream(input));
}
return newInstance(input, false);
}
/** Create a new CodedInputStream wrapping the given {@code Iterable <ByteBuffer>}. | CodedInputStream::newInstance | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
public static CodedInputStream newInstance(final byte[] buf) {
return newInstance(buf, 0, buf.length);
} |
Reads and decodes protocol message fields.
<p>This class contains two kinds of methods: methods that read specific protocol message
constructs and field types (e.g. {@link #readTag()} and {@link #readInt32()}) and methods that
read low-level values (e.g. {@link #readRawVarint32()} and {@link #readRawBytes}). If you are
reading encoded protocol messages, you should use the former methods, but if you are reading some
other format of your own design, use the latter.
@author [email protected] Kenton Varda
public abstract class CodedInputStream {
private static final int DEFAULT_BUFFER_SIZE = 4096;
// Integer.MAX_VALUE == 0x7FFFFFF == INT_MAX from limits.h
private static final int DEFAULT_SIZE_LIMIT = Integer.MAX_VALUE;
private static volatile int defaultRecursionLimit = 100;
/** Visible for subclasses. See setRecursionLimit()
int recursionDepth;
int recursionLimit = defaultRecursionLimit;
/** Visible for subclasses. See setSizeLimit()
int sizeLimit = DEFAULT_SIZE_LIMIT;
/** Used to adapt to the experimental {@link Reader} interface.
CodedInputStreamReader wrapper;
/** Create a new CodedInputStream wrapping the given InputStream.
public static CodedInputStream newInstance(final InputStream input) {
return newInstance(input, DEFAULT_BUFFER_SIZE);
}
/** Create a new CodedInputStream wrapping the given InputStream, with a specified buffer size.
public static CodedInputStream newInstance(final InputStream input, int bufferSize) {
if (bufferSize <= 0) {
throw new IllegalArgumentException("bufferSize must be > 0");
}
if (input == null) {
// Ideally we would throw here. This is done for backward compatibility.
return newInstance(EMPTY_BYTE_ARRAY);
}
return new StreamDecoder(input, bufferSize);
}
/** Create a new CodedInputStream wrapping the given {@code Iterable <ByteBuffer>}.
public static CodedInputStream newInstance(final Iterable<ByteBuffer> input) {
if (!UnsafeDirectNioDecoder.isSupported()) {
return newInstance(new IterableByteBufferInputStream(input));
}
return newInstance(input, false);
}
/** Create a new CodedInputStream wrapping the given {@code Iterable <ByteBuffer>}.
static CodedInputStream newInstance(
final Iterable<ByteBuffer> bufs, final boolean bufferIsImmutable) {
// flag is to check the type of input's ByteBuffers.
// flag equals 1: all ByteBuffers have array.
// flag equals 2: all ByteBuffers are direct ByteBuffers.
// flag equals 3: some ByteBuffers are direct and some have array.
// flag greater than 3: other cases.
int flag = 0;
// Total size of the input
int totalSize = 0;
for (ByteBuffer buf : bufs) {
totalSize += buf.remaining();
if (buf.hasArray()) {
flag |= 1;
} else if (buf.isDirect()) {
flag |= 2;
} else {
flag |= 4;
}
}
if (flag == 2) {
return new IterableDirectByteBufferDecoder(bufs, totalSize, bufferIsImmutable);
} else {
// TODO(yilunchong): add another decoders to deal case 1 and 3.
return newInstance(new IterableByteBufferInputStream(bufs));
}
}
/** Create a new CodedInputStream wrapping the given byte array. | CodedInputStream::newInstance | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
public static CodedInputStream newInstance(final byte[] buf, final int off, final int len) {
return newInstance(buf, off, len, /* bufferIsImmutable= */ false);
} |
Reads and decodes protocol message fields.
<p>This class contains two kinds of methods: methods that read specific protocol message
constructs and field types (e.g. {@link #readTag()} and {@link #readInt32()}) and methods that
read low-level values (e.g. {@link #readRawVarint32()} and {@link #readRawBytes}). If you are
reading encoded protocol messages, you should use the former methods, but if you are reading some
other format of your own design, use the latter.
@author [email protected] Kenton Varda
public abstract class CodedInputStream {
private static final int DEFAULT_BUFFER_SIZE = 4096;
// Integer.MAX_VALUE == 0x7FFFFFF == INT_MAX from limits.h
private static final int DEFAULT_SIZE_LIMIT = Integer.MAX_VALUE;
private static volatile int defaultRecursionLimit = 100;
/** Visible for subclasses. See setRecursionLimit()
int recursionDepth;
int recursionLimit = defaultRecursionLimit;
/** Visible for subclasses. See setSizeLimit()
int sizeLimit = DEFAULT_SIZE_LIMIT;
/** Used to adapt to the experimental {@link Reader} interface.
CodedInputStreamReader wrapper;
/** Create a new CodedInputStream wrapping the given InputStream.
public static CodedInputStream newInstance(final InputStream input) {
return newInstance(input, DEFAULT_BUFFER_SIZE);
}
/** Create a new CodedInputStream wrapping the given InputStream, with a specified buffer size.
public static CodedInputStream newInstance(final InputStream input, int bufferSize) {
if (bufferSize <= 0) {
throw new IllegalArgumentException("bufferSize must be > 0");
}
if (input == null) {
// Ideally we would throw here. This is done for backward compatibility.
return newInstance(EMPTY_BYTE_ARRAY);
}
return new StreamDecoder(input, bufferSize);
}
/** Create a new CodedInputStream wrapping the given {@code Iterable <ByteBuffer>}.
public static CodedInputStream newInstance(final Iterable<ByteBuffer> input) {
if (!UnsafeDirectNioDecoder.isSupported()) {
return newInstance(new IterableByteBufferInputStream(input));
}
return newInstance(input, false);
}
/** Create a new CodedInputStream wrapping the given {@code Iterable <ByteBuffer>}.
static CodedInputStream newInstance(
final Iterable<ByteBuffer> bufs, final boolean bufferIsImmutable) {
// flag is to check the type of input's ByteBuffers.
// flag equals 1: all ByteBuffers have array.
// flag equals 2: all ByteBuffers are direct ByteBuffers.
// flag equals 3: some ByteBuffers are direct and some have array.
// flag greater than 3: other cases.
int flag = 0;
// Total size of the input
int totalSize = 0;
for (ByteBuffer buf : bufs) {
totalSize += buf.remaining();
if (buf.hasArray()) {
flag |= 1;
} else if (buf.isDirect()) {
flag |= 2;
} else {
flag |= 4;
}
}
if (flag == 2) {
return new IterableDirectByteBufferDecoder(bufs, totalSize, bufferIsImmutable);
} else {
// TODO(yilunchong): add another decoders to deal case 1 and 3.
return newInstance(new IterableByteBufferInputStream(bufs));
}
}
/** Create a new CodedInputStream wrapping the given byte array.
public static CodedInputStream newInstance(final byte[] buf) {
return newInstance(buf, 0, buf.length);
}
/** Create a new CodedInputStream wrapping the given byte array slice. | CodedInputStream::newInstance | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
static CodedInputStream newInstance(
final byte[] buf, final int off, final int len, final boolean bufferIsImmutable) {
ArrayDecoder result = new ArrayDecoder(buf, off, len, bufferIsImmutable);
try {
// Some uses of CodedInputStream can be more efficient if they know
// exactly how many bytes are available. By pushing the end point of the
// buffer as a limit, we allow them to get this information via
// getBytesUntilLimit(). Pushing a limit that we know is at the end of
// the stream can never hurt, since we can never past that point anyway.
result.pushLimit(len);
} catch (InvalidProtocolBufferException ex) {
// The only reason pushLimit() might throw an exception here is if len
// is negative. Normally pushLimit()'s parameter comes directly off the
// wire, so it's important to catch exceptions in case of corrupt or
// malicious data. However, in this case, we expect that len is not a
// user-supplied value, so we can assume that it being negative indicates
// a programming error. Therefore, throwing an unchecked exception is
// appropriate.
throw new IllegalArgumentException(ex);
}
return result;
} |
Reads and decodes protocol message fields.
<p>This class contains two kinds of methods: methods that read specific protocol message
constructs and field types (e.g. {@link #readTag()} and {@link #readInt32()}) and methods that
read low-level values (e.g. {@link #readRawVarint32()} and {@link #readRawBytes}). If you are
reading encoded protocol messages, you should use the former methods, but if you are reading some
other format of your own design, use the latter.
@author [email protected] Kenton Varda
public abstract class CodedInputStream {
private static final int DEFAULT_BUFFER_SIZE = 4096;
// Integer.MAX_VALUE == 0x7FFFFFF == INT_MAX from limits.h
private static final int DEFAULT_SIZE_LIMIT = Integer.MAX_VALUE;
private static volatile int defaultRecursionLimit = 100;
/** Visible for subclasses. See setRecursionLimit()
int recursionDepth;
int recursionLimit = defaultRecursionLimit;
/** Visible for subclasses. See setSizeLimit()
int sizeLimit = DEFAULT_SIZE_LIMIT;
/** Used to adapt to the experimental {@link Reader} interface.
CodedInputStreamReader wrapper;
/** Create a new CodedInputStream wrapping the given InputStream.
public static CodedInputStream newInstance(final InputStream input) {
return newInstance(input, DEFAULT_BUFFER_SIZE);
}
/** Create a new CodedInputStream wrapping the given InputStream, with a specified buffer size.
public static CodedInputStream newInstance(final InputStream input, int bufferSize) {
if (bufferSize <= 0) {
throw new IllegalArgumentException("bufferSize must be > 0");
}
if (input == null) {
// Ideally we would throw here. This is done for backward compatibility.
return newInstance(EMPTY_BYTE_ARRAY);
}
return new StreamDecoder(input, bufferSize);
}
/** Create a new CodedInputStream wrapping the given {@code Iterable <ByteBuffer>}.
public static CodedInputStream newInstance(final Iterable<ByteBuffer> input) {
if (!UnsafeDirectNioDecoder.isSupported()) {
return newInstance(new IterableByteBufferInputStream(input));
}
return newInstance(input, false);
}
/** Create a new CodedInputStream wrapping the given {@code Iterable <ByteBuffer>}.
static CodedInputStream newInstance(
final Iterable<ByteBuffer> bufs, final boolean bufferIsImmutable) {
// flag is to check the type of input's ByteBuffers.
// flag equals 1: all ByteBuffers have array.
// flag equals 2: all ByteBuffers are direct ByteBuffers.
// flag equals 3: some ByteBuffers are direct and some have array.
// flag greater than 3: other cases.
int flag = 0;
// Total size of the input
int totalSize = 0;
for (ByteBuffer buf : bufs) {
totalSize += buf.remaining();
if (buf.hasArray()) {
flag |= 1;
} else if (buf.isDirect()) {
flag |= 2;
} else {
flag |= 4;
}
}
if (flag == 2) {
return new IterableDirectByteBufferDecoder(bufs, totalSize, bufferIsImmutable);
} else {
// TODO(yilunchong): add another decoders to deal case 1 and 3.
return newInstance(new IterableByteBufferInputStream(bufs));
}
}
/** Create a new CodedInputStream wrapping the given byte array.
public static CodedInputStream newInstance(final byte[] buf) {
return newInstance(buf, 0, buf.length);
}
/** Create a new CodedInputStream wrapping the given byte array slice.
public static CodedInputStream newInstance(final byte[] buf, final int off, final int len) {
return newInstance(buf, off, len, /* bufferIsImmutable= */ false);
}
/** Create a new CodedInputStream wrapping the given byte array slice. | CodedInputStream::newInstance | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
public static CodedInputStream newInstance(ByteBuffer buf) {
return newInstance(buf, /* bufferIsImmutable= */ false);
} |
Create a new CodedInputStream wrapping the given ByteBuffer. The data starting from the
ByteBuffer's current position to its limit will be read. The returned CodedInputStream may or
may not share the underlying data in the ByteBuffer, therefore the ByteBuffer cannot be changed
while the CodedInputStream is in use. Note that the ByteBuffer's position won't be changed by
this function. Concurrent calls with the same ByteBuffer object are safe if no other thread is
trying to alter the ByteBuffer's status.
| CodedInputStream::newInstance | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
static CodedInputStream newInstance(ByteBuffer buf, boolean bufferIsImmutable) {
if (buf.hasArray()) {
return newInstance(
buf.array(), buf.arrayOffset() + buf.position(), buf.remaining(), bufferIsImmutable);
}
if (buf.isDirect() && UnsafeDirectNioDecoder.isSupported()) {
return new UnsafeDirectNioDecoder(buf, bufferIsImmutable);
}
// The buffer is non-direct and does not expose the underlying array. Using the ByteBuffer API
// to access individual bytes is very slow, so just copy the buffer to an array.
// TODO(nathanmittler): Re-evaluate with Java 9
byte[] buffer = new byte[buf.remaining()];
buf.duplicate().get(buffer);
return newInstance(buffer, 0, buffer.length, true);
} |
Create a new CodedInputStream wrapping the given ByteBuffer. The data starting from the
ByteBuffer's current position to its limit will be read. The returned CodedInputStream may or
may not share the underlying data in the ByteBuffer, therefore the ByteBuffer cannot be changed
while the CodedInputStream is in use. Note that the ByteBuffer's position won't be changed by
this function. Concurrent calls with the same ByteBuffer object are safe if no other thread is
trying to alter the ByteBuffer's status.
public static CodedInputStream newInstance(ByteBuffer buf) {
return newInstance(buf, /* bufferIsImmutable= */ false);
}
/** Create a new CodedInputStream wrapping the given buffer. | CodedInputStream::newInstance | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
private CodedInputStream() {} |
Create a new CodedInputStream wrapping the given ByteBuffer. The data starting from the
ByteBuffer's current position to its limit will be read. The returned CodedInputStream may or
may not share the underlying data in the ByteBuffer, therefore the ByteBuffer cannot be changed
while the CodedInputStream is in use. Note that the ByteBuffer's position won't be changed by
this function. Concurrent calls with the same ByteBuffer object are safe if no other thread is
trying to alter the ByteBuffer's status.
public static CodedInputStream newInstance(ByteBuffer buf) {
return newInstance(buf, /* bufferIsImmutable= */ false);
}
/** Create a new CodedInputStream wrapping the given buffer.
static CodedInputStream newInstance(ByteBuffer buf, boolean bufferIsImmutable) {
if (buf.hasArray()) {
return newInstance(
buf.array(), buf.arrayOffset() + buf.position(), buf.remaining(), bufferIsImmutable);
}
if (buf.isDirect() && UnsafeDirectNioDecoder.isSupported()) {
return new UnsafeDirectNioDecoder(buf, bufferIsImmutable);
}
// The buffer is non-direct and does not expose the underlying array. Using the ByteBuffer API
// to access individual bytes is very slow, so just copy the buffer to an array.
// TODO(nathanmittler): Re-evaluate with Java 9
byte[] buffer = new byte[buf.remaining()];
buf.duplicate().get(buffer);
return newInstance(buffer, 0, buffer.length, true);
}
public void checkRecursionLimit() throws InvalidProtocolBufferException {
if (recursionDepth >= recursionLimit) {
throw InvalidProtocolBufferException.recursionLimitExceeded();
}
}
/** Disable construction/inheritance outside of this class. | CodedInputStream::CodedInputStream | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
public final int setRecursionLimit(final int limit) {
if (limit < 0) {
throw new IllegalArgumentException("Recursion limit cannot be negative: " + limit);
}
final int oldLimit = recursionLimit;
recursionLimit = limit;
return oldLimit;
} |
Set the maximum message recursion depth. In order to prevent malicious messages from causing
stack overflows, {@code CodedInputStream} limits how deeply messages may be nested. The default
limit is 100.
@return the old limit.
| CodedInputStream::setRecursionLimit | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
public final int setSizeLimit(final int limit) {
if (limit < 0) {
throw new IllegalArgumentException("Size limit cannot be negative: " + limit);
}
final int oldLimit = sizeLimit;
sizeLimit = limit;
return oldLimit;
} |
Only valid for {@link InputStream}-backed streams.
<p>Set the maximum message size. In order to prevent malicious messages from exhausting memory
or causing integer overflows, {@code CodedInputStream} limits how large a message may be. The
default limit is {@code Integer.MAX_VALUE}. You should set this limit as small as you can
without harming your app's functionality. Note that size limits only apply when reading from an
{@code InputStream}, not when constructed around a raw byte array.
<p>If you want to read several messages from a single CodedInputStream, you could call {@link
#resetSizeCounter()} after each one to avoid hitting the size limit.
@return the old limit.
| CodedInputStream::setSizeLimit | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
final void discardUnknownFields() {
shouldDiscardUnknownFields = true;
} |
Sets this {@code CodedInputStream} to discard unknown fields. Only applies to full runtime
messages; lite messages will always preserve unknowns.
<p>Note calling this function alone will have NO immediate effect on the underlying input data.
The unknown fields will be discarded during parsing. This affects both Proto2 and Proto3 full
runtime.
| CodedInputStream::discardUnknownFields | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
final void unsetDiscardUnknownFields() {
shouldDiscardUnknownFields = false;
} |
Reverts the unknown fields preservation behavior for Proto2 and Proto3 full runtime to their
default.
| CodedInputStream::unsetDiscardUnknownFields | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
final boolean shouldDiscardUnknownFields() {
return shouldDiscardUnknownFields;
} |
Whether unknown fields in this input stream should be discarded during parsing into full
runtime messages.
| CodedInputStream::shouldDiscardUnknownFields | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
public static int decodeZigZag32(final int n) {
return (n >>> 1) ^ -(n & 1);
} |
Decode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers into values that can be
efficiently encoded with varint. (Otherwise, negative values must be sign-extended to 64 bits
to be varint encoded, thus always taking 10 bytes on the wire.)
@param n An unsigned 32-bit integer, stored in a signed int because Java has no explicit
unsigned support.
@return A signed 32-bit integer.
| CodedInputStream::decodeZigZag32 | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
public static long decodeZigZag64(final long n) {
return (n >>> 1) ^ -(n & 1);
} |
Decode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers into values that can be
efficiently encoded with varint. (Otherwise, negative values must be sign-extended to 64 bits
to be varint encoded, thus always taking 10 bytes on the wire.)
@param n An unsigned 64-bit integer, stored in a signed int because Java has no explicit
unsigned support.
@return A signed 64-bit integer.
| CodedInputStream::decodeZigZag64 | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
public static int readRawVarint32(final int firstByte, final InputStream input)
throws IOException {
if ((firstByte & 0x80) == 0) {
return firstByte;
}
int result = firstByte & 0x7f;
int offset = 7;
for (; offset < 32; offset += 7) {
final int b = input.read();
if (b == -1) {
throw InvalidProtocolBufferException.truncatedMessage();
}
result |= (b & 0x7f) << offset;
if ((b & 0x80) == 0) {
return result;
}
}
// Keep reading up to 64 bits.
for (; offset < 64; offset += 7) {
final int b = input.read();
if (b == -1) {
throw InvalidProtocolBufferException.truncatedMessage();
}
if ((b & 0x80) == 0) {
return result;
}
}
throw InvalidProtocolBufferException.malformedVarint();
} |
Like {@link #readRawVarint32(InputStream)}, but expects that the caller has already read one
byte. This allows the caller to determine if EOF has been reached before attempting to read.
| CodedInputStream::readRawVarint32 | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
static int readRawVarint32(final InputStream input) throws IOException {
final int firstByte = input.read();
if (firstByte == -1) {
throw InvalidProtocolBufferException.truncatedMessage();
}
return readRawVarint32(firstByte, input);
} |
Reads a varint from the input one byte at a time, so that it does not read any bytes after the
end of the varint. If you simply wrapped the stream in a CodedInputStream and used {@link
#readRawVarint32(InputStream)} then you would probably end up reading past the end of the
varint since CodedInputStream buffers its input.
| CodedInputStream::readRawVarint32 | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
private static int read(InputStream input, byte[] data, int offset, int length)
throws IOException {
try {
return input.read(data, offset, length);
} catch (InvalidProtocolBufferException e) {
e.setThrownFromInputStream();
throw e;
}
} |
The total number of bytes read before the current buffer. The total bytes read up to the
current position can be computed as {@code totalBytesRetired + pos}. This value may be
negative if reading started in the middle of the current buffer (e.g. if the constructor that
takes a byte array and an offset was used).
private int totalBytesRetired;
/** The absolute position of the end of the current message.
private int currentLimit = Integer.MAX_VALUE;
private StreamDecoder(final InputStream input, int bufferSize) {
checkNotNull(input, "input");
this.input = input;
this.buffer = new byte[bufferSize];
this.bufferSize = 0;
pos = 0;
totalBytesRetired = 0;
}
/*
The following wrapper methods exist so that InvalidProtocolBufferExceptions thrown by the
InputStream can be differentiated from ones thrown by CodedInputStream itself. Each call to
an InputStream method that can throw IOException must be wrapped like this. We do this
because we sometimes need to modify IPBE instances after they are thrown far away from where
they are thrown (ex. to add unfinished messages) and we use this signal elsewhere in the
exception catch chain to know when to perform these operations directly or to wrap the
exception in their own IPBE so the extra information can be communicated without trampling
downstream information.
| StreamDecoder::read | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
ByteBuffer getSkippedData() {
if (byteArrayStream == null) {
return ByteBuffer.wrap(buffer, lastPos, pos - lastPos);
} else {
byteArrayStream.write(buffer, lastPos, pos);
return ByteBuffer.wrap(byteArrayStream.toByteArray());
}
} |
The total number of bytes read before the current buffer. The total bytes read up to the
current position can be computed as {@code totalBytesRetired + pos}. This value may be
negative if reading started in the middle of the current buffer (e.g. if the constructor that
takes a byte array and an offset was used).
private int totalBytesRetired;
/** The absolute position of the end of the current message.
private int currentLimit = Integer.MAX_VALUE;
private StreamDecoder(final InputStream input, int bufferSize) {
checkNotNull(input, "input");
this.input = input;
this.buffer = new byte[bufferSize];
this.bufferSize = 0;
pos = 0;
totalBytesRetired = 0;
}
/*
The following wrapper methods exist so that InvalidProtocolBufferExceptions thrown by the
InputStream can be differentiated from ones thrown by CodedInputStream itself. Each call to
an InputStream method that can throw IOException must be wrapped like this. We do this
because we sometimes need to modify IPBE instances after they are thrown far away from where
they are thrown (ex. to add unfinished messages) and we use this signal elsewhere in the
exception catch chain to know when to perform these operations directly or to wrap the
exception in their own IPBE so the extra information can be communicated without trampling
downstream information.
private static int read(InputStream input, byte[] data, int offset, int length)
throws IOException {
try {
return input.read(data, offset, length);
} catch (InvalidProtocolBufferException e) {
e.setThrownFromInputStream();
throw e;
}
}
private static long skip(InputStream input, long length) throws IOException {
try {
return input.skip(length);
} catch (InvalidProtocolBufferException e) {
e.setThrownFromInputStream();
throw e;
}
}
private static int available(InputStream input) throws IOException {
try {
return input.available();
} catch (InvalidProtocolBufferException e) {
e.setThrownFromInputStream();
throw e;
}
}
@Override
public int readTag() throws IOException {
if (isAtEnd()) {
lastTag = 0;
return 0;
}
lastTag = readRawVarint32();
if (WireFormat.getTagFieldNumber(lastTag) == 0) {
// If we actually read zero (or any tag number corresponding to field
// number zero), that's not a valid tag.
throw InvalidProtocolBufferException.invalidTag();
}
return lastTag;
}
@Override
public void checkLastTagWas(final int value) throws InvalidProtocolBufferException {
if (lastTag != value) {
throw InvalidProtocolBufferException.invalidEndTag();
}
}
@Override
public int getLastTag() {
return lastTag;
}
@Override
public boolean skipField(final int tag) throws IOException {
switch (WireFormat.getTagWireType(tag)) {
case WireFormat.WIRETYPE_VARINT:
skipRawVarint();
return true;
case WireFormat.WIRETYPE_FIXED64:
skipRawBytes(FIXED64_SIZE);
return true;
case WireFormat.WIRETYPE_LENGTH_DELIMITED:
skipRawBytes(readRawVarint32());
return true;
case WireFormat.WIRETYPE_START_GROUP:
skipMessage();
checkLastTagWas(
WireFormat.makeTag(WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP));
return true;
case WireFormat.WIRETYPE_END_GROUP:
return false;
case WireFormat.WIRETYPE_FIXED32:
skipRawBytes(FIXED32_SIZE);
return true;
default:
throw InvalidProtocolBufferException.invalidWireType();
}
}
@Override
public boolean skipField(final int tag, final CodedOutputStream output) throws IOException {
switch (WireFormat.getTagWireType(tag)) {
case WireFormat.WIRETYPE_VARINT:
{
long value = readInt64();
output.writeUInt32NoTag(tag);
output.writeUInt64NoTag(value);
return true;
}
case WireFormat.WIRETYPE_FIXED64:
{
long value = readRawLittleEndian64();
output.writeUInt32NoTag(tag);
output.writeFixed64NoTag(value);
return true;
}
case WireFormat.WIRETYPE_LENGTH_DELIMITED:
{
ByteString value = readBytes();
output.writeUInt32NoTag(tag);
output.writeBytesNoTag(value);
return true;
}
case WireFormat.WIRETYPE_START_GROUP:
{
output.writeUInt32NoTag(tag);
skipMessage(output);
int endtag =
WireFormat.makeTag(
WireFormat.getTagFieldNumber(tag), WireFormat.WIRETYPE_END_GROUP);
checkLastTagWas(endtag);
output.writeUInt32NoTag(endtag);
return true;
}
case WireFormat.WIRETYPE_END_GROUP:
{
return false;
}
case WireFormat.WIRETYPE_FIXED32:
{
int value = readRawLittleEndian32();
output.writeUInt32NoTag(tag);
output.writeFixed32NoTag(value);
return true;
}
default:
throw InvalidProtocolBufferException.invalidWireType();
}
}
@Override
public void skipMessage() throws IOException {
while (true) {
final int tag = readTag();
if (tag == 0 || !skipField(tag)) {
return;
}
}
}
@Override
public void skipMessage(CodedOutputStream output) throws IOException {
while (true) {
final int tag = readTag();
if (tag == 0 || !skipField(tag, output)) {
return;
}
}
}
/** Collects the bytes skipped and returns the data in a ByteBuffer.
private class SkippedDataSink implements RefillCallback {
private int lastPos = pos;
private ByteArrayOutputStream byteArrayStream;
@Override
public void onRefill() {
if (byteArrayStream == null) {
byteArrayStream = new ByteArrayOutputStream();
}
byteArrayStream.write(buffer, lastPos, pos - lastPos);
lastPos = 0;
}
/** Gets skipped data in a ByteBuffer. This method should only be called once. | SkippedDataSink::getSkippedData | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
private void refillBuffer(int n) throws IOException {
if (!tryRefillBuffer(n)) {
// We have to distinguish the exception between sizeLimitExceeded and truncatedMessage. So
// we just throw an sizeLimitExceeded exception here if it exceeds the sizeLimit
if (n > sizeLimit - totalBytesRetired - pos) {
throw InvalidProtocolBufferException.sizeLimitExceeded();
} else {
throw InvalidProtocolBufferException.truncatedMessage();
}
}
} |
Reads more bytes from the input, making at least {@code n} bytes available in the buffer.
Caller must ensure that the requested space is not yet available, and that the requested
space is less than BUFFER_SIZE.
@throws InvalidProtocolBufferException The end of the stream or the current limit was
reached.
| StreamDecoder::refillBuffer | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
private boolean tryRefillBuffer(int n) throws IOException {
if (pos + n <= bufferSize) {
throw new IllegalStateException(
"refillBuffer() called when " + n + " bytes were already available in buffer");
}
// Check whether the size of total message needs to read is bigger than the size limit.
// We shouldn't throw an exception here as isAtEnd() function needs to get this function's
// return as the result.
if (n > sizeLimit - totalBytesRetired - pos) {
return false;
}
// Shouldn't throw the exception here either.
if (totalBytesRetired + pos + n > currentLimit) {
// Oops, we hit a limit.
return false;
}
if (refillCallback != null) {
refillCallback.onRefill();
}
int tempPos = pos;
if (tempPos > 0) {
if (bufferSize > tempPos) {
System.arraycopy(buffer, tempPos, buffer, 0, bufferSize - tempPos);
}
totalBytesRetired += tempPos;
bufferSize -= tempPos;
pos = 0;
}
// Here we should refill the buffer as many bytes as possible.
int bytesRead =
read(
input,
buffer,
bufferSize,
Math.min(
// the size of allocated but unused bytes in the buffer
buffer.length - bufferSize,
// do not exceed the total bytes limit
sizeLimit - totalBytesRetired - bufferSize));
if (bytesRead == 0 || bytesRead < -1 || bytesRead > buffer.length) {
throw new IllegalStateException(
input.getClass()
+ "#read(byte[]) returned invalid result: "
+ bytesRead
+ "\nThe InputStream implementation is buggy.");
}
if (bytesRead > 0) {
bufferSize += bytesRead;
recomputeBufferSizeAfterLimit();
return (bufferSize >= n) ? true : tryRefillBuffer(n);
}
return false;
} |
Tries to read more bytes from the input, making at least {@code n} bytes available in the
buffer. Caller must ensure that the requested space is not yet available, and that the
requested space is less than BUFFER_SIZE.
@return {@code true} If the bytes could be made available; {@code false} 1. Current at the
end of the stream 2. The current limit was reached 3. The total size limit was reached
| StreamDecoder::tryRefillBuffer | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
private byte[] readRawBytesSlowPath(
final int size, boolean ensureNoLeakedReferences) throws IOException {
// Attempt to read the data in one byte array when it's safe to do.
byte[] result = readRawBytesSlowPathOneChunk(size);
if (result != null) {
return ensureNoLeakedReferences ? result.clone() : result;
}
final int originalBufferPos = pos;
final int bufferedBytes = bufferSize - pos;
// Mark the current buffer consumed.
totalBytesRetired += bufferSize;
pos = 0;
bufferSize = 0;
// Determine the number of bytes we need to read from the input stream.
int sizeLeft = size - bufferedBytes;
// The size is very large. For security reasons we read them in small
// chunks.
List<byte[]> chunks = readRawBytesSlowPathRemainingChunks(sizeLeft);
// OK, got everything. Now concatenate it all into one buffer.
final byte[] bytes = new byte[size];
// Start by copying the leftover bytes from this.buffer.
System.arraycopy(buffer, originalBufferPos, bytes, 0, bufferedBytes);
// And now all the chunks.
int tempPos = bufferedBytes;
for (final byte[] chunk : chunks) {
System.arraycopy(chunk, 0, bytes, tempPos, chunk.length);
tempPos += chunk.length;
}
// Done.
return bytes;
} |
Exactly like readRawBytes, but caller must have already checked the fast path: (size <=
(bufferSize - pos) && size > 0)
If ensureNoLeakedReferences is true, the value is guaranteed to have not escaped to
untrusted code.
| StreamDecoder::readRawBytesSlowPath | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
private byte[] readRawBytesSlowPathOneChunk(final int size) throws IOException {
if (size == 0) {
return Internal.EMPTY_BYTE_ARRAY;
}
if (size < 0) {
throw InvalidProtocolBufferException.negativeSize();
}
// Integer-overflow-conscious check that the message size so far has not exceeded sizeLimit.
int currentMessageSize = totalBytesRetired + pos + size;
if (currentMessageSize - sizeLimit > 0) {
throw InvalidProtocolBufferException.sizeLimitExceeded();
}
// Verify that the message size so far has not exceeded currentLimit.
if (currentMessageSize > currentLimit) {
// Read to the end of the stream anyway.
skipRawBytes(currentLimit - totalBytesRetired - pos);
throw InvalidProtocolBufferException.truncatedMessage();
}
final int bufferedBytes = bufferSize - pos;
// Determine the number of bytes we need to read from the input stream.
int sizeLeft = size - bufferedBytes;
// TODO(nathanmittler): Consider using a value larger than DEFAULT_BUFFER_SIZE.
if (sizeLeft < DEFAULT_BUFFER_SIZE || sizeLeft <= available(input)) {
// Either the bytes we need are known to be available, or the required buffer is
// within an allowed threshold - go ahead and allocate the buffer now.
final byte[] bytes = new byte[size];
// Copy all of the buffered bytes to the result buffer.
System.arraycopy(buffer, pos, bytes, 0, bufferedBytes);
totalBytesRetired += bufferSize;
pos = 0;
bufferSize = 0;
// Fill the remaining bytes from the input stream.
int tempPos = bufferedBytes;
while (tempPos < bytes.length) {
int n = read(input, bytes, tempPos, size - tempPos);
if (n == -1) {
throw InvalidProtocolBufferException.truncatedMessage();
}
totalBytesRetired += n;
tempPos += n;
}
return bytes;
}
return null;
} |
Attempts to read the data in one byte array when it's safe to do. Returns null if the size to
read is too large and needs to be allocated in smaller chunks for security reasons.
Returns a byte[] that may have escaped to user code via InputStream APIs.
| StreamDecoder::readRawBytesSlowPathOneChunk | java | Reginer/aosp-android-jar | android-34/src/com/google/protobuf/CodedInputStream.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/google/protobuf/CodedInputStream.java | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.