下面列出了androidx.annotation.VisibleForTesting#PRIVATE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Will return an error to the remote client with the error code (24)GATT_ERROR with the provided offset
* and a zero data array
*
* @param conn The gatt server connection
* @param device The bluetooth device
* @param requestId The request id
* @param offset The offset
*/
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
void returnErrorToRemoteClient(GattServerConnection conn, BluetoothDevice device, int requestId, int offset) {
handler.post(() -> {
try {
conn.getServer().sendResponse(device, requestId, GattStatus.GATT_ERROR.getCode(), offset, new byte[0]);
} catch (NullPointerException e) {
Timber.w(e, "[%s] Looks like BluetoothGattServer#sendResponse(...) can run into the unboxing bug also. No response sent, peripheral may disconnect.", getDeviceMacFromDevice(device));
}
});
}
/** @see LithoViewTestHelper#findTestItems(LithoView, String) */
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
Deque<TestItem> findTestItems(String testKey) {
if (mTestItemMap == null) {
throw new UnsupportedOperationException(
"Trying to access TestItems while "
+ "ComponentsConfiguration.isEndToEndTestRun is false.");
}
final Deque<TestItem> items = mTestItemMap.get(testKey);
return items == null ? new LinkedList<TestItem>() : items;
}
/** @see LithoViewTestHelper#findTestItems(LithoView, String) */
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
Deque<TestItem> findTestItems(String testKey) {
if (mTestItemMap == null) {
throw new UnsupportedOperationException(
"Trying to access TestItems while "
+ "ComponentsConfiguration.isEndToEndTestRun is false.");
}
final Deque<TestItem> items = mTestItemMap.get(testKey);
return items == null ? new LinkedList<TestItem>() : items;
}
@DoNotStrip
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
Deque<TestItem> findTestItems(String testKey) {
if (mUseExtensions && mLithoHostListenerCoordinator != null) {
if (mLithoHostListenerCoordinator.getEndToEndTestingExtension() == null) {
throw new IllegalStateException(
"Trying to access TestItems while "
+ "ComponentsConfiguration.isEndToEndTestRun is false.");
}
return mLithoHostListenerCoordinator.getEndToEndTestingExtension().findTestItems(testKey);
} else {
return mMountState.findTestItems(testKey);
}
}
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
int findStickyHeaderPosition(int currentFirstVisiblePosition) {
for (int i = currentFirstVisiblePosition; i >= 0; i--) {
if (mHasStickyHeader.isSticky(i)) {
return i;
}
}
return RecyclerView.NO_POSITION;
}
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
public Change(
@Type int ct,
int index,
int toIndex,
int count,
@Nullable RenderInfo renderInfo,
@Nullable List<RenderInfo> renderInfos,
@Nullable List<?> prevData,
@Nullable List<?> nextData) {
mType = ct;
mIndex = index;
mToIndex = toIndex;
mCount = count;
mRenderInfo = renderInfo == null ? ComponentRenderInfo.createEmpty() : renderInfo;
if (renderInfos == null) {
mRenderInfos = EMPTY;
} else {
int size = renderInfos.size();
mRenderInfos = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
final RenderInfo renderInfoTemp = renderInfos.get(i);
mRenderInfos.add(
renderInfoTemp == null ? ComponentRenderInfo.createEmpty() : renderInfoTemp);
}
}
if (prevData != null) {
mPrevData = Collections.unmodifiableList(prevData);
}
if (nextData != null) {
mNextData = Collections.unmodifiableList(nextData);
}
}
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
public static synchronized Looper getDefaultChangeSetThreadLooper() {
if (sDefaultChangeSetThreadLooper == null) {
HandlerThread defaultThread =
new HandlerThread(
DEFAULT_CHANGESET_THREAD_NAME,
ComponentsConfiguration.DEFAULT_CHANGE_SET_THREAD_PRIORITY);
defaultThread.start();
sDefaultChangeSetThreadLooper = defaultThread.getLooper();
}
return sDefaultChangeSetThreadLooper;
}
/**
* Deterimines if either the passed in param "paddingPosition" or the default value,
* {@link #DEFAULT_BRICK_POSITION}, should be returned.
*
* @param paddingPosition used to compare with {@link #NO_PADDING_POSITION}
* @return either the "paddingPosition" value or {@link #DEFAULT_BRICK_POSITION}
*/
@SuppressWarnings("WeakerAccess")
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
int getPaddingPositionOrDefault(int paddingPosition) {
return NO_PADDING_POSITION == paddingPosition
? DEFAULT_BRICK_POSITION
: paddingPosition;
}
/**
* Safely notifies of a single item insertion.
*
* @param item which was just inserted.
*/
@SuppressWarnings("WeakerAccess")
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
void safeNotifyItemInserted(@Nullable BaseBrick item) {
int adapterIndex = adapterIndex(item);
if (adapterIndex != NO_INDEX) {
brickRecyclerAdapter.safeNotifyItemInserted(adapterIndex);
}
}
/**
* Safely notifies of a range insertion.
*
* @param item which was just inserted.
* @param visibleCount the item count for the range
*/
@SuppressWarnings("WeakerAccess")
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
void safeNotifyItemRangeInserted(@Nullable BaseBrick item, int visibleCount) {
int adapterIndex = adapterIndex(item);
if (adapterIndex != NO_INDEX) {
brickRecyclerAdapter.safeNotifyItemRangeInserted(adapterIndex, visibleCount);
}
}
/**
* Helper method to tell manager to update the items returned from getRecyclerViewItems().
*/
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
void dataHasChanged() {
dataHasChanged = true;
for (BrickBehavior behavior : behaviors) {
behavior.onDataSetChanged();
}
}
/**
* Creates CharSequence from template string by its parameters. The template string will be
* transformed to contain "^1"-style placeholder values dynamically to match the format of
* {@link TextUtils#expandTemplate(CharSequence, CharSequence...)} and formatted by other
* none-string type parameters.
*
* @param templateString template string that may contains parameters with strings.
* @param parameters object arrays that are supposed but not necessary to be string. If it is
* string, the corresponding placeholder value will be changed to "^1"-style. If not string
* type, the placeholder is kept and adjust the index.
* @return CharSequence that composed by template string with "^1"-style placeholder values.
*/
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
protected static CharSequence toExpandableTemplate(String templateString, Object[] parameters) {
String expandTemplateString = templateString;
List<Object> otherTypeList = new ArrayList<>();
int spanTypeIndex = 1;
int otherTypeIndex = 1;
for (int i = 1; i <= parameters.length; i++) {
Object param = parameters[i - 1];
if (param instanceof CharSequence) {
// replaces string type "%1$s" or "%s" to "^1" and so on.
if (expandTemplateString.contains("%" + i + "$s")) {
expandTemplateString =
expandTemplateString.replace(("%" + i + "$s"), ("^" + spanTypeIndex));
} else if (expandTemplateString.contains("%s")) {
expandTemplateString = expandTemplateString.replaceFirst("%s", ("^" + spanTypeIndex));
}
spanTypeIndex++;
} else {
// keeps and assigns correct index to other type parameters
expandTemplateString = expandTemplateString.replace(("%" + i), ("%" + otherTypeIndex));
otherTypeList.add(param);
otherTypeIndex++;
}
}
return String.format(expandTemplateString, otherTypeList.toArray());
}
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
public int createScrollInstanceId() {
int scrollInstanceId = nextScrollInstanceId;
nextScrollInstanceId++;
if (nextScrollInstanceId < 0) {
nextScrollInstanceId = 0;
}
return scrollInstanceId;
}
/** Delays feedback execution. */
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
protected void startDelay(EventId eventId, Feedback.Part feedback) {
int messageId = toMessageId(feedback.interruptGroup(), feedback.interruptLevel());
final Message message =
feedbackDelayer.obtainMessage(messageId, new EventIdAnd<Feedback.Part>(feedback, eventId));
feedbackDelayer.sendMessageDelayed(message, feedback.delayMs());
messageIdToSenderName.put(messageId, feedback.senderName());
}
/** Cancels all delayed feedback for group, at or below level. */
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
protected void cancelDelay(
@InterruptGroup int group, @InterruptLevel int level, String senderName) {
for (@InterruptLevel int l = 0; l <= level; l++) {
feedbackDelayer.removeMessages(toMessageId(group, l));
dumpInterruptLog(toMessageId(group, l), senderName);
}
}
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
InternalNode getLayoutCreatedInWillRenderForTesting() {
return mLayoutCreatedInWillRender;
}
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
public void onAttachedToWindowForTest() {
onAttachedToWindow();
}
/** Checks whether a delay exists for a given group and level. */
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
protected boolean delayExists(@InterruptGroup int group, @InterruptLevel int level) {
return feedbackDelayer.hasMessages(toMessageId(group, level));
}
/** Allows tests to advance the handler time. */
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
protected Looper getDelayLooper() {
return feedbackDelayer.getLooper();
}
/** Returns a unique result combining group and level. */
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
protected static int toMessageId(@InterruptGroup int group, @InterruptLevel int level) {
return (group * GROUP_DIGIT) + level;
}