src/api-impl: fix up code style, mainly for code imported from AOSP

used the following (plus manual edits):
`clang-format --style="{BasedOnStyle: LLVM, IndentWidth: 8, UseTab: Always, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: true, ColumnLimit: 0}`
This commit is contained in:
Mis012
2023-06-22 11:45:46 +02:00
parent 824b821f5a
commit 0a9591c474
208 changed files with 154568 additions and 150150 deletions

View File

@@ -20,19 +20,18 @@ package android.util;
* Base class for all checked exceptions thrown by the Android frameworks.
*/
public class AndroidException extends Exception {
public AndroidException() {
}
public AndroidException() {
}
public AndroidException(String name) {
super(name);
}
public AndroidException(String name) {
super(name);
}
public AndroidException(String name, Throwable cause) {
super(name, cause);
}
public AndroidException(String name, Throwable cause) {
super(name, cause);
}
public AndroidException(Exception cause) {
super(cause);
}
public AndroidException(Exception cause) {
super(cause);
}
};

View File

@@ -20,19 +20,18 @@ package android.util;
* Base class for all unchecked exceptions thrown by the Android frameworks.
*/
public class AndroidRuntimeException extends RuntimeException {
public AndroidRuntimeException() {
}
public AndroidRuntimeException() {
}
public AndroidRuntimeException(String name) {
super(name);
}
public AndroidRuntimeException(String name) {
super(name);
}
public AndroidRuntimeException(String name, Throwable cause) {
super(name, cause);
}
public AndroidRuntimeException(String name, Throwable cause) {
super(name, cause);
}
public AndroidRuntimeException(Exception cause) {
super(cause);
}
public AndroidRuntimeException(Exception cause) {
super(cause);
}
};

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -24,7 +24,7 @@ import java.io.IOException;
* to be disambiguated from errors in the underlying streams (e.g. actual connection errors.)
*/
public class Base64DataException extends IOException {
public Base64DataException(String detailMessage) {
super(detailMessage);
}
public Base64DataException(String detailMessage) {
super(detailMessage);
}
}

View File

@@ -25,129 +25,130 @@ import java.io.InputStream;
* it.
*/
public class Base64InputStream extends FilterInputStream {
private final Base64.Coder coder;
private final Base64.Coder coder;
private static byte[] EMPTY = new byte[0];
private static byte[] EMPTY = new byte[0];
private static final int BUFFER_SIZE = 2048;
private boolean eof;
private byte[] inputBuffer;
private int outputStart;
private int outputEnd;
private static final int BUFFER_SIZE = 2048;
private boolean eof;
private byte[] inputBuffer;
private int outputStart;
private int outputEnd;
/**
* An InputStream that performs Base64 decoding on the data read
* from the wrapped stream.
*
* @param in the InputStream to read the source data from
* @param flags bit flags for controlling the decoder; see the
* constants in {@link Base64}
*/
public Base64InputStream(InputStream in, int flags) {
this(in, flags, false);
}
/**
* An InputStream that performs Base64 decoding on the data read
* from the wrapped stream.
*
* @param in the InputStream to read the source data from
* @param flags bit flags for controlling the decoder; see the
* constants in {@link Base64}
*/
public Base64InputStream(InputStream in, int flags) {
this(in, flags, false);
}
/**
* Performs Base64 encoding or decoding on the data read from the
* wrapped InputStream.
*
* @param in the InputStream to read the source data from
* @param flags bit flags for controlling the decoder; see the
* constants in {@link Base64}
* @param encode true to encode, false to decode
*
* @hide
*/
public Base64InputStream(InputStream in, int flags, boolean encode) {
super(in);
eof = false;
inputBuffer = new byte[BUFFER_SIZE];
if (encode) {
coder = new Base64.Encoder(flags, null);
} else {
coder = new Base64.Decoder(flags, null);
}
coder.output = new byte[coder.maxOutputSize(BUFFER_SIZE)];
outputStart = 0;
outputEnd = 0;
}
/**
* Performs Base64 encoding or decoding on the data read from the
* wrapped InputStream.
*
* @param in the InputStream to read the source data from
* @param flags bit flags for controlling the decoder; see the
* constants in {@link Base64}
* @param encode true to encode, false to decode
*
* @hide
*/
public Base64InputStream(InputStream in, int flags, boolean encode) {
super(in);
eof = false;
inputBuffer = new byte[BUFFER_SIZE];
if (encode) {
coder = new Base64.Encoder(flags, null);
} else {
coder = new Base64.Decoder(flags, null);
}
coder.output = new byte[coder.maxOutputSize(BUFFER_SIZE)];
outputStart = 0;
outputEnd = 0;
}
public boolean markSupported() {
return false;
}
public boolean markSupported() {
return false;
}
public void mark(int readlimit) {
throw new UnsupportedOperationException();
}
public void mark(int readlimit) {
throw new UnsupportedOperationException();
}
public void reset() {
throw new UnsupportedOperationException();
}
public void reset() {
throw new UnsupportedOperationException();
}
public void close() throws IOException {
in.close();
inputBuffer = null;
}
public void close() throws IOException {
in.close();
inputBuffer = null;
}
public int available() {
return outputEnd - outputStart;
}
public int available() {
return outputEnd - outputStart;
}
public long skip(long n) throws IOException {
if (outputStart >= outputEnd) {
refill();
}
if (outputStart >= outputEnd) {
return 0;
}
long bytes = Math.min(n, outputEnd-outputStart);
outputStart += bytes;
return bytes;
}
public long skip(long n) throws IOException {
if (outputStart >= outputEnd) {
refill();
}
if (outputStart >= outputEnd) {
return 0;
}
long bytes = Math.min(n, outputEnd - outputStart);
outputStart += bytes;
return bytes;
}
public int read() throws IOException {
if (outputStart >= outputEnd) {
refill();
}
if (outputStart >= outputEnd) {
return -1;
} else {
return coder.output[outputStart++] & 0xff;
}
}
public int read() throws IOException {
if (outputStart >= outputEnd) {
refill();
}
if (outputStart >= outputEnd) {
return -1;
} else {
return coder.output[outputStart++] & 0xff;
}
}
public int read(byte[] b, int off, int len) throws IOException {
if (outputStart >= outputEnd) {
refill();
}
if (outputStart >= outputEnd) {
return -1;
}
int bytes = Math.min(len, outputEnd-outputStart);
System.arraycopy(coder.output, outputStart, b, off, bytes);
outputStart += bytes;
return bytes;
}
public int read(byte[] b, int off, int len) throws IOException {
if (outputStart >= outputEnd) {
refill();
}
if (outputStart >= outputEnd) {
return -1;
}
int bytes = Math.min(len, outputEnd - outputStart);
System.arraycopy(coder.output, outputStart, b, off, bytes);
outputStart += bytes;
return bytes;
}
/**
* Read data from the input stream into inputBuffer, then
* decode/encode it into the empty coder.output, and reset the
* outputStart and outputEnd pointers.
*/
private void refill() throws IOException {
if (eof) return;
int bytesRead = in.read(inputBuffer);
boolean success;
if (bytesRead == -1) {
eof = true;
success = coder.process(EMPTY, 0, 0, true);
} else {
success = coder.process(inputBuffer, 0, bytesRead, false);
}
if (!success) {
throw new Base64DataException("bad base-64");
}
outputEnd = coder.op;
outputStart = 0;
}
/**
* Read data from the input stream into inputBuffer, then
* decode/encode it into the empty coder.output, and reset the
* outputStart and outputEnd pointers.
*/
private void refill() throws IOException {
if (eof)
return;
int bytesRead = in.read(inputBuffer);
boolean success;
if (bytesRead == -1) {
eof = true;
success = coder.process(EMPTY, 0, 0, true);
} else {
success = coder.process(inputBuffer, 0, bytesRead, false);
}
if (!success) {
throw new Base64DataException("bad base-64");
}
outputEnd = coder.op;
outputStart = 0;
}
}

