/* * Copyright (C) 2021 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.screenshot; import static android.util.MathUtils.constrain; import static com.google.common.util.concurrent.Futures.immediateFuture; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static java.lang.Math.abs; import static java.lang.Math.max; import static java.lang.Math.min; import android.graphics.Rect; import android.hardware.HardwareBuffer; import android.media.Image; import android.util.Log; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; /** * A flexible test double for {@link ScrollCaptureClient.Session}. *
* FakeSession provides the ability to emulate both the available scrollable content range as well
* as the current visible bounds. Visible bounds may vary because the target view itself may be
* slid vertically during capture, with portions may become clipped by parent views. This scenario
* frequently occurs with UIs constructed from nested scrolling views or collapsing headers.
*/
class FakeSession implements ScrollCaptureClient.Session {
private static final String TAG = "FakeSession";
// Available range of content
private final Rect mAvailable;
/** bounds for scrollDelta (y), range with bottom adjusted to account for page height. */
private final Rect mAvailableTop;
private final Rect mVisiblePage;
private final int mTileHeight;
private final int mMaxTiles;
private int mScrollDelta;
private int mPageHeight;
private int mTargetHeight;
FakeSession(int pageHeight, float maxPages, int tileHeight, int visiblePageTop,
int visiblePageBottom, int availableTop, int availableBottom,
int maxTiles) {
mPageHeight = pageHeight;
mTileHeight = tileHeight;
mAvailable = new Rect(0, availableTop, getPageWidth(), availableBottom);
mAvailableTop = new Rect(mAvailable);
mAvailableTop.inset(0, 0, 0, pageHeight);
mVisiblePage = new Rect(0, visiblePageTop, getPageWidth(), visiblePageBottom);
mTargetHeight = (int) (pageHeight * maxPages);
mMaxTiles = maxTiles;
}
private static Image mockImage() {
Image image = mock(Image.class);
when(image.getHardwareBuffer()).thenReturn(mock(HardwareBuffer.class));
return image;
}
public int getScrollDelta() {
return mScrollDelta;
}
@Override
public ListenableFuture