private boolean canSplitLayoutOnCurrentThread() { return ThreadUtils.isMainThread() ? mainService != null : bgService != null; }
/** * True if we have manually unmounted content (e.g. via unmountAllItems) which means that while we * may not have a new LayoutState, the mounted content does not match what the viewport for the * LithoView may be. */ boolean needsRemount() { assertMainThread(); return mNeedsRemount; }
@GuardedBy("this") private boolean hasSizeSpec() { assertHoldsLock(this); return mWidthSpec != SIZE_UNINITIALIZED && mHeightSpec != SIZE_UNINITIALIZED; }
LithoAffinityBooster booster = null; if (isMainThread() && !futureTask.isDone() && runningThreadId != Process.myTid()) { ? ThreadUtils.tryInheritThreadPriorityFromCurrentThread(runningThreadId) : ThreadUtils.tryRaiseThreadPriority( runningThreadId, Process.THREAD_PRIORITY_DISPLAY); didRaiseThreadPriority = true;
@After public void teardown() { ThreadUtils.setMainThreadOverride(ThreadUtils.OVERRIDE_DISABLED); }
/** * Try to raise the priority of {@param threadId} to the priority of the calling thread * * @return the original thread priority of the target thread. */ public static int tryInheritThreadPriorityFromCurrentThread(int threadId) { return tryRaiseThreadPriority(threadId, Process.getThreadPriority(Process.myTid())); }
@Test public void testClearRefreshingFromNonUIThread() { when(mSectionsRecyclerView.isRefreshing()).thenReturn(true); ThreadUtils.setMainThreadOverride(ThreadUtils.OVERRIDE_MAIN_THREAD_FALSE); mRecyclerEventsController.clearRefreshing(); verify(mSectionsRecyclerView, times(1)).removeCallbacks(any(Runnable.class)); verify(mSectionsRecyclerView, times(1)).post(any(Runnable.class)); }
/** * Sets whether the next mount will be the first mount of this ComponentTree. This is used to * determine whether to run animations or not (we want animations to run on the first mount of * this ComponentTree, but not other times the mounted ComponentTree id changes). Ideally, we want * animations to only occur when the ComponentTree is updated on screen or is first inserted into * a list onscreen, but that requires more integration with the list controller, e.g. sections, * than we currently have. */ void setIsFirstMountOfComponentTree() { assertMainThread(); mIsFirstMountOfComponentTree = true; }
public static void assertMainThread() { if (!ComponentsConfiguration.IS_INTERNAL_BUILD || ComponentsConfiguration.isEndToEndTestRun) { return; } else if (!isMainThread()) { throw new IllegalStateException("This should run on the main thread."); } }
@GuardedBy("this") private boolean isCompatibleComponentAndSpec(LayoutState layoutState) { assertHoldsLock(this); return mRoot != null && isCompatibleComponentAndSpec( layoutState, mRoot.getId(), mWidthSpec, mHeightSpec); }
@Test public void testClearRefreshingFromUIThread() { when(mSectionsRecyclerView.isRefreshing()).thenReturn(true); ThreadUtils.setMainThreadOverride(ThreadUtils.OVERRIDE_MAIN_THREAD_TRUE); mRecyclerEventsController.clearRefreshing(); verify(mSectionsRecyclerView).setRefreshing(false); verify(mSectionsRecyclerView, never()).removeCallbacks(any(Runnable.class)); verify(mSectionsRecyclerView, never()).post(any(Runnable.class)); }
int getItemCount() { assertMainThread(); return mLayoutOutputsIds == null ? 0 : mLayoutOutputsIds.length; }
private static void focusRequestOnUiThread(Runnable runnable) { if (isMainThread()) { runnable.run(); } else { sMainThreadHandler.obtainMessage(MESSAGE_FOCUS_REQUEST, runnable).sendToTarget(); } }
@GuardedBy("this") private boolean hasCompatibleComponentAndSpec() { assertHoldsLock(this); return isCompatibleComponentAndSpec(mMainThreadLayoutState) || isCompatibleComponentAndSpec(mBackgroundLayoutState); }
@Test public void testShowRefreshingFromUIThread() { when(mSectionsRecyclerView.isRefreshing()).thenReturn(false); ThreadUtils.setMainThreadOverride(ThreadUtils.OVERRIDE_MAIN_THREAD_TRUE); mRecyclerEventsController.showRefreshing(); verify(mSectionsRecyclerView).setRefreshing(true); }
boolean isDirty() { assertMainThread(); return mIsDirty; }
private void postLoadingStateToFocusDispatch(final LoadingEvent.LoadingState loadingState) { if (isMainThread()) { setLoadingStateToFocusDispatch(loadingState); } else { sMainThreadHandler .obtainMessage( MESSAGE_FOCUS_DISPATCHER_LOADING_STATE_UPDATE, new Runnable() { @Override public void run() { setLoadingStateToFocusDispatch(loadingState); } }) .sendToTarget(); } }
@CheckReturnValue @ReturnsOwnership @ThreadConfined(ThreadConfined.UI) @GuardedBy("this") private boolean isBestMainThreadLayout() { assertHoldsLock(this); // If everything matches perfectly then we prefer mMainThreadLayoutState // because that means we don't need to remount. if (isCompatibleComponentAndSpec(mMainThreadLayoutState)) { return true; } else if (isCompatibleSpec(mBackgroundLayoutState, mWidthSpec, mHeightSpec) || !isCompatibleSpec(mMainThreadLayoutState, mWidthSpec, mHeightSpec)) { // If mMainThreadLayoutState isn't a perfect match, we'll prefer // mBackgroundLayoutState since it will have the more recent create. return false; } else { // If the main thread layout is still compatible size-wise, and the // background one is not, then we'll do nothing. We want to keep the same // main thread layout so that we don't force main thread re-layout. return true; } }
LithoView getLithoView() { assertMainThread(); return mLithoView; }
/** * Transfer mBackgroundLayoutState to mMainThreadLayoutState. This will proxy * to the main thread if necessary. If the component/size-spec changes in the * meantime, then the transfer will be aborted. */ private void postBackgroundLayoutStateUpdated() { if (isMainThread()) { // We need to possibly update mMainThreadLayoutState. This call will // cause the host view to be invalidated and re-laid out, if necessary. backgroundLayoutStateUpdated(); } else { // If we aren't on the main thread, we send a message to the main thread // to invoke backgroundLayoutStateUpdated. sMainThreadHandler.obtainMessage(MESSAGE_WHAT_BACKGROUND_LAYOUT_STATE_UPDATED, this) .sendToTarget(); } }