View File

@@ -25,131 +25,132 @@ import java.io.OutputStream;
* it, writing the resulting data to another OutputStream.
*/
public class Base64OutputStream extends FilterOutputStream {
private final Base64.Coder coder;
private final int flags;
private final Base64.Coder coder;
private final int flags;
private byte[] buffer = null;
private int bpos = 0;
private byte[] buffer = null;
private int bpos = 0;
private static byte[] EMPTY = new byte[0];
private static byte[] EMPTY = new byte[0];
/**
* Performs Base64 encoding on the data written to the stream,
* writing the encoded data to another OutputStream.
*
* @param out the OutputStream to write the encoded data to
* @param flags bit flags for controlling the encoder; see the
* constants in {@link Base64}
*/
public Base64OutputStream(OutputStream out, int flags) {
this(out, flags, true);
}
/**
* Performs Base64 encoding on the data written to the stream,
* writing the encoded data to another OutputStream.
*
* @param out the OutputStream to write the encoded data to
* @param flags bit flags for controlling the encoder; see the
* constants in {@link Base64}
*/
public Base64OutputStream(OutputStream out, int flags) {
this(out, flags, true);
}
/**
* Performs Base64 encoding or decoding on the data written to the
* stream, writing the encoded/decoded data to another
* OutputStream.
*
* @param out the OutputStream to write the encoded data to
* @param flags bit flags for controlling the encoder; see the
* constants in {@link Base64}
* @param encode true to encode, false to decode
*
* @hide
*/
public Base64OutputStream(OutputStream out, int flags, boolean encode) {
super(out);
this.flags = flags;
if (encode) {
coder = new Base64.Encoder(flags, null);
} else {
coder = new Base64.Decoder(flags, null);
}
}
/**
* Performs Base64 encoding or decoding on the data written to the
* stream, writing the encoded/decoded data to another
* OutputStream.
*
* @param out the OutputStream to write the encoded data to
* @param flags bit flags for controlling the encoder; see the
* constants in {@link Base64}
* @param encode true to encode, false to decode
*
* @hide
*/
public Base64OutputStream(OutputStream out, int flags, boolean encode) {
super(out);
this.flags = flags;
if (encode) {
coder = new Base64.Encoder(flags, null);
} else {
coder = new Base64.Decoder(flags, null);
}
}
public void write(int b) throws IOException {
// To avoid invoking the encoder/decoder routines for single
// bytes, we buffer up calls to write(int) in an internal
// byte array to transform them into writes of decently-sized
// arrays.
public void write(int b) throws IOException {
// To avoid invoking the encoder/decoder routines for single
// bytes, we buffer up calls to write(int) in an internal
// byte array to transform them into writes of decently-sized
// arrays.
if (buffer == null) {
buffer = new byte[1024];
}
if (bpos >= buffer.length) {
// internal buffer full; write it out.
internalWrite(buffer, 0, bpos, false);
bpos = 0;
}
buffer[bpos++] = (byte) b;
}
if (buffer == null) {
buffer = new byte[1024];
}
if (bpos >= buffer.length) {
// internal buffer full; write it out.
internalWrite(buffer, 0, bpos, false);
bpos = 0;
}
buffer[bpos++] = (byte)b;
}
/**
* Flush any buffered data from calls to write(int). Needed
* before doing a write(byte[], int, int) or a close().
*/
private void flushBuffer() throws IOException {
if (bpos > 0) {
internalWrite(buffer, 0, bpos, false);
bpos = 0;
}
}
/**
* Flush any buffered data from calls to write(int). Needed
* before doing a write(byte[], int, int) or a close().
*/
private void flushBuffer() throws IOException {
if (bpos > 0) {
internalWrite(buffer, 0, bpos, false);
bpos = 0;
}
}
public void write(byte[] b, int off, int len) throws IOException {
if (len <= 0) return;
flushBuffer();
internalWrite(b, off, len, false);
}
public void write(byte[] b, int off, int len) throws IOException {
if (len <= 0)
return;
flushBuffer();
internalWrite(b, off, len, false);
}
public void close() throws IOException {
IOException thrown = null;
try {
flushBuffer();
internalWrite(EMPTY, 0, 0, true);
} catch (IOException e) {
thrown = e;
}
public void close() throws IOException {
IOException thrown = null;
try {
flushBuffer();
internalWrite(EMPTY, 0, 0, true);
} catch (IOException e) {
thrown = e;
}
try {
if ((flags & Base64.NO_CLOSE) == 0) {
out.close();
} else {
out.flush();
}
} catch (IOException e) {
if (thrown != null) {
thrown = e;
}
}
try {
if ((flags & Base64.NO_CLOSE) == 0) {
out.close();
} else {
out.flush();
}
} catch (IOException e) {
if (thrown != null) {
thrown = e;
}
}
if (thrown != null) {
throw thrown;
}
}
if (thrown != null) {
throw thrown;
}
}
/**
* Write the given bytes to the encoder/decoder.
*
* @param finish true if this is the last batch of input, to cause
* encoder/decoder state to be finalized.
*/
private void internalWrite(byte[] b, int off, int len, boolean finish) throws IOException {
coder.output = embiggen(coder.output, coder.maxOutputSize(len));
if (!coder.process(b, off, len, finish)) {
throw new Base64DataException("bad base-64");
}
out.write(coder.output, 0, coder.op);
}
/**
* Write the given bytes to the encoder/decoder.
*
* @param finish true if this is the last batch of input, to cause
* encoder/decoder state to be finalized.
*/
private void internalWrite(byte[] b, int off, int len, boolean finish) throws IOException {
coder.output = embiggen(coder.output, coder.maxOutputSize(len));
if (!coder.process(b, off, len, finish)) {
throw new Base64DataException("bad base-64");
}
out.write(coder.output, 0, coder.op);
}
/**
* If b.length is at least len, return b. Otherwise return a new
* byte array of length len.
*/
private byte[] embiggen(byte[] b, int len) {
if (b == null || b.length < len) {
return new byte[len];
} else {
return b;
}
}
/**
* If b.length is at least len, return b. Otherwise return a new
* byte array of length len.
*/
private byte[] embiggen(byte[] b, int len) {
if (b == null || b.length < len) {
return new byte[len];
} else {
return b;
}
}
}

