Fix missing null check in collectRootScrollCaptureTargets
If no window-level handlers have been added, the list is null (lazily init). Test: atest com.android.systemui.screenshot.ScrollCaptureTest Change-Id: I39d4295cebb091fa89f65c5917ba08bc2396ed37
This commit is contained in:
@@ -8905,6 +8905,9 @@ public final class ViewRootImpl implements ViewParent,
|
||||
* @param targets the search queue for targets
|
||||
*/
|
||||
private void collectRootScrollCaptureTargets(Queue<ScrollCaptureTarget> targets) {
|
||||
if (mRootScrollCaptureCallbacks == null) {
|
||||
return;
|
||||
}
|
||||
for (ScrollCaptureCallback cb : mRootScrollCaptureCallbacks) {
|
||||
// Add to the list for consideration
|
||||
Point offset = new Point(mView.getLeft(), mView.getTop());
|
||||
|
||||
@@ -80,6 +80,8 @@
|
||||
android:excludeFromRecents="true"
|
||||
/>
|
||||
|
||||
<activity android:name="com.android.systemui.screenshot.ScrollViewActivity"
|
||||
android:exported="false" />
|
||||
<provider
|
||||
android:name="androidx.lifecycle.ProcessLifecycleOwnerInitializer"
|
||||
tools:replace="android:authorities"
|
||||
|
||||
21
packages/SystemUI/tests/res/values/strings.xml
Normal file
21
packages/SystemUI/tests/res/values/strings.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2020 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.
|
||||
-->
|
||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
||||
|
||||
<string name="test_content">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ultrices condimentum ultricies. Sed elementum at massa id sagittis. Nullam dictum massa lorem, nec ornare nunc pharetra vitae. Duis ultrices, felis eu condimentum congue, erat orci efficitur purus, ac rutrum odio lacus sed sapien. Suspendisse erat augue, eleifend eget auctor sagittis, porta eget nibh. Mauris pulvinar urna non justo condimentum, ut vehicula sapien finibus. Aliquam nibh magna, tincidunt ut viverra sed, placerat et turpis. Nam placerat, dui sed tincidunt consectetur, ante velit posuere mauris, tincidunt finibus velit lectus ac tortor. Cras eget lectus feugiat, porttitor velit nec, malesuada massa.</string>
|
||||
|
||||
</resources>
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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 org.junit.Assert.fail;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
import android.os.RemoteException;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.IScrollCaptureClient;
|
||||
import android.view.IScrollCaptureController;
|
||||
import android.view.IWindowManager;
|
||||
import android.view.WindowManagerGlobal;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Tests the of internal framework Scroll Capture API from SystemUI.
|
||||
*/
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
@SmallTest
|
||||
public class ScrollCaptureTest extends SysuiTestCase {
|
||||
private static final String TAG = "ScrollCaptureTest";
|
||||
|
||||
/**
|
||||
* Verifies that a request traverses from SystemUI, to WindowManager and to the app process and
|
||||
* is returned without error. Device must be unlocked.
|
||||
*/
|
||||
@Test
|
||||
public void testBasicOperation() throws InterruptedException {
|
||||
IWindowManager wms = WindowManagerGlobal.getWindowManagerService();
|
||||
|
||||
// Start an activity to be on top that will be targeted
|
||||
InstrumentationRegistry.getInstrumentation().startActivitySync(
|
||||
new Intent(mContext, ScrollViewActivity.class).addFlags(
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
try {
|
||||
wms.requestScrollCapture(Display.DEFAULT_DISPLAY, null, -1,
|
||||
new IScrollCaptureController.Stub() {
|
||||
@Override
|
||||
public void onClientConnected(
|
||||
IScrollCaptureClient client, Rect scrollBounds,
|
||||
Point positionInWindow) {
|
||||
Log.d(TAG,
|
||||
"client connected: " + client + "[scrollBounds= " + scrollBounds
|
||||
+ ", positionInWindow=" + positionInWindow + "]");
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClientUnavailable() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCaptureStarted() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCaptureBufferSent(long frameNumber, Rect capturedArea) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionClosed() {
|
||||
}
|
||||
});
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "request failed", e);
|
||||
fail("caught remote exception " + e);
|
||||
}
|
||||
latch.await(1000, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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 android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.util.TypedValue;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class ScrollViewActivity extends Activity {
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
ScrollView scrollView = new ScrollView(this);
|
||||
LinearLayout linearLayout = new LinearLayout(this);
|
||||
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
||||
TextView text = new TextView(this);
|
||||
text.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 40);
|
||||
text.setText(com.android.systemui.R.string.test_content);
|
||||
linearLayout.addView(text);
|
||||
scrollView.addView(linearLayout);
|
||||
setContentView(scrollView);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user