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 int getCompactedRows() {
if (!isCompacted) {
throw new IllegalStateException(
"Illegal Invocation of the method before compact()");
}
return rows;
} |
Unicode Properties Vectors associated with code point ranges.
Rows of primitive integers in a contiguous array store the range limits and
the properties vectors.
In each row, row[0] contains the start code point and row[1] contains the
limit code point, which is the start of the next range.
Initially, there is only one range [0..0x110000] with values 0.
It would be possible to store only one range boundary per row, but
self-contained rows allow to later sort them by contents.
@hide Only a subset of ICU is exposed in Android
public class PropsVectors {
private int v[];
private int columns; // number of columns, plus two for start
// and limit values
private int maxRows;
private int rows;
private int prevRow; // search optimization: remember last row seen
private boolean isCompacted;
// internal function to compare elements in v and target. Return true iff
// elements in v starting from index1 to index1 + length - 1
// are exactly the same as elements in target
// starting from index2 to index2 + length - 1
private boolean areElementsSame(int index1, int[] target, int index2,
int length) {
for (int i = 0; i < length; ++i) {
if (v[index1 + i] != target[index2 + i]) {
return false;
}
}
return true;
}
// internal function which given rangeStart, returns
// index where v[index]<=rangeStart<v[index+1].
// The returned index is a multiple of columns, and therefore
// points to the start of a row.
private int findRow(int rangeStart) {
int index = 0;
// check the vicinity of the last-seen row (start
// searching with an unrolled loop)
index = prevRow * columns;
if (rangeStart >= v[index]) {
if (rangeStart < v[index + 1]) {
// same row as last seen
return index;
} else {
index += columns;
if (rangeStart < v[index + 1]) {
++prevRow;
return index;
} else {
index += columns;
if (rangeStart < v[index + 1]) {
prevRow += 2;
return index;
} else if ((rangeStart - v[index + 1]) < 10) {
// we are close, continue looping
prevRow += 2;
do {
++prevRow;
index += columns;
} while (rangeStart >= v[index + 1]);
return index;
}
}
}
} else if (rangeStart < v[1]) {
// the very first row
prevRow = 0;
return 0;
}
// do a binary search for the start of the range
int start = 0;
int mid = 0;
int limit = rows;
while (start < limit - 1) {
mid = (start + limit) / 2;
index = columns * mid;
if (rangeStart < v[index]) {
limit = mid;
} else if (rangeStart < v[index + 1]) {
prevRow = mid;
return index;
} else {
start = mid;
}
}
// must be found because all ranges together always cover
// all of Unicode
prevRow = start;
index = start * columns;
return index;
}
/*
Special pseudo code points for storing the initialValue and the
errorValue which are used to initialize a Trie or similar.
public final static int FIRST_SPECIAL_CP = 0x110000;
public final static int INITIAL_VALUE_CP = 0x110000;
public final static int ERROR_VALUE_CP = 0x110001;
public final static int MAX_CP = 0x110001;
public final static int INITIAL_ROWS = 1 << 12;
public final static int MEDIUM_ROWS = 1 << 16;
public final static int MAX_ROWS = MAX_CP + 1;
/*
Constructor.
@param numOfColumns Number of value integers (32-bit int) per row.
public PropsVectors(int numOfColumns) {
if (numOfColumns < 1) {
throw new IllegalArgumentException("numOfColumns need to be no "
+ "less than 1; but it is " + numOfColumns);
}
columns = numOfColumns + 2; // count range start and limit columns
v = new int[INITIAL_ROWS * columns];
maxRows = INITIAL_ROWS;
rows = 2 + (MAX_CP - FIRST_SPECIAL_CP);
prevRow = 0;
isCompacted = false;
v[0] = 0;
v[1] = 0x110000;
int index = columns;
for (int cp = FIRST_SPECIAL_CP; cp <= MAX_CP; ++cp) {
v[index] = cp;
v[index + 1] = cp + 1;
index += columns;
}
}
/*
In rows for code points [start..end], select the column, reset the mask
bits and set the value bits (ANDed with the mask).
@throws IllegalArgumentException
@throws IllegalStateException
@throws IndexOutOfBoundsException
public void setValue(int start, int end, int column, int value, int mask) {
if (start < 0 || start > end || end > MAX_CP || column < 0
|| column >= (columns - 2)) {
throw new IllegalArgumentException();
}
if (isCompacted) {
throw new IllegalStateException("Shouldn't be called after"
+ "compact()!");
}
int firstRow, lastRow;
int limit = end + 1;
boolean splitFirstRow, splitLastRow;
// skip range start and limit columns
column += 2;
value &= mask;
// find the rows whose ranges overlap with the input range
// find the first and last row, always successful
firstRow = findRow(start);
lastRow = findRow(end);
/*
Rows need to be split if they partially overlap with the input range
(only possible for the first and last rows) and if their value
differs from the input value.
splitFirstRow = (start != v[firstRow] && value != (v[firstRow + column] & mask));
splitLastRow = (limit != v[lastRow + 1] && value != (v[lastRow + column] & mask));
// split first/last rows if necessary
if (splitFirstRow || splitLastRow) {
int rowsToExpand = 0;
if (splitFirstRow) {
++rowsToExpand;
}
if (splitLastRow) {
++rowsToExpand;
}
int newMaxRows = 0;
if ((rows + rowsToExpand) > maxRows) {
if (maxRows < MEDIUM_ROWS) {
newMaxRows = MEDIUM_ROWS;
} else if (maxRows < MAX_ROWS) {
newMaxRows = MAX_ROWS;
} else {
throw new IndexOutOfBoundsException(
"MAX_ROWS exceeded! Increase it to a higher value" +
"in the implementation");
}
int[] temp = new int[newMaxRows * columns];
System.arraycopy(v, 0, temp, 0, rows * columns);
v = temp;
maxRows = newMaxRows;
}
// count the number of row cells to move after the last row,
// and move them
int count = (rows * columns) - (lastRow + columns);
if (count > 0) {
System.arraycopy(v, lastRow + columns, v, lastRow
+ (1 + rowsToExpand) * columns, count);
}
rows += rowsToExpand;
// split the first row, and move the firstRow pointer
// to the second part
if (splitFirstRow) {
// copy all affected rows up one and move the lastRow pointer
count = lastRow - firstRow + columns;
System.arraycopy(v, firstRow, v, firstRow + columns, count);
lastRow += columns;
// split the range and move the firstRow pointer
v[firstRow + 1] = v[firstRow + columns] = start;
firstRow += columns;
}
// split the last row
if (splitLastRow) {
// copy the last row data
System.arraycopy(v, lastRow, v, lastRow + columns, columns);
// split the range and move the firstRow pointer
v[lastRow + 1] = v[lastRow + columns] = limit;
}
}
// set the "row last seen" to the last row for the range
prevRow = lastRow / columns;
// set the input value in all remaining rows
firstRow += column;
lastRow += column;
mask = ~mask;
for (;;) {
v[firstRow] = (v[firstRow] & mask) | value;
if (firstRow == lastRow) {
break;
}
firstRow += columns;
}
}
/*
Always returns 0 if called after compact().
public int getValue(int c, int column) {
if (isCompacted || c < 0 || c > MAX_CP || column < 0
|| column >= (columns - 2)) {
return 0;
}
int index = findRow(c);
return v[index + 2 + column];
}
/*
Returns an array which contains value elements
in row rowIndex.
@throws IllegalStateException
@throws IllegalArgumentException
public int[] getRow(int rowIndex) {
if (isCompacted) {
throw new IllegalStateException(
"Illegal Invocation of the method after compact()");
}
if (rowIndex < 0 || rowIndex > rows) {
throw new IllegalArgumentException("rowIndex out of bound!");
}
int[] rowToReturn = new int[columns - 2];
System.arraycopy(v, rowIndex * columns + 2, rowToReturn, 0,
columns - 2);
return rowToReturn;
}
/*
Returns an int which is the start codepoint
in row rowIndex.
@throws IllegalStateException
@throws IllegalArgumentException
public int getRowStart(int rowIndex) {
if (isCompacted) {
throw new IllegalStateException(
"Illegal Invocation of the method after compact()");
}
if (rowIndex < 0 || rowIndex > rows) {
throw new IllegalArgumentException("rowIndex out of bound!");
}
return v[rowIndex * columns];
}
/*
Returns an int which is the limit codepoint
minus 1 in row rowIndex.
@throws IllegalStateException
@throws IllegalArgumentException
public int getRowEnd(int rowIndex) {
if (isCompacted) {
throw new IllegalStateException(
"Illegal Invocation of the method after compact()");
}
if (rowIndex < 0 || rowIndex > rows) {
throw new IllegalArgumentException("rowIndex out of bound!");
}
return v[rowIndex * columns + 1] - 1;
}
/*
Compact the vectors:
- modify the memory
- keep only unique vectors
- store them contiguously from the beginning of the memory
- for each (non-unique) row, call the respective function in
CompactHandler
The handler's rowIndex is the index of the row in the compacted
memory block. Therefore, it starts at 0 increases in increments of the
columns value.
In a first phase, only special values are delivered (each exactly once).
Then CompactHandler::startRealValues() is called
where rowIndex is the length of the compacted array.
Then, in the second phase, the CompactHandler::setRowIndexForRange() is
called for each row of real values.
public void compact(CompactHandler compactor) {
if (isCompacted) {
return;
}
// Set the flag now: Sorting and compacting destroys the builder
// data structure.
isCompacted = true;
int valueColumns = columns - 2; // not counting start & limit
// sort the properties vectors to find unique vector values
Integer[] indexArray = new Integer[rows];
for (int i = 0; i < rows; ++i) {
indexArray[i] = columns * i;
}
Arrays.sort(indexArray, new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
int indexOfRow1 = o1.intValue();
int indexOfRow2 = o2.intValue();
int count = columns; // includes start/limit columns
// start comparing after start/limit
// but wrap around to them
int index = 2;
do {
if (v[indexOfRow1 + index] != v[indexOfRow2 + index]) {
return v[indexOfRow1 + index] < v[indexOfRow2 + index] ? -1
: 1;
}
if (++index == columns) {
index = 0;
}
} while (--count > 0);
return 0;
}
});
/*
Find and set the special values. This has to do almost the same work
as the compaction below, to find the indexes where the special-value
rows will move.
int count = -valueColumns;
for (int i = 0; i < rows; ++i) {
int start = v[indexArray[i].intValue()];
// count a new values vector if it is different
// from the current one
if (count < 0 || !areElementsSame(indexArray[i].intValue() + 2, v,
indexArray[i-1].intValue() + 2, valueColumns)) {
count += valueColumns;
}
if (start == INITIAL_VALUE_CP) {
compactor.setRowIndexForInitialValue(count);
} else if (start == ERROR_VALUE_CP) {
compactor.setRowIndexForErrorValue(count);
}
}
// count is at the beginning of the last vector,
// add valueColumns to include that last vector
count += valueColumns;
// Call the handler once more to signal the start of
// delivering real values.
compactor.startRealValues(count);
/*
Move vector contents up to a contiguous array with only unique
vector values, and call the handler function for each vector.
This destroys the Properties Vector structure and replaces it
with an array of just vector values.
int[] temp = new int[count];
count = -valueColumns;
for (int i = 0; i < rows; ++i) {
int start = v[indexArray[i].intValue()];
int limit = v[indexArray[i].intValue() + 1];
// count a new values vector if it is different
// from the current one
if (count < 0 || !areElementsSame(indexArray[i].intValue() + 2,
temp, count, valueColumns)) {
count += valueColumns;
System.arraycopy(v, indexArray[i].intValue() + 2, temp, count,
valueColumns);
}
if (start < FIRST_SPECIAL_CP) {
compactor.setRowIndexForRange(start, limit - 1, count);
}
}
v = temp;
// count is at the beginning of the last vector,
// add one to include that last vector
rows = count / valueColumns + 1;
}
/*
Get the vectors array after calling compact().
@throws IllegalStateException
public int[] getCompactedArray() {
if (!isCompacted) {
throw new IllegalStateException(
"Illegal Invocation of the method before compact()");
}
return v;
}
/*
Get the number of rows for the compacted array.
@throws IllegalStateException
| PropsVectors::getCompactedRows | java | Reginer/aosp-android-jar | android-35/src/android/icu/impl/PropsVectors.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-35/src/android/icu/impl/PropsVectors.java | MIT |
public int getCompactedColumns() {
if (!isCompacted) {
throw new IllegalStateException(
"Illegal Invocation of the method before compact()");
}
return columns - 2;
} |
Unicode Properties Vectors associated with code point ranges.
Rows of primitive integers in a contiguous array store the range limits and
the properties vectors.
In each row, row[0] contains the start code point and row[1] contains the
limit code point, which is the start of the next range.
Initially, there is only one range [0..0x110000] with values 0.
It would be possible to store only one range boundary per row, but
self-contained rows allow to later sort them by contents.
@hide Only a subset of ICU is exposed in Android
public class PropsVectors {
private int v[];
private int columns; // number of columns, plus two for start
// and limit values
private int maxRows;
private int rows;
private int prevRow; // search optimization: remember last row seen
private boolean isCompacted;
// internal function to compare elements in v and target. Return true iff
// elements in v starting from index1 to index1 + length - 1
// are exactly the same as elements in target
// starting from index2 to index2 + length - 1
private boolean areElementsSame(int index1, int[] target, int index2,
int length) {
for (int i = 0; i < length; ++i) {
if (v[index1 + i] != target[index2 + i]) {
return false;
}
}
return true;
}
// internal function which given rangeStart, returns
// index where v[index]<=rangeStart<v[index+1].
// The returned index is a multiple of columns, and therefore
// points to the start of a row.
private int findRow(int rangeStart) {
int index = 0;
// check the vicinity of the last-seen row (start
// searching with an unrolled loop)
index = prevRow * columns;
if (rangeStart >= v[index]) {
if (rangeStart < v[index + 1]) {
// same row as last seen
return index;
} else {
index += columns;
if (rangeStart < v[index + 1]) {
++prevRow;
return index;
} else {
index += columns;
if (rangeStart < v[index + 1]) {
prevRow += 2;
return index;
} else if ((rangeStart - v[index + 1]) < 10) {
// we are close, continue looping
prevRow += 2;
do {
++prevRow;
index += columns;
} while (rangeStart >= v[index + 1]);
return index;
}
}
}
} else if (rangeStart < v[1]) {
// the very first row
prevRow = 0;
return 0;
}
// do a binary search for the start of the range
int start = 0;
int mid = 0;
int limit = rows;
while (start < limit - 1) {
mid = (start + limit) / 2;
index = columns * mid;
if (rangeStart < v[index]) {
limit = mid;
} else if (rangeStart < v[index + 1]) {
prevRow = mid;
return index;
} else {
start = mid;
}
}
// must be found because all ranges together always cover
// all of Unicode
prevRow = start;
index = start * columns;
return index;
}
/*
Special pseudo code points for storing the initialValue and the
errorValue which are used to initialize a Trie or similar.
public final static int FIRST_SPECIAL_CP = 0x110000;
public final static int INITIAL_VALUE_CP = 0x110000;
public final static int ERROR_VALUE_CP = 0x110001;
public final static int MAX_CP = 0x110001;
public final static int INITIAL_ROWS = 1 << 12;
public final static int MEDIUM_ROWS = 1 << 16;
public final static int MAX_ROWS = MAX_CP + 1;
/*
Constructor.
@param numOfColumns Number of value integers (32-bit int) per row.
public PropsVectors(int numOfColumns) {
if (numOfColumns < 1) {
throw new IllegalArgumentException("numOfColumns need to be no "
+ "less than 1; but it is " + numOfColumns);
}
columns = numOfColumns + 2; // count range start and limit columns
v = new int[INITIAL_ROWS * columns];
maxRows = INITIAL_ROWS;
rows = 2 + (MAX_CP - FIRST_SPECIAL_CP);
prevRow = 0;
isCompacted = false;
v[0] = 0;
v[1] = 0x110000;
int index = columns;
for (int cp = FIRST_SPECIAL_CP; cp <= MAX_CP; ++cp) {
v[index] = cp;
v[index + 1] = cp + 1;
index += columns;
}
}
/*
In rows for code points [start..end], select the column, reset the mask
bits and set the value bits (ANDed with the mask).
@throws IllegalArgumentException
@throws IllegalStateException
@throws IndexOutOfBoundsException
public void setValue(int start, int end, int column, int value, int mask) {
if (start < 0 || start > end || end > MAX_CP || column < 0
|| column >= (columns - 2)) {
throw new IllegalArgumentException();
}
if (isCompacted) {
throw new IllegalStateException("Shouldn't be called after"
+ "compact()!");
}
int firstRow, lastRow;
int limit = end + 1;
boolean splitFirstRow, splitLastRow;
// skip range start and limit columns
column += 2;
value &= mask;
// find the rows whose ranges overlap with the input range
// find the first and last row, always successful
firstRow = findRow(start);
lastRow = findRow(end);
/*
Rows need to be split if they partially overlap with the input range
(only possible for the first and last rows) and if their value
differs from the input value.
splitFirstRow = (start != v[firstRow] && value != (v[firstRow + column] & mask));
splitLastRow = (limit != v[lastRow + 1] && value != (v[lastRow + column] & mask));
// split first/last rows if necessary
if (splitFirstRow || splitLastRow) {
int rowsToExpand = 0;
if (splitFirstRow) {
++rowsToExpand;
}
if (splitLastRow) {
++rowsToExpand;
}
int newMaxRows = 0;
if ((rows + rowsToExpand) > maxRows) {
if (maxRows < MEDIUM_ROWS) {
newMaxRows = MEDIUM_ROWS;
} else if (maxRows < MAX_ROWS) {
newMaxRows = MAX_ROWS;
} else {
throw new IndexOutOfBoundsException(
"MAX_ROWS exceeded! Increase it to a higher value" +
"in the implementation");
}
int[] temp = new int[newMaxRows * columns];
System.arraycopy(v, 0, temp, 0, rows * columns);
v = temp;
maxRows = newMaxRows;
}
// count the number of row cells to move after the last row,
// and move them
int count = (rows * columns) - (lastRow + columns);
if (count > 0) {
System.arraycopy(v, lastRow + columns, v, lastRow
+ (1 + rowsToExpand) * columns, count);
}
rows += rowsToExpand;
// split the first row, and move the firstRow pointer
// to the second part
if (splitFirstRow) {
// copy all affected rows up one and move the lastRow pointer
count = lastRow - firstRow + columns;
System.arraycopy(v, firstRow, v, firstRow + columns, count);
lastRow += columns;
// split the range and move the firstRow pointer
v[firstRow + 1] = v[firstRow + columns] = start;
firstRow += columns;
}
// split the last row
if (splitLastRow) {
// copy the last row data
System.arraycopy(v, lastRow, v, lastRow + columns, columns);
// split the range and move the firstRow pointer
v[lastRow + 1] = v[lastRow + columns] = limit;
}
}
// set the "row last seen" to the last row for the range
prevRow = lastRow / columns;
// set the input value in all remaining rows
firstRow += column;
lastRow += column;
mask = ~mask;
for (;;) {
v[firstRow] = (v[firstRow] & mask) | value;
if (firstRow == lastRow) {
break;
}
firstRow += columns;
}
}
/*
Always returns 0 if called after compact().
public int getValue(int c, int column) {
if (isCompacted || c < 0 || c > MAX_CP || column < 0
|| column >= (columns - 2)) {
return 0;
}
int index = findRow(c);
return v[index + 2 + column];
}
/*
Returns an array which contains value elements
in row rowIndex.
@throws IllegalStateException
@throws IllegalArgumentException
public int[] getRow(int rowIndex) {
if (isCompacted) {
throw new IllegalStateException(
"Illegal Invocation of the method after compact()");
}
if (rowIndex < 0 || rowIndex > rows) {
throw new IllegalArgumentException("rowIndex out of bound!");
}
int[] rowToReturn = new int[columns - 2];
System.arraycopy(v, rowIndex * columns + 2, rowToReturn, 0,
columns - 2);
return rowToReturn;
}
/*
Returns an int which is the start codepoint
in row rowIndex.
@throws IllegalStateException
@throws IllegalArgumentException
public int getRowStart(int rowIndex) {
if (isCompacted) {
throw new IllegalStateException(
"Illegal Invocation of the method after compact()");
}
if (rowIndex < 0 || rowIndex > rows) {
throw new IllegalArgumentException("rowIndex out of bound!");
}
return v[rowIndex * columns];
}
/*
Returns an int which is the limit codepoint
minus 1 in row rowIndex.
@throws IllegalStateException
@throws IllegalArgumentException
public int getRowEnd(int rowIndex) {
if (isCompacted) {
throw new IllegalStateException(
"Illegal Invocation of the method after compact()");
}
if (rowIndex < 0 || rowIndex > rows) {
throw new IllegalArgumentException("rowIndex out of bound!");
}
return v[rowIndex * columns + 1] - 1;
}
/*
Compact the vectors:
- modify the memory
- keep only unique vectors
- store them contiguously from the beginning of the memory
- for each (non-unique) row, call the respective function in
CompactHandler
The handler's rowIndex is the index of the row in the compacted
memory block. Therefore, it starts at 0 increases in increments of the
columns value.
In a first phase, only special values are delivered (each exactly once).
Then CompactHandler::startRealValues() is called
where rowIndex is the length of the compacted array.
Then, in the second phase, the CompactHandler::setRowIndexForRange() is
called for each row of real values.
public void compact(CompactHandler compactor) {
if (isCompacted) {
return;
}
// Set the flag now: Sorting and compacting destroys the builder
// data structure.
isCompacted = true;
int valueColumns = columns - 2; // not counting start & limit
// sort the properties vectors to find unique vector values
Integer[] indexArray = new Integer[rows];
for (int i = 0; i < rows; ++i) {
indexArray[i] = columns * i;
}
Arrays.sort(indexArray, new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
int indexOfRow1 = o1.intValue();
int indexOfRow2 = o2.intValue();
int count = columns; // includes start/limit columns
// start comparing after start/limit
// but wrap around to them
int index = 2;
do {
if (v[indexOfRow1 + index] != v[indexOfRow2 + index]) {
return v[indexOfRow1 + index] < v[indexOfRow2 + index] ? -1
: 1;
}
if (++index == columns) {
index = 0;
}
} while (--count > 0);
return 0;
}
});
/*
Find and set the special values. This has to do almost the same work
as the compaction below, to find the indexes where the special-value
rows will move.
int count = -valueColumns;
for (int i = 0; i < rows; ++i) {
int start = v[indexArray[i].intValue()];
// count a new values vector if it is different
// from the current one
if (count < 0 || !areElementsSame(indexArray[i].intValue() + 2, v,
indexArray[i-1].intValue() + 2, valueColumns)) {
count += valueColumns;
}
if (start == INITIAL_VALUE_CP) {
compactor.setRowIndexForInitialValue(count);
} else if (start == ERROR_VALUE_CP) {
compactor.setRowIndexForErrorValue(count);
}
}
// count is at the beginning of the last vector,
// add valueColumns to include that last vector
count += valueColumns;
// Call the handler once more to signal the start of
// delivering real values.
compactor.startRealValues(count);
/*
Move vector contents up to a contiguous array with only unique
vector values, and call the handler function for each vector.
This destroys the Properties Vector structure and replaces it
with an array of just vector values.
int[] temp = new int[count];
count = -valueColumns;
for (int i = 0; i < rows; ++i) {
int start = v[indexArray[i].intValue()];
int limit = v[indexArray[i].intValue() + 1];
// count a new values vector if it is different
// from the current one
if (count < 0 || !areElementsSame(indexArray[i].intValue() + 2,
temp, count, valueColumns)) {
count += valueColumns;
System.arraycopy(v, indexArray[i].intValue() + 2, temp, count,
valueColumns);
}
if (start < FIRST_SPECIAL_CP) {
compactor.setRowIndexForRange(start, limit - 1, count);
}
}
v = temp;
// count is at the beginning of the last vector,
// add one to include that last vector
rows = count / valueColumns + 1;
}
/*
Get the vectors array after calling compact().
@throws IllegalStateException
public int[] getCompactedArray() {
if (!isCompacted) {
throw new IllegalStateException(
"Illegal Invocation of the method before compact()");
}
return v;
}
/*
Get the number of rows for the compacted array.
@throws IllegalStateException
public int getCompactedRows() {
if (!isCompacted) {
throw new IllegalStateException(
"Illegal Invocation of the method before compact()");
}
return rows;
}
/*
Get the number of columns for the compacted array.
@throws IllegalStateException
| PropsVectors::getCompactedColumns | java | Reginer/aosp-android-jar | android-35/src/android/icu/impl/PropsVectors.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-35/src/android/icu/impl/PropsVectors.java | MIT |
public IntTrie compactToTrieWithRowIndexes() {
PVecToTrieCompactHandler compactor = new PVecToTrieCompactHandler();
compact(compactor);
return compactor.builder.serialize(new DefaultGetFoldedValue(
compactor.builder), new DefaultGetFoldingOffset());
} |
Unicode Properties Vectors associated with code point ranges.
Rows of primitive integers in a contiguous array store the range limits and
the properties vectors.
In each row, row[0] contains the start code point and row[1] contains the
limit code point, which is the start of the next range.
Initially, there is only one range [0..0x110000] with values 0.
It would be possible to store only one range boundary per row, but
self-contained rows allow to later sort them by contents.
@hide Only a subset of ICU is exposed in Android
public class PropsVectors {
private int v[];
private int columns; // number of columns, plus two for start
// and limit values
private int maxRows;
private int rows;
private int prevRow; // search optimization: remember last row seen
private boolean isCompacted;
// internal function to compare elements in v and target. Return true iff
// elements in v starting from index1 to index1 + length - 1
// are exactly the same as elements in target
// starting from index2 to index2 + length - 1
private boolean areElementsSame(int index1, int[] target, int index2,
int length) {
for (int i = 0; i < length; ++i) {
if (v[index1 + i] != target[index2 + i]) {
return false;
}
}
return true;
}
// internal function which given rangeStart, returns
// index where v[index]<=rangeStart<v[index+1].
// The returned index is a multiple of columns, and therefore
// points to the start of a row.
private int findRow(int rangeStart) {
int index = 0;
// check the vicinity of the last-seen row (start
// searching with an unrolled loop)
index = prevRow * columns;
if (rangeStart >= v[index]) {
if (rangeStart < v[index + 1]) {
// same row as last seen
return index;
} else {
index += columns;
if (rangeStart < v[index + 1]) {
++prevRow;
return index;
} else {
index += columns;
if (rangeStart < v[index + 1]) {
prevRow += 2;
return index;
} else if ((rangeStart - v[index + 1]) < 10) {
// we are close, continue looping
prevRow += 2;
do {
++prevRow;
index += columns;
} while (rangeStart >= v[index + 1]);
return index;
}
}
}
} else if (rangeStart < v[1]) {
// the very first row
prevRow = 0;
return 0;
}
// do a binary search for the start of the range
int start = 0;
int mid = 0;
int limit = rows;
while (start < limit - 1) {
mid = (start + limit) / 2;
index = columns * mid;
if (rangeStart < v[index]) {
limit = mid;
} else if (rangeStart < v[index + 1]) {
prevRow = mid;
return index;
} else {
start = mid;
}
}
// must be found because all ranges together always cover
// all of Unicode
prevRow = start;
index = start * columns;
return index;
}
/*
Special pseudo code points for storing the initialValue and the
errorValue which are used to initialize a Trie or similar.
public final static int FIRST_SPECIAL_CP = 0x110000;
public final static int INITIAL_VALUE_CP = 0x110000;
public final static int ERROR_VALUE_CP = 0x110001;
public final static int MAX_CP = 0x110001;
public final static int INITIAL_ROWS = 1 << 12;
public final static int MEDIUM_ROWS = 1 << 16;
public final static int MAX_ROWS = MAX_CP + 1;
/*
Constructor.
@param numOfColumns Number of value integers (32-bit int) per row.
public PropsVectors(int numOfColumns) {
if (numOfColumns < 1) {
throw new IllegalArgumentException("numOfColumns need to be no "
+ "less than 1; but it is " + numOfColumns);
}
columns = numOfColumns + 2; // count range start and limit columns
v = new int[INITIAL_ROWS * columns];
maxRows = INITIAL_ROWS;
rows = 2 + (MAX_CP - FIRST_SPECIAL_CP);
prevRow = 0;
isCompacted = false;
v[0] = 0;
v[1] = 0x110000;
int index = columns;
for (int cp = FIRST_SPECIAL_CP; cp <= MAX_CP; ++cp) {
v[index] = cp;
v[index + 1] = cp + 1;
index += columns;
}
}
/*
In rows for code points [start..end], select the column, reset the mask
bits and set the value bits (ANDed with the mask).
@throws IllegalArgumentException
@throws IllegalStateException
@throws IndexOutOfBoundsException
public void setValue(int start, int end, int column, int value, int mask) {
if (start < 0 || start > end || end > MAX_CP || column < 0
|| column >= (columns - 2)) {
throw new IllegalArgumentException();
}
if (isCompacted) {
throw new IllegalStateException("Shouldn't be called after"
+ "compact()!");
}
int firstRow, lastRow;
int limit = end + 1;
boolean splitFirstRow, splitLastRow;
// skip range start and limit columns
column += 2;
value &= mask;
// find the rows whose ranges overlap with the input range
// find the first and last row, always successful
firstRow = findRow(start);
lastRow = findRow(end);
/*
Rows need to be split if they partially overlap with the input range
(only possible for the first and last rows) and if their value
differs from the input value.
splitFirstRow = (start != v[firstRow] && value != (v[firstRow + column] & mask));
splitLastRow = (limit != v[lastRow + 1] && value != (v[lastRow + column] & mask));
// split first/last rows if necessary
if (splitFirstRow || splitLastRow) {
int rowsToExpand = 0;
if (splitFirstRow) {
++rowsToExpand;
}
if (splitLastRow) {
++rowsToExpand;
}
int newMaxRows = 0;
if ((rows + rowsToExpand) > maxRows) {
if (maxRows < MEDIUM_ROWS) {
newMaxRows = MEDIUM_ROWS;
} else if (maxRows < MAX_ROWS) {
newMaxRows = MAX_ROWS;
} else {
throw new IndexOutOfBoundsException(
"MAX_ROWS exceeded! Increase it to a higher value" +
"in the implementation");
}
int[] temp = new int[newMaxRows * columns];
System.arraycopy(v, 0, temp, 0, rows * columns);
v = temp;
maxRows = newMaxRows;
}
// count the number of row cells to move after the last row,
// and move them
int count = (rows * columns) - (lastRow + columns);
if (count > 0) {
System.arraycopy(v, lastRow + columns, v, lastRow
+ (1 + rowsToExpand) * columns, count);
}
rows += rowsToExpand;
// split the first row, and move the firstRow pointer
// to the second part
if (splitFirstRow) {
// copy all affected rows up one and move the lastRow pointer
count = lastRow - firstRow + columns;
System.arraycopy(v, firstRow, v, firstRow + columns, count);
lastRow += columns;
// split the range and move the firstRow pointer
v[firstRow + 1] = v[firstRow + columns] = start;
firstRow += columns;
}
// split the last row
if (splitLastRow) {
// copy the last row data
System.arraycopy(v, lastRow, v, lastRow + columns, columns);
// split the range and move the firstRow pointer
v[lastRow + 1] = v[lastRow + columns] = limit;
}
}
// set the "row last seen" to the last row for the range
prevRow = lastRow / columns;
// set the input value in all remaining rows
firstRow += column;
lastRow += column;
mask = ~mask;
for (;;) {
v[firstRow] = (v[firstRow] & mask) | value;
if (firstRow == lastRow) {
break;
}
firstRow += columns;
}
}
/*
Always returns 0 if called after compact().
public int getValue(int c, int column) {
if (isCompacted || c < 0 || c > MAX_CP || column < 0
|| column >= (columns - 2)) {
return 0;
}
int index = findRow(c);
return v[index + 2 + column];
}
/*
Returns an array which contains value elements
in row rowIndex.
@throws IllegalStateException
@throws IllegalArgumentException
public int[] getRow(int rowIndex) {
if (isCompacted) {
throw new IllegalStateException(
"Illegal Invocation of the method after compact()");
}
if (rowIndex < 0 || rowIndex > rows) {
throw new IllegalArgumentException("rowIndex out of bound!");
}
int[] rowToReturn = new int[columns - 2];
System.arraycopy(v, rowIndex * columns + 2, rowToReturn, 0,
columns - 2);
return rowToReturn;
}
/*
Returns an int which is the start codepoint
in row rowIndex.
@throws IllegalStateException
@throws IllegalArgumentException
public int getRowStart(int rowIndex) {
if (isCompacted) {
throw new IllegalStateException(
"Illegal Invocation of the method after compact()");
}
if (rowIndex < 0 || rowIndex > rows) {
throw new IllegalArgumentException("rowIndex out of bound!");
}
return v[rowIndex * columns];
}
/*
Returns an int which is the limit codepoint
minus 1 in row rowIndex.
@throws IllegalStateException
@throws IllegalArgumentException
public int getRowEnd(int rowIndex) {
if (isCompacted) {
throw new IllegalStateException(
"Illegal Invocation of the method after compact()");
}
if (rowIndex < 0 || rowIndex > rows) {
throw new IllegalArgumentException("rowIndex out of bound!");
}
return v[rowIndex * columns + 1] - 1;
}
/*
Compact the vectors:
- modify the memory
- keep only unique vectors
- store them contiguously from the beginning of the memory
- for each (non-unique) row, call the respective function in
CompactHandler
The handler's rowIndex is the index of the row in the compacted
memory block. Therefore, it starts at 0 increases in increments of the
columns value.
In a first phase, only special values are delivered (each exactly once).
Then CompactHandler::startRealValues() is called
where rowIndex is the length of the compacted array.
Then, in the second phase, the CompactHandler::setRowIndexForRange() is
called for each row of real values.
public void compact(CompactHandler compactor) {
if (isCompacted) {
return;
}
// Set the flag now: Sorting and compacting destroys the builder
// data structure.
isCompacted = true;
int valueColumns = columns - 2; // not counting start & limit
// sort the properties vectors to find unique vector values
Integer[] indexArray = new Integer[rows];
for (int i = 0; i < rows; ++i) {
indexArray[i] = columns * i;
}
Arrays.sort(indexArray, new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
int indexOfRow1 = o1.intValue();
int indexOfRow2 = o2.intValue();
int count = columns; // includes start/limit columns
// start comparing after start/limit
// but wrap around to them
int index = 2;
do {
if (v[indexOfRow1 + index] != v[indexOfRow2 + index]) {
return v[indexOfRow1 + index] < v[indexOfRow2 + index] ? -1
: 1;
}
if (++index == columns) {
index = 0;
}
} while (--count > 0);
return 0;
}
});
/*
Find and set the special values. This has to do almost the same work
as the compaction below, to find the indexes where the special-value
rows will move.
int count = -valueColumns;
for (int i = 0; i < rows; ++i) {
int start = v[indexArray[i].intValue()];
// count a new values vector if it is different
// from the current one
if (count < 0 || !areElementsSame(indexArray[i].intValue() + 2, v,
indexArray[i-1].intValue() + 2, valueColumns)) {
count += valueColumns;
}
if (start == INITIAL_VALUE_CP) {
compactor.setRowIndexForInitialValue(count);
} else if (start == ERROR_VALUE_CP) {
compactor.setRowIndexForErrorValue(count);
}
}
// count is at the beginning of the last vector,
// add valueColumns to include that last vector
count += valueColumns;
// Call the handler once more to signal the start of
// delivering real values.
compactor.startRealValues(count);
/*
Move vector contents up to a contiguous array with only unique
vector values, and call the handler function for each vector.
This destroys the Properties Vector structure and replaces it
with an array of just vector values.
int[] temp = new int[count];
count = -valueColumns;
for (int i = 0; i < rows; ++i) {
int start = v[indexArray[i].intValue()];
int limit = v[indexArray[i].intValue() + 1];
// count a new values vector if it is different
// from the current one
if (count < 0 || !areElementsSame(indexArray[i].intValue() + 2,
temp, count, valueColumns)) {
count += valueColumns;
System.arraycopy(v, indexArray[i].intValue() + 2, temp, count,
valueColumns);
}
if (start < FIRST_SPECIAL_CP) {
compactor.setRowIndexForRange(start, limit - 1, count);
}
}
v = temp;
// count is at the beginning of the last vector,
// add one to include that last vector
rows = count / valueColumns + 1;
}
/*
Get the vectors array after calling compact().
@throws IllegalStateException
public int[] getCompactedArray() {
if (!isCompacted) {
throw new IllegalStateException(
"Illegal Invocation of the method before compact()");
}
return v;
}
/*
Get the number of rows for the compacted array.
@throws IllegalStateException
public int getCompactedRows() {
if (!isCompacted) {
throw new IllegalStateException(
"Illegal Invocation of the method before compact()");
}
return rows;
}
/*
Get the number of columns for the compacted array.
@throws IllegalStateException
public int getCompactedColumns() {
if (!isCompacted) {
throw new IllegalStateException(
"Illegal Invocation of the method before compact()");
}
return columns - 2;
}
/*
Call compact(), create a IntTrie with indexes into the compacted
vectors array.
| PropsVectors::compactToTrieWithRowIndexes | java | Reginer/aosp-android-jar | android-35/src/android/icu/impl/PropsVectors.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-35/src/android/icu/impl/PropsVectors.java | MIT |
public List<Sensor> getSensorList(int type) {
// cache the returned lists the first time
List<Sensor> list;
final List<Sensor> fullList = getFullSensorList();
synchronized (mSensorListByType) {
list = mSensorListByType.get(type);
if (list == null) {
if (type == Sensor.TYPE_ALL) {
list = fullList;
} else {
list = new ArrayList<Sensor>();
for (Sensor i : fullList) {
if (i.getType() == type) {
list.add(i);
}
}
}
list = Collections.unmodifiableList(list);
mSensorListByType.append(type, list);
}
}
return list;
} |
Use this method to get the list of available sensors of a certain type.
Make multiple calls to get sensors of different types or use
{@link android.hardware.Sensor#TYPE_ALL Sensor.TYPE_ALL} to get all the
sensors. Note that the {@link android.hardware.Sensor#getName()} is
expected to yield a value that is unique across any sensors that return
the same value for {@link android.hardware.Sensor#getType()}.
<p class="note">
NOTE: Both wake-up and non wake-up sensors matching the given type are
returned. Check {@link Sensor#isWakeUpSensor()} to know the wake-up properties
of the returned {@link Sensor}.
</p>
@param type
of sensors requested
@return a list of sensors matching the asked type.
@see #getDefaultSensor(int)
@see Sensor
| SensorManager::getSensorList | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public List<Sensor> getDynamicSensorList(int type) {
// cache the returned lists the first time
final List<Sensor> fullList = getFullDynamicSensorList();
if (type == Sensor.TYPE_ALL) {
return Collections.unmodifiableList(fullList);
} else {
List<Sensor> list = new ArrayList();
for (Sensor i : fullList) {
if (i.getType() == type) {
list.add(i);
}
}
return Collections.unmodifiableList(list);
}
} |
Use this method to get a list of available dynamic sensors of a certain type.
Make multiple calls to get sensors of different types or use
{@link android.hardware.Sensor#TYPE_ALL Sensor.TYPE_ALL} to get all dynamic sensors.
<p class="note">
NOTE: Both wake-up and non wake-up sensors matching the given type are
returned. Check {@link Sensor#isWakeUpSensor()} to know the wake-up properties
of the returned {@link Sensor}.
</p>
@param type of sensors requested
@return a list of dynamic sensors matching the requested type.
@see Sensor
| SensorManager::getDynamicSensorList | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public Sensor getDefaultSensor(int type) {
// TODO: need to be smarter, for now, just return the 1st sensor
List<Sensor> l = getSensorList(type);
boolean wakeUpSensor = false;
// For the following sensor types, return a wake-up sensor. These types are by default
// defined as wake-up sensors. For the rest of the SDK defined sensor types return a
// non_wake-up version.
if (type == Sensor.TYPE_PROXIMITY || type == Sensor.TYPE_SIGNIFICANT_MOTION
|| type == Sensor.TYPE_TILT_DETECTOR || type == Sensor.TYPE_WAKE_GESTURE
|| type == Sensor.TYPE_GLANCE_GESTURE || type == Sensor.TYPE_PICK_UP_GESTURE
|| type == Sensor.TYPE_WRIST_TILT_GESTURE
|| type == Sensor.TYPE_DYNAMIC_SENSOR_META || type == Sensor.TYPE_HINGE_ANGLE) {
wakeUpSensor = true;
}
for (Sensor sensor : l) {
if (sensor.isWakeUpSensor() == wakeUpSensor) return sensor;
}
return null;
} |
Use this method to get the default sensor for a given type. Note that the
returned sensor could be a composite sensor, and its data could be
averaged or filtered. If you need to access the raw sensors use
{@link SensorManager#getSensorList(int) getSensorList}.
@param type
of sensors requested
@return the default sensor matching the requested type if one exists and the application
has the necessary permissions, or null otherwise.
@see #getSensorList(int)
@see Sensor
| SensorManager::getDefaultSensor | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public Sensor getDefaultSensor(int type, boolean wakeUp) {
List<Sensor> l = getSensorList(type);
for (Sensor sensor : l) {
if (sensor.isWakeUpSensor() == wakeUp) {
return sensor;
}
}
return null;
} |
Return a Sensor with the given type and wakeUp properties. If multiple sensors of this
type exist, any one of them may be returned.
<p>
For example,
<ul>
<li>getDefaultSensor({@link Sensor#TYPE_ACCELEROMETER}, true) returns a wake-up
accelerometer sensor if it exists. </li>
<li>getDefaultSensor({@link Sensor#TYPE_PROXIMITY}, false) returns a non wake-up
proximity sensor if it exists. </li>
<li>getDefaultSensor({@link Sensor#TYPE_PROXIMITY}, true) returns a wake-up proximity
sensor which is the same as the Sensor returned by {@link #getDefaultSensor(int)}. </li>
</ul>
</p>
<p class="note">
Note: Sensors like {@link Sensor#TYPE_PROXIMITY} and {@link Sensor#TYPE_SIGNIFICANT_MOTION}
are declared as wake-up sensors by default.
</p>
@param type
type of sensor requested
@param wakeUp
flag to indicate whether the Sensor is a wake-up or non wake-up sensor.
@return the default sensor matching the requested type and wakeUp properties if one exists
and the application has the necessary permissions, or null otherwise.
@see Sensor#isWakeUpSensor()
| SensorManager::getDefaultSensor | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public void unregisterListener(SensorEventListener listener, Sensor sensor) {
if (listener == null || sensor == null) {
return;
}
unregisterListenerImpl(listener, sensor);
} |
Unregisters a listener for the sensors with which it is registered.
<p class="note"></p>
Note: Don't use this method with a one shot trigger sensor such as
{@link Sensor#TYPE_SIGNIFICANT_MOTION}.
Use {@link #cancelTriggerSensor(TriggerEventListener, Sensor)} instead.
</p>
@param listener
a SensorEventListener object
@param sensor
the sensor to unregister from
@see #unregisterListener(SensorEventListener)
@see #registerListener(SensorEventListener, Sensor, int)
| SensorManager::unregisterListener | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public void unregisterListener(SensorEventListener listener) {
if (listener == null) {
return;
}
unregisterListenerImpl(listener, null);
} |
Unregisters a listener for all sensors.
@param listener
a SensorListener object
@see #unregisterListener(SensorEventListener, Sensor)
@see #registerListener(SensorEventListener, Sensor, int)
| SensorManager::unregisterListener | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public boolean registerListener(SensorEventListener listener, Sensor sensor,
int samplingPeriodUs) {
return registerListener(listener, sensor, samplingPeriodUs, null);
} |
Registers a {@link android.hardware.SensorEventListener SensorEventListener} for the given
sensor at the given sampling frequency.
<p>
The events will be delivered to the provided {@code SensorEventListener} as soon as they are
available. To reduce the power consumption, applications can use
{@link #registerListener(SensorEventListener, Sensor, int, int)} instead and specify a
positive non-zero maximum reporting latency.
</p>
<p>
In the case of non-wake-up sensors, the events are only delivered while the Application
Processor (AP) is not in suspend mode. See {@link Sensor#isWakeUpSensor()} for more details.
To ensure delivery of events from non-wake-up sensors even when the screen is OFF, the
application registering to the sensor must hold a partial wake-lock to keep the AP awake,
otherwise some events might be lost while the AP is asleep. Note that although events might
be lost while the AP is asleep, the sensor will still consume power if it is not explicitly
deactivated by the application. Applications must unregister their {@code
SensorEventListener}s in their activity's {@code onPause()} method to avoid consuming power
while the device is inactive. See {@link #registerListener(SensorEventListener, Sensor, int,
int)} for more details on hardware FIFO (queueing) capabilities and when some sensor events
might be lost.
</p>
<p>
In the case of wake-up sensors, each event generated by the sensor will cause the AP to
wake-up, ensuring that each event can be delivered. Because of this, registering to a wake-up
sensor has very significant power implications. Call {@link Sensor#isWakeUpSensor()} to check
whether a sensor is a wake-up sensor. See
{@link #registerListener(SensorEventListener, Sensor, int, int)} for information on how to
reduce the power impact of registering to wake-up sensors.
</p>
<p class="note">
Note: Don't use this method with one-shot trigger sensors such as
{@link Sensor#TYPE_SIGNIFICANT_MOTION}. Use
{@link #requestTriggerSensor(TriggerEventListener, Sensor)} instead. Use
{@link Sensor#getReportingMode()} to obtain the reporting mode of a given sensor.
</p>
@param listener A {@link android.hardware.SensorEventListener SensorEventListener} object.
@param sensor The {@link android.hardware.Sensor Sensor} to register to.
@param samplingPeriodUs The rate {@link android.hardware.SensorEvent sensor events} are
delivered at. This is only a hint to the system. Events may be received faster or
slower than the specified rate. Usually events are received faster. The value must
be one of {@link #SENSOR_DELAY_NORMAL}, {@link #SENSOR_DELAY_UI},
{@link #SENSOR_DELAY_GAME}, or {@link #SENSOR_DELAY_FASTEST} or, the desired delay
between events in microseconds. Specifying the delay in microseconds only works
from Android 2.3 (API level 9) onwards. For earlier releases, you must use one of
the {@code SENSOR_DELAY_*} constants.
@return <code>true</code> if the sensor is supported and successfully enabled.
@see #registerListener(SensorEventListener, Sensor, int, Handler)
@see #unregisterListener(SensorEventListener)
@see #unregisterListener(SensorEventListener, Sensor)
| SensorManager::registerListener | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public boolean registerListener(SensorEventListener listener, Sensor sensor,
int samplingPeriodUs, int maxReportLatencyUs) {
int delay = getDelay(samplingPeriodUs);
return registerListenerImpl(listener, sensor, delay, null, maxReportLatencyUs, 0);
} |
Registers a {@link android.hardware.SensorEventListener SensorEventListener} for the given
sensor at the given sampling frequency and the given maximum reporting latency.
<p>
This function is similar to {@link #registerListener(SensorEventListener, Sensor, int)} but
it allows events to stay temporarily in the hardware FIFO (queue) before being delivered. The
events can be stored in the hardware FIFO up to {@code maxReportLatencyUs} microseconds. Once
one of the events in the FIFO needs to be reported, all of the events in the FIFO are
reported sequentially. This means that some events will be reported before the maximum
reporting latency has elapsed.
</p><p>
When {@code maxReportLatencyUs} is 0, the call is equivalent to a call to
{@link #registerListener(SensorEventListener, Sensor, int)}, as it requires the events to be
delivered as soon as possible.
</p><p>
When {@code sensor.maxFifoEventCount()} is 0, the sensor does not use a FIFO, so the call
will also be equivalent to {@link #registerListener(SensorEventListener, Sensor, int)}.
</p><p>
Setting {@code maxReportLatencyUs} to a positive value allows to reduce the number of
interrupts the AP (Application Processor) receives, hence reducing power consumption, as the
AP can switch to a lower power state while the sensor is capturing the data. This is
especially important when registering to wake-up sensors, for which each interrupt causes the
AP to wake up if it was in suspend mode. See {@link Sensor#isWakeUpSensor()} for more
information on wake-up sensors.
</p>
<p class="note">
</p>
Note: Don't use this method with one-shot trigger sensors such as
{@link Sensor#TYPE_SIGNIFICANT_MOTION}. Use
{@link #requestTriggerSensor(TriggerEventListener, Sensor)} instead. </p>
@param listener A {@link android.hardware.SensorEventListener SensorEventListener} object
that will receive the sensor events. If the application is interested in receiving
flush complete notifications, it should register with
{@link android.hardware.SensorEventListener SensorEventListener2} instead.
@param sensor The {@link android.hardware.Sensor Sensor} to register to.
@param samplingPeriodUs The desired delay between two consecutive events in microseconds.
This is only a hint to the system. Events may be received faster or slower than
the specified rate. Usually events are received faster. Can be one of
{@link #SENSOR_DELAY_NORMAL}, {@link #SENSOR_DELAY_UI},
{@link #SENSOR_DELAY_GAME}, {@link #SENSOR_DELAY_FASTEST} or the delay in
microseconds.
@param maxReportLatencyUs Maximum time in microseconds that events can be delayed before
being reported to the application. A large value allows reducing the power
consumption associated with the sensor. If maxReportLatencyUs is set to zero,
events are delivered as soon as they are available, which is equivalent to calling
{@link #registerListener(SensorEventListener, Sensor, int)}.
@return <code>true</code> if the sensor is supported and successfully enabled.
@see #registerListener(SensorEventListener, Sensor, int)
@see #unregisterListener(SensorEventListener)
@see #flush(SensorEventListener)
| SensorManager::registerListener | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public boolean registerListener(SensorEventListener listener, Sensor sensor,
int samplingPeriodUs, Handler handler) {
int delay = getDelay(samplingPeriodUs);
return registerListenerImpl(listener, sensor, delay, handler, 0, 0);
} |
Registers a {@link android.hardware.SensorEventListener SensorEventListener} for the given
sensor. Events are delivered in continuous mode as soon as they are available. To reduce the
power consumption, applications can use
{@link #registerListener(SensorEventListener, Sensor, int, int)} instead and specify a
positive non-zero maximum reporting latency.
<p class="note">
</p>
Note: Don't use this method with a one shot trigger sensor such as
{@link Sensor#TYPE_SIGNIFICANT_MOTION}. Use
{@link #requestTriggerSensor(TriggerEventListener, Sensor)} instead. </p>
@param listener A {@link android.hardware.SensorEventListener SensorEventListener} object.
@param sensor The {@link android.hardware.Sensor Sensor} to register to.
@param samplingPeriodUs The rate {@link android.hardware.SensorEvent sensor events} are
delivered at. This is only a hint to the system. Events may be received faster or
slower than the specified rate. Usually events are received faster. The value must
be one of {@link #SENSOR_DELAY_NORMAL}, {@link #SENSOR_DELAY_UI},
{@link #SENSOR_DELAY_GAME}, or {@link #SENSOR_DELAY_FASTEST} or, the desired
delay between events in microseconds. Specifying the delay in microseconds only
works from Android 2.3 (API level 9) onwards. For earlier releases, you must use
one of the {@code SENSOR_DELAY_*} constants.
@param handler The {@link android.os.Handler Handler} the {@link android.hardware.SensorEvent
sensor events} will be delivered to.
@return <code>true</code> if the sensor is supported and successfully enabled.
@see #registerListener(SensorEventListener, Sensor, int)
@see #unregisterListener(SensorEventListener)
@see #unregisterListener(SensorEventListener, Sensor)
| SensorManager::registerListener | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public boolean registerListener(SensorEventListener listener, Sensor sensor,
int samplingPeriodUs, int maxReportLatencyUs, Handler handler) {
int delayUs = getDelay(samplingPeriodUs);
return registerListenerImpl(listener, sensor, delayUs, handler, maxReportLatencyUs, 0);
} |
Registers a {@link android.hardware.SensorEventListener SensorEventListener} for the given
sensor at the given sampling frequency and the given maximum reporting latency.
@param listener A {@link android.hardware.SensorEventListener SensorEventListener} object
that will receive the sensor events. If the application is interested in receiving
flush complete notifications, it should register with
{@link android.hardware.SensorEventListener SensorEventListener2} instead.
@param sensor The {@link android.hardware.Sensor Sensor} to register to.
@param samplingPeriodUs The desired delay between two consecutive events in microseconds.
This is only a hint to the system. Events may be received faster or slower than
the specified rate. Usually events are received faster. Can be one of
{@link #SENSOR_DELAY_NORMAL}, {@link #SENSOR_DELAY_UI},
{@link #SENSOR_DELAY_GAME}, {@link #SENSOR_DELAY_FASTEST} or the delay in
microseconds.
@param maxReportLatencyUs Maximum time in microseconds that events can be delayed before
being reported to the application. A large value allows reducing the power
consumption associated with the sensor. If maxReportLatencyUs is set to zero,
events are delivered as soon as they are available, which is equivalent to calling
{@link #registerListener(SensorEventListener, Sensor, int)}.
@param handler The {@link android.os.Handler Handler} the {@link android.hardware.SensorEvent
sensor events} will be delivered to.
@return <code>true</code> if the sensor is supported and successfully enabled.
@see #registerListener(SensorEventListener, Sensor, int, int)
| SensorManager::registerListener | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public boolean flush(SensorEventListener listener) {
return flushImpl(listener);
} |
Flushes the FIFO of all the sensors registered for this listener. If there are events
in the FIFO of the sensor, they are returned as if the maxReportLantecy of the FIFO has
expired. Events are returned in the usual way through the SensorEventListener.
This call doesn't affect the maxReportLantecy for this sensor. This call is asynchronous and
returns immediately.
{@link android.hardware.SensorEventListener2#onFlushCompleted onFlushCompleted} is called
after all the events in the batch at the time of calling this method have been delivered
successfully. If the hardware doesn't support flush, it still returns true and a trivial
flush complete event is sent after the current event for all the clients registered for this
sensor.
@param listener A {@link android.hardware.SensorEventListener SensorEventListener} object
which was previously used in a registerListener call.
@return <code>true</code> if the flush is initiated successfully on all the sensors
registered for this listener, false if no sensor is previously registered for this
listener or flush on one of the sensors fails.
@see #registerListener(SensorEventListener, Sensor, int, int)
@throws IllegalArgumentException when listener is null.
| SensorManager::flush | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public SensorDirectChannel createDirectChannel(MemoryFile mem) {
return createDirectChannelImpl(mem, null);
} |
Create a sensor direct channel backed by shared memory wrapped in MemoryFile object.
The resulting channel can be used for delivering sensor events to native code, other
processes, GPU/DSP or other co-processors without CPU intervention. This is the recommanded
for high performance sensor applications that use high sensor rates (e.g. greater than 200Hz)
and cares about sensor event latency.
Use the returned {@link android.hardware.SensorDirectChannel} object to configure direct
report of sensor events. After use, call {@link android.hardware.SensorDirectChannel#close()}
to free up resource in sensor system associated with the direct channel.
@param mem A {@link android.os.MemoryFile} shared memory object.
@return A {@link android.hardware.SensorDirectChannel} object.
@throws NullPointerException when mem is null.
@throws UncheckedIOException if not able to create channel.
@see SensorDirectChannel#close()
| SensorManager::createDirectChannel | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public SensorDirectChannel createDirectChannel(HardwareBuffer mem) {
return createDirectChannelImpl(null, mem);
} |
Create a sensor direct channel backed by shared memory wrapped in HardwareBuffer object.
The resulting channel can be used for delivering sensor events to native code, other
processes, GPU/DSP or other co-processors without CPU intervention. This is the recommanded
for high performance sensor applications that use high sensor rates (e.g. greater than 200Hz)
and cares about sensor event latency.
Use the returned {@link android.hardware.SensorDirectChannel} object to configure direct
report of sensor events. After use, call {@link android.hardware.SensorDirectChannel#close()}
to free up resource in sensor system associated with the direct channel.
@param mem A {@link android.hardware.HardwareBuffer} shared memory object.
@return A {@link android.hardware.SensorDirectChannel} object.
@throws NullPointerException when mem is null.
@throws UncheckedIOException if not able to create channel.
@see SensorDirectChannel#close()
| SensorManager::createDirectChannel | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
void destroyDirectChannel(SensorDirectChannel channel) {
destroyDirectChannelImpl(channel);
} |
Create a sensor direct channel backed by shared memory wrapped in HardwareBuffer object.
The resulting channel can be used for delivering sensor events to native code, other
processes, GPU/DSP or other co-processors without CPU intervention. This is the recommanded
for high performance sensor applications that use high sensor rates (e.g. greater than 200Hz)
and cares about sensor event latency.
Use the returned {@link android.hardware.SensorDirectChannel} object to configure direct
report of sensor events. After use, call {@link android.hardware.SensorDirectChannel#close()}
to free up resource in sensor system associated with the direct channel.
@param mem A {@link android.hardware.HardwareBuffer} shared memory object.
@return A {@link android.hardware.SensorDirectChannel} object.
@throws NullPointerException when mem is null.
@throws UncheckedIOException if not able to create channel.
@see SensorDirectChannel#close()
public SensorDirectChannel createDirectChannel(HardwareBuffer mem) {
return createDirectChannelImpl(null, mem);
}
/** @hide
protected abstract SensorDirectChannel createDirectChannelImpl(
MemoryFile memoryFile, HardwareBuffer hardwareBuffer);
/** @hide | SensorManager::destroyDirectChannel | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public void onDynamicSensorConnected(Sensor sensor) {} |
Called when there is a dynamic sensor being connected to the system.
@param sensor the newly connected sensor. See {@link android.hardware.Sensor Sensor}.
| DynamicSensorCallback::onDynamicSensorConnected | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public void onDynamicSensorDisconnected(Sensor sensor) {} |
Called when there is a dynamic sensor being disconnected from the system.
@param sensor the disconnected sensor. See {@link android.hardware.Sensor Sensor}.
| DynamicSensorCallback::onDynamicSensorDisconnected | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public void registerDynamicSensorCallback(DynamicSensorCallback callback) {
registerDynamicSensorCallback(callback, null);
} |
Add a {@link android.hardware.SensorManager.DynamicSensorCallback
DynamicSensorCallback} to receive dynamic sensor connection callbacks. Repeat
registration with the already registered callback object will have no additional effect.
@param callback An object that implements the
{@link android.hardware.SensorManager.DynamicSensorCallback
DynamicSensorCallback}
interface for receiving callbacks.
@see #registerDynamicSensorCallback(DynamicSensorCallback, Handler)
@throws IllegalArgumentException when callback is null.
| DynamicSensorCallback::registerDynamicSensorCallback | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public void registerDynamicSensorCallback(
DynamicSensorCallback callback, Handler handler) {
registerDynamicSensorCallbackImpl(callback, handler);
} |
Add a {@link android.hardware.SensorManager.DynamicSensorCallback
DynamicSensorCallback} to receive dynamic sensor connection callbacks. Repeat
registration with the already registered callback object will have no additional effect.
@param callback An object that implements the
{@link android.hardware.SensorManager.DynamicSensorCallback
DynamicSensorCallback} interface for receiving callbacks.
@param handler The {@link android.os.Handler Handler} the {@link
android.hardware.SensorManager.DynamicSensorCallback
sensor connection events} will be delivered to.
@throws IllegalArgumentException when callback is null.
| DynamicSensorCallback::registerDynamicSensorCallback | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public void unregisterDynamicSensorCallback(DynamicSensorCallback callback) {
unregisterDynamicSensorCallbackImpl(callback);
} |
Remove a {@link android.hardware.SensorManager.DynamicSensorCallback
DynamicSensorCallback} to stop sending dynamic sensor connection events to that
callback.
@param callback An object that implements the
{@link android.hardware.SensorManager.DynamicSensorCallback
DynamicSensorCallback}
interface for receiving callbacks.
| DynamicSensorCallback::unregisterDynamicSensorCallback | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public boolean isDynamicSensorDiscoverySupported() {
List<Sensor> sensors = getSensorList(Sensor.TYPE_DYNAMIC_SENSOR_META);
return sensors.size() > 0;
} |
Tell if dynamic sensor discovery feature is supported by system.
@return <code>true</code> if dynamic sensor discovery is supported, <code>false</code>
otherwise.
| DynamicSensorCallback::isDynamicSensorDiscoverySupported | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public static float getInclination(float[] I) {
if (I.length == 9) {
return (float) Math.atan2(I[5], I[4]);
} else {
return (float) Math.atan2(I[6], I[5]);
}
} |
Computes the geomagnetic inclination angle in radians from the
inclination matrix <b>I</b> returned by {@link #getRotationMatrix}.
@param I
inclination matrix see {@link #getRotationMatrix}.
@return The geomagnetic inclination angle in radians.
@see #getRotationMatrix(float[], float[], float[], float[])
@see #getOrientation(float[], float[])
@see GeomagneticField
| DynamicSensorCallback::getInclination | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public static float[] getOrientation(float[] R, float[] values) {
/*
* 4x4 (length=16) case:
* / R[ 0] R[ 1] R[ 2] 0 \
* | R[ 4] R[ 5] R[ 6] 0 |
* | R[ 8] R[ 9] R[10] 0 |
* \ 0 0 0 1 /
*
* 3x3 (length=9) case:
* / R[ 0] R[ 1] R[ 2] \
* | R[ 3] R[ 4] R[ 5] |
* \ R[ 6] R[ 7] R[ 8] /
*
*/
if (R.length == 9) {
values[0] = (float) Math.atan2(R[1], R[4]);
values[1] = (float) Math.asin(-R[7]);
values[2] = (float) Math.atan2(-R[6], R[8]);
} else {
values[0] = (float) Math.atan2(R[1], R[5]);
values[1] = (float) Math.asin(-R[9]);
values[2] = (float) Math.atan2(-R[8], R[10]);
}
return values;
} |
Computes the device's orientation based on the rotation matrix.
<p>
When it returns, the array values are as follows:
<ul>
<li>values[0]: <i>Azimuth</i>, angle of rotation about the -z axis.
This value represents the angle between the device's y
axis and the magnetic north pole. When facing north, this
angle is 0, when facing south, this angle is π.
Likewise, when facing east, this angle is π/2, and
when facing west, this angle is -π/2. The range of
values is -π to π.</li>
<li>values[1]: <i>Pitch</i>, angle of rotation about the x axis.
This value represents the angle between a plane parallel
to the device's screen and a plane parallel to the ground.
Assuming that the bottom edge of the device faces the
user and that the screen is face-up, tilting the top edge
of the device toward the ground creates a positive pitch
angle. The range of values is -π to π.</li>
<li>values[2]: <i>Roll</i>, angle of rotation about the y axis. This
value represents the angle between a plane perpendicular
to the device's screen and a plane perpendicular to the
ground. Assuming that the bottom edge of the device faces
the user and that the screen is face-up, tilting the left
edge of the device toward the ground creates a positive
roll angle. The range of values is -π/2 to π/2.</li>
</ul>
<p>
Applying these three rotations in the azimuth, pitch, roll order
transforms an identity matrix to the rotation matrix passed into this
method. Also, note that all three orientation angles are expressed in
<b>radians</b>.
@param R
rotation matrix see {@link #getRotationMatrix}.
@param values
an array of 3 floats to hold the result.
@return The array values passed as argument.
@see #getRotationMatrix(float[], float[], float[], float[])
@see GeomagneticField
| DynamicSensorCallback::getOrientation | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public static float getAltitude(float p0, float p) {
final float coef = 1.0f / 5.255f;
return 44330.0f * (1.0f - (float) Math.pow(p / p0, coef));
} |
Computes the Altitude in meters from the atmospheric pressure and the
pressure at sea level.
<p>
Typically the atmospheric pressure is read from a
{@link Sensor#TYPE_PRESSURE} sensor. The pressure at sea level must be
known, usually it can be retrieved from airport databases in the
vicinity. If unknown, you can use {@link #PRESSURE_STANDARD_ATMOSPHERE}
as an approximation, but absolute altitudes won't be accurate.
</p>
<p>
To calculate altitude differences, you must calculate the difference
between the altitudes at both points. If you don't know the altitude
as sea level, you can use {@link #PRESSURE_STANDARD_ATMOSPHERE} instead,
which will give good results considering the range of pressure typically
involved.
</p>
<p>
<code><ul>
float altitude_difference =
getAltitude(SensorManager.PRESSURE_STANDARD_ATMOSPHERE, pressure_at_point2)
- getAltitude(SensorManager.PRESSURE_STANDARD_ATMOSPHERE, pressure_at_point1);
</ul></code>
</p>
@param p0 pressure at sea level
@param p atmospheric pressure
@return Altitude in meters
| DynamicSensorCallback::getAltitude | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public static void getRotationMatrixFromVector(float[] R, float[] rotationVector) {
float q0;
float q1 = rotationVector[0];
float q2 = rotationVector[1];
float q3 = rotationVector[2];
if (rotationVector.length >= 4) {
q0 = rotationVector[3];
} else {
q0 = 1 - q1 * q1 - q2 * q2 - q3 * q3;
q0 = (q0 > 0) ? (float) Math.sqrt(q0) : 0;
}
float sq_q1 = 2 * q1 * q1;
float sq_q2 = 2 * q2 * q2;
float sq_q3 = 2 * q3 * q3;
float q1_q2 = 2 * q1 * q2;
float q3_q0 = 2 * q3 * q0;
float q1_q3 = 2 * q1 * q3;
float q2_q0 = 2 * q2 * q0;
float q2_q3 = 2 * q2 * q3;
float q1_q0 = 2 * q1 * q0;
if (R.length == 9) {
R[0] = 1 - sq_q2 - sq_q3;
R[1] = q1_q2 - q3_q0;
R[2] = q1_q3 + q2_q0;
R[3] = q1_q2 + q3_q0;
R[4] = 1 - sq_q1 - sq_q3;
R[5] = q2_q3 - q1_q0;
R[6] = q1_q3 - q2_q0;
R[7] = q2_q3 + q1_q0;
R[8] = 1 - sq_q1 - sq_q2;
} else if (R.length == 16) {
R[0] = 1 - sq_q2 - sq_q3;
R[1] = q1_q2 - q3_q0;
R[2] = q1_q3 + q2_q0;
R[3] = 0.0f;
R[4] = q1_q2 + q3_q0;
R[5] = 1 - sq_q1 - sq_q3;
R[6] = q2_q3 - q1_q0;
R[7] = 0.0f;
R[8] = q1_q3 - q2_q0;
R[9] = q2_q3 + q1_q0;
R[10] = 1 - sq_q1 - sq_q2;
R[11] = 0.0f;
R[12] = R[13] = R[14] = 0.0f;
R[15] = 1.0f;
}
} | Helper function to convert a rotation vector to a rotation matrix.
Given a rotation vector (presumably from a ROTATION_VECTOR sensor), returns a
9 or 16 element rotation matrix in the array R. R must have length 9 or 16.
If R.length == 9, the following matrix is returned:
<pre>
/ R[ 0] R[ 1] R[ 2] \
| R[ 3] R[ 4] R[ 5] |
\ R[ 6] R[ 7] R[ 8] /
</pre>
If R.length == 16, the following matrix is returned:
<pre>
/ R[ 0] R[ 1] R[ 2] 0 \
| R[ 4] R[ 5] R[ 6] 0 |
| R[ 8] R[ 9] R[10] 0 |
\ 0 0 0 1 /
</pre>
@param rotationVector the rotation vector to convert
@param R an array of floats in which to store the rotation matrix
| DynamicSensorCallback::getRotationMatrixFromVector | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public static void getQuaternionFromVector(float[] Q, float[] rv) {
if (rv.length >= 4) {
Q[0] = rv[3];
} else {
Q[0] = 1 - rv[0] * rv[0] - rv[1] * rv[1] - rv[2] * rv[2];
Q[0] = (Q[0] > 0) ? (float) Math.sqrt(Q[0]) : 0;
}
Q[1] = rv[0];
Q[2] = rv[1];
Q[3] = rv[2];
} | Helper function to convert a rotation vector to a normalized quaternion.
Given a rotation vector (presumably from a ROTATION_VECTOR sensor), returns a normalized
quaternion in the array Q. The quaternion is stored as [w, x, y, z]
@param rv the rotation vector to convert
@param Q an array of floats in which to store the computed quaternion
| DynamicSensorCallback::getQuaternionFromVector | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public boolean requestTriggerSensor(TriggerEventListener listener, Sensor sensor) {
return requestTriggerSensorImpl(listener, sensor);
} |
Requests receiving trigger events for a trigger sensor.
<p>
When the sensor detects a trigger event condition, such as significant motion in
the case of the {@link Sensor#TYPE_SIGNIFICANT_MOTION}, the provided trigger listener
will be invoked once and then its request to receive trigger events will be canceled.
To continue receiving trigger events, the application must request to receive trigger
events again.
</p>
@param listener The listener on which the
{@link TriggerEventListener#onTrigger(TriggerEvent)} will be delivered.
@param sensor The sensor to be enabled.
@return true if the sensor was successfully enabled.
@throws IllegalArgumentException when sensor is null or not a trigger sensor.
| DynamicSensorCallback::requestTriggerSensor | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public boolean cancelTriggerSensor(TriggerEventListener listener, Sensor sensor) {
return cancelTriggerSensorImpl(listener, sensor, true);
} |
Cancels receiving trigger events for a trigger sensor.
<p>
Note that a Trigger sensor will be auto disabled if
{@link TriggerEventListener#onTrigger(TriggerEvent)} has triggered.
This method is provided in case the user wants to explicitly cancel the request
to receive trigger events.
</p>
@param listener The listener on which the
{@link TriggerEventListener#onTrigger(TriggerEvent)}
is delivered.It should be the same as the one used
in {@link #requestTriggerSensor(TriggerEventListener, Sensor)}
@param sensor The sensor for which the trigger request should be canceled.
If null, it cancels receiving trigger for all sensors associated
with the listener.
@return true if successfully canceled.
@throws IllegalArgumentException when sensor is a trigger sensor.
| DynamicSensorCallback::cancelTriggerSensor | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public boolean setOperationParameter(SensorAdditionalInfo parameter) {
return setOperationParameterImpl(parameter);
} |
@hide
protected abstract boolean injectSensorDataImpl(Sensor sensor, float[] values, int accuracy,
long timestamp);
private LegacySensorManager getLegacySensorManager() {
synchronized (mSensorListByType) {
if (mLegacySensorManager == null) {
Log.i(TAG, "This application is using deprecated SensorManager API which will "
+ "be removed someday. Please consider switching to the new API.");
mLegacySensorManager = new LegacySensorManager(this);
}
return mLegacySensorManager;
}
}
private static int getDelay(int rate) {
int delay = -1;
switch (rate) {
case SENSOR_DELAY_FASTEST:
delay = 0;
break;
case SENSOR_DELAY_GAME:
delay = 20000;
break;
case SENSOR_DELAY_UI:
delay = 66667;
break;
case SENSOR_DELAY_NORMAL:
delay = 200000;
break;
default:
delay = rate;
break;
}
return delay;
}
/** @hide | DynamicSensorCallback::setOperationParameter | java | Reginer/aosp-android-jar | android-31/src/android/hardware/SensorManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-31/src/android/hardware/SensorManager.java | MIT |
public void onSessionCreated(@Nullable Session session) {
} |
This is called after {@link TvInputManager#createSession} has been processed.
@param session A {@link TvInputManager.Session} instance created. This can be
{@code null} if the creation request failed.
| SessionCallback::onSessionCreated | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onSessionReleased(Session session) {
} |
This is called when {@link TvInputManager.Session} is released.
This typically happens when the process hosting the session has crashed or been killed.
@param session A {@link TvInputManager.Session} instance released.
| SessionCallback::onSessionReleased | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onChannelRetuned(Session session, Uri channelUri) {
} |
This is called when the channel of this session is changed by the underlying TV input
without any {@link TvInputManager.Session#tune(Uri)} request.
@param session A {@link TvInputManager.Session} associated with this callback.
@param channelUri The URI of a channel.
| SessionCallback::onChannelRetuned | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onTracksChanged(Session session, List<TvTrackInfo> tracks) {
} |
This is called when the track information of the session has been changed.
@param session A {@link TvInputManager.Session} associated with this callback.
@param tracks A list which includes track information.
| SessionCallback::onTracksChanged | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onTrackSelected(Session session, int type, @Nullable String trackId) {
} |
This is called when a track for a given type is selected.
@param session A {@link TvInputManager.Session} associated with this callback.
@param type The type of the selected track. The type can be
{@link TvTrackInfo#TYPE_AUDIO}, {@link TvTrackInfo#TYPE_VIDEO} or
{@link TvTrackInfo#TYPE_SUBTITLE}.
@param trackId The ID of the selected track. When {@code null} the currently selected
track for a given type should be unselected.
| SessionCallback::onTrackSelected | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onVideoSizeChanged(Session session, int width, int height) {
} |
This is invoked when the video size has been changed. It is also called when the first
time video size information becomes available after the session is tuned to a specific
channel.
@param session A {@link TvInputManager.Session} associated with this callback.
@param width The width of the video.
@param height The height of the video.
| SessionCallback::onVideoSizeChanged | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onVideoAvailable(Session session) {
} |
This is called when the video is available, so the TV input starts the playback.
@param session A {@link TvInputManager.Session} associated with this callback.
| SessionCallback::onVideoAvailable | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onVideoUnavailable(Session session, int reason) {
} |
This is called when the video is not available, so the TV input stops the playback.
@param session A {@link TvInputManager.Session} associated with this callback.
@param reason The reason why the TV input stopped the playback:
<ul>
<li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_UNKNOWN}
<li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_TUNING}
<li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_WEAK_SIGNAL}
<li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_BUFFERING}
<li>{@link TvInputManager#VIDEO_UNAVAILABLE_REASON_AUDIO_ONLY}
</ul>
| SessionCallback::onVideoUnavailable | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onContentAllowed(Session session) {
} |
This is called when the current program content turns out to be allowed to watch since
its content rating is not blocked by parental controls.
@param session A {@link TvInputManager.Session} associated with this callback.
| SessionCallback::onContentAllowed | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onContentBlocked(Session session, TvContentRating rating) {
} |
This is called when the current program content turns out to be not allowed to watch
since its content rating is blocked by parental controls.
@param session A {@link TvInputManager.Session} associated with this callback.
@param rating The content ration of the blocked program.
| SessionCallback::onContentBlocked | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onLayoutSurface(Session session, int left, int top, int right, int bottom) {
} |
This is called when {@link TvInputService.Session#layoutSurface} is called to change the
layout of surface.
@param session A {@link TvInputManager.Session} associated with this callback.
@param left Left position.
@param top Top position.
@param right Right position.
@param bottom Bottom position.
| SessionCallback::onLayoutSurface | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onSessionEvent(Session session, String eventType, Bundle eventArgs) {
} |
This is called when a custom event has been sent from this session.
@param session A {@link TvInputManager.Session} associated with this callback
@param eventType The type of the event.
@param eventArgs Optional arguments of the event.
| SessionCallback::onSessionEvent | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onTimeShiftStatusChanged(Session session, int status) {
} |
This is called when the time shift status is changed.
@param session A {@link TvInputManager.Session} associated with this callback.
@param status The current time shift status. Should be one of the followings.
<ul>
<li>{@link TvInputManager#TIME_SHIFT_STATUS_UNSUPPORTED}
<li>{@link TvInputManager#TIME_SHIFT_STATUS_UNAVAILABLE}
<li>{@link TvInputManager#TIME_SHIFT_STATUS_AVAILABLE}
</ul>
| SessionCallback::onTimeShiftStatusChanged | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onTimeShiftStartPositionChanged(Session session, long timeMs) {
} |
This is called when the start position for time shifting has changed.
@param session A {@link TvInputManager.Session} associated with this callback.
@param timeMs The start position for time shifting, in milliseconds since the epoch.
| SessionCallback::onTimeShiftStartPositionChanged | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onTimeShiftCurrentPositionChanged(Session session, long timeMs) {
} |
This is called when the current position for time shifting is changed.
@param session A {@link TvInputManager.Session} associated with this callback.
@param timeMs The current position for time shifting, in milliseconds since the epoch.
| SessionCallback::onTimeShiftCurrentPositionChanged | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onAitInfoUpdated(Session session, AitInfo aitInfo) {
} |
This is called when AIT info is updated.
@param session A {@link TvInputManager.Session} associated with this callback.
@param aitInfo The current AIT info.
| SessionCallback::onAitInfoUpdated | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onSignalStrengthUpdated(Session session, @SignalStrength int strength) {
} |
This is called when signal strength is updated.
@param session A {@link TvInputManager.Session} associated with this callback.
@param strength The current signal strength.
| SessionCallback::onSignalStrengthUpdated | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onTuned(Session session, Uri channelUri) {
} |
This is called when the session has been tuned to the given channel.
@param channelUri The URI of a channel.
| SessionCallback::onTuned | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
void onRecordingStopped(Session session, Uri recordedProgramUri) {
} |
This is called when the current recording session has stopped recording and created a
new data entry in the {@link TvContract.RecordedPrograms} table that describes the newly
recorded program.
@param recordedProgramUri The URI for the newly recorded program.
| SessionCallback::onRecordingStopped | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
void onError(Session session, @TvInputManager.RecordingError int error) {
} |
This is called when an issue has occurred. It may be called at any time after the current
recording session is created until it is released.
@param error The error code.
| SessionCallback::onError | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onInputStateChanged(String inputId, @InputState int state) {
} |
This is called when the state of a given TV input is changed.
@param inputId The ID of the TV input.
@param state State of the TV input. The value is one of the following:
<ul>
<li>{@link TvInputManager#INPUT_STATE_CONNECTED}
<li>{@link TvInputManager#INPUT_STATE_CONNECTED_STANDBY}
<li>{@link TvInputManager#INPUT_STATE_DISCONNECTED}
</ul>
| TvInputCallback::onInputStateChanged | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onInputAdded(String inputId) {
} |
This is called when a TV input is added to the system.
<p>Normally it happens when the user installs a new TV input package that implements
{@link TvInputService} interface.
@param inputId The ID of the TV input.
| TvInputCallback::onInputAdded | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onInputRemoved(String inputId) {
} |
This is called when a TV input is removed from the system.
<p>Normally it happens when the user uninstalls the previously installed TV input
package.
@param inputId The ID of the TV input.
| TvInputCallback::onInputRemoved | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onInputUpdated(String inputId) {
} |
This is called when a TV input is updated on the system.
<p>Normally it happens when a previously installed TV input package is re-installed or
the media on which a newer version of the package exists becomes available/unavailable.
@param inputId The ID of the TV input.
| TvInputCallback::onInputUpdated | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void onTvInputInfoUpdated(TvInputInfo inputInfo) {
} |
This is called when the information about an existing TV input has been updated.
<p>Because the system automatically creates a <code>TvInputInfo</code> object for each TV
input based on the information collected from the <code>AndroidManifest.xml</code>, this
method is only called back when such information has changed dynamically.
@param inputInfo The <code>TvInputInfo</code> object that contains new information.
| TvInputCallback::onTvInputInfoUpdated | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public TvInputManager(ITvInputManager service, int userId) {
mService = service;
mUserId = userId;
mClient = new ITvInputClient.Stub() {
@Override
public void onSessionCreated(String inputId, IBinder token, InputChannel channel,
int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
if (record == null) {
Log.e(TAG, "Callback not found for " + token);
return;
}
Session session = null;
if (token != null) {
session = new Session(token, channel, mService, mUserId, seq,
mSessionCallbackRecordMap);
} else {
mSessionCallbackRecordMap.delete(seq);
}
record.postSessionCreated(session);
}
}
@Override
public void onSessionReleased(int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
mSessionCallbackRecordMap.delete(seq);
if (record == null) {
Log.e(TAG, "Callback not found for seq:" + seq);
return;
}
record.mSession.releaseInternal();
record.postSessionReleased();
}
}
@Override
public void onChannelRetuned(Uri channelUri, int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
if (record == null) {
Log.e(TAG, "Callback not found for seq " + seq);
return;
}
record.postChannelRetuned(channelUri);
}
}
@Override
public void onTracksChanged(List<TvTrackInfo> tracks, int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
if (record == null) {
Log.e(TAG, "Callback not found for seq " + seq);
return;
}
if (record.mSession.updateTracks(tracks)) {
record.postTracksChanged(tracks);
postVideoSizeChangedIfNeededLocked(record);
}
}
}
@Override
public void onTrackSelected(int type, String trackId, int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
if (record == null) {
Log.e(TAG, "Callback not found for seq " + seq);
return;
}
if (record.mSession.updateTrackSelection(type, trackId)) {
record.postTrackSelected(type, trackId);
postVideoSizeChangedIfNeededLocked(record);
}
}
}
private void postVideoSizeChangedIfNeededLocked(SessionCallbackRecord record) {
TvTrackInfo track = record.mSession.getVideoTrackToNotify();
if (track != null) {
record.postVideoSizeChanged(track.getVideoWidth(), track.getVideoHeight());
}
}
@Override
public void onVideoAvailable(int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
if (record == null) {
Log.e(TAG, "Callback not found for seq " + seq);
return;
}
record.postVideoAvailable();
}
}
@Override
public void onVideoUnavailable(int reason, int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
if (record == null) {
Log.e(TAG, "Callback not found for seq " + seq);
return;
}
record.postVideoUnavailable(reason);
}
}
@Override
public void onContentAllowed(int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
if (record == null) {
Log.e(TAG, "Callback not found for seq " + seq);
return;
}
record.postContentAllowed();
}
}
@Override
public void onContentBlocked(String rating, int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
if (record == null) {
Log.e(TAG, "Callback not found for seq " + seq);
return;
}
record.postContentBlocked(TvContentRating.unflattenFromString(rating));
}
}
@Override
public void onLayoutSurface(int left, int top, int right, int bottom, int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
if (record == null) {
Log.e(TAG, "Callback not found for seq " + seq);
return;
}
record.postLayoutSurface(left, top, right, bottom);
}
}
@Override
public void onSessionEvent(String eventType, Bundle eventArgs, int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
if (record == null) {
Log.e(TAG, "Callback not found for seq " + seq);
return;
}
record.postSessionEvent(eventType, eventArgs);
}
}
@Override
public void onTimeShiftStatusChanged(int status, int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
if (record == null) {
Log.e(TAG, "Callback not found for seq " + seq);
return;
}
record.postTimeShiftStatusChanged(status);
}
}
@Override
public void onTimeShiftStartPositionChanged(long timeMs, int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
if (record == null) {
Log.e(TAG, "Callback not found for seq " + seq);
return;
}
record.postTimeShiftStartPositionChanged(timeMs);
}
}
@Override
public void onTimeShiftCurrentPositionChanged(long timeMs, int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
if (record == null) {
Log.e(TAG, "Callback not found for seq " + seq);
return;
}
record.postTimeShiftCurrentPositionChanged(timeMs);
}
}
@Override
public void onAitInfoUpdated(AitInfo aitInfo, int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
if (record == null) {
Log.e(TAG, "Callback not found for seq " + seq);
return;
}
record.postAitInfoUpdated(aitInfo);
}
}
@Override
public void onSignalStrength(int strength, int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
if (record == null) {
Log.e(TAG, "Callback not found for seq " + seq);
return;
}
record.postSignalStrength(strength);
}
}
@Override
public void onTuned(Uri channelUri, int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
if (record == null) {
Log.e(TAG, "Callback not found for seq " + seq);
return;
}
record.postTuned(channelUri);
// TODO: synchronized and wrap the channelUri
}
}
@Override
public void onRecordingStopped(Uri recordedProgramUri, int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
if (record == null) {
Log.e(TAG, "Callback not found for seq " + seq);
return;
}
record.postRecordingStopped(recordedProgramUri);
}
}
@Override
public void onError(int error, int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
if (record == null) {
Log.e(TAG, "Callback not found for seq " + seq);
return;
}
record.postError(error);
}
}
@Override
public void onBroadcastInfoResponse(BroadcastInfoResponse response, int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
if (record == null) {
Log.e(TAG, "Callback not found for seq " + seq);
return;
}
record.postBroadcastInfoResponse(response);
}
}
@Override
public void onAdResponse(AdResponse response, int seq) {
synchronized (mSessionCallbackRecordMap) {
SessionCallbackRecord record = mSessionCallbackRecordMap.get(seq);
if (record == null) {
Log.e(TAG, "Callback not found for seq " + seq);
return;
}
record.postAdResponse(response);
}
}
};
ITvInputManagerCallback managerCallback = new ITvInputManagerCallback.Stub() {
@Override
public void onInputAdded(String inputId) {
synchronized (mLock) {
mStateMap.put(inputId, INPUT_STATE_CONNECTED);
for (TvInputCallbackRecord record : mCallbackRecords) {
record.postInputAdded(inputId);
}
}
}
@Override
public void onInputRemoved(String inputId) {
synchronized (mLock) {
mStateMap.remove(inputId);
for (TvInputCallbackRecord record : mCallbackRecords) {
record.postInputRemoved(inputId);
}
}
}
@Override
public void onInputUpdated(String inputId) {
synchronized (mLock) {
for (TvInputCallbackRecord record : mCallbackRecords) {
record.postInputUpdated(inputId);
}
}
}
@Override
public void onInputStateChanged(String inputId, int state) {
synchronized (mLock) {
mStateMap.put(inputId, state);
for (TvInputCallbackRecord record : mCallbackRecords) {
record.postInputStateChanged(inputId, state);
}
}
}
@Override
public void onTvInputInfoUpdated(TvInputInfo inputInfo) {
synchronized (mLock) {
for (TvInputCallbackRecord record : mCallbackRecords) {
record.postTvInputInfoUpdated(inputInfo);
}
}
}
@Override
public void onCurrentTunedInfosUpdated(List<TunedInfo> currentTunedInfos) {
synchronized (mLock) {
for (TvInputCallbackRecord record : mCallbackRecords) {
record.postCurrentTunedInfosUpdated(currentTunedInfos);
}
}
}
};
try {
if (mService != null) {
mService.registerCallback(managerCallback, mUserId);
List<TvInputInfo> infos = mService.getTvInputList(mUserId);
synchronized (mLock) {
for (TvInputInfo info : infos) {
String inputId = info.getId();
mStateMap.put(inputId, mService.getTvInputState(inputId, mUserId));
}
}
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
@hide
| HardwareCallback::TvInputManager | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void release() {
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.releaseSession(mToken, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
releaseInternal();
} |
Releases this session.
| Session::release | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
void setMain() {
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.setMainSession(mToken, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Sets this as the main session. The main session is a session whose corresponding TV
input determines the HDMI-CEC active source device.
@see TvView#setMain
| Session::setMain | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void setSurface(Surface surface) {
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
// surface can be null.
try {
mService.setSurface(mToken, surface, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Sets the {@link android.view.Surface} for this session.
@param surface A {@link android.view.Surface} used to render video.
| Session::setSurface | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void dispatchSurfaceChanged(int format, int width, int height) {
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.dispatchSurfaceChanged(mToken, format, width, height, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Notifies of any structural changes (format or size) of the surface passed in
{@link #setSurface}.
@param format The new PixelFormat of the surface.
@param width The new width of the surface.
@param height The new height of the surface.
| Session::dispatchSurfaceChanged | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void setStreamVolume(float volume) {
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
if (volume < 0.0f || volume > 1.0f) {
throw new IllegalArgumentException("volume should be between 0.0f and 1.0f");
}
mService.setVolume(mToken, volume, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Sets the relative stream volume of this session to handle a change of audio focus.
@param volume A volume value between 0.0f to 1.0f.
@throws IllegalArgumentException if the volume value is out of range.
| Session::setStreamVolume | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void tune(Uri channelUri) {
tune(channelUri, null);
} |
Tunes to a given channel.
@param channelUri The URI of a channel.
| Session::tune | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void tune(@NonNull Uri channelUri, Bundle params) {
Preconditions.checkNotNull(channelUri);
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
synchronized (mMetadataLock) {
mAudioTracks.clear();
mVideoTracks.clear();
mSubtitleTracks.clear();
mSelectedAudioTrackId = null;
mSelectedVideoTrackId = null;
mSelectedSubtitleTrackId = null;
mVideoWidth = 0;
mVideoHeight = 0;
}
try {
mService.tune(mToken, channelUri, params, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Tunes to a given channel.
@param channelUri The URI of a channel.
@param params A set of extra parameters which might be handled with this tune event.
| Session::tune | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void setCaptionEnabled(boolean enabled) {
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.setCaptionEnabled(mToken, enabled, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Enables or disables the caption for this session.
@param enabled {@code true} to enable, {@code false} to disable.
| Session::setCaptionEnabled | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void selectTrack(int type, @Nullable String trackId) {
synchronized (mMetadataLock) {
if (type == TvTrackInfo.TYPE_AUDIO) {
if (trackId != null && !containsTrack(mAudioTracks, trackId)) {
Log.w(TAG, "Invalid audio trackId: " + trackId);
return;
}
} else if (type == TvTrackInfo.TYPE_VIDEO) {
if (trackId != null && !containsTrack(mVideoTracks, trackId)) {
Log.w(TAG, "Invalid video trackId: " + trackId);
return;
}
} else if (type == TvTrackInfo.TYPE_SUBTITLE) {
if (trackId != null && !containsTrack(mSubtitleTracks, trackId)) {
Log.w(TAG, "Invalid subtitle trackId: " + trackId);
return;
}
} else {
throw new IllegalArgumentException("invalid type: " + type);
}
}
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.selectTrack(mToken, type, trackId, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Selects a track.
@param type The type of the track to select. The type can be
{@link TvTrackInfo#TYPE_AUDIO}, {@link TvTrackInfo#TYPE_VIDEO} or
{@link TvTrackInfo#TYPE_SUBTITLE}.
@param trackId The ID of the track to select. When {@code null}, the currently selected
track of the given type will be unselected.
@see #getTracks
| Session::selectTrack | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void setInteractiveAppNotificationEnabled(boolean enabled) {
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.setInteractiveAppNotificationEnabled(mToken, enabled, mUserId);
mIAppNotificationEnabled = enabled;
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Enables interactive app notification.
@param enabled {@code true} if you want to enable interactive app notifications.
{@code false} otherwise.
| Session::setInteractiveAppNotificationEnabled | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
boolean updateTracks(List<TvTrackInfo> tracks) {
synchronized (mMetadataLock) {
mAudioTracks.clear();
mVideoTracks.clear();
mSubtitleTracks.clear();
for (TvTrackInfo track : tracks) {
if (track.getType() == TvTrackInfo.TYPE_AUDIO) {
mAudioTracks.add(track);
} else if (track.getType() == TvTrackInfo.TYPE_VIDEO) {
mVideoTracks.add(track);
} else if (track.getType() == TvTrackInfo.TYPE_SUBTITLE) {
mSubtitleTracks.add(track);
}
}
return !mAudioTracks.isEmpty() || !mVideoTracks.isEmpty()
|| !mSubtitleTracks.isEmpty();
}
} |
Responds to onTracksChanged() and updates the internal track information. Returns true if
there is an update.
| Session::updateTracks | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
boolean updateTrackSelection(int type, String trackId) {
synchronized (mMetadataLock) {
if (type == TvTrackInfo.TYPE_AUDIO
&& !TextUtils.equals(trackId, mSelectedAudioTrackId)) {
mSelectedAudioTrackId = trackId;
return true;
} else if (type == TvTrackInfo.TYPE_VIDEO
&& !TextUtils.equals(trackId, mSelectedVideoTrackId)) {
mSelectedVideoTrackId = trackId;
return true;
} else if (type == TvTrackInfo.TYPE_SUBTITLE
&& !TextUtils.equals(trackId, mSelectedSubtitleTrackId)) {
mSelectedSubtitleTrackId = trackId;
return true;
}
}
return false;
} |
Responds to onTrackSelected() and updates the internal track selection information.
Returns true if there is an update.
| Session::updateTrackSelection | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
TvTrackInfo getVideoTrackToNotify() {
synchronized (mMetadataLock) {
if (!mVideoTracks.isEmpty() && mSelectedVideoTrackId != null) {
for (TvTrackInfo track : mVideoTracks) {
if (track.getId().equals(mSelectedVideoTrackId)) {
int videoWidth = track.getVideoWidth();
int videoHeight = track.getVideoHeight();
if (mVideoWidth != videoWidth || mVideoHeight != videoHeight) {
mVideoWidth = videoWidth;
mVideoHeight = videoHeight;
return track;
}
}
}
}
}
return null;
} |
Returns the new/updated video track that contains new video size information. Returns
null if there is no video track to notify. Subsequent calls of this method results in a
non-null video track returned only by the first call and null returned by following
calls. The caller should immediately notify of the video size change upon receiving the
track.
| Session::getVideoTrackToNotify | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
void timeShiftPlay(Uri recordedProgramUri) {
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.timeShiftPlay(mToken, recordedProgramUri, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Plays a given recorded TV program.
| Session::timeShiftPlay | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
void timeShiftPause() {
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.timeShiftPause(mToken, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Pauses the playback. Call {@link #timeShiftResume()} to restart the playback.
| Session::timeShiftPause | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
void timeShiftResume() {
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.timeShiftResume(mToken, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Resumes the playback. No-op if it is already playing the channel.
| Session::timeShiftResume | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
void timeShiftSeekTo(long timeMs) {
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.timeShiftSeekTo(mToken, timeMs, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Seeks to a specified time position.
<p>Normally, the position is given within range between the start and the current time,
inclusively.
@param timeMs The time position to seek to, in milliseconds since the epoch.
@see TvView.TimeShiftPositionCallback#onTimeShiftStartPositionChanged
| Session::timeShiftSeekTo | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
void timeShiftSetPlaybackParams(PlaybackParams params) {
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.timeShiftSetPlaybackParams(mToken, params, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Sets playback rate using {@link android.media.PlaybackParams}.
@param params The playback params.
| Session::timeShiftSetPlaybackParams | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
void timeShiftEnablePositionTracking(boolean enable) {
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.timeShiftEnablePositionTracking(mToken, enable, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Enable/disable position tracking.
@param enable {@code true} to enable tracking, {@code false} otherwise.
| Session::timeShiftEnablePositionTracking | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
void startRecording(@Nullable Uri programUri) {
startRecording(programUri, null);
} |
Starts TV program recording in the current recording session.
@param programUri The URI for the TV program to record as a hint, built by
{@link TvContract#buildProgramUri(long)}. Can be {@code null}.
| Session::startRecording | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
void startRecording(@Nullable Uri programUri, @Nullable Bundle params) {
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.startRecording(mToken, programUri, params, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Starts TV program recording in the current recording session.
@param programUri The URI for the TV program to record as a hint, built by
{@link TvContract#buildProgramUri(long)}. Can be {@code null}.
@param params A set of extra parameters which might be handled with this event.
| Session::startRecording | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
void stopRecording() {
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.stopRecording(mToken, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Stops TV program recording in the current recording session.
| Session::stopRecording | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
void pauseRecording(@NonNull Bundle params) {
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.pauseRecording(mToken, params, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Pauses TV program recording in the current recording session.
@param params Domain-specific data for this request. Keys <em>must</em> be a scoped
name, i.e. prefixed with a package name you own, so that different developers
will not create conflicting keys.
{@link TvRecordingClient#pauseRecording(Bundle)}.
| Session::pauseRecording | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
void resumeRecording(@NonNull Bundle params) {
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.resumeRecording(mToken, params, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Resumes TV program recording in the current recording session.
@param params Domain-specific data for this request. Keys <em>must</em> be a scoped
name, i.e. prefixed with a package name you own, so that different developers
will not create conflicting keys.
{@link TvRecordingClient#resumeRecording(Bundle)}.
| Session::resumeRecording | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void sendAppPrivateCommand(String action, Bundle data) {
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.sendAppPrivateCommand(mToken, action, data, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Calls {@link TvInputService.Session#appPrivateCommand(String, Bundle)
TvInputService.Session.appPrivateCommand()} on the current TvView.
@param action Name of the command to be performed. This <em>must</em> be a scoped name,
i.e. prefixed with a package name you own, so that different developers will
not create conflicting commands.
@param data Any data to include with the command.
| Session::sendAppPrivateCommand | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
void createOverlayView(@NonNull View view, @NonNull Rect frame) {
Preconditions.checkNotNull(view);
Preconditions.checkNotNull(frame);
if (view.getWindowToken() == null) {
throw new IllegalStateException("view must be attached to a window");
}
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.createOverlayView(mToken, view.getWindowToken(), frame, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Creates an overlay view. Once the overlay view is created, {@link #relayoutOverlayView}
should be called whenever the layout of its containing view is changed.
{@link #removeOverlayView()} should be called to remove the overlay view.
Since a session can have only one overlay view, this method should be called only once
or it can be called again after calling {@link #removeOverlayView()}.
@param view A view playing TV.
@param frame A position of the overlay view.
@throws IllegalStateException if {@code view} is not attached to a window.
| Session::createOverlayView | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
void relayoutOverlayView(@NonNull Rect frame) {
Preconditions.checkNotNull(frame);
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.relayoutOverlayView(mToken, frame, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Relayouts the current overlay view.
@param frame A new position of the overlay view.
| Session::relayoutOverlayView | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
void removeOverlayView() {
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.removeOverlayView(mToken, mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Removes the current overlay view.
| Session::removeOverlayView | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
void unblockContent(@NonNull TvContentRating unblockedRating) {
Preconditions.checkNotNull(unblockedRating);
if (mToken == null) {
Log.w(TAG, "The session has been already released");
return;
}
try {
mService.unblockContent(mToken, unblockedRating.flattenToString(), mUserId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
} |
Requests to unblock content blocked by parental controls.
| Session::unblockContent | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public int dispatchInputEvent(@NonNull InputEvent event, Object token,
@NonNull FinishedInputEventCallback callback, @NonNull Handler handler) {
Preconditions.checkNotNull(event);
Preconditions.checkNotNull(callback);
Preconditions.checkNotNull(handler);
synchronized (mHandler) {
if (mChannel == null) {
return DISPATCH_NOT_HANDLED;
}
PendingEvent p = obtainPendingEventLocked(event, token, callback, handler);
if (Looper.myLooper() == Looper.getMainLooper()) {
// Already running on the main thread so we can send the event immediately.
return sendInputEventOnMainLooperLocked(p);
}
// Post the event to the main thread.
Message msg = mHandler.obtainMessage(InputEventHandler.MSG_SEND_INPUT_EVENT, p);
msg.setAsynchronous(true);
mHandler.sendMessage(msg);
return DISPATCH_IN_PROGRESS;
}
} |
Dispatches an input event to this session.
@param event An {@link InputEvent} to dispatch. Cannot be {@code null}.
@param token A token used to identify the input event later in the callback.
@param callback A callback used to receive the dispatch result. Cannot be {@code null}.
@param handler A {@link Handler} that the dispatch result will be delivered to. Cannot be
{@code null}.
@return Returns {@link #DISPATCH_HANDLED} if the event was handled. Returns
{@link #DISPATCH_NOT_HANDLED} if the event was not handled. Returns
{@link #DISPATCH_IN_PROGRESS} if the event is in progress and the callback will
be invoked later.
@hide
| Session::dispatchInputEvent | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void overrideAudioSink(int audioType, String audioAddress, int samplingRate,
int channelMask, int format) {
try {
mInterface.overrideAudioSink(audioType, audioAddress, samplingRate, channelMask,
format);
} catch (RemoteException e) {
throw new RuntimeException(e);
}
} |
Override default audio sink from audio policy.
@param audioType device type of the audio sink to override with.
@param audioAddress device address of the audio sink to override with.
@param samplingRate desired sampling rate. Use default when it's 0.
@param channelMask desired channel mask. Use default when it's
AudioFormat.CHANNEL_OUT_DEFAULT.
@param format desired format. Use default when it's AudioFormat.ENCODING_DEFAULT.
| Hardware::overrideAudioSink | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public void overrideAudioSink(@NonNull AudioDeviceInfo device,
@IntRange(from = 0) int samplingRate,
int channelMask, @Encoding int format) {
Objects.requireNonNull(device);
try {
mInterface.overrideAudioSink(
AudioDeviceInfo.convertDeviceTypeToInternalDevice(device.getType()),
device.getAddress(), samplingRate, channelMask, format);
} catch (RemoteException e) {
throw new RuntimeException(e);
}
} |
Override default audio sink from audio policy.
@param device {@link android.media.AudioDeviceInfo} to use.
@param samplingRate desired sampling rate. Use default when it's 0.
@param channelMask desired channel mask. Use default when it's
AudioFormat.CHANNEL_OUT_DEFAULT.
@param format desired format. Use default when it's AudioFormat.ENCODING_DEFAULT.
| Hardware::overrideAudioSink | java | Reginer/aosp-android-jar | android-33/src/android/media/tv/TvInputManager.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-33/src/android/media/tv/TvInputManager.java | MIT |
public setAttributeNS07(final DOMTestDocumentBuilderFactory factory) throws org.w3c.domts.DOMTestIncompatibleException {
super(factory);
//
// check if loaded documents are supported for content type
//
String contentType = getContentType();
preload(contentType, "staffNS", true);
} |
Constructor.
@param factory document factory, may not be null
@throws org.w3c.domts.DOMTestIncompatibleException Thrown if test is not compatible with parser configuration
| setAttributeNS07::setAttributeNS07 | java | Reginer/aosp-android-jar | android-32/src/org/w3c/domts/level2/core/setAttributeNS07.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/org/w3c/domts/level2/core/setAttributeNS07.java | MIT |
public void runTest() throws Throwable {
String namespaceURI = "http://www.nist.gov";
String qualifiedName = "xmlns";
Document doc;
NodeList elementList;
Node testAddr;
doc = (Document) load("staffNS", true);
elementList = doc.getElementsByTagName("employee");
testAddr = elementList.item(0);
{
boolean success = false;
try {
((Element) /*Node */testAddr).setAttributeNS(namespaceURI, qualifiedName, "newValue");
} catch (DOMException ex) {
success = (ex.code == DOMException.NAMESPACE_ERR);
}
assertTrue("throw_NAMESPACE_ERR", success);
}
} |
Runs the test case.
@throws Throwable Any uncaught exception causes test to fail
| setAttributeNS07::runTest | java | Reginer/aosp-android-jar | android-32/src/org/w3c/domts/level2/core/setAttributeNS07.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/org/w3c/domts/level2/core/setAttributeNS07.java | MIT |
public String getTargetURI() {
return "http://www.w3.org/2001/DOM-Test-Suite/level2/core/setAttributeNS07";
} |
Gets URI that identifies the test.
@return uri identifier of test
| setAttributeNS07::getTargetURI | java | Reginer/aosp-android-jar | android-32/src/org/w3c/domts/level2/core/setAttributeNS07.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/org/w3c/domts/level2/core/setAttributeNS07.java | MIT |
public static void main(final String[] args) {
DOMTestCase.doMain(setAttributeNS07.class, args);
} |
Runs this test from the command line.
@param args command line arguments
| setAttributeNS07::main | java | Reginer/aosp-android-jar | android-32/src/org/w3c/domts/level2/core/setAttributeNS07.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/org/w3c/domts/level2/core/setAttributeNS07.java | MIT |
public static ASN1Primitive fromByteArray(byte[] data)
throws IOException
{
ASN1InputStream aIn = new ASN1InputStream(data);
try
{
ASN1Primitive o = aIn.readObject();
if (aIn.available() != 0)
{
throw new IOException("Extra data detected in stream");
}
return o;
}
catch (ClassCastException e)
{
throw new IOException("cannot recognise object in stream");
}
} |
Create a base ASN.1 object from a byte stream.
@param data the byte stream to parse.
@return the base ASN.1 object represented by the byte stream.
@exception IOException if there is a problem parsing the data, or parsing the stream did not exhaust the available data.
| ASN1Primitive::fromByteArray | java | Reginer/aosp-android-jar | android-34/src/com/android/org/bouncycastle/asn1/ASN1Primitive.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/org/bouncycastle/asn1/ASN1Primitive.java | MIT |
ASN1Primitive toDERObject()
{
return this;
} |
Return the current object as one which encodes using Distinguished Encoding Rules.
@return a DER version of this.
| ASN1Primitive::toDERObject | java | Reginer/aosp-android-jar | android-34/src/com/android/org/bouncycastle/asn1/ASN1Primitive.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/org/bouncycastle/asn1/ASN1Primitive.java | MIT |
ASN1Primitive toDLObject()
{
return this;
} |
Return the current object as one which encodes using Definite Length encoding.
@return a DL version of this.
| ASN1Primitive::toDLObject | java | Reginer/aosp-android-jar | android-34/src/com/android/org/bouncycastle/asn1/ASN1Primitive.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/org/bouncycastle/asn1/ASN1Primitive.java | MIT |
public ASN1Primitive toASN1Primitive()
{
ASN1EncodableVector v = new ASN1EncodableVector(3);
if (fieldIdentifier.equals(prime_field))
{
v.add(new X9FieldElement(curve.getA()).toASN1Primitive());
v.add(new X9FieldElement(curve.getB()).toASN1Primitive());
}
else if (fieldIdentifier.equals(characteristic_two_field))
{
v.add(new X9FieldElement(curve.getA()).toASN1Primitive());
v.add(new X9FieldElement(curve.getB()).toASN1Primitive());
}
if (seed != null)
{
v.add(new DERBitString(seed));
}
return new DERSequence(v);
} |
Produce an object suitable for an ASN1OutputStream.
<pre>
Curve ::= SEQUENCE {
a FieldElement,
b FieldElement,
seed BIT STRING OPTIONAL
}
</pre>
| X9Curve::toASN1Primitive | java | Reginer/aosp-android-jar | android-34/src/com/android/org/bouncycastle/asn1/x9/X9Curve.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-34/src/com/android/org/bouncycastle/asn1/x9/X9Curve.java | MIT |
private void movePrefixedSettingsToNewTable(
SQLiteDatabase db, String sourceTable, String destTable, String[] prefixesToMove) {
SQLiteStatement insertStmt = null;
SQLiteStatement deleteStmt = null;
db.beginTransaction();
try {
insertStmt = db.compileStatement("INSERT INTO " + destTable
+ " (name,value) SELECT name,value FROM " + sourceTable
+ " WHERE substr(name,0,?)=?");
deleteStmt = db.compileStatement(
"DELETE FROM " + sourceTable + " WHERE substr(name,0,?)=?");
for (String prefix : prefixesToMove) {
insertStmt.bindLong(1, prefix.length() + 1);
insertStmt.bindString(2, prefix);
insertStmt.execute();
deleteStmt.bindLong(1, prefix.length() + 1);
deleteStmt.bindString(2, prefix);
deleteStmt.execute();
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
if (insertStmt != null) {
insertStmt.close();
}
if (deleteStmt != null) {
deleteStmt.close();
}
}
} |
Move any settings with the given prefixes from the source table to the
destination table.
| DatabaseHelper::movePrefixedSettingsToNewTable | java | Reginer/aosp-android-jar | android-32/src/com/android/providers/settings/DatabaseHelper.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/com/android/providers/settings/DatabaseHelper.java | MIT |
private void loadBookmarks(SQLiteDatabase db) {
ContentValues values = new ContentValues();
PackageManager packageManager = mContext.getPackageManager();
try {
XmlResourceParser parser = mContext.getResources().getXml(R.xml.bookmarks);
XmlUtils.beginDocument(parser, "bookmarks");
final int depth = parser.getDepth();
int type;
while (((type = parser.next()) != XmlPullParser.END_TAG ||
parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
if (type != XmlPullParser.START_TAG) {
continue;
}
String name = parser.getName();
if (!"bookmark".equals(name)) {
break;
}
String pkg = parser.getAttributeValue(null, "package");
String cls = parser.getAttributeValue(null, "class");
String shortcutStr = parser.getAttributeValue(null, "shortcut");
String category = parser.getAttributeValue(null, "category");
int shortcutValue = shortcutStr.charAt(0);
if (TextUtils.isEmpty(shortcutStr)) {
Log.w(TAG, "Unable to get shortcut for: " + pkg + "/" + cls);
continue;
}
final Intent intent;
final String title;
if (pkg != null && cls != null) {
ActivityInfo info = null;
ComponentName cn = new ComponentName(pkg, cls);
try {
info = packageManager.getActivityInfo(cn, 0);
} catch (PackageManager.NameNotFoundException e) {
String[] packages = packageManager.canonicalToCurrentPackageNames(
new String[] { pkg });
cn = new ComponentName(packages[0], cls);
try {
info = packageManager.getActivityInfo(cn, 0);
} catch (PackageManager.NameNotFoundException e1) {
Log.w(TAG, "Unable to add bookmark: " + pkg + "/" + cls, e);
continue;
}
}
intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(cn);
title = info.loadLabel(packageManager).toString();
} else if (category != null) {
intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
title = "";
} else {
Log.w(TAG, "Unable to add bookmark for shortcut " + shortcutStr
+ ": missing package/class or category attributes");
continue;
}
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
values.put(Settings.Bookmarks.INTENT, intent.toUri(0));
values.put(Settings.Bookmarks.TITLE, title);
values.put(Settings.Bookmarks.SHORTCUT, shortcutValue);
db.delete("bookmarks", "shortcut = ?",
new String[] { Integer.toString(shortcutValue) });
db.insert("bookmarks", null, values);
}
} catch (XmlPullParserException e) {
Log.w(TAG, "Got execption parsing bookmarks.", e);
} catch (IOException e) {
Log.w(TAG, "Got execption parsing bookmarks.", e);
}
} |
Loads the default set of bookmarked shortcuts from an xml file.
@param db The database to write the values into
| DatabaseHelper::loadBookmarks | java | Reginer/aosp-android-jar | android-32/src/com/android/providers/settings/DatabaseHelper.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/com/android/providers/settings/DatabaseHelper.java | MIT |
private void loadVolumeLevels(SQLiteDatabase db) {
SQLiteStatement stmt = null;
try {
stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
+ " VALUES(?,?);");
loadSetting(stmt, Settings.System.VOLUME_MUSIC,
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_MUSIC));
loadSetting(stmt, Settings.System.VOLUME_RING,
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_RING));
loadSetting(stmt, Settings.System.VOLUME_SYSTEM,
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_SYSTEM));
loadSetting(
stmt,
Settings.System.VOLUME_VOICE,
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_VOICE_CALL));
loadSetting(stmt, Settings.System.VOLUME_ALARM,
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_ALARM));
loadSetting(
stmt,
Settings.System.VOLUME_NOTIFICATION,
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_NOTIFICATION));
loadSetting(
stmt,
Settings.System.VOLUME_BLUETOOTH_SCO,
AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO));
// By default:
// - ringtones, notification, system and music streams are affected by ringer mode
// on non voice capable devices (tablets)
// - ringtones, notification and system streams are affected by ringer mode
// on voice capable devices (phones)
int ringerModeAffectedStreams = (1 << AudioManager.STREAM_RING) |
(1 << AudioManager.STREAM_NOTIFICATION) |
(1 << AudioManager.STREAM_SYSTEM) |
(1 << AudioManager.STREAM_SYSTEM_ENFORCED);
if (!mContext.getResources().getBoolean(
com.android.internal.R.bool.config_voice_capable)) {
ringerModeAffectedStreams |= (1 << AudioManager.STREAM_MUSIC);
}
loadSetting(stmt, Settings.System.MODE_RINGER_STREAMS_AFFECTED,
ringerModeAffectedStreams);
loadSetting(stmt, Settings.System.MUTE_STREAMS_AFFECTED,
AudioSystem.DEFAULT_MUTE_STREAMS_AFFECTED);
} finally {
if (stmt != null) stmt.close();
}
} |
Loads the default volume levels. It is actually inserting the index of
the volume array for each of the volume controls.
@param db the database to insert the volume levels into
| DatabaseHelper::loadVolumeLevels | java | Reginer/aosp-android-jar | android-32/src/com/android/providers/settings/DatabaseHelper.java | https://github.com/Reginer/aosp-android-jar/blob/master/android-32/src/com/android/providers/settings/DatabaseHelper.java | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.