View File

@@ -17,47 +17,47 @@
package android.util;
class ContainerHelpers {
static final boolean[] EMPTY_BOOLEANS = new boolean[0];
static final int[] EMPTY_INTS = new int[0];
static final long[] EMPTY_LONGS = new long[0];
static final Object[] EMPTY_OBJECTS = new Object[0];
static final boolean[] EMPTY_BOOLEANS = new boolean[0];
static final int[] EMPTY_INTS = new int[0];
static final long[] EMPTY_LONGS = new long[0];
static final Object[] EMPTY_OBJECTS = new Object[0];
// This is Arrays.binarySearch(), but doesn't do any argument validation.
static int binarySearch(int[] array, int size, int value) {
int lo = 0;
int hi = size - 1;
// This is Arrays.binarySearch(), but doesn't do any argument validation.
static int binarySearch(int[] array, int size, int value) {
int lo = 0;
int hi = size - 1;
while (lo <= hi) {
final int mid = (lo + hi) >>> 1;
final int midVal = array[mid];
while (lo <= hi) {
final int mid = (lo + hi) >>> 1;
final int midVal = array[mid];
if (midVal < value) {
lo = mid + 1;
} else if (midVal > value) {
hi = mid - 1;
} else {
return mid; // value found
}
}
return ~lo; // value not present
}
if (midVal < value) {
lo = mid + 1;
} else if (midVal > value) {
hi = mid - 1;
} else {
return mid; // value found
}
}
return ~lo; // value not present
}
static int binarySearch(long[] array, int size, long value) {
int lo = 0;
int hi = size - 1;
static int binarySearch(long[] array, int size, long value) {
int lo = 0;
int hi = size - 1;
while (lo <= hi) {
final int mid = (lo + hi) >>> 1;
final long midVal = array[mid];
while (lo <= hi) {
final int mid = (lo + hi) >>> 1;
final long midVal = array[mid];
if (midVal < value) {
lo = mid + 1;
} else if (midVal > value) {
hi = mid - 1;
} else {
return mid; // value found
}
}
return ~lo; // value not present
}
if (midVal < value) {
lo = mid + 1;
} else if (midVal > value) {
hi = mid - 1;
} else {
return mid; // value found
}
}
return ~lo; // value not present
}
}

View File

@@ -1,127 +1,125 @@
package android.util;
import org.xmlpull.v1.XmlPullParser;
import org.kxml2.io.KXmlParser;
import com.android.internal.util.XmlUtils;
import android.util.AttributeSet;
import com.android.internal.util.XmlUtils;
import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParser;
public class DecompiledXmlResourceParser extends KXmlParser implements AttributeSet, AutoCloseable {
public int getAttributeCount() {
return this.getAttributeCount();
}
public int getAttributeCount() {
return this.getAttributeCount();
}
public String getAttributeNamespace (int index) {
return this.getAttributeNamespace(index);
}
public String getAttributeNamespace(int index) {
return this.getAttributeNamespace(index);
}
public String getAttributeName(int index) {
return this.getAttributeName(index);
}
public String getAttributeName(int index) {
return this.getAttributeName(index);
}
public String getAttributeValue(int index) {
return this.getAttributeValue(index);
}
public String getAttributeValue(int index) {
return this.getAttributeValue(index);
}
public String getAttributeValue(String namespace, String name) {
return this.getAttributeValue(namespace, name);
}
public String getAttributeValue(String namespace, String name) {
return this.getAttributeValue(namespace, name);
}
public String getPositionDescription() {
return this.getPositionDescription();
}
public String getPositionDescription() {
return this.getPositionDescription();
}
public int getAttributeNameResource(int index) {
return 0;
}
public int getAttributeNameResource(int index) {
return 0;
}
public int getAttributeListValue(String namespace, String attribute,
String[] options, int defaultValue) {
return XmlUtils.convertValueToList(
getAttributeValue(namespace, attribute), options, defaultValue);
}
public int getAttributeListValue(String namespace, String attribute,
String[] options, int defaultValue) {
return XmlUtils.convertValueToList(
getAttributeValue(namespace, attribute), options, defaultValue);
}
public boolean getAttributeBooleanValue(String namespace, String attribute,
boolean defaultValue) {
return XmlUtils.convertValueToBoolean(
getAttributeValue(namespace, attribute), defaultValue);
}
public boolean getAttributeBooleanValue(String namespace, String attribute,
boolean defaultValue) {
return XmlUtils.convertValueToBoolean(
getAttributeValue(namespace, attribute), defaultValue);
}
public int getAttributeResourceValue(String namespace, String attribute,
int defaultValue) {
return XmlUtils.convertValueToInt(
getAttributeValue(namespace, attribute), defaultValue);
}
public int getAttributeResourceValue(String namespace, String attribute,
int defaultValue) {
return XmlUtils.convertValueToInt(
getAttributeValue(namespace, attribute), defaultValue);
}
public int getAttributeIntValue(String namespace, String attribute,
int defaultValue) {
return XmlUtils.convertValueToInt(
getAttributeValue(namespace, attribute), defaultValue);
}
public int getAttributeIntValue(String namespace, String attribute,
int defaultValue) {
return XmlUtils.convertValueToInt(
getAttributeValue(namespace, attribute), defaultValue);
}
public int getAttributeUnsignedIntValue(String namespace, String attribute,
int defaultValue) {
return XmlUtils.convertValueToUnsignedInt(
getAttributeValue(namespace, attribute), defaultValue);
}
public int getAttributeUnsignedIntValue(String namespace, String attribute,
int defaultValue) {
return XmlUtils.convertValueToUnsignedInt(
getAttributeValue(namespace, attribute), defaultValue);
}
public float getAttributeFloatValue(String namespace, String attribute,
float defaultValue) {
String s = getAttributeValue(namespace, attribute);
if (s != null) {
return Float.parseFloat(s);
}
return defaultValue;
}
public float getAttributeFloatValue(String namespace, String attribute,
float defaultValue) {
String s = getAttributeValue(namespace, attribute);
if (s != null) {
return Float.parseFloat(s);
}
return defaultValue;
}
public int getAttributeListValue(int index,
String[] options, int defaultValue) {
return XmlUtils.convertValueToList(
getAttributeValue(index), options, defaultValue);
}
public int getAttributeListValue(int index,
String[] options, int defaultValue) {
return XmlUtils.convertValueToList(
getAttributeValue(index), options, defaultValue);
}
public boolean getAttributeBooleanValue(int index, boolean defaultValue) {
return XmlUtils.convertValueToBoolean(
getAttributeValue(index), defaultValue);
}
public boolean getAttributeBooleanValue(int index, boolean defaultValue) {
return XmlUtils.convertValueToBoolean(
getAttributeValue(index), defaultValue);
}
public int getAttributeResourceValue(int index, int defaultValue) {
return XmlUtils.convertValueToInt(
getAttributeValue(index), defaultValue);
}
public int getAttributeResourceValue(int index, int defaultValue) {
return XmlUtils.convertValueToInt(
getAttributeValue(index), defaultValue);
}
public int getAttributeIntValue(int index, int defaultValue) {
return XmlUtils.convertValueToInt(
getAttributeValue(index), defaultValue);
}
public int getAttributeIntValue(int index, int defaultValue) {
return XmlUtils.convertValueToInt(
getAttributeValue(index), defaultValue);
}
public int getAttributeUnsignedIntValue(int index, int defaultValue) {
return XmlUtils.convertValueToUnsignedInt(
getAttributeValue(index), defaultValue);
}
public int getAttributeUnsignedIntValue(int index, int defaultValue) {
return XmlUtils.convertValueToUnsignedInt(
getAttributeValue(index), defaultValue);
}
public float getAttributeFloatValue(int index, float defaultValue) {
String s = getAttributeValue(index);
if (s != null) {
return Float.parseFloat(s);
}
return defaultValue;
}
public float getAttributeFloatValue(int index, float defaultValue) {
String s = getAttributeValue(index);
if (s != null) {
return Float.parseFloat(s);
}
return defaultValue;
}
public String getIdAttribute() {
return getAttributeValue(null, "id");
}
public String getIdAttribute() {
return getAttributeValue(null, "id");
}
public String getClassAttribute() {
return getAttributeValue(null, "class");
}
public String getClassAttribute() {
return getAttributeValue(null, "class");
}
public int getIdAttributeResourceValue(int defaultValue) {
return getAttributeResourceValue(null, "id", defaultValue);
}
public int getIdAttributeResourceValue(int defaultValue) {
return getAttributeResourceValue(null, "id", defaultValue);
}
public int getStyleAttribute() {
return getAttributeResourceValue(null, "style", 0);
}
public int getStyleAttribute() {
return getAttributeResourceValue(null, "style", 0);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -23,26 +23,26 @@ package android.util;
*/
public final class LayoutDirection {
// No instantiation
private LayoutDirection() {}
// No instantiation
private LayoutDirection() {}
/**
* Horizontal layout direction is from Left to Right.
*/
public static final int LTR = 0;
/**
* Horizontal layout direction is from Left to Right.
*/
public static final int LTR = 0;
/**
* Horizontal layout direction is from Right to Left.
*/
public static final int RTL = 1;
/**
* Horizontal layout direction is from Right to Left.
*/
public static final int RTL = 1;
/**
* Horizontal layout direction is inherited.
*/
public static final int INHERIT = 2;
/**
* Horizontal layout direction is inherited.
*/
public static final int INHERIT = 2;
/**
* Horizontal layout direction is deduced from the default language script for the locale.
*/
public static final int LOCALE = 3;
/**
* Horizontal layout direction is deduced from the default language script for the locale.
*/
public static final int LOCALE = 3;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -23,28 +23,28 @@ package android.util;
* @hide
*/
public class PrefixPrinter implements Printer {
private final Printer mPrinter;
private final String mPrefix;
private final Printer mPrinter;
private final String mPrefix;
/**
* Creates a new PrefixPrinter.
*
* <p>If prefix is null or empty, the provided printer is returned, rather
* than making a prefixing printer.
*/
public static Printer create(Printer printer, String prefix) {
if (prefix == null || prefix.equals("")) {
return printer;
}
return new PrefixPrinter(printer, prefix);
}
/**
* Creates a new PrefixPrinter.
*
* <p>If prefix is null or empty, the provided printer is returned, rather
* than making a prefixing printer.
*/
public static Printer create(Printer printer, String prefix) {
if (prefix == null || prefix.equals("")) {
return printer;
}
return new PrefixPrinter(printer, prefix);
}
private PrefixPrinter(Printer printer, String prefix) {
mPrinter = printer;
mPrefix = prefix;
}
private PrefixPrinter(Printer printer, String prefix) {
mPrinter = printer;
mPrefix = prefix;
}
public void println(String str) {
mPrinter.println(mPrefix + str);
}
public void println(String str) {
mPrinter.println(mPrefix + str);
}
}

View File

@@ -23,9 +23,9 @@ package android.util;
* {@link android.util.PrintWriterPrinter}.
*/
public interface Printer {
/**
* Write a line of text to the output. There is no need to terminate
* the given string with a newline.
*/
void println(String x);
/**
* Write a line of text to the output. There is no need to terminate
* the given string with a newline.
*/
void println(String x);
}

View File

@@ -24,76 +24,75 @@ import java.io.StringWriter;
*/
public final class Slog {
private Slog() {
}
private Slog() {
}
public static int v(String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.VERBOSE, tag, msg);
}
public static int v(String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.VERBOSE, tag, msg);
}
public static int v(String tag, String msg, Throwable tr) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.VERBOSE, tag,
msg + '\n' + Log.getStackTraceString(tr));
}
public static int v(String tag, String msg, Throwable tr) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.VERBOSE, tag,
msg + '\n' + Log.getStackTraceString(tr));
}
public static int d(String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.DEBUG, tag, msg);
}
public static int d(String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.DEBUG, tag, msg);
}
public static int d(String tag, String msg, Throwable tr) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.DEBUG, tag,
msg + '\n' + Log.getStackTraceString(tr));
}
public static int d(String tag, String msg, Throwable tr) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.DEBUG, tag,
msg + '\n' + Log.getStackTraceString(tr));
}
public static int i(String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.INFO, tag, msg);
}
public static int i(String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.INFO, tag, msg);
}
public static int i(String tag, String msg, Throwable tr) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.INFO, tag,
msg + '\n' + Log.getStackTraceString(tr));
}
public static int i(String tag, String msg, Throwable tr) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.INFO, tag,
msg + '\n' + Log.getStackTraceString(tr));
}
public static int w(String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.WARN, tag, msg);
}
public static int w(String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.WARN, tag, msg);
}
public static int w(String tag, String msg, Throwable tr) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.WARN, tag,
msg + '\n' + Log.getStackTraceString(tr));
}
public static int w(String tag, String msg, Throwable tr) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.WARN, tag,
msg + '\n' + Log.getStackTraceString(tr));
}
public static int w(String tag, Throwable tr) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.WARN, tag, Log.getStackTraceString(tr));
}
public static int w(String tag, Throwable tr) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.WARN, tag, Log.getStackTraceString(tr));
}
public static int e(String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.ERROR, tag, msg);
}
public static int e(String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.ERROR, tag, msg);
}
public static int e(String tag, String msg, Throwable tr) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.ERROR, tag,
msg + '\n' + Log.getStackTraceString(tr));
}
public static int e(String tag, String msg, Throwable tr) {
return Log.println_native(Log.LOG_ID_SYSTEM, Log.ERROR, tag,
msg + '\n' + Log.getStackTraceString(tr));
}
public static int wtf(String tag, String msg) {
return Log.wtf(Log.LOG_ID_SYSTEM, tag, msg, null, false);
}
public static int wtf(String tag, String msg) {
return Log.wtf(Log.LOG_ID_SYSTEM, tag, msg, null, false);
}
public static int wtfStack(String tag, String msg) {
return Log.wtf(Log.LOG_ID_SYSTEM, tag, msg, null, true);
}
public static int wtfStack(String tag, String msg) {
return Log.wtf(Log.LOG_ID_SYSTEM, tag, msg, null, true);
}
public static int wtf(String tag, Throwable tr) {
return Log.wtf(Log.LOG_ID_SYSTEM, tag, tr.getMessage(), tr, false);
}
public static int wtf(String tag, Throwable tr) {
return Log.wtf(Log.LOG_ID_SYSTEM, tag, tr.getMessage(), tr, false);
}
public static int wtf(String tag, String msg, Throwable tr) {
return Log.wtf(Log.LOG_ID_SYSTEM, tag, msg, tr, false);
}
public static int wtf(String tag, String msg, Throwable tr) {
return Log.wtf(Log.LOG_ID_SYSTEM, tag, msg, tr, false);
}
public static int println(int priority, String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, priority, tag, msg);
}
public static int println(int priority, String tag, String msg) {
return Log.println_native(Log.LOG_ID_SYSTEM, priority, tag, msg);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -40,253 +40,253 @@ import com.android.internal.util.ArrayUtils;
* order in the case of <code>valueAt(int)<code>.</p>
*/
public class SparseIntArray implements Cloneable {
private int[] mKeys;
private int[] mValues;
private int mSize;
private int[] mKeys;
private int[] mValues;
private int mSize;
/**
* Creates a new SparseIntArray containing no mappings.
*/
public SparseIntArray() {
this(10);
}
/**
* Creates a new SparseIntArray containing no mappings.
*/
public SparseIntArray() {
this(10);
}
/**
* Creates a new SparseIntArray containing no mappings that will not
* require any additional memory allocation to store the specified
* number of mappings. If you supply an initial capacity of 0, the
* sparse array will be initialized with a light-weight representation
* not requiring any additional array allocations.
*/
public SparseIntArray(int initialCapacity) {
if (initialCapacity == 0) {
mKeys = ContainerHelpers.EMPTY_INTS;
mValues = ContainerHelpers.EMPTY_INTS;
} else {
initialCapacity = ArrayUtils.idealIntArraySize(initialCapacity);
mKeys = new int[initialCapacity];
mValues = new int[initialCapacity];
}
mSize = 0;
}
/**
* Creates a new SparseIntArray containing no mappings that will not
* require any additional memory allocation to store the specified
* number of mappings. If you supply an initial capacity of 0, the
* sparse array will be initialized with a light-weight representation
* not requiring any additional array allocations.
*/
public SparseIntArray(int initialCapacity) {
if (initialCapacity == 0) {
mKeys = ContainerHelpers.EMPTY_INTS;
mValues = ContainerHelpers.EMPTY_INTS;
} else {
initialCapacity = ArrayUtils.idealIntArraySize(initialCapacity);
mKeys = new int[initialCapacity];
mValues = new int[initialCapacity];
}
mSize = 0;
}
@Override
public SparseIntArray clone() {
SparseIntArray clone = null;
try {
clone = (SparseIntArray) super.clone();
clone.mKeys = mKeys.clone();
clone.mValues = mValues.clone();
} catch (CloneNotSupportedException cnse) {
/* ignore */
}
return clone;
}
@Override
public SparseIntArray clone() {
SparseIntArray clone = null;
try {
clone = (SparseIntArray)super.clone();
clone.mKeys = mKeys.clone();
clone.mValues = mValues.clone();
} catch (CloneNotSupportedException cnse) {
/* ignore */
}
return clone;
}
/**
* Gets the int mapped from the specified key, or <code>0</code>
* if no such mapping has been made.
*/
public int get(int key) {
return get(key, 0);
}
/**
* Gets the int mapped from the specified key, or <code>0</code>
* if no such mapping has been made.
*/
public int get(int key) {
return get(key, 0);
}
/**
* Gets the int mapped from the specified key, or the specified value
* if no such mapping has been made.
*/
public int get(int key, int valueIfKeyNotFound) {
int i = ContainerHelpers.binarySearch(mKeys, mSize, key);
/**
* Gets the int mapped from the specified key, or the specified value
* if no such mapping has been made.
*/
public int get(int key, int valueIfKeyNotFound) {
int i = ContainerHelpers.binarySearch(mKeys, mSize, key);
if (i < 0) {
return valueIfKeyNotFound;
} else {
return mValues[i];
}
}
if (i < 0) {
return valueIfKeyNotFound;
} else {
return mValues[i];
}
}
/**
* Removes the mapping from the specified key, if there was any.
*/
public void delete(int key) {
int i = ContainerHelpers.binarySearch(mKeys, mSize, key);
/**
* Removes the mapping from the specified key, if there was any.
*/
public void delete(int key) {
int i = ContainerHelpers.binarySearch(mKeys, mSize, key);
if (i >= 0) {
removeAt(i);
}
}
if (i >= 0) {
removeAt(i);
}
}
/**
* Removes the mapping at the given index.
*/
public void removeAt(int index) {
System.arraycopy(mKeys, index + 1, mKeys, index, mSize - (index + 1));
System.arraycopy(mValues, index + 1, mValues, index, mSize - (index + 1));
mSize--;
}
/**
* Removes the mapping at the given index.
*/
public void removeAt(int index) {
System.arraycopy(mKeys, index + 1, mKeys, index, mSize - (index + 1));
System.arraycopy(mValues, index + 1, mValues, index, mSize - (index + 1));
mSize--;
}
/**
* Adds a mapping from the specified key to the specified value,
* replacing the previous mapping from the specified key if there
* was one.
*/
public void put(int key, int value) {
int i = ContainerHelpers.binarySearch(mKeys, mSize, key);
/**
* Adds a mapping from the specified key to the specified value,
* replacing the previous mapping from the specified key if there
* was one.
*/
public void put(int key, int value) {
int i = ContainerHelpers.binarySearch(mKeys, mSize, key);
if (i >= 0) {
mValues[i] = value;
} else {
i = ~i;
if (i >= 0) {
mValues[i] = value;
} else {
i = ~i;
if (mSize >= mKeys.length) {
int n = ArrayUtils.idealIntArraySize(mSize + 1);
if (mSize >= mKeys.length) {
int n = ArrayUtils.idealIntArraySize(mSize + 1);
int[] nkeys = new int[n];
int[] nvalues = new int[n];
int[] nkeys = new int[n];
int[] nvalues = new int[n];
// Log.e("SparseIntArray", "grow " + mKeys.length + " to " + n);
System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length);
System.arraycopy(mValues, 0, nvalues, 0, mValues.length);
// Log.e("SparseIntArray", "grow " + mKeys.length + " to " + n);
System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length);
System.arraycopy(mValues, 0, nvalues, 0, mValues.length);
mKeys = nkeys;
mValues = nvalues;
}
mKeys = nkeys;
mValues = nvalues;
}
if (mSize - i != 0) {
// Log.e("SparseIntArray", "move " + (mSize - i));
System.arraycopy(mKeys, i, mKeys, i + 1, mSize - i);
System.arraycopy(mValues, i, mValues, i + 1, mSize - i);
}
if (mSize - i != 0) {
// Log.e("SparseIntArray", "move " + (mSize - i));
System.arraycopy(mKeys, i, mKeys, i + 1, mSize - i);
System.arraycopy(mValues, i, mValues, i + 1, mSize - i);
}
mKeys[i] = key;
mValues[i] = value;
mSize++;
}
}
mKeys[i] = key;
mValues[i] = value;
mSize++;
}
}
/**
* Returns the number of key-value mappings that this SparseIntArray
* currently stores.
*/
public int size() {
return mSize;
}
/**
* Returns the number of key-value mappings that this SparseIntArray
* currently stores.
*/
public int size() {
return mSize;
}
/**
* Given an index in the range <code>0...size()-1</code>, returns
* the key from the <code>index</code>th key-value mapping that this
* SparseIntArray stores.
*
* <p>The keys corresponding to indices in ascending order are guaranteed to
* be in ascending order, e.g., <code>keyAt(0)</code> will return the
* smallest key and <code>keyAt(size()-1)</code> will return the largest
* key.</p>
*/
public int keyAt(int index) {
return mKeys[index];
}
/**
* Given an index in the range <code>0...size()-1</code>, returns
* the key from the <code>index</code>th key-value mapping that this
* SparseIntArray stores.
*
* <p>The keys corresponding to indices in ascending order are guaranteed to
* be in ascending order, e.g., <code>keyAt(0)</code> will return the
* smallest key and <code>keyAt(size()-1)</code> will return the largest
* key.</p>
*/
public int keyAt(int index) {
return mKeys[index];
}
/**
* Given an index in the range <code>0...size()-1</code>, returns
* the value from the <code>index</code>th key-value mapping that this
* SparseIntArray stores.
*
* <p>The values corresponding to indices in ascending order are guaranteed
* to be associated with keys in ascending order, e.g.,
* <code>valueAt(0)</code> will return the value associated with the
* smallest key and <code>valueAt(size()-1)</code> will return the value
* associated with the largest key.</p>
*/
public int valueAt(int index) {
return mValues[index];
}
/**
* Given an index in the range <code>0...size()-1</code>, returns
* the value from the <code>index</code>th key-value mapping that this
* SparseIntArray stores.
*
* <p>The values corresponding to indices in ascending order are guaranteed
* to be associated with keys in ascending order, e.g.,
* <code>valueAt(0)</code> will return the value associated with the
* smallest key and <code>valueAt(size()-1)</code> will return the value
* associated with the largest key.</p>
*/
public int valueAt(int index) {
return mValues[index];
}
/**
* Returns the index for which {@link #keyAt} would return the
* specified key, or a negative number if the specified
* key is not mapped.
*/
public int indexOfKey(int key) {
return ContainerHelpers.binarySearch(mKeys, mSize, key);
}
/**
* Returns the index for which {@link #keyAt} would return the
* specified key, or a negative number if the specified
* key is not mapped.
*/
public int indexOfKey(int key) {
return ContainerHelpers.binarySearch(mKeys, mSize, key);
}
/**
* Returns an index for which {@link #valueAt} would return the
* specified key, or a negative number if no keys map to the
* specified value.
* Beware that this is a linear search, unlike lookups by key,
* and that multiple keys can map to the same value and this will
* find only one of them.
*/
public int indexOfValue(int value) {
for (int i = 0; i < mSize; i++)
if (mValues[i] == value)
return i;
/**
* Returns an index for which {@link #valueAt} would return the
* specified key, or a negative number if no keys map to the
* specified value.
* Beware that this is a linear search, unlike lookups by key,
* and that multiple keys can map to the same value and this will
* find only one of them.
*/
public int indexOfValue(int value) {
for (int i = 0; i < mSize; i++)
if (mValues[i] == value)
return i;
return -1;
}
return -1;
}
/**
* Removes all key-value mappings from this SparseIntArray.
*/
public void clear() {
mSize = 0;
}
/**
* Removes all key-value mappings from this SparseIntArray.
*/
public void clear() {
mSize = 0;
}
/**
* Puts a key/value pair into the array, optimizing for the case where
* the key is greater than all existing keys in the array.
*/
public void append(int key, int value) {
if (mSize != 0 && key <= mKeys[mSize - 1]) {
put(key, value);
return;
}
/**
* Puts a key/value pair into the array, optimizing for the case where
* the key is greater than all existing keys in the array.
*/
public void append(int key, int value) {
if (mSize != 0 && key <= mKeys[mSize - 1]) {
put(key, value);
return;
}
int pos = mSize;
if (pos >= mKeys.length) {
int n = ArrayUtils.idealIntArraySize(pos + 1);
int pos = mSize;
if (pos >= mKeys.length) {
int n = ArrayUtils.idealIntArraySize(pos + 1);
int[] nkeys = new int[n];
int[] nvalues = new int[n];
int[] nkeys = new int[n];
int[] nvalues = new int[n];
// Log.e("SparseIntArray", "grow " + mKeys.length + " to " + n);
System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length);
System.arraycopy(mValues, 0, nvalues, 0, mValues.length);
// Log.e("SparseIntArray", "grow " + mKeys.length + " to " + n);
System.arraycopy(mKeys, 0, nkeys, 0, mKeys.length);
System.arraycopy(mValues, 0, nvalues, 0, mValues.length);
mKeys = nkeys;
mValues = nvalues;
}
mKeys = nkeys;
mValues = nvalues;
}
mKeys[pos] = key;
mValues[pos] = value;
mSize = pos + 1;
}
mKeys[pos] = key;
mValues[pos] = value;
mSize = pos + 1;
}
/**
* {@inheritDoc}
*
* <p>This implementation composes a string by iterating over its mappings.
*/
@Override
public String toString() {
if (size() <= 0) {
return "{}";
}
/**
* {@inheritDoc}
*
* <p>This implementation composes a string by iterating over its mappings.
*/
@Override
public String toString() {
if (size() <= 0) {
return "{}";
}
StringBuilder buffer = new StringBuilder(mSize * 28);
buffer.append('{');
for (int i=0; i<mSize; i++) {
if (i > 0) {
buffer.append(", ");
}
int key = keyAt(i);
buffer.append(key);
buffer.append('=');
int value = valueAt(i);
buffer.append(value);
}
buffer.append('}');
return buffer.toString();
}
StringBuilder buffer = new StringBuilder(mSize * 28);
buffer.append('{');
for (int i = 0; i < mSize; i++) {
if (i > 0) {
buffer.append(", ");
}
int key = keyAt(i);
buffer.append(key);
buffer.append('=');
int value = valueAt(i);
buffer.append(value);
}
buffer.append('}');
return buffer.toString();
}
}

Some files were not shown because too many files have changed in this diff Show More